oonbotti2/botcmd.py

48 lines
1.9 KiB
Python
Raw Normal View History

import o2_botcmd
2018-01-03 16:08:24 +00:00
# initialize(*, config)
2017-09-06 17:47:32 +00:00
# Called to initialize the IRC bot
# Runs before even logger is brought up, and blocks further bringup until it's done
2018-01-03 16:08:24 +00:00
# config is a configpatser.ConfigParser object containig contents of bot.conf
def initialize(*, config):
o2_botcmd.init()
2017-09-06 17:47:32 +00:00
# on_connect(*, irc)
# Called after IRC bot has connected and sent the USER/NICk commands but not yet attempted anything else
# Called for every reconnect
# Blocks the bot until it's done, including PING/PONG handling
2018-01-03 16:08:24 +00:00
# irc is the IRC API object
def on_connect(*, irc):
2021-01-20 18:09:43 +00:00
with open('startcmd.txt', 'r') as f:
2021-01-20 18:04:09 +00:00
for i in f:
while i[-1:] == '\n': i = i[:-1]
irc.send_raw(i.encode())
# on_quit(*, irc)
# Called just before IRC bot sends QUIT
# Blocks the bot until it's done, including PING/PONG handling
# irc is the IRC API object
def on_quit(*, irc):
o2_botcmd.cron.ctrl('QUIT')
2017-09-06 17:47:32 +00:00
# handle_message(*, prefix, message, nick, channel, irc)
# Called for PRIVMSGs.
# prefix is the prefix at the start of the message, without the leading ':'
# message is the contents of the message
# nick is who sent the message
# channel is where you should send the response (note: in queries nick == channel)
# irc is the IRC API object
# All strings are bytestrings
2017-09-06 17:47:32 +00:00
def handle_message(*, prefix, message, nick, channel, irc):
o2_botcmd.parse(nick, channel, b'PRIVMSG', [channel, message], irc)
2017-09-06 17:47:32 +00:00
# handle_nonmessage(*, prefix, command, arguments, irc)
# Called for all other commands than PINGs and PRIVMSGs.
# prefix is the prefix at the start of the message, without the leading ':'
# command is the command or number code
# arguments is rest of the arguments of the command, represented as a list. ':'-arguments are handled automatically
2018-01-03 16:08:24 +00:00
# irc is the IRC API object
# All strings are bytestrings
2017-09-06 17:47:32 +00:00
def handle_nonmessage(*, prefix, command, arguments, irc):
o2_botcmd.parse(prefix.split(b'!')[0], None, command, arguments, irc)