Esempio n. 1
0
    def _slot(self, lastItem):
        irc = lastItem.irc
        msg = lastItem.msg
        channel = lastItem.channel
        prefix = lastItem.prefix
        nick = prefix.split('!')[0]
        kind = lastItem.kind

        try:
            ircdb.users.getUser(msg.prefix)  # May raise KeyError
            capability = self.registryValue('exempt')
            if capability:
                if ircdb.checkCapability(msg.prefix, capability):
                    return
        except KeyError:
            pass
        punishment = self.registryValue('%s.punishment' % kind, channel)
        reason = _('%s flood detected') % kind
        if punishment == 'kick':
            msg = ircmsgs.kick(channel, nick, reason)
            irc.queueMsg(msg)
        elif punishment == 'ban':
            msg = ircmsgs.ban(channel, prefix)
            irc.queueMsg(msg)
        elif punishment == 'kban':
            msg = ircmsgs.kick(channel, nick, reason)
            irc.queueMsg(msg)
            msg = ircmsgs.ban(channel, prefix)
            irc.queueMsg(msg)
        elif punishment.startswith('mode'):
            msg = ircmsgs.mode(channel, punishment[len('mode'):])
            irc.queueMsg(msg)
        elif punishment.startswith('command '):
            tokens = callbacks.tokenize(punishment[len('command '):])
            self.Proxy(irc, msg, tokens)
Esempio n. 2
0
    def _slot(self, lastItem):
        irc = lastItem.irc
        msg = lastItem.msg
        channel = lastItem.channel
        prefix = lastItem.prefix
        nick = prefix.split('!')[0]
        kind = lastItem.kind

        try:
            ircdb.users.getUser(msg.prefix) # May raise KeyError
            capability = self.registryValue('exempt')
            if capability:
                if ircdb.checkCapability(msg.prefix, capability):
                    return
        except KeyError:
            pass
        punishment = self.registryValue('%s.punishment' % kind, channel)
        reason = _('%s flood detected') % kind
        if punishment == 'kick':
            msg = ircmsgs.kick(channel, nick, reason)
            irc.queueMsg(msg)
        elif punishment == 'ban':
            msg = ircmsgs.ban(channel, prefix)
            irc.queueMsg(msg)
        elif punishment == 'kban':
            msg = ircmsgs.kick(channel, nick, reason)
            irc.queueMsg(msg)
            msg = ircmsgs.ban(channel, prefix)
            irc.queueMsg(msg)
        elif punishment.startswith('mode'):
            msg = ircmsgs.mode(channel, punishment[len('mode'):])
            irc.queueMsg(msg)
        elif punishment.startswith('command '):
            tokens = callbacks.tokenize(punishment[len('command '):])
            self.Proxy(irc, msg, tokens)
Esempio n. 3
0
 def testBan(self):
     channel = '#osu'
     ban = '*!*@*.edu'
     exception = '*!*@*ohio-state.edu'
     noException = ircmsgs.ban(channel, ban)
     self.assertEqual(ircutils.separateModes(noException.args[1:]),
                      [('+b', ban)])
     withException = ircmsgs.ban(channel, ban, exception)
     self.assertEqual(ircutils.separateModes(withException.args[1:]),
                      [('+b', ban), ('+e', exception)])
Esempio n. 4
0
 def testBan(self):
     channel = '#osu'
     ban = '*!*@*.edu'
     exception = '*!*@*ohio-state.edu'
     noException = ircmsgs.ban(channel, ban)
     self.assertEqual(ircutils.separateModes(noException.args[1:]),
                      [('+b', ban)])
     withException = ircmsgs.ban(channel, ban, exception)
     self.assertEqual(ircutils.separateModes(withException.args[1:]),
                      [('+b', ban), ('+e', exception)])
Esempio n. 5
0
    def _slot(self, lastItem):
        irc = lastItem.irc
        msg = lastItem.msg
        channel = lastItem.channel
        prefix = lastItem.prefix
        nick = prefix.split('!')[0]
        kind = lastItem.kind

        if not ircutils.isChannel(channel):
                return
        if not self.registryValue('enable', channel):
            return

        try:
            ircdb.users.getUser(msg.prefix) # May raise KeyError
            capability = self.registryValue('exempt')
            if capability:
                if ircdb.checkCapability(msg.prefix,
                        ','.join([channel, capability])):
                    self.log.info('Not punishing %s: they are immune.' %
                            prefix)
                    return
        except KeyError:
            pass
        punishment = self.registryValue('%s.punishment' % kind, channel)
        reason = _('%s flood detected') % kind

        if punishment == 'kick':
            self._eventCatcher(irc, msg, 'kicked', kicked_prefix=prefix)
        if kind == 'kicked':
            reason = _('You exceeded your kick quota.')

        banmaskstyle = conf.supybot.protocols.irc.banmask
        banmask = banmaskstyle.makeBanmask(prefix)
        if punishment == 'kick':
            msg = ircmsgs.kick(channel, nick, reason)
            irc.queueMsg(msg)
        elif punishment == 'ban':
            msg = ircmsgs.ban(channel, banmask)
            irc.queueMsg(msg)
        elif punishment == 'kban':
            msg = ircmsgs.ban(channel, banmask)
            irc.queueMsg(msg)
            msg = ircmsgs.kick(channel, nick, reason)
            irc.queueMsg(msg)
        elif punishment.startswith('mode'):
            msg = ircmsgs.mode(channel, punishment[len('mode'):])
            irc.queueMsg(msg)
        elif punishment.startswith('umode'):
            msg = ircmsgs.mode(channel, (punishment[len('umode'):], nick))
            irc.queueMsg(msg)
        elif punishment.startswith('command '):
            tokens = callbacks.tokenize(punishment[len('command '):])
            self.Proxy(irc, msg, tokens)
 def doPrivmsg(self, irc, msg):
     channel, text = msg.args
     text = text.lower()
     if '#' in channel:
         #print self.regex
         #irc.reply('testing %s against %s' % (text, self._regexString))
         if self.regex.match(text):
             try:
                 hostmask = irc.state.nickToHostmask(msg.nick)
             except KeyError:
                 return
             (nick, user, host) = ircutils.splitHostmask(hostmask)
             user = self._fnUser.sub('*', user)
             banmask = ircutils.joinHostmask('*', user, msg.host)
             if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
                 return
             irc.queueMsg(ban(channel, banmask, 'For swearing. 5 minute timeout'))
             irc.queueMsg(kick(channel, msg.nick, 'For swearing'))
             def unBan():
                 if channel in irc.state.channels and \
                    banmask in irc.state.channels[channel].bans:
                     irc.queueMsg(unban(channel, banmask))
             schedule.addEvent(unBan, time.time()+300)
         elif 'f*g' in text.split():
             try:
                 hostmask = irc.state.nickToHostmask(msg.nick)
             except KeyError:
                 return
             (nick, user, host) = ircutils.splitHostmask(hostmask)
             irc.reply('No thanks %s I don\'t smoke' % user)
     return msg
