paritybot

A fun IRC bot.
git clone https://git.sr.ht/~jbauer/paritybot
Log | Files | Refs | README | LICENSE

run.py (2312B)


      1 #!/usr/bin/env python3
      2 
      3 import sys
      4 import signal
      5 from bot import Bot
      6 
      7 def main():
      8     bot = Bot()
      9     bot.load_config()
     10     bot.connect()
     11 
     12     def signal_handler(sig, frame):
     13         print("\n!!CAUGHT SIGINT!!")
     14         bot.disconnect()
     15         bot.save_config()
     16         sys.exit(0)
     17 
     18     signal.signal(signal.SIGINT, signal_handler)
     19 
     20     while True:
     21         try:
     22             incoming = bot.listen()
     23 
     24             # Respond to pings
     25             if "PING " in incoming:
     26                 print("Responding to PING.")
     27                 message = "PONG :" + bot.nick
     28                 bot.send_message(message)
     29                 continue
     30 
     31             # Properly respond to DMs
     32             if bot.get_channel(incoming) == bot.nick:
     33                 incoming = incoming.replace(bot.nick, bot.get_user(incoming))
     34 
     35             # Supported commands
     36             if ":+quit" in incoming:
     37                 quit = bot.quit(incoming)
     38                 if quit:
     39                     sys.exit(0)
     40             elif ":+help" in incoming:
     41                 bot.command_help(incoming)
     42             elif ":+version" in incoming:
     43                 bot.command_version(incoming)
     44             elif ":+quote" in incoming:
     45                 bot.command_quote(incoming)
     46             elif ":+time" in incoming:
     47                 bot.command_time(incoming)
     48             elif ":+roll" in incoming:
     49                 bot.command_roll(incoming)
     50             elif ":+weather" in incoming:
     51                 bot.command_weather(incoming)
     52             elif ":+8ball" in incoming:
     53                 bot.command_eightball(incoming)
     54             elif ":+repeat" in incoming:
     55                 bot.command_repeatsetup(incoming)
     56             elif ":+addadmin" in incoming:
     57                 bot.command_addadmin(incoming)
     58             elif ":+rmadmin" in incoming:
     59                 bot.command_rmadmin(incoming)
     60             elif ":+admins" in incoming:
     61                 bot.command_admins(incoming)
     62             elif ":+showexception" in incoming:
     63                 bot.command_showexception(incoming)
     64             elif ":+chgpass" in incoming:
     65                 bot.command_chgpass(incoming)
     66         except Exception as e:
     67             # Don't die when something goes wrong
     68             bot.handle_exception(incoming, e)
     69             print(e)
     70             continue
     71 
     72 
     73 if __name__ == '__main__':
     74     main()