Example #1
0
    def cmd_ban(self, context):
        if not context.channel:
            returnValue("Run this command in a channel (or specify a channel name after the command).")
        if len(context.args) < 1:
            returnValue("You must specify a mask to ban.")
        mask = context.args[0]
        reason = " ".join(context.args[1:])

        if "!" not in mask:
            for u in context.channel.users.values():
                if mask.lower() == u.name.lower():
                    mask = "*!*@{}".format(u.hostname)
        if "!" not in mask:
            returnValue("{} is neither a nick!user@host mask nor the name of a user on the channel.".format(mask))

        banned = yield self.track_ban(context.channel, context.user.name, mask, reason)
        kb = False
        for u in context.channel.users.values():
            if matches(mask, u.hostmask):
                kb = True
                self.op.kick(
                    context.channel.name,
                    u.name,
                    "Banned by {}".format(context.user.name) + (": {}".format(reason) if reason else ""),
                )

        if kb:
            self.trim_bans(context.channel, 1)
            self.op.mode(context.channel.name, "b", True, mask)
            self.op.run_queue(context.channel)
        else:
            if banned:
                returnValue("{} banned successfully.".format(mask))
            else:
                returnValue("{} was already banned.".format(mask))
Example #2
0
 def _kick_banned(self, channel, mask, banner, reason=None):
     for name, user in channel.users.items():
         if matches(mask, user.hostmask):
             self.op.kick(
                 str(channel), user.name, 'Banned by {}'.format(banner) +
                 (': {}'.format(reason) if reason else ''))
     self.op.run_queue(channel)
     self.wait.remove(mask)
Example #3
0
 def _kick_banned(self, channel, mask, banner, reason=None):
     for name, user in channel.users.items():
         if matches(mask, user.hostmask):
             self.op.kick(
                 str(channel), user.name, "Banned by {}".format(banner) + (": {}".format(reason) if reason else "")
             )
     self.op.run_queue(channel)
     self.wait.remove(mask)
Example #4
0
 def on_UserKicked(self, event):
     banner = None
     message = event.message
     if event.kicker.name == "ChanServ":
         m = re.match(r"\((.*?)\) (.*)", message)
         if m: banner, message = m.groups()
     for mask in self.wait:
         if event.kickee.hostmask and matches(mask, event.kickee.hostmask):
             self.update_ban(mask, message, banner)
Example #5
0
 def on_UserKicked(self, event):
     banner = None
     message = event.message
     if event.kicker.name == "ChanServ":
         m = re.match(r"\((.*?)\) (.*)", message)
         if m:
             banner, message = m.groups()
     for mask in self.wait:
         if event.kickee.hostmask and matches(mask, event.kickee.hostmask):
             self.update_ban(mask, message, banner)
Example #6
0
    def cmd_unban(self, context):
        if not context.channel:
            returnValue(
                "Run this command in a channel (or specify a channel name after the command)."
            )
        if len(context.args) < 1:
            returnValue("You must specify a mask to unban.")

        mask = context.args[0]
        if '!' in mask:
            complain = True
            if mask.lower() in set(b[0].lower() for b in context.channel.bans):
                self.op.mode(context.channel.name, 'b', False, str(mask))
                self.op.run_queue(context.channel)
                complain = False
            removed = yield self.remove_ban(context.args[0],
                                            context.channel.name)
            if complain:
                if removed:
                    returnValue("Forgot ban for {}.".format(context.args[0]))
                else:
                    returnValue("Mask is not in ban database.")
        else:
            nick = mask
            complain = True

            data = yield self.bot.irc.whois(mask)
            if not data:
                returnValue("No suck nickname: {}".format(nick))
            mask = "{0}!{user}@{host}".format(nick, **data)
            bans = [
                mask_ for mask_, setter, time in context.channel.bans
                if matches(mask_, mask)
            ]
            for b in bans:
                complain = False
                self.op.mode(context.channel.name, 'b', False, str(b))
            if bans: self.op.run_queue(context.channel)

            ban = yield self.find_ban(context.channel.name, mask)
            if ban:
                self.remove_ban(ban.banmask, context.channel.name)
                if complain:
                    returnValue("Forgot ban for {}.".format(ban.banmask))
            elif complain:
                returnValue("User not banned.")