Esempio n. 7
0
	def saveLast(self,irc,msg,match):
		r".+"
		channel = msg.args[0]

		try: self.buffer[channel]
		except: self.buffer[channel]=[]

# Stuff for multikick
		if channel in self.kickuser:
			for each in self.kickuser[channel]:
				if each in msg.nick.lower() and not self.kickuser[channel][each]['num'] <= 0:
					irc.queueMsg(ircmsgs.ban(msg.args[0], msg.nick))
					irc.queueMsg(ircmsgs.kick(msg.args[0], msg.nick, "{}".format(self.kickuser[channel][each]['msg'].replace('#n',str(self.kickuser[channel][each]['num'])))))
					self.kickuser[channel][each]['num']-=1
					def un():
						irc.queueMsg(ircmsgs.unban(msg.args[0],msg.nick))
					schedule.addEvent(un,time.time()+random.randint(10,60)) # 30,120
# END
		line = match.group(0).replace('\x01ACTION','*').strip('\x01')

		if msg.nick.lower() in self.annoyUser:
			def fu():
				irc.queueMsg(ircmsgs.IrcMsg('NOTICE {} :\x02\x03{},{}{}'.format(msg.nick,random.randint(0,15),random.randint(0,15),line)))
			schedule.addEvent(fu,time.time()+random.randint(2,60))

		if re.match(r"^u[/].*[/].*[/].*$", match.group(0)) or re.match(r"^s[/].*[/].*$", match.group(0)):
			return 1
		self.buffer[channel].insert(0,[msg.nick,line])
		if len(self.buffer[channel]) > self.buffsize: self.buffer[channel].pop(self.buffsize)
		return 1
Esempio n. 8
0
	def floodPunish(self, irc, msg, floodType, dummy = False):
		channel = msg.args[0]

		if (not irc.nick in irc.state.channels[channel].ops) and\
		   (not irc.nick in irc.state.channels[channel].halfops):
			self.log.warning("%s flooded in %s, but not opped.",\
				msg.nick, channel)
			return

		if msg.nick in self.immunities:
			self.log.debug("Not punnishing %s, they are immune.",
				msg.nick)
			return

		if msg.nick in irc.state.channels[channel].ops or\
		   msg.nick in irc.state.channels[channel].halfops or\
		   msg.nick in irc.state.channels[channel].voices:
			self.log.debug("%s flooded in %s. But"\
				+ " I will not punish them because they have"\
				+ " special access.", msg.nick, channel)
			return

		if ircdb.checkCapability(msg.prefix, 'trusted') or\
		   ircdb.checkCapability(msg.prefix, 'admin') or\
		   ircdb.checkCapability(msg.prefix, channel + ',op'):
			self.log.debug("%s flooded in %s. But"\
				+ " I will not punish them because they are"\
				+ " trusted.", msg.nick, channel)
			return

		if msg.host in self.offenses and self.offenses[msg.host] > 2:
			hostmask = irc.state.nickToHostmask(msg.nick)
			banmaskstyle = conf.supybot.protocols.irc.banmask
			banmask = banmaskstyle.makeBanmask(hostmask)
			if not dummy:
				irc.queueMsg(ircmsgs.ban(channel, banmask))
			self.log.warning("Banned %s (%s) from %s for repeated"\
				+ " flooding.", banmask, msg.nick, channel)

		reason = floodType + " flood detected."
		if floodType == "Paste":
			reason += " Use a pastebin like pastebin.ubuntu.com or gist.github.com."

		if not dummy:
			irc.queueMsg(ircmsgs.kick(channel, msg.nick, reason))

		self.log.warning("Kicked %s from %s for %s flooding.",\
				msg.nick, channel, floodType)

		# Don't schedule the same nick twice
		if not (msg.host in self.offenses):
			schedule.addEvent(self.clearOffenses, time.time()+300,
					args=[msg.host])
			self.offenses[msg.host] = 0 # Incremented below
		self.offenses[msg.host] += 1

		self.immunities[msg.nick] = True
		schedule.addEvent(self.unImmunify, time.time()+3,
				args=[msg.nick])
Esempio n. 9
0
 def doBan():
     irc.queueMsg(ircmsgs.ban(channel, banmask))
     if expiry > 0:
         def f():
             if channel in irc.state.channels and \
                banmask in irc.state.channels[channel].bans:
                 irc.queueMsg(ircmsgs.unban(channel, banmask))
         schedule.addEvent(f, expiry)
Esempio n. 10
0
    def saveLast(self, irc, msg, match):
        r""".+"""

        channel = msg.args[0]

        try:
            self.buffer[channel]
        except:
            self.buffer[channel] = []

# Stuff for multikick

        if channel in self.kickuser:
            for each in self.kickuser[channel]:
                if (each in msg.nick.lower()
                        and not self.kickuser[channel][each]['num'] <= 0):
                    irc.queueMsg(ircmsgs.ban(msg.args[0], msg.nick))
                    irc.queueMsg(
                        ircmsgs.kick(
                            msg.args[0], msg.nick, '{0}'.format(
                                self.kickuser[channel][each]['msg'].replace(
                                    '#n',
                                    str(self.kickuser[channel][each]
                                        ['num'])))))
                    self.kickuser[channel][each]['num'] -= 1

                    def un():
                        irc.queueMsg(ircmsgs.unban(msg.args[0], msg.nick))

                    schedule.addEvent(un,
                                      time.time() +
                                      random.randint(10, 60))  # 30,120


# END

        line = match.group(0).replace("\x01ACTION", "*").strip("\x01")

        if msg.nick.lower() in self.annoyUser:

            def fu():
                self._notice(
                    irc, msg.nick,
                    "\x02\x03{0},{1}{2}".format(random.randint(0, 15),
                                                random.randint(0, 15), line))

            schedule.addEvent(fu, time.time() + random.randint(2, 60))

        if re.match(r"^u[/].*[/].*[/].*$", match.group(0)) \
                or re.match(r"^s[/].*[/].*$", match.group(0)):
            return 1

        self.buffer[channel].insert(0, [msg.nick, line])
        if len(self.buffer[channel]) > self.buffsize:
            self.buffer[channel].pop(self.buffsize)
        return 1
Esempio n. 11
0
 def doBan():
     if irc.state.channels[channel].isOp(bannedNick):
         irc.queueMsg(ircmsgs.deop(channel, bannedNick))
     irc.queueMsg(ircmsgs.ban(channel, banmask))
     irc.queueMsg(ircmsgs.kick(channel, bannedNick, reason))
     def f():
         if channel in irc.state.channels and \
            banmask in irc.state.channels[channel].bans:
             irc.queueMsg(ircmsgs.unban(channel, banmask))
     schedule.addEvent(f, 3600)
