def _on_pubmsg(self, conn, event): message = event.args[0] message = re.sub("<\S+>", "", message) match = re.match("\s*(\S+)\s*[,:]\s*(.*?)\s*$", message) if match: to = match.group(1) text = match.group(2) else: to = None text = message speaker = nm_to_n(event.source) m = re.search("\\bw(oo+)s?\\b([!.?,])?", text.lower()) # forecast is 70% chance of woo chance = 0.7 if m and random.random() < chance: punc = {"!" : "!", "." : ".", "?" : "!"} woo = "w%s%s" % (m.group(1), punc.get(m.group(2), "")) if random.random() < 0.1: # be extra vocal sometimes woo = "w%s%s" % (m.group(1)*2, punc.get(m.group(2), "")) conn.privmsg(event.target, woo)
def _on_join(self, c, e): ch = e.target nick = nm_to_n(e.source) user = self.bot.ircdb.get_user(nickmask=e.source) if not user: return uperms = user.get_perms() ## first do any invites #channels = self.bot.ircdb.channels #for chan_name, chan_obj in channels.items(): # #self.bot.log(9, 'irc._on_join: checking %s' % chan_name) # if not chan_obj.is_invite_only(): continue # #self.bot.log(9, 'irc._on_join: %s is invite-only' % chan_name) # if chan_obj.has_user(nick): continue # #self.bot.log(9, 'irc._on_join: %s is not on %s' % (nick, chan_name)) # context = {'bot': self.bot, 'channel': 'NONE', 'target': chan_name} # if self._invite_cperm.trycheck(uperms, context): # self.bot.log(3, 'IRC: inviting %s to %s' \ # % (user.userid, chan_name)) # c.invite(nick, chan_name) # give ops if not self._i_have_op(ch): return context = {'bot': self.bot, 'channel': 'NONE', 'target': ch} if self._autoop_cperm.trycheck(uperms, context): self.bot.log(3, 'IRC: op-ing %s on %s' % (user.userid, ch)) c.mode(ch, '+o '+nick)
def _on_command_not_found(self, c, e): if not e.raw.channel == None: channel = e.raw.channel speaker = nm_to_n(e.source) question = e.raw.cmd + " " + e.raw.args self._handle_question(c, channel, speaker, question) else: e.raw.reply("[Magic3PiBall] Address me on the channel.") return "NO MORE"
def _on_invite(self, c, e): channel = e.args[0] nick = nm_to_n(e.source) user = self.bot.ircdb.get_user(nickmask=e.source) if not user: return uperms = user.get_perms() context = {'bot': self.bot, 'channel': 'NONE'} if self._join_cperm.trycheck(uperms, context): self.bot.conn.join(channel)
def _on_join(self, c, e): channel = e.target nick = nm_to_n(e.source) if nick == self.bot.nick: self.log(6,"_on_join(...)") if not channel in self.MD.status.channels: self._add_channel(channel) else: self.log(4,"_on_join(): %s channel tree already exists" % (channel)) self.log(4, str(self.MD.status.channels))
def _on_pubmsg(self, conn, event): import string, re message = event.args[0] message = re.sub("<\S+>", "", message) match = re.match('"(.*)" --\S+, \d+-\S+\d+.', message) if match: message = match.group(1) match = re.match("\s*(\S+)\s*[,:]\s*(.*?)\s*$", message) if match: to = match.group(1) text = match.group(2) else: to = None text = message speaker = nm_to_n(event.source) # drop any extra whitespace in the string text = string.join(string.split(text), " ") user = self.bot.ircdb.get_user(nickmask=event.source) if user is not None: uperms = list(user.get_perms()) else: uperms = list(self.bot.permdb.get_unknown_perms()) uperms.append(self._nolearn_uperm) if "ignore" in uperms: return "NO MORE" # convert text to Unicode text = text.decode("utf-8") # if spoken to directly, generate a reply if str(to).lower() == self.bot.nick.lower(): self._brain.learn(text) reply = self._brain.reply(text) # convert to utf-8 for output reply = reply.encode("utf-8") conn.privmsg(event.target, "%s: %s" % (speaker, reply)) else: self._brain.learn(text) return "NO MORE"
def _on_pubmsg(self, c, e): args = string.split(e.args[0]) if args[0] == "%s:" % (self.bot.nick): return channel = e.target speaker = nm_to_n(e.source) if (args[0] == self.settings["qprefix"]): self.log(6,"_on_pubmsg(...): analyzing %s's question" % (speaker)) question = string.join(args[1:]) self._handle_question(c, channel, speaker, question) elif random.random() > self.settings["global_match_threshold"]: self.log(6,"_on_pubmsg(...): analyzing %s's message" % (speaker)) self._handle_match(c, channel, speaker, e.args[0]) return
def _on_permission_denied(self, c, e): if not e.raw.channel == None: channel = e.raw.channel speaker = nm_to_n(e.source) language = self._get_spoken_language(channel) if language == None or not language in self.MD.languages: self.log(4,"_on_permission_denied(): bad spoken language %s -- aborting" % (language)) return context = \ self.MD.languages[language].answers.special.permission_denied if len(context) > 0: answer = self._format_text(channel, speaker, random.choice(context.dir())) c.privmsg(channel, answer) else: c.privmsg(current, "No can do.") else: e.raw.reply("[Magic3PiBall] Address me on the channel.") return "NO MORE"
def _do_command(self, nm, channel, command, connection, event): """called by the pubmsg and privmsg handlers creates the reply object and command object, and passes it on to _run()""" self.bot.log(3, 'COMMAND: %s, %s, %s' % (nm, channel, command)) if isinstance(connection, DirectConnection): #nick = '!'+nm # the '!' marks it as direct - it's hard to # # get one in a REAL irc nick :) nick = nm # nickmask now starts with '!' reply = DirectConnectionReply(nick=nick, channel=channel, connection=connection) else: nick = nm_to_n(nm) reply = IRCReply(nick=nick, channel=channel, connection=connection) com, args = self._cmd_split(command) cmd = Command(bot=self.bot, nick=nick, nickmask=nm, channel=channel, connection=connection, cmd=com, args=args, _reply_object=reply, event=event) self._run(cmd)
def _on_part(self, c, e): channel = e.target nick = nm_to_n(e.source) if nick == self.bot.nick: self.log(6,"_on_part(...)") self._delete_channel(channel)
if m.group("prefix"): prefix = m.group("prefix") if not self.real_server_name: self.real_server_name = prefix if m.group("command"): command = string.lower(m.group("command")) if m.group("argument"): a = string.split(m.group("argument"), " :", 1) arguments = string.split(a[0]) if len(a) == 2: arguments.append(a[1]) if command == "nick": if nm_to_n(prefix) == self.real_nickname: self.real_nickname = arguments[0] if command in ["privmsg", "notice"]: target, message = arguments[0], arguments[1] messages = _ctcp_dequote(message) if command == "privmsg": if is_channel(target): command = "pubmsg" else: if is_channel(target): command = "pubnotice" else: command = "privnotice"