def run(self): config = self.config while True: try: data = self.irc.nextMessage() if not self.irc.check_for_message(data): continue message_dict = self.irc.get_message(data) channel = message_dict["channel"] message = message_dict["message"] username = message_dict["username"] message_dict["time"] = time.time() sent_at = message_dict["time"] resp0 = "%s" % (username) resp1 = "%s" % (channel) resp2 = "%s" % (message) write_to_log(channel, username, message) part = message.split(" ")[0] valid = False if commands.is_valid_command(message): valid = True if commands.is_valid_command(part): valid = True if not valid: continue self.handleCommand(part, channel, username, message) except Exception as err: raise traceback.print_exc(file=self.log)
def run(self): config = self.config while True: try: data = self.irc.nextMessage() if not self.irc.check_for_message(data): continue message_dict = self.irc.get_message(data) channel = message_dict['channel'] globals.global_channel = channel.lstrip('#') print "channel", channel.lstrip('#') print "globals.channel", globals.global_channel.lstrip('#') message = message_dict['message'] # .lower() username = message_dict['username'] globals.CURRENT_USER = username ppi(channel, message, username) # check if message is a command with no arguments part = message.split(' ')[0] valid = False if commands.is_valid_command(message): valid = True if commands.is_valid_command(part): valid = True if not valid: continue self.handleCommand(part, channel, username, message) except Exception as err: raise traceback.print_exc(file=self.log)
def run(self): config = self.config while True: try: data = self.irc.nextMessage() if not self.irc.check_for_message(data): continue message_dict = self.irc.get_message(data) channel = message_dict['channel'] globals.global_channel = channel.lstrip('#') print "channel", channel.lstrip('#') print "globals.channel", globals.global_channel.lstrip('#') message = message_dict['message'] # .lower() username = message_dict['username'] globals.CURRENT_USER = username ppi(channel, message, username) # check if message is a command with no arguments part = message.split(' ')[0] valid = False if commands.is_valid_command(message): valid = True if commands.is_valid_command(part): valid = True if not valid: continue self.handleCommand(part, channel, username, message) except Exception as err: raise traceback.print_exc(file=self.log)
def privmsg(self, username, channel, message): if (channel == "#" + PRIMARY_CHANNEL or channel == "#" + SUPERUSER or channel == "#" + TEST_USER): if username == "twitchnotify": self.check_for_sub(channel, [username], message) chan = channel.lstrip("#") if message[0] == "!": trigger = message.split()[0] fetch_command = self.return_custom_command(chan, trigger.lstrip("!"), username) if fetch_command: self.IRC.send_message(channel, fetch_command) part = message.split(' ')[0] valid = False if commands.is_valid_command(message): valid = True if commands.is_valid_command(part): valid = True if not valid: return resp = self.handle_command(part, channel, username, message) if resp: self.IRC.send_message(channel, resp) return
def privmsg(self, username, channel, message): if spam_detector(username, message) is True: # # uncomment the line below to enable spam_detector # self.ban_for_spam(channel, username, message) pass chan = channel.lstrip("#") if message[0] == "!": message_split = message.split() fetch_command = get_custom_command(chan, message_split[0]) if len(fetch_command) > 0: if message_split[0] == fetch_command[0][1]: resp = self.return_custom_command(channel, message_split, username) if resp: self.IRC.send_message(channel, resp) save_message(username, channel, message) part = message.split(' ')[0] valid = False if commands.is_valid_command(message): valid = True if commands.is_valid_command(part): valid = True if not valid: return resp = self.handle_command(part, channel, username, message) if resp: self.IRC.send_message(channel, resp) return
def privmsg(self, user, channel, message): """Called when the bot receives a message.""" username = user.split("!")[0].lstrip(":") globals.CURRENT_USER = username chan = channel.lstrip("#") globals.CURRENT_CHANNEL = chan chan = channel.lstrip("#") # TODO add spam detector here chan = channel.lstrip("#") if message[0] == "!": message_split = message.split() fetch_command = Database().get_command(message_split[0], chan) if fetch_command and len(fetch_command) > 0: if message_split[0] == fetch_command[3]: self.return_custom_command( channel, message_split, username, fetch_command) return part = message.split(' ')[0] valid = False if commands.is_valid_command(message): valid = True if commands.is_valid_command(part): valid = True if not valid: return resp = self.handle_command( part, channel, username, message) if resp: self.msg(channel, resp.replace("\n", "").replace("\r", "") + "\r\n")
def privmsg(self, username, channel, message): if (channel == "#" + PRIMARY_CHANNEL or channel == "#" + SUPERUSER or channel == "#" + TEST_USER): if username == "twitchnotify": self.check_for_sub(channel, [username], message) chan = channel.lstrip("#") if message[0] == "!": trigger = message.split()[0] fetch_command = self.return_custom_command( chan, trigger.lstrip("!"), username) if fetch_command: self.IRC.send_message(channel, fetch_command) part = message.split(' ')[0] valid = False if commands.is_valid_command(message): valid = True if commands.is_valid_command(part): valid = True if not valid: return resp = self.handle_command( part, channel, username, message) if resp: self.IRC.send_message(channel, resp) return
def run(self): config = self.config while True: try: data = self.irc.nextMessage() if not self.irc.check_for_message(data): continue message_dict = self.irc.get_message(data) channel = message_dict["channel"] message = message_dict["message"] username = message_dict["username"] message_dict["time"] = time.time() sent_at = message_dict["time"] resp0 = "%s" % (username) resp1 = "%s" % (channel) resp2 = "%s" % (message) write_to_log(channel, username, message) part = message.split(" ")[0] valid = False if commands.is_valid_command(message): valid = True if commands.is_valid_command(part): valid = True if not valid: continue self.handleCommand(part, channel, username, message) except Exception as err: raise traceback.print_exc(file=self.log)
def run(self): irc = self.irc sock = self.socket general = self.general while True: data = sock.recv(general['buffer_size']).rstrip() if len(data) == 0: pp('Connection was lost, reconnecting.') sock = self.irc.get_irc_socket_object() if general['debug']: datasplit = data.split('\n') for line in datasplit: pp(line, 'DEBUG') # check for ping, reply with pong irc.check_for_ping(data) if irc.check_for_message(data): message_dict = irc.get_message(data) channel = message_dict['channel'] message = message_dict['message'] username = message_dict['username'] ppi(channel, message, username) cleanmessage = message[1:] commandsplit = cleanmessage.split(' ')[0] # check if message is a command with no arguments if commands.is_valid_command(cleanmessage, self.channel) or commands.is_valid_command(commandsplit, self.channel): command = commands.get_command(cleanmessage if cleanmessage == commandsplit else commandsplit, self.channel) args = cleanmessage.split(' ') args.pop(0) if command: pp("{0} has executed !{1} in {2}".format(username, command.command, channel)) irc.send_message(command.execute(irc, self.channel, username, args)) else: pp("Invalid command !{0} from {1} in {2}".format(command.command, username, channel))
def run(self): # This is a very handy function, so I'm not deleting it yet # def check_for_sub(channel, username, message): # # >> :[email protected] PRIVMSG #curvyllama :KiefyWonder subscribed for 5 months in a row! # # >> :[email protected] PRIVMSG #curvyllama :KiefyWonder just subscribed! # # Photo_phocus just subscribed to jonsandman! # # HermanNugent subscribed to JonSandman for 7 months in a row! # # first sub points = 1000 # # resub = 250 # db = Database() # try: # channel = channel.lstrip("#") # message_split = message.rstrip("!").split() # subbed_user = message_split[0].lower() # if message_split[1] == "just" and len(message_split) < 4: # points = 1000 # db.add_user([subbed_user], channel) # db.modify_points(subbed_user, channel, points) # resp = "/me {0} just subscribed for the first time!\ # {1} cash for you!".format(subbed_user, points) # self.irc.send_message("#" + channel, resp) # elif message_split[1] == "subscribed" and len(message_split) < 9: # months_subbed = message_split[3] # points = 250 # db.add_user([subbed_user], channel) # db.modify_points(subbed_user, channel, points) # resp = "/me {0} has just resubscribed for {1} months \ # straight and is getting {2} cash!".format(subbed_user, months_subbed, points) # self.irc.send_message("#" + channel, resp) # except Exception as error: # print error # For admin created commands. Not that useful but I'll keep it in case I have to implement it # def custom_command(channel, message, username, elements): # db = Database() # command = elements[3] # chan = channel.lstrip("#") # replacement_user = username # if len(message) > 1: # replacement_user = message[1] # if elements[6] == "mod": # user_dict, __ = get_dict_for_users() # if username in user_dict["chatters"]["moderators"]: # resp = elements[4].replace("{}", replacement_user).replace( # "[]", str(elements[5])) # self.irc.send_message(channel, resp) # db.increment_command(command, chan) # else: # resp = "This is a moderator-only command" # self.irc.send_message(channel, resp) # elif elements[6] == "reg": # resp = elements[4].replace("{}", replacement_user).replace( # "[]", str(elements[5])) # self.irc.send_message(channel, resp) # db.increment_command(command, chan) #Main process while True: try: data = self.irc.nextMessage() if self.irc.check_for_message(data): message_dict = self.irc.get_message(data) channel = message_dict['channel'] message = message_dict['message'] username = message_dict['username'] elif self.irc.check_for_whisper(data): message_dict = self.irc.get_whisper(data) channel = self.config["channels"][0] message = message_dict['message'] username = message_dict['username'] if message.startswith("!"): resp = '/w %s Please type your command in the channel chat' % (username) pbot(resp, channel) self.irc.send_message(channel, resp) continue else: continue globals.CURRENT_CHANNEL = channel.lstrip('#') globals.CURRENT_USER = username chan = channel.lstrip("#") #Part of the "subscribed" functionality # if username == "twitchnotify": # check_for_sub(channel, username, message) part = message.split(' ')[0] valid = False if commands.is_valid_command(message): valid = True if commands.is_valid_command(part): valid = True if not valid: continue self.handleCommand(part, channel, username, message) except Exception as error: print error
def run(self): # This is a very handy function, so I'm not deleting it yet # def check_for_sub(channel, username, message): # # >> :[email protected] PRIVMSG #curvyllama :KiefyWonder subscribed for 5 months in a row! # # >> :[email protected] PRIVMSG #curvyllama :KiefyWonder just subscribed! # # Photo_phocus just subscribed to jonsandman! # # HermanNugent subscribed to JonSandman for 7 months in a row! # # first sub points = 1000 # # resub = 250 # db = Database() # try: # channel = channel.lstrip("#") # message_split = message.rstrip("!").split() # subbed_user = message_split[0].lower() # if message_split[1] == "just" and len(message_split) < 4: # points = 1000 # db.add_user([subbed_user], channel) # db.modify_points(subbed_user, channel, points) # resp = "/me {0} just subscribed for the first time!\ # {1} cash for you!".format(subbed_user, points) # self.irc.send_message("#" + channel, resp) # elif message_split[1] == "subscribed" and len(message_split) < 9: # months_subbed = message_split[3] # points = 250 # db.add_user([subbed_user], channel) # db.modify_points(subbed_user, channel, points) # resp = "/me {0} has just resubscribed for {1} months \ # straight and is getting {2} cash!".format(subbed_user, months_subbed, points) # self.irc.send_message("#" + channel, resp) # except Exception as error: # print error # For admin created commands. Not that useful but I'll keep it in case I have to implement it # def custom_command(channel, message, username, elements): # db = Database() # command = elements[3] # chan = channel.lstrip("#") # replacement_user = username # if len(message) > 1: # replacement_user = message[1] # if elements[6] == "mod": # user_dict, __ = get_dict_for_users() # if username in user_dict["chatters"]["moderators"]: # resp = elements[4].replace("{}", replacement_user).replace( # "[]", str(elements[5])) # self.irc.send_message(channel, resp) # db.increment_command(command, chan) # else: # resp = "This is a moderator-only command" # self.irc.send_message(channel, resp) # elif elements[6] == "reg": # resp = elements[4].replace("{}", replacement_user).replace( # "[]", str(elements[5])) # self.irc.send_message(channel, resp) # db.increment_command(command, chan) #Main process while True: try: data = self.irc.nextMessage() if self.irc.check_for_message(data): message_dict = self.irc.get_message(data) channel = message_dict['channel'] message = message_dict['message'] username = message_dict['username'] elif self.irc.check_for_whisper(data): message_dict = self.irc.get_whisper(data) channel = self.config["channels"][0] message = message_dict['message'] username = message_dict['username'] if message.startswith("!"): resp = '/w %s Please type your command in the channel chat' % ( username) pbot(resp, channel) self.irc.send_message(channel, resp) continue else: continue globals.CURRENT_CHANNEL = channel.lstrip('#') globals.CURRENT_USER = username chan = channel.lstrip("#") #Part of the "subscribed" functionality # if username == "twitchnotify": # check_for_sub(channel, username, message) part = message.split(' ')[0] valid = False if commands.is_valid_command(message): valid = True if commands.is_valid_command(part): valid = True if not valid: continue self.handleCommand(part, channel, username, message) except Exception as error: print error
def run(self): irc = self.irc sock = self.socket config = self.config while True: data = sock.recv(config['socket_buffer_size']).rstrip() if len(data) == 0: pp('Connection was lost, reconnecting.') sock = self.irc.get_irc_socket_object() if config['debug']: print data # check for ping, reply with pong irc.check_for_ping(data) if irc.check_for_message(data): message_dict = irc.get_message(data) channel = message_dict['channel'] message = message_dict['message'] username = message_dict['username'] ppi(channel, message, username) # check if message is a command with no arguments if commands.is_valid_command( message) or commands.is_valid_command( message.split(' ')[0]): command = message if commands.check_returns_function(command.split(' ')[0]): if commands.check_has_correct_args( command, command.split(' ')[0]): args = command.split(' ') del args[0] command = command.split(' ')[0] if commands.is_on_cooldown(command, channel): pbot( 'Command is on cooldown. (%s) (%s) (%ss remaining)' % (command, username, commands.get_cooldown_remaining( command, channel)), channel) else: pbot( 'Command is valid an not on cooldown. (%s) (%s)' % (command, username), channel) result = commands.pass_to_function( command, args, username) commands.update_last_used(command, channel) if result: resp = '@%s - %s' % (username, result) pbot(resp, channel) irc.send_message(channel, resp) else: if commands.is_on_cooldown(command, channel): pbot( 'Command is on cooldown. (%s) (%s) (%ss remaining)' % (command, username, commands.get_cooldown_remaining( command, channel)), channel) elif commands.check_has_return(command): pbot( 'Command is valid and not on cooldown. (%s) (%s)' % (command, username), channel) commands.update_last_used(command, channel) resp = '@%s - %s' % (username, commands.get_return(command)) commands.update_last_used(command, channel) pbot(resp, channel) irc.send_message(channel, resp)
def run(self): def check_for_sub(channel, username, message): # >> :[email protected] PRIVMSG #curvyllama :KiefyWonder subscribed for 5 months in a row! # >> :[email protected] PRIVMSG #curvyllama :KiefyWonder just subscribed! # Photo_phocus just subscribed to jonsandman! # HermanNugent subscribed to JonSandman for 7 months in a row! # first sub points = 1000 # resub = 250 db = Database() try: channel = channel.lstrip("#") message_split = message.rstrip("!").split() subbed_user = message_split[0].lower() if message_split[1] == "just" and len(message_split) < 4: points = 1000 db.add_user([subbed_user], channel) db.modify_points(subbed_user, channel, points) resp = "/me {0} just subscribed for the first time!\ {1} cash for you!".format(subbed_user, points) self.irc.send_message("#" + channel, resp) elif message_split[1] == "subscribed" and len(message_split) < 9: months_subbed = message_split[3] points = 250 db.add_user([subbed_user], channel) db.modify_points(subbed_user, channel, points) resp = "/me {0} has just resubscribed for {1} months \ straight and is getting {2} cash!".format(subbed_user, months_subbed, points) self.irc.send_message("#" + channel, resp) except Exception as error: print error def custom_command(channel, message, username, elements): db = Database() command = elements[3] chan = channel.lstrip("#") replacement_user = username if len(message) > 1: replacement_user = message[1] if elements[6] == "mod": user_dict, __ = get_dict_for_users() if username in user_dict["chatters"]["moderators"]: resp = elements[4].replace("{}", replacement_user).replace( "[]", str(elements[5])) self.irc.send_message(channel, resp) db.increment_command(command, chan) else: resp = "This is a moderator-only command" self.irc.send_message(channel, resp) elif elements[6] == "reg": resp = elements[4].replace("{}", replacement_user).replace( "[]", str(elements[5])) self.irc.send_message(channel, resp) db.increment_command(command, chan) while True: try: data = self.irc.nextMessage() if not self.irc.check_for_message(data): continue message_dict = self.irc.get_message(data) channel = message_dict['channel'] globals.CURRENT_CHANNEL = channel.lstrip('#') message = message_dict['message'] # .lower() username = message_dict['username'] globals.CURRENT_USER = username chan = channel.lstrip("#") if message[0] == "!": command = message.split(" ")[0] command_data = self.db.get_command(command, chan) if command_data: message_split = message.split(" ") custom_command( channel, message_split, username, command_data) if username == "twitchnotify": check_for_sub(channel, username, message) part = message.split(' ')[0] valid = False if commands.is_valid_command(message): valid = True if commands.is_valid_command(part): valid = True if not valid: continue self.handleCommand(part, channel, username, message) except Exception as error: print error
def run(self): irc = self.irc sock = self.socket config = self.config ALWAYS_LEARN = False while True: data = sock.recv(config['socket_buffer_size']).rstrip() if len(data) == 0: pp('Connection was lost, reconnecting.') sock = self.irc.get_irc_socket_object() if config['debug']: print(data) # check for ping, reply with pong irc.check_for_ping(data) if irc.check_for_message(data): message_dict = irc.get_message(data) channel = message_dict['channel'] message = message_dict['message'] username = message_dict['username'] botCommand = ('@ShrikeChanBot' in message) or ('!learn' in message) if username is 'shrikechanbot': print('skip bot messages') else: if ALWAYS_LEARN and not botCommand and self.last_message != '': clean_message = message.replace('@ShrikeChanBot', '').replace( '!learn', '').strip() chatbot.learn_response( Statement(text=clean_message), Statement(text=self.last_message)) print('LEARNING', clean_message, '>', self.last_message, '=', chatbot.get_response(clean_message)) self.last_message = clean_message ppi(channel, message, username) # check if message is a command with no arguments if commands.is_valid_command( message) or commands.is_valid_command( message.split(' ')[0]): command = message if commands.check_returns_function( command.split(' ')[0]): if commands.check_has_correct_args( command, command.split(' ')[0]): args = command.split(' ') del args[0] command = command.split(' ')[0] if commands.is_on_cooldown(command, channel): pbot( 'Command is on cooldown. (%s) (%s) (%ss remaining)' % (command, username, commands.get_cooldown_remaining( command, channel)), channel) else: pbot( 'Command is valid and not on cooldown. (%s) (%s)' % (command, username), channel) if botCommand: args = message result = commands.pass_to_function( command, args, chatbot, self.last_message) commands.update_last_used(command, channel) if result: resp = '%s @%s' % (result, username) pbot(resp, channel) irc.send_message(channel, resp) else: if commands.is_on_cooldown(command, channel): pbot( 'Command is on cooldown. (%s) (%s) (%ss remaining)' % (command, username, commands.get_cooldown_remaining( command, channel)), channel) elif commands.check_has_return(command): pbot( 'Command is valid and not on cooldown. (%s) (%s)' % (command, username), channel) commands.update_last_used(command, channel) resp = '%s @%s' % ( commands.get_return(command), username) commands.update_last_used(command, channel) pbot(resp, channel) irc.send_message(channel, resp) if ALWAYS_LEARN or botCommand: self.last_message = message.replace( '@ShrikeChanBot', '').replace('!learn', '').strip()
def run(self): irc = self.irc sock = self.socket config = self.config for rank in self.ranks: self.ranks[rank].start() resp = u'! 98bot進入聊天室,計算聊天等級開始。' irc.send_message(rank, resp) while True: data = sock.recv(config['socket_buffer_size']).rstrip() if len(data) == 0: pp('Connection was lost, reconnecting.') sock = self.irc.get_irc_socket_object() if config['debug']: print data # check for ping, reply with pong irc.check_for_ping(data) if irc.check_for_message(data): message_dict = irc.get_message(data) channel = message_dict['channel'] message = message_dict['message'] username = message_dict['username'] if username.lower() in self.config['ignore']: continue # give XP to this user rks = self.ranks.get(channel, None) if rks is not None and rks.live == True: rks.newchat(username) if rks.quiet: continue #I'm lazy to write a module msg = message.strip().split(' ') target = username if len(msg) > 1: target = msg[1].lower() if msg[0].lower() == '!rank': if username == channel[1:] and len( msg) == 1: #broadcaster don't have level u = rks.top() if u is not None: if u[4].lower() == u[1].lower(): resp = u'! 報告台主,目前講話最多的是 %s,%s級,經驗值%s/%s。' % ( u[4], str(u[3]), str( u[2]), str(threshold[u[3]])) else: resp = u'! 報告台主,目前講話最多的是%s (%s),%s級,經驗值%s/%s。' % ( u[4], u[1], str(u[3]), str( u[2]), str(threshold[u[3]])) else: resp = u'! 報告台主,你到現在都沒有半個觀眾講過話,幫QQ' else: u = rks.find(target) if u is not None: if u[4].lower() == u[1].lower(): resp = u'! %s 目前%s級,排第%s名,經驗值%s/%s。' % ( u[4], str(u[3]), str(u[0]), str( u[2]), str(threshold[u[3]])) else: resp = u'! %s (%s) 目前%s級,排第%s名,經驗值%s/%s。' % ( u[4], u[1], str(u[3]), str(u[0]), str( u[2]), str(threshold[u[3]])) else: resp = u'! 找不到 %s 的等級,大概還沒講過話吧。' % target irc.send_message(channel, resp) continue # for checking the bot is online if message.strip().lower() == '!98bot' or message.strip( ).split(' ')[0].lower() == '!98bot': if rks.live: resp = u'! 正在努力記錄大家的經驗值。' else: resp = u'! 目前沒開台沒經驗值,但我不會阻止你講話~' irc.send_message(channel, resp) continue # check if message is a command with no arguments if commands.is_valid_command( message) or commands.is_valid_command( message.split(' ')[0]): command = message if commands.check_returns_function(command.split(' ')[0]): if commands.check_has_correct_args( command, command.split(' ')[0]): args = command.split(' ') del args[0] command = command.split(' ')[0] if commands.is_on_cooldown(command, channel): pbot( 'Command is on cooldown. (%s) (%s) (%ss remaining)' % (command, username, commands.get_cooldown_remaining( command, channel)), channel) else: pbot( 'Command is valid an not on cooldown. (%s) (%s)' % (command, username), channel) result = commands.pass_to_function( command, args) commands.update_last_used(command, channel) if result: resp = '%s' % result pbot(resp, channel) irc.send_message(channel, resp) else: if commands.is_on_cooldown(command, channel): pbot( 'Command is on cooldown. (%s) (%s) (%ss remaining)' % (command, username, commands.get_cooldown_remaining( command, channel)), channel) elif commands.check_has_return(command): pbot( 'Command is valid and not on cooldown. (%s) (%s)' % (command, username), channel) commands.update_last_used(command, channel) resp = '%s' % commands.get_return(command) commands.update_last_used(command, channel) pbot(resp, channel) irc.send_message(channel, resp)
def run(self): def check_for_sub(channel, username, message): try: message_split = message.rstrip("!").split() subbed_user = message_split[0] if message_split[1] == "just": modify_user_points(subbed_user, 100) resp = "/me {0} treats for {1} for a first time subscription!".format( 100, subbed_user) self.irc.send_message(channel, resp) save_message(BOT_USER, channel, resp) elif message_split[1] == "subscribed": months_subbed = message_split[5] modify_user_points(subbed_user, int(months_subbed) * 100) resp = "/me {0} has just resubscribed for {1} months straight and is getting {2} treats for loyalty!".format( subbed_user, months_subbed, int(months_subbed) * 100) self.irc.send_message(channel, resp) save_message(BOT_USER, channel, resp) except Exception as error: # pragma: no cover print error def return_custom_command(channel, message, username): chan = channel.lstrip("#") elements = get_custom_command_elements( chan, message[0]) replacement_user = username if len(message) > 1: replacement_user = message[1] resp = elements[1].replace( "{}", replacement_user).replace("[]", str(elements[2] + 1)) if elements[0] == "mod": user_dict, __ = get_dict_for_users() if username in user_dict["chatters"]["moderators"]: self.irc.send_message(channel, resp) increment_command_counter(chan, message[0]) save_message(BOT_USER, channel, resp) elif elements[0] == "reg": self.irc.send_message(channel, resp) increment_command_counter(chan, message[0]) save_message(BOT_USER, channel, resp) def ban_for_spam(channel, user): ban = "/ban {0}".format(user) unban = "/unban {0}".format(user) self.irc.send_message(channel, ban) self.irc.send_message(channel, unban) save_message(BOT_USER, channel, message) while True: try: data = self.irc.nextMessage() if not self.irc.check_for_message(data): continue message_dict = self.irc.get_message(data) channel = message_dict['channel'] globals.CURRENT_CHANNEL = channel.lstrip('#') message = message_dict['message'] # .lower() username = message_dict['username'] globals.CURRENT_USER = username if channel == "#" + PRIMARY_CHANNEL or channel == "#" + SUPERUSER or channel == "#" + TEST_USER: write_to_log(channel, username, message) # check for sub message if username == "twitchnotify": check_for_sub(channel, username, message) if spam_detector(username, message) is True: ban_for_spam(channel, user) chan = channel.lstrip("#") if message[0] == "!": message_split = message.split() fetch_command = get_custom_command(chan, message_split[0]) if len(fetch_command) > 0: if message_split[0] == fetch_command[0][1]: return_custom_command( channel, message_split, username) save_message(username, channel, message) # check if message is a command with no arguments part = message.split(' ')[0] valid = False if commands.is_valid_command(message): valid = True if commands.is_valid_command(part): valid = True if not valid: continue self.handleCommand(part, channel, username, message) except Exception as error: print error
def run(self): irc = self.irc sock = self.socket config = self.config while True: data = sock.recv(config['socket_buffer_size']).rstrip() if len(data) == 0: pp('Connection was lost, reconnecting.') sock = self.irc.get_irc_socket_object() if config['debug']: print data # check for ping, reply with pong irc.check_for_ping(data) if irc.check_for_message(data): message_dict = irc.get_message(data) channel = message_dict['channel'] message = message_dict['message'] username = message_dict['username'] ppi(channel, message, username) #custom triggers stop = re.match('stop ([0-9]+)', message) if stop: time.sleep(int(stop.group(1))) continue #pause for some time to prevent hitting request limit time.sleep(randint(2,4)) print "sending rando" irc.random_chat(config['channels'][0]) # check if message is a command with no arguments if commands.is_valid_command(message) or commands.is_valid_command(message.split(' ')[0]): command = message if commands.check_returns_function(command.split(' ')[0]): if commands.check_has_correct_args(command, command.split(' ')[0]): args = command.split(' ') del args[0] command = command.split(' ')[0] if commands.is_on_cooldown(command, channel): pbot('Command is on cooldown. (%s) (%s) (%ss remaining)' % ( command, username, commands.get_cooldown_remaining(command, channel)), channel ) else: pbot('Command is valid an not on cooldown. (%s) (%s)' % ( command, username), channel ) result = commands.pass_to_function(command, args) commands.update_last_used(command, channel) if result: resp = '(%s) > %s' % (username, result) pbot(resp, channel) irc.send_message(channel, resp) else: if commands.is_on_cooldown(command, channel): pbot('Command is on cooldown. (%s) (%s) (%ss remaining)' % ( command, username, commands.get_cooldown_remaining(command, channel)), channel ) elif commands.check_has_return(command): pbot('Command is valid and not on cooldown. (%s) (%s)' % ( command, username), channel ) commands.update_last_used(command, channel) resp = '(%s) > %s' % (username, commands.get_return(command)) commands.update_last_used(command, channel) pbot(resp, channel) irc.send_message(channel, resp)
def run(self): irc = self.irc sock = self.socket config = self.config while True: data = sock.recv(config['socket_buffer_size']).rstrip() if len(data) == 0: pp('Connection was lost, reconnecting.') sock = self.irc.get_irc_socket_object() if config['debug']: print data # check for ping, reply with pong irc.check_for_ping(data) for channel in config['channels'] : channel_runtime.of(channel) if irc.check_for_message(data): message_dict = irc.get_message(data) channel = message_dict['channel'] message = message_dict['message'] username = message_dict['username'] ppi(channel, message, username) # check if message is a command with no arguments if commands.is_valid_command(message) or commands.is_valid_command(message.split(' ')[0]): command = message if commands.is_protected(message.split(' ')[0]) \ and not username in channel_runtime.of(channel).moderators: continue if commands.check_returns_function(command.split(' ')[0]): if commands.check_has_correct_args(command, command.split(' ')[0]): args = command.split(' ') del args[0] command = command.split(' ')[0] """if commands.is_on_cooldown(command, channel): pbot('Command is on cooldown. (%s) (%s) (%ss remaining)' % ( command, username, commands.get_cooldown_remaining(command, channel)), channel ) else: pbot('Command is valid an not on cooldown. (%s) (%s)' % ( command, username), channel )""" #args.append(username) result = commands.pass_to_function(command, args, username, channel_runtime.of(channel)) commands.update_last_used(command, channel) if result: resp = '%s' % result pbot(resp, channel) irc.send_message(channel, resp) else: """if commands.is_on_cooldown(command, channel): pbot('Command is on cooldown. (%s) (%s) (%ss remaining)' % ( command, username, commands.get_cooldown_remaining(command, channel)), channel ) elif commands.check_has_return(command): pbot('Command is valid and not on cooldown. (%s) (%s)' % ( command, username), channel )""" commands.update_last_used(command, channel) resp = '%s' % commands.get_return(command) commands.update_last_used(command, channel) if resp != "nothing": pbot(resp, channel) irc.send_message(channel, resp)
def run(self): irc = self.irc sock = self.socket config = self.config tasks.run_tasks() while True: data = sock.recv(config['socket_buffer_size']).rstrip() if len(data) == 0: pp('Connection was lost, reconnecting.') sock = self.irc.get_irc_socket_object() if config['debug']: print(data) # check for ping, reply with pong irc.check_for_ping(data) if irc.check_for_message(data): message_dict = irc.get_message(data) channel = message_dict['channel'] message = message_dict['message'] username = message_dict['username'] ppi(channel, message, username) # check if message is a command with no arguments if commands.is_valid_command(message) or commands.is_valid_command(message.split(' ')[0]): command = message if commands.check_returns_function(command.split(' ')[0]): if commands.check_has_correct_args(command, command.split(' ')[0]): args = command.split(' ') del args[0] command = command.split(' ')[0] if commands.is_on_cooldown(command, channel): pbot('Command is on cooldown. (%s) (%s) (%ss remaining)' % ( command, username, commands.get_cooldown_remaining(command, channel)), channel ) else: pbot('Command is valid an not on cooldown. (%s) (%s)' % ( command, username), channel ) result = commands.pass_to_function(command, args) commands.update_last_used(command, channel) if result: # resp = '(%s) > %s' % (username, result) resp = '%s' % (result) pbot(resp, channel) irc.send_message(channel, resp) else: if commands.is_on_cooldown(command, channel): pbot('Command is on cooldown. (%s) (%s) (%ss remaining)' % ( command, username, commands.get_cooldown_remaining(command, channel)), channel ) elif commands.check_has_return(command): pbot('Command is valid and not on cooldown. (%s) (%s)' % ( command, username), channel ) commands.update_last_used(command, channel) resp = '(%s) > %s' % (username, commands.get_return(command)) commands.update_last_used(command, channel) pbot(resp, channel) irc.send_message(channel, resp)
def run(self): irc = self.irc sock = self.socket config = self.config while True: data_raw = sock.recv(config['socket_buffer_size']).rstrip() for data in data_raw.split('\r'): data = data.strip() if len(data) == 0: pp('Connection was lost, reconnecting.') sock = self.irc.get_irc_socket_object() if config['debug']: print data # check for ping, reply with pong if irc.check_for_ping(data): continue if irc.check_for_join(data): user, channel = irc.get_join(data) self.users[channel].add(user.lower()) pp("User {0} joined {1}".format(user, channel)) continue if irc.check_for_part(data): user, channel = irc.get_part(data) try: self.users[channel].remove(user.lower()) except KeyError: pass pp("User {0} left {1}".format(user, channel)) continue if irc.check_for_message(data): message_dict = irc.get_message(data) channel = message_dict['channel'] message = message_dict['message'] username = message_dict['username'] ppi(channel, message, username) # check if message is a command with no arguments if commands.is_valid_command( message) or commands.is_valid_command( message.split(' ')[0]): command = message if commands.check_returns_function( command.split(' ')[0]): if commands.check_has_correct_args( command, command.split(' ')[0]): command_name = command.split(' ')[0] args = command.split(' ')[1:] if commands.is_on_cooldown( command_name, channel): pbot( 'Command is on cooldown. (%s) (%s) (%ss remaining)' % (command, username, commands.get_cooldown_remaining( command_name, channel)), channel) else: pbot( 'Command is valid an not on cooldown. (%s) (%s)' % (command, username), channel) result = commands.pass_to_function( command_name[1:], args, username, self.users[channel]) commands.update_last_used( command_name, channel) if result: for r in result: resp = '(%s) > %s' % (username, r) pbot(resp, channel) irc.send_message(channel, resp) else: if commands.is_on_cooldown(command, channel): pbot( 'Command is on cooldown. (%s) (%s) (%ss remaining)' % (command, username, commands.get_cooldown_remaining( command, channel)), channel) elif commands.check_has_return(command): pbot( 'Command is valid and not on cooldown. (%s) (%s)' % (command, username), channel) commands.update_last_used(command, channel) resp = '(%s) > %s' % ( username, commands.get_return(command)) commands.update_last_used(command, channel) pbot(resp, channel) irc.send_message(channel, resp)