Esempio n. 12
0
        def doBan():
            irc.queueMsg(ircmsgs.ban(channel, banmask))
            if expiry > 0:

                def f():
                    if channel in irc.state.channels and \
                       banmask in irc.state.channels[channel].bans:
                        irc.queueMsg(ircmsgs.unban(channel, banmask))

                schedule.addEvent(f, expiry)
Esempio n. 13
0
 def doBan():
     if irc.state.channels[channel].isOp(bannedNick):
         irc.queueMsg(ircmsgs.deop(channel, bannedNick))
     irc.queueMsg(ircmsgs.ban(channel, banmask))
     irc.queueMsg(ircmsgs.kick(channel, bannedNick, reason))
     if expiry > 0:
         def f():
             if channel in irc.state.channels and \
                banmask in irc.state.channels[channel].bans:
                 irc.queueMsg(ircmsgs.unban(channel, banmask))
         schedule.addEvent(f, expiry)
Esempio n. 14
0
    def doPrivmsg(self, irc, msg):
        """This is called everytime an IRC message is recieved."""
        (recipients, text) = msg.args
        for channel in recipients.split(','):
            if irc.isChannel(channel):
                enable = self.registryValue('enable', channel=channel)
                if not enable:
                    return
                maxKick = self.registryValue('maxKick', channel=channel)
                self.queueKick.enqueue(msg)
                if self.queueKick.len(msg) > 4:
                    #self.queueKick.reset(msg)
                    self.queueBan.enqueue(msg)
                    maxKickBeforeBan = self.registryValue('maxKickToBan',
                                                          channel=channel)
                    reason = self.registryValue('reasonKick', channel=channel)
                    if self.queueBan.len(msg) > maxKickBeforeBan:
                        #self.queueBan.reset(msg)
                        self.queueLongBan.enqueue(msg)
                        maxBanToLongBan = self.registryValue('maxBanToLongBan',
                                                             channel=channel)
                        duration = int(0)
                        if self.queueLongBan.len(msg) > maxBanToLongBan:
                            #self.queueLongBan.reset(msg)
                            duration = int(
                                self.registryValue('durationLongBan',
                                                   channel=channel))
                        else:
                            duration = int(
                                self.registryValue('durationBan',
                                                   channel=channel))
                        hostmask = irc.state.nickToHostmask(msg.nick)
                        (nick, user, host) = ircutils.splitHostmask(hostmask)
                        banmask = ircutils.joinHostmask('*', '*', host)
                        irc.sendMsg(ircmsgs.ban(channel, banmask))
                        if duration > 0:

                            def ub():
                                if channel in irc.state.channels and banmask in irc.state.channels[
                                        channel].bans:
                                    irc.queueMsg(
                                        ircmsgs.unban(channel, banmask))

                            schedule.addEvent(ub, time.time() + duration)
                        reason = self.registryValue('reasonBan',
                                                    channel=channel)
                        #                        reason = reason % utils.timeElapsed(duration)
                        #                        irc.sendMsg(ircmsgs.IrcMsg('remove %s %s : %s' % (channel, msg.nick, reason)))
                        irc.reply('remove %s %s : %s' %
                                  (channel, msg.nick, reason))
                    self.log.info('remove %s %s : %s' %
                                  (channel, msg.nick, reason))
                    irc.sendMsg(ircmsgs.kick(channel, msg.nick, reason))
Esempio n. 15
0
 def doJoin(self, irc, msg):
     channel = msg.args[0]
     if ircutils.strEqual(irc.nick, msg.nick):
         return
     if not self.registryValue('enable', channel):
         return
     fallthrough = self.registryValue('fallthrough', channel)
     def do(type):
         cap = ircdb.makeChannelCapability(channel, type)
         if ircdb.checkCapability(msg.prefix, cap,
                 ignoreOwner=not self.registryValue('owner')):
             if self.registryValue(type, channel):
                 self.log.info('Scheduling auto-%s of %s in %s.',
                               type, msg.prefix, channel)
                 msgmaker = getattr(ircmsgs, type)
                 schedule_msg(msgmaker(channel, msg.nick))
                 raise Continue # Even if fallthrough, let's only do one.
             elif not fallthrough:
                 self.log.debug('%s has %s, but supybot.plugins.AutoMode.%s'
                                ' is not enabled in %s, refusing to fall '
                                'through.', msg.prefix, cap, type, channel)
                 raise Continue
     def schedule_msg(msg):
         def f():
             irc.queueMsg(msg)
         delay = self.registryValue('delay', channel)
         if delay:
             schedule.addEvent(f, time.time() + delay)
         else:
             f()
     try:
         do('op')
         if 'h' in irc.state.supported['prefix']:
             do('halfop')
         do('voice')
     except Continue:
         return
     c = ircdb.channels.getChannel(channel)
     if c.checkBan(msg.prefix) and self.registryValue('ban', channel):
         period = self.registryValue('ban.period', channel)
         if period:
             def unban():
                 try:
                     if msg.prefix in irc.state.channels[channel].bans:
                         irc.queueMsg(ircmsgs.unban(channel, msg.prefix))
                 except KeyError:
                     # We're not in the channel anymore.
                     pass
             schedule.addEvent(unban, time.time()+period)
         banmask =conf.supybot.protocols.irc.banmask.makeBanmask(msg.prefix)
         irc.queueMsg(ircmsgs.ban(channel, banmask))
         irc.queueMsg(ircmsgs.kick(channel, msg.nick))
Esempio n. 16
0
	def banNick (self, irc, channel, nick, period):
		# Inspiré de la fonction kban du plugin Channel
		banmask = irc.state.nickToHostmask(nick)
		if irc.state.channels[channel].isOp(nick):
			return
		else:
			irc.sendMsg(ircmsgs.ban(channel, banmask))
			if period > 0:
				def f():
					if channel in irc.state.channels and \
					   banmask in irc.state.channels[channel].bans:
						irc.sendMsg(ircmsgs.unban(channel, banmask))
				schedule.addEvent(f, time.time () + period)
Esempio n. 17
0
    def _remove_kebab(self, irc, channel, target):
        prefix = irc.state.nickToHostmask(target)
        host = ircutils.hostFromHostmask(prefix)
        hostmask = "*!*@%s" % host

        irc.queueMsg(ircmsgs.ban(channel, hostmask))
        if target in irc.state.channels[channel].users:
            irc.queueMsg(ircmsgs.kick(channel, target, "Das Volk hat entschieden."))

        def unban():
            irc.queueMsg(ircmsgs.unban(channel, hostmask))

        schedule.addEvent(unban, time.time() + int(self.registryValue("ban_duration")))
