Example #1
0
    def opall(self, irc, msg, args, channel):
        """[<channel>]

        Ops everyone in the channel. <channel> is only necessary
        if the message isn't sent in the channel itself.
        """

        chanstate = irc.state.channels[channel]
        users = [user for user in chanstate.users if not chanstate.isOp(user)]

        for batch in self._split_modes(users):
            irc.queueMsg(ircmsgs.ops(channel, batch))
Example #2
0
 def f(L):
     return ircmsgs.ops(channel, L)
Example #3
0
 def f(L):
     return ircmsgs.ops(channel, L)
Example #4
0
 def testOps(self):
     m = ircmsgs.ops('#foo', ['foo', 'bar', 'baz'])
     self.assertEqual(str(m), 'MODE #foo +ooo foo bar :baz\r\n')
Example #5
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()
Example #6
0
 def testOps(self):
     m = ircmsgs.ops('#foo', ['foo', 'bar', 'baz'])
     self.assertEqual(str(m), 'MODE #foo +ooo foo bar :baz\r\n')
Example #7
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()