class Bot: def __init__(self): self._irc_handler = TwitchIRCHandler() self._command_handler = CommandHandler(self._irc_handler) self._cancel_send_random_emotes = lambda: None def __enter__(self): self._irc_handler.connect() if EMOTE_FREQ_MINUTES: self._cancel_send_random_emotes = self._send_random_emotes() return self def __exit__(self, *_): self._cancel_send_random_emotes() self._irc_handler.disconnect() @repeat_every(EMOTE_FREQ_MINUTES * 60) def _send_random_emotes(self): with suppress(Exception): self._command_handler.emote() def main_loop(self): while True: for message in self._irc_handler.get_messages(): self._command_handler(message)
def __init__(self): self.command_handler = CommandHandler() self.commands = [ k for k in list(self.command_handler.__class__.__dict__.keys()) if "__" not in k ] self.listen_for_commands()
def on_pvtmsg(self, user, msg): # P """ Received when a user sends the client a private message. :param user: The user sending a private message as User object. :type user: Users.User :param msg: The text message as TextMessage object. :type msg: TextMessage """ if user.handle != self.users.client.handle: mh = MessageHandler(self, user, CONF, msg) # write message to console mh.console() if self.users.client.is_mod: # check private message for ban string self.pool.add_task(mh.handle) # initialize the command handler ch = CommandHandler(self, user, msg, CONF, self.pool) # handle command ch.handle()
def __init__(self): self._irc_handler = TwitchIRCHandler() self._command_handler = CommandHandler(self._irc_handler) self._cancel_send_random_emotes = lambda: None
###IMPORTS from util import RpiListener from handlers import CommandHandler ###IMPORTS listener = RpiListener() cp = CommandHandler() listener.bind() print "Established listener. Waiting for incoming commands." listener.startListening() while True: print "Listening..." cmd = listener.listenForCmd() answer = cp.parseCmd(cmd) running = listener.answer(answer) if answer == "SHUTDOWN": break print "Stopping listening" listener.stopListening() listener.unbind()