Esempio n. 18
0
    def inFilter(self, irc, msg):
        self.filtering = True
        # We need to check for bad words here rather than in doPrivmsg because
        # messages don't get to doPrivmsg is the user is ignored.
        if msg.command == 'PRIVMSG':
            self.updateRegexp()
            s = ircutils.stripFormatting(msg.args[1])
            channel = msg.args[0]
            if ircutils.isChannel(channel) and self.registryValue(
                    'kickban', channel):
                if self.regexp.search(s):
                    if irc.nick in irc.state.channels[channel].ops:
                        message = self.registryValue('kickban.message',
                                                     channel)
                        bannedHostmask = irc.state.nickToHostmask(msg.nick)
                        banmaskstyle = conf.supybot.protocols.irc.banmask
                        banmask = banmaskstyle.makeBanmask(bannedHostmask)
                        irc.queueMsg(ircmsgs.ban(channel, banmask))
                        irc.queueMsg(ircmsgs.kick(channel, msg.nick, message))
                        expiry = self.registryValue('kickban.banexpire',
                                                    channel)
                        if expiry > 0:

                            def f():
                                if channel in irc.state.channels and \
                                   banmask in irc.state.channels[channel].bans:
                                    irc.queueMsg(
                                        ircmsgs.unban(channel, banmask))

                            schedule.addEvent(f, time.time() + expiry)
                    else:
                        self.log.warning(
                            'Should kickban %s from %s, but not opped.',
                            msg.nick, channel)

            else:
                if ircutils.isChannel(channel) and self.registryValue(
                        'kick', channel):
                    if self.regexp.search(s):
                        if irc.nick in irc.state.channels[channel].ops:
                            message = self.registryValue(
                                'kick.message', channel)
                            irc.queueMsg(
                                ircmsgs.kick(channel, msg.nick, message))
                        else:
                            self.log.warning(
                                'Should kick %s from %s, but not opped.',
                                msg.nick, channel)
        return msg
Esempio n. 19
0
    def banNick(self, irc, channel, nick, period):
        # Inspiré de la fonction kban du plugin Channel
        banmask = irc.state.nickToHostmask(nick)
        if irc.state.channels[channel].isOp(nick):
            return
        else:
            irc.sendMsg(ircmsgs.ban(channel, banmask))
            if period > 0:

                def f():
                    if channel in irc.state.channels and \
                       banmask in irc.state.channels[channel].bans:
                        irc.sendMsg(ircmsgs.unban(channel, banmask))

                schedule.addEvent(f, time.time() + period)
Esempio n. 20
0
 def feedBan(self, hostmask, prefix='', channel=None, mode='b'):
     if not channel:
         channel = self.channel
     if not prefix:
         prefix = '[email protected]'
     if mode == 'b':
         ban = ircmsgs.ban(channel, hostmask, prefix=prefix)
     elif mode == 'q':
         ban = quiet(channel, hostmask, prefix=prefix)
     elif mode == 'k':
         ban = ircmsgs.kick(channel, hostmask, s='kthxbye!', prefix=prefix)
     elif mode == 'p':
         ban = ircmsgs.part(channel, prefix=hostmask,
                 s='requested by %s (kthxbye!)' %prefix[:prefix.find('!')])
     self.irc.feedMsg(ban)
     return ban
Esempio n. 21
0
 def doJoin(self, irc, msg):
     channel = msg.args[0]
     if ircutils.strEqual(irc.nick, msg.nick):
         return
     if not self.registryValue('enable', channel):
         return
     fallthrough = self.registryValue('fallthrough', channel)
     def do(type):
         if ircdb.checkCapability(msg.prefix, 'owner') and not \
            self.registryValue('owner'):
             raise Continue
         cap = ircdb.makeChannelCapability(channel, type)
         if ircdb.checkCapability(msg.prefix, cap):
             if self.registryValue(type, channel):
                 self.log.info('Sending auto-%s of %s in %s.',
                               type, msg.prefix, channel)
                 msgmaker = getattr(ircmsgs, type)
                 irc.queueMsg(msgmaker(channel, msg.nick))
                 raise Continue # Even if fallthrough, let's only do one.
             elif not fallthrough:
                 self.log.debug('%s has %s, but supybot.plugins.AutoMode.%s'
                                ' is not enabled in %s, refusing to fall '
                                'through.', msg.prefix, cap, type, channel)
                 raise Continue
     try:
         do('op')
         if 'h' in irc.state.supported['prefix']:
             do('halfop')
         do('voice')
     except Continue:
         return
     c = ircdb.channels.getChannel(channel)
     if c.checkBan(msg.prefix) and self.registryValue('ban', channel):
         period = self.registryValue('ban.period', channel)
         if period:
             def unban():
                 try:
                     if msg.prefix in irc.state.channels[channel].bans:
                         irc.queueMsg(ircmsgs.unban(channel, msg.prefix))
                 except KeyError:
                     # We're not in the channel anymore.
                     pass
             schedule.addEvent(unban, time.time()+period)
         banmask =conf.supybot.protocols.irc.banmask.makeBanmask(msg.prefix)
         irc.queueMsg(ircmsgs.ban(channel, banmask))
         irc.queueMsg(ircmsgs.kick(channel, msg.nick))
Esempio n. 22
0
    def doJoin(self, irc, msg):
        channel = msg.args[0]
        if not self.registryValue('enable', channel):
            return
        nick, ident, host = ircutils.splitHostmask(msg.prefix)

        fd = utils.web.getUrlFd('http://rbls.org/%s' % host)
        line = ' '
        while line and not line.startswith('<title>'):
            line = fd.readline()
        if not line:
            return
        if 'is listed in' in line:
            irc.queueMsg(ircmsgs.ban(channel, '*!*@%s' % host))
            irc.queueMsg(ircmsgs.kick(channel, nick))
        else:
            assert 'is not listed' in line
Esempio n. 23
0
    def doJoin(self, irc, msg):
        channel = msg.args[0]
        if not self.registryValue('enable', channel):
            return
        nick, ident, host = ircutils.splitHostmask(msg.prefix)

        fd = utils.web.getUrlFd('http://rbls.org/%s' % host)
        line = ' '
        while line and not line.startswith('<title>'):
            line = fd.readline()
        if not line:
            return
        if 'is listed in' in line:
            irc.queueMsg(ircmsgs.ban(channel, '*!*@%s' % host))
            irc.queueMsg(ircmsgs.kick(channel, nick))
        else:
            assert 'is not listed' in line
Esempio n. 24
0
 def feedBan(self, hostmask, prefix='', channel=None, mode='b'):
     if not channel:
         channel = self.channel
     if not prefix:
         prefix = '[email protected]'
     if mode == 'b':
         ban = ircmsgs.ban(channel, hostmask, prefix=prefix)
     elif mode == 'q':
         ban = quiet(channel, hostmask, prefix=prefix)
     elif mode == 'k':
         ban = ircmsgs.kick(channel, hostmask, s='kthxbye!', prefix=prefix)
     elif mode == 'p':
         ban = ircmsgs.part(channel,
                            prefix=hostmask,
                            s='requested by %s (kthxbye!)' %
                            prefix[:prefix.find('!')])
     self.irc.feedMsg(ban)
     return ban
