def _parse_message(self, channel, message): message = irc.stripFormatting(message) if channel == self.channel and self._is_channel_command(message): return message.split(' ')[1], message.split(' ')[2:] elif channel == self.nickname: return message.split(' ')[0], message.split(' ')[1:] return None, None
def privmsg(self, user, channel, message): timeRightNow = time.time() nick = user.split('!')[0] user_ip = user.split('@')[1] user_name = [] for name in self.user_list: user_name.append(name["nick"]) if message.startswith(self.nickname): if search(r'(^|\s)+ignore*(\s|$)+', message, IGNORECASE) and user_ip == self.owner: self.ignoreList.append(message.split(" ")[2]) elif search(r'(^|\s)+unignore*(\s|$)+', message, IGNORECASE) and user_ip == self.owner: self.ignoreList.remove(message.split(" ")[2]) elif timeRightNow - self.currentTime > 5: self.user_list = [names for names in self.user_list if names not in self.botList] if channel == self.nickname and user_ip != self.owner: return elif search(r"(^|\s)+say*(!|\?)*(\s|$)", message, IGNORECASE): if user_ip == self.owner: self.msg(self.channel, message.split('say ')[1]) elif nick in self.ignoreList: return elif search(r'(^|\s)+help*(\s|$)+', message, IGNORECASE): self.currentTime = time.time() self.msg(self.channel, "I love all the adtran co-ops with all my heart, and with so much hatred in this irc (@berns @burnbot), I would like to spread some kindess. Give me someone to compliment!") elif search(r'(^|\s)+attack*(\s|$)+', message, IGNORECASE): self.currentTime = time.time() self.msg(self.channel, "I will not \n") elif search(r"(^|\s)+compliment*(!|\?)*(\s|$)", message, IGNORECASE): self.currentTime = time.time() items = message.split(" ") burn_name = "" if len(items) > 2: burn_name = irc.stripFormatting(message.split(" ")[2]) if len(items) == 2: self.msg(self.channel, random.choice(user_name) + ": " + random.choice(self.jokes)) elif burn_name.lower() == self.nickname.lower(): self.msg(self.channel, "self love <3." + "\n" + self.nickname.lower() + ": " + random.choice(self.jokes)) elif burn_name.lower() == self.owner_name.lower(): self.msg(self.channel, "she\'s the best, isn\'t she?" + "\n" + self.owner_name.lower() + ": " + random.choice(self.jokes)) elif burn_name.lower() == "burnbot": self.msg(self.channel, "burnBot: I'm rubber and you're glue...") elif burn_name not in user_name: if user_ip == self.owner: self.msg(self.channel, burn_name + ": " + random.choice(self.jokes)) print (burn_name) else: self.msg(self.channel, "Fiddle sticks! User not found. Prepare for ultimate compliments. \n" + nick + ": " + random.choice(self.jokes)) elif burn_name in self.botList: if user_ip == self.owner: self.msg(self.channel, burn_name + ": " + random.choice(self.jokes)) else: self.msg(self.channel, "Sweet human. Compliments are really only meant for people. Here's one for you anyway " + nick + "<3 \n" + nick + ": " + random.choice(self.jokes)) else: self.msg(self.channel, burn_name + ": " + random.choice(self.jokes)) print (self.currentTime)
def parse_decide(self, msg, user): """ Chooses one random option """ short_user = user.split("!")[0] msg = irc.stripFormatting(msg).strip() choices = shlex.split(msg) if len(choices) < 3: self.irc_send_say("%s, please provide 2 or more options" % short_user) return del choices[0] self.irc_send_say("%s, the dice choose: %s" % (short_user, random.choice(choices)))
def check_msg(self, user, message): user = user.lower() if user == self.bot.nickname.lower() or user in self.user_whitelist: return False message = irc.stripFormatting(message) temp = re.sub(self.bot.nickname, "BOTNAME", message, flags=re.IGNORECASE) if any(pattern.search(temp) for pattern in self.msg_whitelist): return False return (self.check_msg_content(message) or self.check_spam(user, message) or self.check_mass_highlight(message))
def privmsg(self, user, channel, message): if not self.isArtChannel(channel): return message = irc.stripFormatting(message).lower() if self.isHelpCommand(message): self.printHelpMessage() elif self.isListTagsCommand(message): self.printTags() elif self.isPaintCommand(message): self.paintMessageByNumArgs(message)
def action(self, user, channel, data): """ called when a user does something in the channel """ logger.info("%s: user '%s' did '%s'", channel, user, data) short_user = user.split('!')[0] # did this involve the bot? action = irc.stripFormatting(data).lower() pos = action.find(self.nickname.lower()) if pos != -1: verb_clause = action[0:pos].lower().strip() if verb_clause == "hugs": # hug back after a delay reactor.callLater(1.0, self.irc_send_me, "hugs %s" % short_user)
def privmsg(self, user, channel, message): message = irc.stripFormatting(message) cmd, args = self._parse_message(channel, message) if cmd in self._commands: type, callback = self._commands[cmd] if self._valid_context(type, user, channel): nick = self.get_nick_from_user(user) try: callback(nick, *args) except TypeError: if not self._is_user_command(type, channel): self.msg(nick, callback.__doc__) else: for trigger, callback in self._content_triggers: if search(trigger, message) is not None: callback(user, channel, message)
def privmsg(self, user, channel, msg): father = self.check_for_daddy(user) msg = irc.stripFormatting(msg).strip() lowmsg = msg.lower() # handle !commands if lowmsg.startswith('!'): command = lowmsg.split(' ')[0] if command == "!startwar" or command == "!throwdown": self.parse_startwar(msg, user, command) elif command == "!starwar": self.parse_starwars(msg, user) elif command == "!echo": if father == 1: self.parse_echo(msg, user) elif command == "!do": if father == 1: self.parse_do(msg, user) elif command == "!status": self.wwMgr.get_status(user) elif command == "!time": self.irc_send_me("thinks the time is " + datetime.today().strftime('%Y-%m-%d %I:%M:%S %p')) elif command == "!joinwar": self.parse_join_wordwar(msg, user) elif command == "!leavewar" or command == "!forfeit" or command == "!surrender": self.parse_leave_wordwar(msg, user) elif command == "!help": self.print_usage(user) elif command == "!reloaddeath": load_death_and_prompt_arrays() elif command == "!rejoinroom": self.signedOn() elif command == "!leaveroom": if (father == 1): self.part_room() elif command == "!changevictim": self.parse_changevictim(msg, user) elif command == "!victim": if (father == 1): self.irc_send_msg(user, "The victim is currently: " + self.victim) elif command == "!prompt": prompt = getRandomPrompt() # if (self.check_for_daddy(user) == 1): # self.irc_send_say("Yes, father.") irc.IRCClient.say(self, channel, string.strip("Here's one: %s" % prompt)) elif command == "!decide": self.parse_decide(msg, user)
def _fields_from_yaml(self, name): path = os.path.join(self.log_dir, name) with open(path) as f: content = [] for element in yaml.full_load_all(f.read()): if element["levelname"] == "MSG": msg = irc.stripFormatting(element["message"]) content.append(msg) datestr = name.lstrip(self.channel + ".").rstrip(".yaml") try: date = datetime.strptime(datestr, "%Y-%m-%d") except ValueError: # default to today date = datetime.now() # U+2026 is "horizontal ellipsis" c = u"\u2026 ".join(content) return c, date
def _fields_from_yaml(self, name): path = os.path.join(self.log_dir, name) with open(path) as f: content = [] for element in yaml.load_all(f.read()): if element["levelname"] == "MSG": msg = irc.stripFormatting(element["message"]) if PY3: content.append(msg) else: content.append(msg.decode("utf-8", 'replace')) datestr = name.lstrip(self.channel + ".").rstrip(".yaml") try: date = datetime.strptime(datestr, "%Y-%m-%d") except ValueError: # default to today date = datetime.now() # U+2026 is "horizontal ellipsis" c = u"\u2026 ".join(content) return c, date
def burn(self, message, user_name, user_ip, nick): self.currentTime = time.time() items = message.split(" ") burn_name = "" if len(items) > 2: burn_name = irc.stripFormatting(message.split(" ")[2]) if len(items) == 2: self.msg(self.channel, choice(user_name) + ": " + choice(self.jokes)) elif burn_name.lower() == self.nickname.lower(): self.msg(self.channel, "Burn baby, burn.") elif burn_name.lower() == self.owner_name.lower(): self.msg(self.channel, 'Feel the burn') elif burn_name not in user_name: if user_ip == self.owner: self.msg(self.channel, burn_name + ": " + choice(self.jokes)) else: self.user_not_found(nick) elif burn_name in self.botList: self.anti_bot_burn(user_ip, burn_name, nick) else: self.msg(self.channel, burn_name + ": " + choice(self.jokes))
def privmsg(self, user, channel, message): timeRightNow = time.time() nick = user.split('!')[0] user_ip = user.split('@')[1] if message.startswith(self.nickname): if search(r'(^|\s)+ignore*(\s|$)+', message, IGNORECASE) and user_ip == self.owner: self.ignoreList.append(message.split(" ")[2]) elif search(r'(^|\s)+unignore*(\s|$)+', message, IGNORECASE) and user_ip == self.owner: self.ignoreList.remove(message.split(" ")[2]) elif timeRightNow - self.currentTime > 5: self.user_list = [ names for names in self.user_list if names not in self.botList ] if channel == self.nickname and user_ip != self.owner: return elif search(r"(^|\s)+say*(!|\?)*(\s|$)", message, IGNORECASE): if user_ip == self.owner: self.msg(self.channel, message.split('say ')[1]) elif nick in self.ignoreList: return elif search(r'(^|\s)+help*(\s|$)+', message, IGNORECASE): self.currentTime = time.time() self.msg( self.channel, "Just point me in the direction of who to burn :^). <warning>Be wary of whom/what you try to burn.</warning>" ) elif search(r"(^|\s)+burn*(!|\?)*(\s|$)", message, IGNORECASE): self.currentTime = time.time() items = message.split(" ") burn_name = "" if len(items) > 2: burn_name = irc.stripFormatting(message.split(" ")[2]) if len(items) == 2: self.msg( self.channel, random.choice(self.user_list) + ": " + random.choice(self.jokes)) elif burn_name.lower() == self.nickname.lower(): self.msg(self.channel, "Burn baby, burn.") elif burn_name.lower() == self.owner_name.lower(): self.msg(self.channel, 'Feel the burn') elif burn_name not in self.user_list: if user_ip == self.owner: self.msg( self.channel, burn_name + ": " + random.choice(self.jokes)) print burn_name else: self.msg( self.channel, "Error 69: User NOT FOUND. Prepare for ultimate burning. \n" + nick + ": " + random.choice(self.jokes)) elif burn_name in self.botList: if user_ip == self.owner: self.msg( self.channel, burn_name + ": " + random.choice(self.jokes)) else: self.msg( self.channel, "Silly human. Burns are for people. You looking to get burned " + nick + "?\n" + nick + ": " + random.choice(self.jokes)) else: self.msg(self.channel, burn_name + ": " + random.choice(self.jokes)) print self.currentTime
def privmsg(self, user, channel, msg): """Triggered by messages""" # strip '!' user, temp = user.split('!', 1) userhost = temp.split("@")[-1] channel = channel.lower() if channel in self.channelwatchers: for watcher in self.channelwatchers[channel]: watcher.msg(user, msg) # try if the user should be ignored if self.ignore_user(user): return # strip the formatting try: msg = irc.stripFormatting(msg) except AttributeError: # twisted < 13.1 pass msg = msg.strip() self.log.info("{channel} | {user} : {msg}", channel=channel, user=user, msg=msg) cmdmode = False # Commands pat = re.compile(r"^" + self.nickname + r"(:|,)?\s") if pat.search(msg): cmdmode = True index = 1 # Private Chat if channel == self.nickname.lower(): if not cmdmode: cmdmode = True index = 0 channel = user if cmdmode: temp = msg.split(" ")[index:] while temp[0] == "": temp.pop(0) command = temp[0] args = temp[1:] if command in self.commands: self.commands[command].send((args, user, userhost, channel)) else: self.log.debug("No such command: {cmd}", cmd=command) # Triggers matches = [(re.search(re.compile(regex.replace("$NICKNAME", self.nickname)), msg), gen) for regex, gen in self.triggers.items()] # filter out empty matches matches = [gen for match, gen in matches if match] # send message to generator functions for gen in matches: gen.send((msg, user, userhost, channel)) if self.config["Simple Triggers"]: triggers = self.config["Simple Triggers"] # options in ini are automatically converted to lower case # adjust $NICKNAME matches = [trigger for trigger in triggers if re.search(re.compile(trigger["trigger"].replace( "$nickname", self.nickname), re.IGNORECASE), msg)] for trigger in matches: self.simple_trigger.send((trigger, user, userhost, channel))
def handleMessage(self, user, channel, msgText, type='say'): """Called when the bot receives a message, which can be either in a channel or in a private message, as text or an action.""" message = IrcMessage(irc.stripFormatting(msgText), self, type, user, channel) #Let the CommandHandler see if something needs to be said GlobalStore.commandhandler.fireCommand(message)
def privmsg(self, user, channel, msg): """Triggered by messages""" # strip '!' print user user, temp = user.split('!', 1) userhost = temp.split("@")[-1] # try if the user should be ignored if self.ignore_user(user): return print("%s - %s : %s" % (user, channel, msg)) # strip the formatting try: msg = irc.stripFormatting(msg) except AttributeError: # twisted < 13.1 pass msg = msg.strip() cmdmode = False # Commands pat = re.compile(ur"^" + self.nickname + ur"(:|,)?\s") if pat.search(msg): cmdmode = True index = 1 # Private Chat if channel == self.nickname: if not cmdmode: cmdmode = True index = 0 channel = user if cmdmode: command = msg.split()[index] args = msg.split(" ")[index+1:] if args: while args[0] == "": args.pop(0) if command in self.commands: self.commands[command].send((args, user, userhost, channel)) else: print("No such command: %s" % command) # Triggers matches = [(re.search(re.compile(regex.replace("$NICKNAME", self.nickname)), msg), gen) for regex, gen in self.triggers.iteritems()] # filter out empty matches matches = [gen for match, gen in matches if match] # send message to generator functions for gen in matches: gen.send((msg, user, userhost, channel)) if self.cm.has_section("Simple Triggers"): triggers = self.cm.options("Simple Triggers") # options in ini are automatically converted to lower case # adjust $NICKNAME matches = [trigger for trigger in triggers if re.search(re.compile(trigger.replace("$nickname", self.nickname), re.IGNORECASE), msg)] for trigger in matches: self.simple_trigger.send((trigger, user, userhost, channel))
def privmsg(self, user, channel, msg): """Triggered by messages""" # strip '!' user, temp = user.split('!', 1) userhost = temp.split("@")[-1] channel = channel.lower() if channel in self.channelwatchers: for watcher in self.channelwatchers[channel]: watcher.msg(user, msg) # try if the user should be ignored if self.ignore_user(user): return # strip the formatting try: msg = irc.stripFormatting(msg) except AttributeError: # twisted < 13.1 pass msg = msg.strip() self.log.info("{channel} | {user} : {msg}", channel=channel, user=user, msg=msg) cmdmode = False # Commands pat = re.compile(r"^" + self.nickname + r"(:|,)?\s") if pat.search(msg): cmdmode = True index = 1 # Private Chat if channel == self.nickname.lower(): if not cmdmode: cmdmode = True index = 0 channel = user if cmdmode: temp = msg.split(" ")[index:] while temp[0] == "": temp.pop(0) command = temp[0] args = temp[1:] if command in self.aliases: args = self.aliases[command].arguments.copy() while "$USER" in args: index = args.index("$USER") args[index] = user # replace $ARGS with arguments from command if "$ARGS" in args: index = args.index("$ARGS") args.remove("$ARGS") for arg in temp[-1:0:-1]: args.insert(index, arg) command = self.aliases[command].command if command in self.commands: self.commands[command].send((args, user, userhost, channel)) else: self.log.debug("No such command: {cmd}", cmd=command) # Triggers matches = [ (re.search(re.compile(regex.replace("$NICKNAME", self.nickname)), msg), gen) for regex, gen in self.triggers.items() ] # filter out empty matches matches = [gen for match, gen in matches if match] # send message to generator functions for gen in matches: gen.send((msg, user, userhost, channel)) if self.config["Simple Triggers"]: triggers = self.config["Simple Triggers"] # options in ini are automatically converted to lower case # adjust $NICKNAME matches = [ trigger for trigger in triggers if re.search( re.compile( trigger["trigger"].replace("$nickname", self.nickname), re.IGNORECASE), msg) ] for trigger in matches: self.simple_trigger.send((trigger, user, userhost, channel))