paritybot/run.py

75 lines
2.3 KiB
Python
Executable File

#!/usr/bin/env python3
import sys
import signal
from bot import Bot
def main():
bot = Bot()
bot.load_config()
bot.connect()
def signal_handler(sig, frame):
print("\n!!CAUGHT SIGINT!!")
bot.disconnect()
bot.save_config()
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
while True:
try:
incoming = bot.listen()
# Respond to pings
if "PING " in incoming:
print("Responding to PING.")
message = "PONG :" + bot.nick
bot.send_message(message)
continue
# Properly respond to DMs
if bot.get_channel(incoming) == bot.nick:
incoming = incoming.replace(bot.nick, bot.get_user(incoming))
# Supported commands
if ":+quit" in incoming:
quit = bot.quit(incoming)
if quit:
sys.exit(0)
elif ":+help" in incoming:
bot.command_help(incoming)
elif ":+version" in incoming:
bot.command_version(incoming)
elif ":+quote" in incoming:
bot.command_quote(incoming)
elif ":+time" in incoming:
bot.command_time(incoming)
elif ":+roll" in incoming:
bot.command_roll(incoming)
elif ":+weather" in incoming:
bot.command_weather(incoming)
elif ":+8ball" in incoming:
bot.command_eightball(incoming)
elif ":+repeat" in incoming:
bot.command_repeatsetup(incoming)
elif ":+addadmin" in incoming:
bot.command_addadmin(incoming)
elif ":+rmadmin" in incoming:
bot.command_rmadmin(incoming)
elif ":+admins" in incoming:
bot.command_admins(incoming)
elif ":+showexception" in incoming:
bot.command_showexception(incoming)
elif ":+chgpass" in incoming:
bot.command_chgpass(incoming)
except Exception as e:
# Don't die when something goes wrong
bot.handle_exception(incoming, e)
print(e)
continue
if __name__ == '__main__':
main()