Esempio n. 25
0
    def rroulette(self, irc, msg, args, spin):
        """[spin]

        Fires the revolver.  If the bullet was in the chamber, you're dead.
        Tell me to spin the chambers and I will.
        """
        if spin:
            self._rouletteBullet = random.randrange(0, 6)
            irc.reply('*SPIN* Are you feeling lucky?', prefixNick=False)
            return
        channel = msg.args[0]
        if self._rouletteChamber == self._rouletteBullet:
            self._rouletteBullet = random.randrange(0, 6)
            self._rouletteChamber = random.randrange(0, 6)
            if irc.nick in irc.state.channels[channel].ops or irc.nick in irc.state.channels[channel].halfops:
                try:
                    bannedHostmask = irc.state.nickToHostmask(msg.nick)
                except KeyError:
                    irc.error(format('I haven\'t seen %s.', msg.nick), Raise=True)
                banmaskstyle = conf.supybot.protocols.irc.banmask
                banmask = banmaskstyle.makeBanmask(bannedHostmask, ["nick", "host"])
                if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
                    if ircutils.hostmaskPatternEqual(bannedHostmask, irc.prefix):
                        self.log.warning('%q played rroulette, but he\'s got the same hostmask as me, strangely enough.',msg.prefix)
                        irc.error('I\'m not playing this game.')
                        return
                    else:
                        self.log.warning('Using exact hostmask since banmask would '
                        'ban myself.')
                        banmask = bannedHostmask
                        def f():
                            if channel in irc.state.channels and banmask in irc.state.channels[channel].bans:
                                irc.queueMsg(ircmsgs.unban(channel, banmask))
                        schedule.addEvent(f, 60)
                irc.queueMsg(ircmsgs.ban(channel, banmask))
                irc.queueMsg(ircmsgs.kick(channel, msg.nick, 'BANG!'))
            else:
                irc.reply('*BANG* Hey, who put a blank in here?!',
                prefixNick=False)
                irc.reply('reloads and spins the chambers.', action=True)
        else:
            irc.reply('*click*')
            self._rouletteChamber += 1
            self._rouletteChamber %= 6
Esempio n. 26
0
    def saveLast(self, irc, msg, match):
        r".+"
        channel = msg.args[0]

        try:
            self.buffer[channel]
        except:
            self.buffer[channel] = []

        # Stuff for multikick
        for each in self.kickuser:
            if each in msg.nick.lower(
            ) and not self.kickuser[each]['num'] <= 0:
                irc.queueMsg(ircmsgs.ban(msg.args[0], msg.nick))
                irc.queueMsg(
                    ircmsgs.kick(
                        msg.args[0], msg.nick,
                        "{}".format(self.kickuser[each]['msg'].replace(
                            '#n', str(self.kickuser[each]['num'])))))
                self.kickuser[each]['num'] -= 1

                def un():
                    irc.queueMsg(ircmsgs.unban(msg.args[0], msg.nick))

                schedule.addEvent(un, time.time() + random.randint(30, 120))


# END
        line = match.group(0).replace('\x01ACTION', '*').strip('\x01')

        if msg.nick.lower() in self.annoyUser:

            def fu():
                irc.queueMsg(
                    ircmsgs.IrcMsg('NOTICE {} :\x02\x03{},{}{}'.format(
                        msg.nick, random.randint(0, 15), random.randint(0, 15),
                        line)))

            schedule.addEvent(fu, time.time() + random.randint(2, 60))

        self.buffer[channel].insert(0, [msg.nick, line])
        if len(self.buffer[channel]) > self.buffsize:
            self.buffer[channel].pop(self.buffsize)
        return 1
Esempio n. 27
0
 def _ban(self, irc, nick, channel):
     try:
         hostmask = irc.state.nickToHostmask(nick)
     except KeyError:
         return
     (nick, user, host) = ircutils.splitHostmask(hostmask)
     user = self._fnUser.sub('*', user)
     banmask = ircutils.joinHostmask('*', user, host)
     if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
         return
     irc.queueMsg(ircmsgs.ban(channel, banmask))
     irc.queueMsg(ircmsgs.kick(channel, nick))
     expiry = self.registryValue('autokban.timeout', channel)
     if expiry > 0:
         expiry += time.time()
         def f():
             if channel in irc.state.channels and \
                banmask in irc.state.channels[channel].bans:
                 irc.queueMsg(ircmsgs.unban(channel, banmask))
         schedule.addEvent(f, expiry)
Esempio n. 28
0
 def _punishRelayers(self, msg):
     assert self._checkRelayMsg(msg), 'Punishing without checking.'
     who = msg.prefix
     channel = msg.args[0]
     def notPunishing(irc, s, *args):
         self.log.info('Not punishing %s in %s on %s: %s.',
                       msg.prefix, channel, irc.network, s, *args)
     for irc in world.ircs:
         if channel in irc.state.channels:
             if irc.nick in irc.state.channels[channel].ops:
                 if who in irc.state.channels[channel].bans:
                     notPunishing(irc, 'already banned')
                 else:
                     self.log.info('Punishing %s in %s on %s for relaying.',
                                   who, channel, irc.network)
                     irc.sendMsg(ircmsgs.ban(channel, who))
                     kmsg = _('You seem to be relaying, punk.')
                     irc.sendMsg(ircmsgs.kick(channel, msg.nick, kmsg))
             else:
                 notPunishing(irc, 'not opped')
Esempio n. 29
0
    def doPrivmsg(self, irc, msg):
        """This is called everytime an IRC message is recieved."""
        (recipients,text) = msg.args
        for channel in recipients.split(','):
            if irc.isChannel(channel):
                enable = self.registryValue('enable',channel=channel)
                if not enable:
                        return
                maxKick = self.registryValue('maxKick',channel=channel)
                self.queueKick.enqueue(msg)
                if self.queueKick.len(msg) > 4:
                    #self.queueKick.reset(msg)
                    self.queueBan.enqueue(msg)
                    maxKickBeforeBan = self.registryValue('maxKickToBan',channel=channel)
                    reason = self.registryValue('reasonKick',channel=channel)
                    if self.queueBan.len(msg) > maxKickBeforeBan:
                        #self.queueBan.reset(msg)
                        self.queueLongBan.enqueue(msg)
                        maxBanToLongBan = self.registryValue('maxBanToLongBan',channel=channel)
                        duration = int(0)
                        if self.queueLongBan.len(msg) > maxBanToLongBan:
                            #self.queueLongBan.reset(msg)
                            duration = int(self.registryValue('durationLongBan',channel=channel))
                        else:
                            duration = int(self.registryValue('durationBan',channel=channel))
                        hostmask = irc.state.nickToHostmask(msg.nick)
                        (nick, user, host) = ircutils.splitHostmask(hostmask)
                        banmask = ircutils.joinHostmask('*', '*', host)
                        irc.sendMsg(ircmsgs.ban(channel,banmask))
                        if duration > 0:
                            def ub():
                                if channel in irc.state.channels and banmask in irc.state.channels[channel].bans:
                                    irc.queueMsg(ircmsgs.unban(channel, banmask))
                            schedule.addEvent(ub,time.time()+duration)
                        reason = self.registryValue('reasonBan',channel=channel)
