test-bot.py 937 B

12345678910111213141516171819202122232425262728293031323334
  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. continue
  21. # print(text)
  22. text_list = text.split(' ')
  23. #print(text_list)
  24. if text_list[1] == "PRIVMSG":
  25. channel = text_list[2]
  26. msg = ' '.join(text_list[3:]).strip()
  27. bot_msg = text.split(':')[-1].strip()
  28. if bot_msg.lower() == "test" or bot_msg.lower() == "echo":
  29. ircc.send(channel, f"{bot_msg} back")