def get_challenge_input(challenge_number, host=HOST, port=PORT, nick=NICK): """Connect to the IRC and join channel, and return the socket and the challenge input.""" # Connect to the IRC and join room irc_socket = connect_to_host(host, port, nick) # Give some time to authenticate before joining channel sleep(2) join_channel(irc_socket, CHANNEL) response = send_private_message(irc_socket, "Candy", ":!ep%s" % str(challenge_number)) return irc_socket, response
def main(): irc.connect(HOST, PORT) irc.send_pass(PASS) irc.send_nick(NICK) irc.join_channel(CHAN) # irc.send_message(CHAN, ".me A WILD BOT JOINED THE CHAT!") print("SYS: A WILD BOT JOINED THE CHAT!") while True: try: data = irc.receive() data = re.split(r"[~\r\n]+", data) # data.pop() for line in data: line = str.rstrip(line) line = str.split(line) if len(line) >= 1: if line[0] == "PING": irc.send_pong(line[1]) if line[1] == "PRIVMSG": parse_message(line) sleep(1 / (20 / 30)) except socket.error: print("Socket died") break except socket.timeout: print("Socket timeout") break except (KeyboardInterrupt, SystemExit): break irc.disconnect() # irc.send_message(CHAN, ".me A WILD BOT LEFT THE CHAT!") print("SYS: A WILD BOT LEFT THE CHAT!")
time.sleep(delay) antiflood_timer = time.time() if message.suffix.startswith("!feedback"): date = str(datetime.now()) with open("feedback", "a") as feedback: feedback.write("\n") feedback.write("<" + date + "> " + message.sender + ": " + message.get_parameter("!feedback")) feedback.write("\n") if "MOTD" in message.suffix: irc.send_message("nickserv", "identify " + password) irc.join_channel(bot_channel) if message.type == "PING": irc.pong(message.server) delta_time = time.time() - timer if blackjack != None and delta_time > 120: irc.send_message(bot_channel, "Took too long to respond. Resetting") irc.send_message( bot_channel, blackjack.guest_player.name + " will receive a 5 minute cooldown") banned_user = ban.BannedUser(blackjack.guest_player.name, bot_channel, 5 * 60) bantracker.banlist.append(banned_user) blackjack = None
def parse_ath_message(mycode, mystr): if mycode.startswith(".bf ", 0, 4) == True: mycode = mycode.replace(".bf ", "") irc.send_msg(bfc.compile_bf(mycode), variables.channel) signal.alarm(0) elif mycode.startswith(".be ", 0, 4) == True: mycode = mycode.replace(".be ", "") irc.send_msg(bec.compile_be(mycode), variables.channel) signal.alarm(0) elif mycode.startswith(".ul ", 0, 4) == True: print mycode mycode = mycode.replace(".ul ", "") irc.send_msg(ulc.compile_ul(mycode), variables.channel) signal.alarm(0) elif mycode.startswith(".test", 0, 5) == True: utils.test() elif mycode.startswith(".eval", 0, 5) == True: output = "Result: " + utils.evaluate_expression(mycode) irc.send_msg(output, variables.channel) elif mycode.startswith(".d2h", 0, 4) == True: utils.decimal_to_hex(mycode) elif mycode.startswith(".h2d", 0, 4) == True: utils.hex_to_decimal(mycode) elif mycode.startswith(".d2b", 0, 4) == True: utils.decimal_to_bin(mycode) elif mycode.startswith(".h2b", 0, 4) == True: utils.hex_to_bin(mycode) elif mycode.startswith(".b2h", 0, 4) == True: utils.bin_to_hex(mycode) elif mycode.startswith(".b2d", 0, 4) == True: utils.bin_to_decimal(mycode) elif mycode.startswith(".join", 0, 5) == True: user = mystr['PREFIX'] user = user.split('!') if user[0] != variables.head_user: irc.send_msg("You need to be: " + variables.head_user + " to make me join a channel", variables.channel) else: mychan = mycode.replace(".join", "") mychan = mychan.replace(" ", "") if mychan == "0": irc.send_msg(variables.i_hate_you, variables.channel) else: irc.join_channel(mychan) elif mycode.startswith(".leave", 0, 6): user = mystr['PREFIX'] user = user.split('!') if user[0] != variables.head_user: irc.send_msg("You need to be: " + variables.head_user + " to make me leave a channel", variables.channel) else: mychan = mycode.replace(".leave", "") mychan = mychan.replace(" ", "") if mychan == "0": irc.send_msg(variables.i_hate_you, variables.channel) else: irc.leave_channel(mychan) elif mycode.startswith(".time ", 0, 6) == True: utils.get_time(mycode) elif mycode.startswith(".ccount ", 0, 8) == True: mycode = mycode.replace(".ccount ", "") length = 0 if check_if_unicode(mycode) == True: length = unicode_len(mycode) else: length = len(mycode) irc.send_msg("Length: " + str(length), variables.channel) elif mycode.startswith(".help", 0, 5) == True: irc.send_msg(help.athena_help, variables.channel) elif mycode.startswith(".list", 0, 5): irc.send_msg("List of modules: " + str(list(imports())), variables.channel) elif mycode.startswith(".xkcd ", 0, 6): irc.send_msg(u'\u200b' + xkcd.search_xkcd(mycode.replace(".xkcd ", "")), variables.channel) elif mycode.startswith(".tr ", 0, 4): mycode = mycode.replace(".tr ", "") lang = mycode[:2] mycode = mycode.replace(lang, "") irc.send_msg(utils.translate_lang(lang, mycode), variables.channel) elif mycode.startswith(".bftxt ", 0, 7): mycode = mycode.replace(".bftxt ", "") irc.send_msg("Output: " + bftxt.bf(mycode), variables.channel) elif mycode.startswith(".df ", 0, 4): mycode = mycode.replace(".df ", "") irc.send_msg("Output: " + deadfish.compile_df(mycode), variables.channel) elif mycode.startswith(".source", 0, 7): irc.send_msg(u"\u200bhttps://github.com/Benderx2/athena_bot", variables.channel)
main_func() except: err = sys.exc_info() exception = sys.exc_info()[0] if exception == KeyboardInterrupt: quit_bot() irc.send_msg("Error! INFO: " + str(err), variables.head_user) irc.send_msg("An error has been reported to the head user. Further details would be disclosed to the public in future. [RESTARTING]", variables.channel) # # # -------------- init code begins here ------------------------------------- # # if len(sys.argv) != 4: print "I expect the following arguments: python bot.py [your nick] [channel to join] [bot nick]" sys.exit("less/too many arguments given") else: variables.head_user = sys.argv[1] variables.channel = sys.argv[2] variables.botnick = sys.argv[3] reload(sys) sys.setdefaultencoding('utf-8') variables.ircsock.connect((variables.server, variables.port)) variables.ircsock.send("USER "+ variables.botnick + " " + variables.botnick +" "+ variables.botnick +" :MOTHERLAND_BOT\n") variables.ircsock.send("NICK " + variables.botnick + "\n") irc.join_channel(variables.channel) signal.signal(signal.SIGALRM, ten_sec_handler) main_loop()
# IRC connection arguments server = 'irc.twitch.tv' nickname = config.username channel = '#' + config.channel port = 6667 password = '******' + config.oauth # Create connection to server c = socket.socket() c.connect((server, port)) # Send server authentication and join channel irc.send_pass(c, password) irc.send_nick(c, nickname) irc.join_channel(c, channel) print(f'Connected to {config.channel}\'s chat') # Create and run thread to handle IRC communications irc_manager = threads.IRCManager(channel_id, c) irc_thread = threading.Thread(target=irc_manager.run) irc_thread.start() print('Started IRC thread...') ############################# # Set up Twitch API threads # ############################# # Create and run new follower alert thread