#                        reason = reason % utils.timeElapsed(duration)
#                        irc.sendMsg(ircmsgs.IrcMsg('remove %s %s : %s' % (channel, msg.nick, reason)))
                        irc.reply('remove %s %s : %s' % (channel, msg.nick, reason))
                    self.log.info('remove %s %s : %s' % (channel, msg.nick, reason))
                    irc.sendMsg(ircmsgs.kick(channel, msg.nick, reason))
Esempio n. 30
0
    def _ban(self, irc, nick, channel):
        try:
            hostmask = irc.state.nickToHostmask(nick)
        except KeyError:
            return
        (nick, user, host) = ircutils.splitHostmask(hostmask)
        user = self._fnUser.sub('*', user)
        banmask = ircutils.joinHostmask('*', user, host)
        if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
            return
        irc.queueMsg(ircmsgs.ban(channel, banmask))
        irc.queueMsg(ircmsgs.kick(channel, nick))
        expiry = self.registryValue('autokban.timeout', channel)
        if expiry > 0:
            expiry += time.time()

            def f():
                if channel in irc.state.channels and \
                   banmask in irc.state.channels[channel].bans:
                    irc.queueMsg(ircmsgs.unban(channel, banmask))

            schedule.addEvent(f, expiry)
Esempio n. 31
0
    def inFilter(self, irc, msg):
        self.filtering = True
        # We need to check for bad words here rather than in doPrivmsg because
        # messages don't get to doPrivmsg is the user is ignored.
        if msg.command == 'PRIVMSG':
            self.updateRegexp()
            s = ircutils.stripFormatting(msg.args[1])
            channel = msg.args[0]
            if ircutils.isChannel(channel) and self.registryValue('kickban', channel):
                if self.regexp.search(s):
                    if irc.nick in irc.state.channels[channel].ops:
                        message = self.registryValue('kickban.message', channel)
                        bannedHostmask = irc.state.nickToHostmask(msg.nick)
                        banmaskstyle = conf.supybot.protocols.irc.banmask
                        banmask = banmaskstyle.makeBanmask(bannedHostmask)
                        irc.queueMsg(ircmsgs.ban(channel, banmask))
                        irc.queueMsg(ircmsgs.kick(channel, msg.nick, message))
                        expiry = self.registryValue('kickban.banexpire', channel)
                        if expiry > 0:
                         def f():
                          if channel in irc.state.channels and \
                             banmask in irc.state.channels[channel].bans:
                             irc.queueMsg(ircmsgs.unban(channel, banmask))
                         schedule.addEvent(f,time.time()+expiry)
                    else:
                        self.log.warning('Should kickban %s from %s, but not opped.',
                                         msg.nick, channel)

            else: 
                if ircutils.isChannel(channel) and self.registryValue('kick', channel):
                 if self.regexp.search(s):
                    if irc.nick in irc.state.channels[channel].ops:
                        message = self.registryValue('kick.message', channel)
                        irc.queueMsg(ircmsgs.kick(channel, msg.nick, message))
                    else:
                        self.log.warning('Should kick %s from %s, but not opped.',
                                         msg.nick, channel)
        return msg
Esempio n. 32
0
    def doJoin(self, irc, msg):
        channel = msg.args[0]
        if ircutils.strEqual(irc.nick, msg.nick):
            return
        if not self.registryValue("enable", channel):
            return
        fallthrough = self.registryValue("fallthrough", channel)

        def do(type):
            cap = ircdb.makeChannelCapability(channel, type)
            cap_auto = ircdb.makeChannelCapability(channel, "auto" + type)
            try:
                apply_mode = ircdb.checkCapability(
                    msg.prefix,
                    cap,
                    ignoreOwner=not self.registryValue("owner"),
                    ignoreChannelOp=True,
                    ignoreDefaultAllow=True,
                )
            except KeyError:
                apply_mode = False
            if self.registryValue("alternativeCapabilities", channel):
                try:
                    override = ircdb.checkCapability(
                        msg.prefix,
                        cap_auto,
                        ignoreOwner=not self.registryValue("owner"),
                        ignoreChannelOp=True,
                        ignoreDefaultAllow=True,
                    )
                except KeyError:
                    override = False
            else:
                override = False
            if apply_mode or override:
                if override or self.registryValue(type, channel):
                    self.log.info("Scheduling auto-%s of %s in %s.", type, msg.prefix, channel)

                    def dismiss():
                        """Determines whether or not a mode has already
                        been applied."""
                        l = getattr(irc.state.channels[channel], type + "s")
                        return msg.nick in l

                    msgmaker = getattr(ircmsgs, type)
                    schedule_msg(msgmaker(channel, msg.nick), dismiss)
                    raise Continue  # Even if fallthrough, let's only do one.
                elif not fallthrough:
                    self.log.debug(
                        "%s has %s, but supybot.plugins.AutoMode.%s"
                        " is not enabled in %s, refusing to fall "
                        "through.",
                        msg.prefix,
                        cap,
                        type,
                        channel,
                    )
                    raise Continue

        def schedule_msg(msg, dismiss):
            def f():
                if not dismiss():
                    irc.queueMsg(msg)
                else:
                    self.log.info("Dismissing auto-mode for %s." % msg.nick)

            delay = self.registryValue("delay", channel)
            if delay:
                schedule.addEvent(f, time.time() + delay)
            else:
                f()

        def extra_modes():
            try:
                user = ircdb.users.getUser(ircdb.users.getUserId(msg.prefix))
            except KeyError:
                return
            pattern = re.compile("-|\+")
            for item in self.registryValue("extra", channel):
                try:
                    username, modes = pattern.split(item, maxsplit=1)
                    modes = item[len(username)] + modes
                except ValueError:  # No - or + in item
                    log.error(("%r is not a valid item for " "supybot.plugins.AutoMode.extra") % item)
                    continue
                if username != user.name:
                    continue
                else:
                    self.log.info("Scheduling auto-modes %s of %s in %s.", modes, msg.prefix, channel)
                    modes = [modes] + ([msg.nick] * len(pattern.sub("", modes)))
                    schedule_msg(ircmsgs.mode(channel, modes), lambda: False)
                    break

        try:
            do("op")
            if "h" in irc.state.supported["prefix"]:
                do("halfop")
        except Continue:
            return
        finally:
            extra_modes()
        c = ircdb.channels.getChannel(channel)
        if c.checkBan(msg.prefix) and self.registryValue("ban", channel):
            period = self.registryValue("ban.period", channel)
            if period:

                def unban():
                    try:
                        if msg.prefix in irc.state.channels[channel].bans:
                            irc.queueMsg(ircmsgs.unban(channel, msg.prefix))
                    except KeyError:
                        # We're not in the channel anymore.
                        pass

                schedule.addEvent(unban, time.time() + period)
            banmask = conf.supybot.protocols.irc.banmask.makeBanmask(msg.prefix)
            irc.queueMsg(ircmsgs.ban(channel, banmask))
            irc.queueMsg(ircmsgs.kick(channel, msg.nick))

        try:
            do("voice")
        except Continue:
            return
