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