Beispiel #1
0
 def f(L):
     return ircmsgs.halfops(channel, L)
Beispiel #2
0
 def f(L):
     return ircmsgs.halfops(channel, L)
Beispiel #3
0
 def testHalfops(self):
     m = ircmsgs.halfops('#foo', ['foo', 'bar', 'baz'])
     self.assertEqual(str(m), 'MODE #foo +hhh foo bar :baz\r\n')
Beispiel #4
0
    def _autoMagic(self, irc, msg, channel):
        # If bot does not got op
        if irc.nick not in irc.state.channels[channel].ops:
            return
        # Read database
        hostdict, _ = self._readFile(channel)

        # If for some reason _readFile() failed
        if hostdict == -3:
            return -3
        elif hostdict == -2:
            return -2
        elif hostdict == -1:
            return -1

        # List of those nicks that are to gain modes
        oplist = []
        halfoplist = []
        voicelist = []

        # For all nicks in channel
        for u in irc.state.channels[channel].users:
            hostname = irc.state.nickToHostmask(u)
            for regex in hostdict.iteritems():
                match = re.search(regex[0], hostname)
                if match:
                    if regex[1] == "op":
                        if u not in irc.state.channels[channel].ops:
                            oplist.append(u)
                    elif regex[1] == "halfop":
                        if u not in irc.state.channels[channel].halfops:
                            halfoplist.append(u)
                    elif regex[1] == "voice":
                        if u not in irc.state.channels[channel].voices:
                            voicelist.append(u)

        maxmodes = 4
        # While there are still people to give op to
        while len(oplist) > 0:
            # Op the first 4, or whatever maxmode is
            irc.queueMsg(ircmsgs.ops(channel, oplist[:maxmodes]))
            # Remove those that have been given op from the list
            oplist = oplist[maxmodes:]
            # If the list is shorter than maxmode, op them all.
            if len(oplist) <= maxmodes:
                irc.queueMsg(ircmsgs.ops(channel, oplist))
                break

        while len(halfoplist) > 0:
            irc.queueMsg(ircmsgs.halfops(channel, halfoplist[:maxmodes]))
            halfoplist = halfoplist[maxmodes:]
            if len(halfoplist) <= maxmodes:
                irc.queueMsg(ircmsgs.halfops(channel, halfoplist))
                break

        while len(voicelist) > 0:
            irc.queueMsg(ircmsgs.voices(channel, voicelist[:maxmodes]))
            voicelist = voicelist[maxmodes:]
            if len(voicelist) <= maxmodes:
                irc.queueMsg(ircmsgs.voices(channel, voicelist))
                break

        # Can't really remember that this does.
        irc.noReply()
Beispiel #5
0
 def testHalfops(self):
     m = ircmsgs.halfops('#foo', ['foo', 'bar', 'baz'])
     self.assertEqual(str(m), 'MODE #foo +hhh foo bar :baz\r\n')
Beispiel #6
0
    def _autoMagic(self, irc, msg, channel):
        # If bot does not got op
        if irc.nick not in irc.state.channels[channel].ops:
            return
        # Read database
        hostdict, _ = self._readFile(channel)

        # If for some reason _readFile() failed
        if hostdict == -3:
            return -3
        elif hostdict == -2:
            return -2
        elif hostdict == -1:
            return -1

        # List of those nicks that are to gain modes
        oplist = []
        halfoplist = []
        voicelist = []

        # For all nicks in channel
        for u in irc.state.channels[channel].users:
            hostname = irc.state.nickToHostmask(u)
            for regex in hostdict.iteritems():
                match = re.search(regex[0], hostname)
                if match:
                    if regex[1] == "op":
                        if u not in irc.state.channels[channel].ops:
                            oplist.append(u)
                    elif regex[1] == "halfop":
                        if u not in irc.state.channels[channel].halfops:
                            halfoplist.append(u)
                    elif regex[1] == "voice":
                        if u not in irc.state.channels[channel].voices:
                            voicelist.append(u)

        maxmodes = 4
        # While there are still people to give op to
        while len(oplist) > 0:
            # Op the first 4, or whatever maxmode is
            irc.queueMsg(ircmsgs.ops(channel, oplist[:maxmodes]))
            # Remove those that have been given op from the list
            oplist = oplist[maxmodes:]
            # If the list is shorter than maxmode, op them all.
            if len(oplist) <= maxmodes:
                irc.queueMsg(ircmsgs.ops(channel, oplist))
                break

        while len(halfoplist) > 0:
            irc.queueMsg(ircmsgs.halfops(channel, halfoplist[:maxmodes]))
            halfoplist = halfoplist[maxmodes:]
            if len(halfoplist) <= maxmodes:
                irc.queueMsg(ircmsgs.halfops(channel, halfoplist))
                break

        while len(voicelist) > 0:
            irc.queueMsg(ircmsgs.voices(channel, voicelist[:maxmodes]))
            voicelist = voicelist[maxmodes:]
            if len(voicelist) <= maxmodes:
                irc.queueMsg(ircmsgs.voices(channel, voicelist))
                break

        # Can't really remember that this does.
        irc.noReply()