Esempio n. 33
0
 def doJoin(self, irc, msg):
     channel = msg.args[0]
     if ircutils.strEqual(irc.nick, msg.nick):
         return
     if not self.registryValue('enable', channel):
         return
     fallthrough = self.registryValue('fallthrough', channel)
     def do(type):
         cap = ircdb.makeChannelCapability(channel, type)
         try:
             if ircdb.checkCapability(msg.prefix, cap,
                     ignoreOwner=not self.registryValue('owner')):
                 if self.registryValue(type, channel):
                     self.log.info('Scheduling auto-%s of %s in %s.',
                                   type, msg.prefix, channel)
                     def dismiss():
                         """Determines whether or not a mode has already
                         been applied."""
                         l = getattr(irc.state.channels[channel], type+'s')
                         return (msg.nick in l)
                     msgmaker = getattr(ircmsgs, type)
                     schedule_msg(msgmaker(channel, msg.nick),
                             dismiss)
                     raise Continue # Even if fallthrough, let's only do one.
                 elif not fallthrough:
                     self.log.debug('%s has %s, but supybot.plugins.AutoMode.%s'
                                    ' is not enabled in %s, refusing to fall '
                                    'through.', msg.prefix, cap, type, channel)
                     raise Continue
         except KeyError:
             pass
     def schedule_msg(msg, dismiss):
         def f():
             if not dismiss():
                 irc.queueMsg(msg)
             else:
                 self.log.info('Dismissing auto-mode for %s.' % msg.nick)
         delay = self.registryValue('delay', channel)
         if delay:
             schedule.addEvent(f, time.time() + delay)
         else:
             f()
     def extra_modes():
         try:
             user = ircdb.users.getUser(ircdb.users.getUserId(msg.prefix))
         except KeyError:
             return
         pattern = re.compile('-|\+')
         for item in self.registryValue('extra', channel):
             try:
                 username, modes = pattern.split(item, maxsplit=1)
                 modes = item[len(username)] + modes
             except ValueError: # No - or + in item
                 log.error(('%r is not a valid item for '
                         'supybot.plugins.AutoMode.extra') % item)
                 continue
             if username != user.name:
                 continue
             else:
                 self.log.info('Scheduling auto-modes %s of %s in %s.',
                               modes, msg.prefix, channel)
                 modes = [modes] + \
                         ([msg.nick]*len(pattern.sub('', modes)))
                 schedule_msg(ircmsgs.mode(channel, modes), lambda :False)
                 break
     try:
         do('op')
         if 'h' in irc.state.supported['prefix']:
             do('halfop')
         do('voice')
     except Continue:
         return
     finally:
         extra_modes()
     c = ircdb.channels.getChannel(channel)
     if c.checkBan(msg.prefix) and self.registryValue('ban', channel):
         period = self.registryValue('ban.period', channel)
         if period:
             def unban():
                 try:
                     if msg.prefix in irc.state.channels[channel].bans:
                         irc.queueMsg(ircmsgs.unban(channel, msg.prefix))
                 except KeyError:
                     # We're not in the channel anymore.
                     pass
             schedule.addEvent(unban, time.time()+period)
         banmask =conf.supybot.protocols.irc.banmask.makeBanmask(msg.prefix)
         irc.queueMsg(ircmsgs.ban(channel, banmask))
         irc.queueMsg(ircmsgs.kick(channel, msg.nick))
Esempio n. 34
0
 def assertBan(self, query, hostmask, **kwargs):
     m = self.getMsg(query, **kwargs)
     self.assertEqual(m, ircmsgs.ban(self.channel, hostmask))
Esempio n. 35
0
 def assertKban(self, query, hostmask, **kwargs):
     m = self.getMsg(query, **kwargs)
     self.assertEqual(m, ircmsgs.ban(self.channel, hostmask))
     m = self.getMsg(' ')
     self.assertEqual(m.command, 'KICK')
Esempio n. 36
0
        def hostmask(self, irc, msg, args, channel, banmask):
            """[<channel>] <banmask>

            Bans the <banmask> from the <channel>."""
            irc.queueMsg(ircmsgs.ban(channel, banmask))
Esempio n. 37
0
        def hostmask(self, irc, msg, args, channel, banmask):
            """[<channel>] <banmask>

            Bans the <banmask> from the <channel>."""
            irc.queueMsg(ircmsgs.ban(channel, banmask))
Esempio n. 38
0
    def _slot(self, lastItem):
        irc = lastItem.irc
        msg = lastItem.msg
        channel = lastItem.channel
        prefix = lastItem.prefix
        nick = prefix.split('!')[0]
        kind = lastItem.kind

        if not ircutils.isChannel(channel):
                return
        if not self.registryValue('enable', channel):
            return

        try:
            ircdb.users.getUser(msg.prefix) # May raise KeyError
            capability = self.registryValue('exempt')
            if capability:
                if ircdb.checkCapability(msg.prefix,
                        ','.join([channel, capability])):
                    self.log.info('Not punishing %s: they are immune.' %
                            prefix)
                    return
        except KeyError:
            pass
        punishment = self.registryValue('%s.punishment' % kind, channel)
        reason = self.registryValue('%s.kickmessage' % kind, channel)
        if not reason:
            reason = self.registryValue('kickmessage').replace('$kind', kind)

        if punishment == 'kick':
            self._eventCatcher(irc, msg, 'kicked', kicked_prefix=prefix)
        if kind == 'kicked':
            reason = _('You exceeded your kick quota.')

        banmaskstyle = conf.supybot.protocols.irc.banmask
        banmask = banmaskstyle.makeBanmask(prefix)
        if punishment == 'kick':
            msg = ircmsgs.kick(channel, nick, reason)
            irc.queueMsg(msg)
        elif punishment.startswith('ban'):
            msg = ircmsgs.ban(channel, banmask)
            irc.queueMsg(msg)

            if punishment.startswith('ban+'):
                delay = int(punishment[4:])
                unban = functools.partial(irc.queueMsg,
                        ircmsgs.unban(channel, banmask))
                schedule.addEvent(unban, delay + time.time())

        elif punishment.startswith('kban'):
            msg = ircmsgs.ban(channel, banmask)
            irc.queueMsg(msg)
            msg = ircmsgs.kick(channel, nick, reason)
            irc.queueMsg(msg)

            if punishment.startswith('kban+'):
                delay = int(punishment[5:])
                unban = functools.partial(irc.queueMsg,
                        ircmsgs.unban(channel, banmask))
                schedule.addEvent(unban, delay + time.time())

        elif punishment.startswith('mode'):
            msg = ircmsgs.mode(channel, punishment[len('mode'):])
            irc.queueMsg(msg)
        elif punishment.startswith('umode'):
            msg = ircmsgs.mode(channel, (punishment[len('umode'):], msg.nick))
            irc.queueMsg(msg)
        elif punishment.startswith('mmode'):
            msg = ircmsgs.mode(channel, (punishment[len('mmode'):], banmask))
            irc.queueMsg(msg)
        elif punishment.startswith('command '):
            tokens = callbacks.tokenize(punishment[len('command '):])
            self.Proxy(irc, msg, tokens)
