def kick(self, cmd): """kick a user from a channel irc.kick [channel] nick(s) [comment] """ args = cmd.shsplit() channel = cmd.channel # default channel comment = "have a nice day!" ircdb = self.bot.ircdb nicks = [] if args and is_channel(args[0]): channel = args.pop(0) while args: if ircdb.users.has_key(args[0]): nicks.append(args.pop(0)) else: break if args: comment = ' '.join(args) if comment.startswith('comment='): comment = comment[8:] if not channel: cmd.reply("What channel?") return elif not self._i_have_op(channel): cmd.reply("I don't have ops on %s" % channel) return chan_obj = self.bot.ircdb.channels[channel] chnicks = chan_obj.users() chopers = chan_obj.opers() for nick in nicks: if nick not in chnicks: cmd.reply("There is no %s on %s" % (nick, channel)) else: self.bot.conn.kick(channel, nick, comment)
def kick(self, cmd): """kick a user from a channel irc.kick [channel] nick(s) [comment] """ args = cmd.shsplit() channel = cmd.channel # default channel comment = "have a nice day!" ircdb = self.bot.ircdb nicks = [] if args and is_channel(args[0]): channel = args.pop(0) while args: if ircdb.users.has_key(args[0]): nicks.append(args.pop(0)) else: break if args: comment = ' '.join(args) if comment.startswith('comment='): comment = comment[8:] if not channel: cmd.reply("What channel?") return elif not self._i_have_op(channel): cmd.reply("I don't have ops on %s" % channel) return chan_obj = self.bot.ircdb.channels[channel] chnicks = chan_obj.users() for nick in nicks: if nick not in chnicks: cmd.reply("There is no %s on %s" % (nick, channel)) else: self.bot.conn.kick(channel, nick, comment)
def op(self, cmd): """give ops to someone irc.op [channel] [nick(s)] """ args = cmd.asplit() channel = cmd.channel # default channel if args and is_channel(args[0]): channel = args.pop(0) if not channel: cmd.reply("What channel?") return elif not self._i_have_op(channel): cmd.reply("I don't have ops on %s" % channel) return if args: nicks = args else: nicks = [cmd.nick] chan_obj = self.bot.ircdb.channels[channel] chnicks = chan_obj.users() chopers = chan_obj.opers() for nick in nicks: if nick not in chnicks: cmd.reply("There is no %s on %s" % (nick, channel)) elif nick in chopers: cmd.reply("%s already has ops on %s" % (nick, channel)) else: self.bot.conn.mode(channel, '+o '+nick)
def nnotice(self, *args): """same as nreply, but with notice instead of privmsg""" target, message = self._get_target_and_message(args) if is_channel(target): message = '%s: %s' % (self.nick, message) if hasattr(self, "bot"): self.bot.log(7, "NoReply.nnotice: %s: %s" % (target, message))
def nreply(self, *args): """same as reply, but if it's a public response, the user's nick (the one who typed the command) is prepended""" target, message = self._get_target_and_message(args) if is_channel(target): message = '%s: %s' % (self.nick, message) if hasattr(self, "bot"): self.bot.log(7, "NoReply.nreply: %s: %s" % (target, message))
def _on_mode(self, c, e): mynick = self.bot.nick modes = parse_channel_modes(' '.join(e.args)) t = e.target if is_channel(t): if not self._i_have_op(t): return for sign, mode, nick in modes: if sign == "+" and mode == "o" and nick == mynick: self._check_all(c, t)
def _on_mode(self, c, e): mynick = self.bot.nick modes = parse_channel_modes(string.join(e.args)) t = e.target if is_channel(t): if not self._i_have_op(t): return for sign, mode, nick in modes: if sign == "+" and mode == "o" and nick == mynick: self._check_all(c, t)
def _notify(self, target, new): if is_channel(target): if not target in self.bot.ircdb.channels.keys(): return else: if not target in self.bot.ircdb.users.keys(): return for art in new: self.bot.conn.privmsg(target, "Slashdot: %s" % art)
def check_target(self, userperms, context, best_match): try: target = context['target'] except KeyError: if context.has_key('cmd'): args = context['cmd'].asplit() channel = context['cmd'].channel if args and is_channel(args[0]): target = args[0] else: target = channel else: target = None if not target: return 0 if target == 'NONE': return 1 uperm = userperms[best_match] try: checklist = uperm.misc[0] except IndexError, e: checklist = uperm.channels return self.check_globlist(checklist, target)
def join(self, cmd): """tell the bot to join a channel irc.join <channel> """ if self.bot.ircdb.channels.has_key(cmd.args): cmd.reply("I'm already on that channel") elif not is_channel(cmd.args): cmd.reply("that's not a legal channel") else: args = cmd.asplit() channel = args[0] key = None if len(args) > 2: cmd.reply("too many arguments") elif len(args) == 2: key = args[1] self.bot.conn.join(channel, key)
def invite(self, cmd): """invite a user to an invite-only channel irc.invite [channel] [nick(s)] """ args = cmd.asplit() channel = cmd.channel # default channel if args and is_channel(args[0]): channel = args.pop(0) if not channel: cmd.reply("What channel?") return if args: nicks = args else: nicks = [cmd.nick] chan_obj = self.bot.ircdb.channels[channel] chnicks = chan_obj.users() for nick in nicks: if nick in chnicks: cmd.reply("%s is already on %s" % (nick, channel)) else: self.bot.conn.invite(nick, channel)
def join(self, cmd): """tell the bot to join a channel irc.join <channel> """ if self.bot.ircdb.channels.has_key(cmd.args): cmd.reply("I'm already on that channel") elif not is_channel(cmd.args): cmd.reply("that's not a legal channel") else: args = cmd.asplit() channel = args[0] key = None if len(args) > 2: cmd.reply("too many arguments") elif len(args) == 2: key = args[1] if key is not None: self.bot.conn.join(channel, key) else: self.bot.conn.join(channel)
def nnotice(self, *args): """same as nreply, but with notice instead of privmsg""" target, message = self._get_target_and_message(args) if is_channel(target): message = '%s: %s' % (self.nick, message) self.connection.notice(target, message)
def nreply(self, *args): """same as reply, but if it's a public response, the user's nick (the one who typed the command) is prepended""" target, message = self._get_target_and_message(args) if is_channel(target): message = '%s: %s' % (self.nick, message) self.connection.privmsg(target, message)
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" for m in messages: if type(m) is types.TupleType: if command in ["privmsg", "pubmsg"]: command = "ctcp" else: command = "ctcpreply" m = list(m)