Example #7
0
    def cmd_unban(self, context):
        if not context.channel:
            returnValue("Run this command in a channel (or specify a channel name after the command).")
        if len(context.args) < 1:
            returnValue("You must specify a mask to unban.")

        mask = context.args[0]
        if "!" in mask:
            complain = True
            if mask.lower() in set(b[0].lower() for b in context.channel.bans):
                self.op.mode(context.channel.name, "b", False, str(mask))
                self.op.run_queue(context.channel)
                complain = False
            removed = yield self.remove_ban(context.args[0], context.channel.name)
            if complain:
                if removed:
                    returnValue("Forgot ban for {}.".format(context.args[0]))
                else:
                    returnValue("Mask is not in ban database.")
        else:
            nick = mask
            complain = True

            data = yield self.bot.irc.whois(mask)
            if not data:
                returnValue("No suck nickname: {}".format(nick))
            mask = "{0}!{user}@{host}".format(nick, **data)
            bans = [mask_ for mask_, setter, time in context.channel.bans if matches(mask_, mask)]
            for b in bans:
                complain = False
                self.op.mode(context.channel.name, "b", False, str(b))
            if bans:
                self.op.run_queue(context.channel)

            ban = yield self.find_ban(context.channel.name, mask)
            if ban:
                self.remove_ban(ban.banmask, context.channel.name)
                if complain:
                    returnValue("Forgot ban for {}.".format(ban.banmask))
            elif complain:
                returnValue("User not banned.")
Example #8
0
    def cmd_ban(self, context):
        if not context.channel:
            returnValue(
                "Run this command in a channel (or specify a channel name after the command)."
            )
        if len(context.args) < 1:
            returnValue("You must specify a mask to ban.")
        mask = context.args[0]
        reason = ' '.join(context.args[1:])

        if '!' not in mask:
            for u in context.channel.users.values():
                if mask.lower() == u.name.lower():
                    mask = "*!*@{}".format(u.hostname)
        if '!' not in mask:
            returnValue(
                "{} is neither a nick!user@host mask nor the name of a user on the channel."
                .format(mask))

        banned = yield self.track_ban(context.channel, context.user.name, mask,
                                      reason)
        kb = False
        for u in context.channel.users.values():
            if matches(mask, u.hostmask):
                kb = True
                self.op.kick(
                    context.channel.name, u.name,
                    'Banned by {}'.format(context.user.name) +
                    (': {}'.format(reason) if reason else ''))

        if kb:
            self.trim_bans(context.channel, 1)
            self.op.mode(context.channel.name, 'b', True, mask)
            self.op.run_queue(context.channel)
        else:
            if banned:
                returnValue("{} banned successfully.".format(mask))
            else:
                returnValue("{} was already banned.".format(mask))
Example #9
0
    def on_UserChangingNick(self, event):
        for channel in event.user.channels:
            if channel.name not in self.channels: continue

            user = channel.getOrCreateUser(event.user.name)

            for mask, setter, time in channel.bans:
                if matches(mask, event.user.hostmask):

                    def inner(b):
                        if b:
                            self.op.kick(
                                channel.name, user.name, 'Banned by {}'.format(
                                    str(b.banner) +
                                    (': {}'.format(b.reason) if b.
                                     reason else '')))
                        else:
                            self.op.kick(channel.name, user.name,
                                         'Banned by {}'.format(setter))
                        self.op.run_queue(channel)

                    b = self.find_ban(channel.name, user.hostmask)
                    b.addCallback(inner)
                    return

            b = self.find_ban(channel.name, user.hostmask)

            def inner(b):
                if not b: return

                self.trim_bans(channel, 1)
                self.op.mode(channel.name, 'b', True, str(b.banmask))
                self.op.kick(channel.name, user.name,
                             'Banned by {}'.format(str(b.banner)))
                self.op.run_queue(channel)

            b.addCallback(inner)
Example #10
0
    def on_UserChangingNick(self, event):
        for channel in event.user.channels:
            if channel.name not in self.channels:
                continue

            user = channel.getOrCreateUser(event.user.name)

            for mask, setter, time in channel.bans:
                if matches(mask, event.user.hostmask):

                    def inner(b):
                        if b:
                            self.op.kick(
                                channel.name,
                                user.name,
                                "Banned by {}".format(str(b.banner) + (": {}".format(b.reason) if b.reason else "")),
                            )
                        else:
                            self.op.kick(channel.name, user.name, "Banned by {}".format(setter))
                        self.op.run_queue(channel)

                    b = self.find_ban(channel.name, user.hostmask)
                    b.addCallback(inner)
                    return

            b = self.find_ban(channel.name, user.hostmask)

            def inner(b):
                if not b:
                    return

                self.trim_bans(channel, 1)
                self.op.mode(channel.name, "b", True, str(b.banmask))
                self.op.kick(channel.name, user.name, "Banned by {}".format(str(b.banner)))
                self.op.run_queue(channel)

            b.addCallback(inner)