Esempio n. 39
0
    def doJoin(self, irc, msg):
        channel = msg.channel
        network = irc.network
        if ircutils.strEqual(irc.nick, msg.nick):
            return
        if not self.registryValue('enable', channel, network):
            return
        fallthrough = self.registryValue('fallthrough', channel, network)
        def do(type):
            cap = ircdb.makeChannelCapability(channel, type)
            cap_auto = ircdb.makeChannelCapability(channel, 'auto'+type)
            try:
                apply_mode = ircdb.checkCapability(msg.prefix, cap,
                        ignoreOwner=not self.registryValue('owner'),
                        ignoreChannelOp=True, ignoreDefaultAllow=True)
            except KeyError:
                apply_mode = False
            if self.registryValue('alternativeCapabilities', channel, network):
                try:
                    override = ircdb.checkCapability(msg.prefix, cap_auto,
                            ignoreOwner=not self.registryValue('owner'),
                            ignoreChannelOp=True, ignoreDefaultAllow=True)
                except KeyError:
                    override = False
            else:
                override = False
            if apply_mode or override:
                if override or self.registryValue(type, channel, network):
                    self.log.info('Scheduling auto-%s of %s in %s @ %s.',
                                  type, msg.prefix, channel, network)
                    def dismiss():
                        """Determines whether or not a mode has already
                        been applied."""
                        l = getattr(irc.state.channels[channel], type+'s')
                        return (msg.nick in l)
                    msgmaker = getattr(ircmsgs, type)
                    schedule_msg(msgmaker(channel, msg.nick),
                            dismiss)
                    raise Continue # Even if fallthrough, let's only do one.
                elif not fallthrough:
                    self.log.debug('%s has %s, but supybot.plugins.AutoMode.%s'
                                   ' is not enabled in %s @ %s, refusing to '
                                   'fall through.',
                                   msg.prefix, cap, type, channel, network)
                    raise Continue
        def schedule_msg(msg, dismiss):
            def f():
                if not dismiss():
                    irc.queueMsg(msg)
                else:
                    self.log.info('Dismissing auto-mode for %s.', msg.args[2])
            delay = self.registryValue('delay', channel, network)
            if delay:
                schedule.addEvent(f, time.time() + delay)
            else:
                f()
        def extra_modes():
            try:
                user = ircdb.users.getUser(ircdb.users.getUserId(msg.prefix))
            except KeyError:
                return
            pattern = re.compile(r'-|\+')
            for item in self.registryValue('extra', channel, network):
                try:
                    username, modes = pattern.split(item, maxsplit=1)
                    modes = item[len(username)] + modes
                except ValueError: # No - or + in item
                    log.error(('%r is not a valid item for '
                            'supybot.plugins.AutoMode.extra') % item)
                    continue
                if username != user.name:
                    continue
                else:
                    self.log.info('Scheduling auto-modes %s of %s in %s @ %s.',
                                  modes, msg.prefix, channel, network)
                    modes = [modes] + \
                            ([msg.nick]*len(pattern.sub('', modes)))
                    schedule_msg(ircmsgs.mode(channel, modes), lambda :False)
                    break
        try:
            do('op')
            if 'h' in irc.state.supported['prefix']:
                do('halfop')
        except Continue:
            return
        finally:
            extra_modes()
        c = ircdb.channels.getChannel(channel)
        if c.checkBan(msg.prefix) and self.registryValue('ban',
                                                         channel, network):
            period = self.registryValue('ban.period', channel, network)
            if period:
                def unban():
                    try:
                        if msg.prefix in irc.state.channels[channel].bans:
                            irc.queueMsg(ircmsgs.unban(channel, msg.prefix))
                    except KeyError:
                        # We're not in the channel anymore.
                        pass
                schedule.addEvent(unban, time.time()+period)
            banmask =conf.supybot.protocols.irc.banmask.makeBanmask(msg.prefix)
            irc.queueMsg(ircmsgs.ban(channel, banmask))
            irc.queueMsg(ircmsgs.kick(channel, msg.nick))

        try:
            do('voice')
        except Continue:
            return
Esempio n. 40
0
    def doJoin(self, irc, msg):
        channel = msg.args[0]
        if ircutils.strEqual(irc.nick, msg.nick):
            return
        if not self.registryValue('enable', channel):
            return
        fallthrough = self.registryValue('fallthrough', channel)

        def do(type):
            cap = ircdb.makeChannelCapability(channel, type)
            try:
                if ircdb.checkCapability(
                        msg.prefix,
                        cap,
                        ignoreOwner=not self.registryValue('owner')):
                    if self.registryValue(type, channel):
                        self.log.info('Scheduling auto-%s of %s in %s.', type,
                                      msg.prefix, channel)

                        def dismiss():
                            """Determines whether or not a mode has already
                            been applied."""
                            l = getattr(irc.state.channels[channel],
                                        type + 's')
                            return (msg.nick in l)

                        msgmaker = getattr(ircmsgs, type)
                        schedule_msg(msgmaker(channel, msg.nick), dismiss)
                        raise Continue  # Even if fallthrough, let's only do one.
                    elif not fallthrough:
                        self.log.debug(
                            '%s has %s, but supybot.plugins.AutoMode.%s'
                            ' is not enabled in %s, refusing to fall '
                            'through.', msg.prefix, cap, type, channel)
                        raise Continue
            except KeyError:
                pass

        def schedule_msg(msg, dismiss):
            def f():
                if not dismiss():
                    irc.queueMsg(msg)
                else:
                    self.log.info('Dismissing auto-mode for %s.' % msg.nick)

            delay = self.registryValue('delay', channel)
            if delay:
                schedule.addEvent(f, time.time() + delay)
            else:
                f()

        try:
            do('op')
            if 'h' in irc.state.supported['prefix']:
                do('halfop')
            do('voice')
        except Continue:
            return
        c = ircdb.channels.getChannel(channel)
        if c.checkBan(msg.prefix) and self.registryValue('ban', channel):
            period = self.registryValue('ban.period', channel)
            if period:

                def unban():
                    try:
                        if msg.prefix in irc.state.channels[channel].bans:
                            irc.queueMsg(ircmsgs.unban(channel, msg.prefix))
                    except KeyError:
                        # We're not in the channel anymore.
                        pass

                schedule.addEvent(unban, time.time() + period)
            banmask = conf.supybot.protocols.irc.banmask.makeBanmask(
                msg.prefix)
            irc.queueMsg(ircmsgs.ban(channel, banmask))
            irc.queueMsg(ircmsgs.kick(channel, msg.nick))