def main(): logfmt = "%(asctime)s %(levelname)s: %(message)s" logging.basicConfig(format=logfmt, level=loglevel) # A bit of magic to make the decoding work better irc.client.ServerConnection.buffer_class.errors = 'replace' specs = [irc.bot.ServerSpec(h, p) for h, p in it.product(hosts, ports)] bot = NSFWBot(specs, nicks[0], realname, reconnection_interval=10, connect_factory=ConnectionFactory()) try: bot.start() except KeyboardInterrupt: bot.die()
def StopBot(): global bot if config.ENABLE_DEMO: config.DEMO.quit=True bot.die("Gui Closed, BRB") sys.exit(0)
def q(*args, **kwargs): bot.die(config.get('irc', 'quit_message')) raise SystemExit()
def checkTerminated(bot, DL): if DL.terminated == True: bot.die()
def sig_handler(sig, frame): print('Caught signal: %s\nShutting down' % sig) bot.die()
def sig_handler(sig, frame): print('Caught signal: %s\nShutting down' % sig) bot.die()
print e.message, e.args # handle when a txt2speech "say" command complete def on_speech_end(self, name, completed): # since we're not using the built pyttsx loop, we need this self.engine.iterate() # handle text-to-speech errors def on_speech_error(self, name, exception): print exception.msg, exception.args while 1: # TODO: this is crap, we need better try/excepts try: bot = IRCNotifier("#pibot", "raspBot", "108.59.11.230", BUTTON, RED_LED, YELLOW_LED, GREEN_LED, "kptkommie", TXT2SPEECH) # set timer for button state checking bot.reactor.execute_every(.2, bot.check_button) # "start" the txt2speech loop bot.engine.startLoop(False) # start the main bot loop bot.start() finally: bot.disconnect("RasPi IRC Notifier 0.1") bot.engine.endLoop() GPIO.cleanup() bot.die()
def _do_command(bot, conn, event, command, msg): # noqa: C901 """ Do the command. """ target = _get_target(event) source_nick = event.source.nick if "".join(command).startswith("whoami"): if source_nick.lower() in bot.admins: conn.privmsg(target, "You are my master {}.".format(source_nick)) return else: conn.privmsg(target, "You are {}.".format(source_nick)) return if command[0] in ["admins", "admin", "master", "masters"]: if len(bot.admins) == 0: conn.privmsg(target, "I don't have any master. I'm free !!") return elif len(bot.admins) == 1: conn.privmsg(target, "My master is {}".format(bot.admins[0])) return else: conn.privmsg(target, "My masters are {}".format(", ".join(bot.admins))) return if command[0] == "register" and source_nick.lower( ) in bot.admins and event.type == "privmsg": conn.privmsg(source_nick, "Good idea, on my way !") conn.privmsg("NickServ", "REGISTER {} {}".format(bot.password, bot.email)) conn.privmsg(source_nick, "Done !") return elif command == "help": conn.privmsg(source_nick, "Help is not yet available.") return elif command[0] in ["die", "pan"]: if source_nick.lower() in bot.admins: bot.die("I was killed by {}.".format(source_nick)) else: conn.privmsg(target, "{}, you can't kill me !".format(source_nick)) for admin in bot.admins: conn.privmsg( admin, "master {}, {} tried to kill me !".format( admin, source_nick)) return elif command[0] == "join": if len(command) == 1: _crystal_ball(conn, target) return else: for c in command[1:]: if c.startswith('#'): conn.join(c) else: conn.privmsg(target, "Invalid channel : {}.".format(c)) return elif command[0] == "addadmin": if len(command) == 1: _crystal_ball(conn, target) return else: for a in command[1:]: bot.admins.append(a) conn.privmsg(target, "My masters are now {}".format(bot.admins)) return elif command[0] == "deladmin": if len(command) == 1: _crystal_ball(conn, target) return else: for a in command[1:]: try: bot.admins.remove(a) except ValueError: pass conn.privmsg(target, "My masters are now {}".format(bot.admins)) return elif command[0] == "recommend": if len(command) == 1: _crystal_ball(conn, target) return else: # Now, it is case sensitive. torec = msg[1:].strip().split()[2:] for user in torec: try: getrec = _getrecommendation(user, bot, conn) conn.privmsg(target, getrec) except KeyError: conn.privmsg(target, "Unknown user : {}. I skip.".format(user)) return elif "debug" in command: conn.privmsg(source_nick, "event = {}".format(event)) conn.privmsg(source_nick, "conn.server = {}".format(conn.server)) conn.privmsg(source_nick, "conn.port = {}".format(conn.port)) conn.privmsg(source_nick, "conn.nickname = {}".format(conn.nickname)) conn.privmsg(source_nick, "conn.username = {}".format(conn.username)) conn.privmsg(source_nick, "conn.ircname = {}".format(conn.ircname)) return else: conn.privmsg( source_nick, "Sorry, I don't understand {}. Ask me for help".format(msg)) return
def checkTerminated(bot, DL): if DL.terminated == True : bot.die()
def StopBot(): global bot if config.ENABLE_DEMO: config.DEMO.quit = True bot.die("Gui Closed, BRB") sys.exit(0)