test-bot.py 986 B

1234567891011121314151617181920212223242526272829303132333435
  1. # -*- coding: utf-8 -*-
  2. import irc
  3. import signal
  4. ## IRC Config
  5. server = "127.0.0.1"
  6. port = 11007
  7. channels = ["#dev", "#memes", "#philosophy", "#markets", "#math", "#random", "#test"]
  8. botnick = "testbot"
  9. ircc = irc.IRC()
  10. ircc.connect(server, port, channels, botnick)
  11. def signal_handler(sig, frame):
  12. print("Caught termination signal, cleaning up and exiting...")
  13. ircc.disconnect(server, port)
  14. print("Shut down successfully")
  15. exit(0)
  16. signal.signal(signal.SIGINT, signal_handler)
  17. while True:
  18. text = ircc.get_response().strip()
  19. if not len(text) > 0:
  20. print("Error: disconnected from server")
  21. exit(-1)
  22. # print(text)
  23. text_list = text.split(' ')
  24. #print(text_list)
  25. if text_list[1] == "PRIVMSG":
  26. channel = text_list[2]
  27. msg = ' '.join(text_list[3:]).strip()
  28. bot_msg = text.split(':')[-1].strip()
  29. if bot_msg.lower() == "test" or bot_msg.lower() == "echo":
  30. ircc.send(channel, f"{bot_msg} back")