示例#1
0
 def doMode(self, irc, msg):
     channel = msg.args[0]
     chanOp = ircdb.makeChannelCapability(channel, 'op')
     chanVoice = ircdb.makeChannelCapability(channel, 'voice')
     chanHalfOp = ircdb.makeChannelCapability(channel, 'halfop')
     if not ircdb.checkCapability(msg.prefix, chanOp):
         irc.sendMsg(ircmsgs.deop(channel, msg.nick))
     for (mode, value) in ircutils.separateModes(msg.args[1:]):
         if not value:
             continue
         if ircutils.strEqual(value, msg.nick):
             # We allow someone to mode themselves to oblivion.
             continue
         if irc.isNick(value):
             hostmask = irc.state.nickToHostmask(value)
             if mode == '+o':
                 if not self.isOp(irc, channel, hostmask):
                     irc.queueMsg(ircmsgs.deop(channel, value))
             elif mode == '+h':
                 if not ircdb.checkCapability(hostmask, chanHalfOp):
                      irc.queueMsg(ircmsgs.dehalfop(channel, value))
             elif mode == '+v':
                 if not ircdb.checkCapability(hostmask, chanVoice):
                     irc.queueMsg(ircmsgs.devoice(channel, value))
             elif mode == '-o':
                 if ircdb.checkCapability(hostmask, chanOp):
                     irc.queueMsg(ircmsgs.op(channel, value))
             elif mode == '-h':
                 if ircdb.checkCapability(hostmask, chanOp):
                     irc.queueMsg(ircmsgs.halfop(channel, value))
             elif mode == '-v':
                 if ircdb.checkCapability(hostmask, chanOp):
                     irc.queueMsg(ircmsgs.voice(channel, value))
         else:
             assert ircutils.isUserHostmask(value)
示例#2
0
文件: plugin.py 项目: rostob/Limnoria
 def doMode(self, irc, msg):
     channel = msg.channel
     chanOp = ircdb.makeChannelCapability(channel, 'op')
     chanVoice = ircdb.makeChannelCapability(channel, 'voice')
     chanHalfOp = ircdb.makeChannelCapability(channel, 'halfop')
     if not ircdb.checkCapability(msg.prefix, chanOp):
         irc.sendMsg(ircmsgs.deop(channel, msg.nick))
     for (mode, value) in ircutils.separateModes(msg.args[1:]):
         if not value:
             continue
         if ircutils.strEqual(value, msg.nick):
             # We allow someone to mode themselves to oblivion.
             continue
         if irc.isNick(value):
             hostmask = irc.state.nickToHostmask(value)
             if mode == '+o':
                 if not self.isOp(irc, channel, hostmask):
                     irc.queueMsg(ircmsgs.deop(channel, value))
             elif mode == '+h':
                 if not ircdb.checkCapability(hostmask, chanHalfOp):
                     irc.queueMsg(ircmsgs.dehalfop(channel, value))
             elif mode == '+v':
                 if not ircdb.checkCapability(hostmask, chanVoice):
                     irc.queueMsg(ircmsgs.devoice(channel, value))
             elif mode == '-o':
                 if ircdb.checkCapability(hostmask, chanOp):
                     irc.queueMsg(ircmsgs.op(channel, value))
             elif mode == '-h':
                 if ircdb.checkCapability(hostmask, chanOp):
                     irc.queueMsg(ircmsgs.halfop(channel, value))
             elif mode == '-v':
                 if ircdb.checkCapability(hostmask, chanOp):
                     irc.queueMsg(ircmsgs.voice(channel, value))
         else:
             assert ircutils.isUserHostmask(value)
示例#3
0
    def testHandlesModes(self):
        st = irclib.IrcState()
        st.addMsg(self.irc, ircmsgs.join('#foo', prefix=self.irc.prefix))
        self.failIf('bar' in st.channels['#foo'].ops)
        st.addMsg(self.irc, ircmsgs.op('#foo', 'bar'))
        self.failUnless('bar' in st.channels['#foo'].ops)
        st.addMsg(self.irc, ircmsgs.deop('#foo', 'bar'))
        self.failIf('bar' in st.channels['#foo'].ops)

        self.failIf('bar' in st.channels['#foo'].voices)
        st.addMsg(self.irc, ircmsgs.voice('#foo', 'bar'))
        self.failUnless('bar' in st.channels['#foo'].voices)
        st.addMsg(self.irc, ircmsgs.devoice('#foo', 'bar'))
        self.failIf('bar' in st.channels['#foo'].voices)

        self.failIf('bar' in st.channels['#foo'].halfops)
        st.addMsg(self.irc, ircmsgs.halfop('#foo', 'bar'))
        self.failUnless('bar' in st.channels['#foo'].halfops)
        st.addMsg(self.irc, ircmsgs.dehalfop('#foo', 'bar'))
        self.failIf('bar' in st.channels['#foo'].halfops)
示例#4
0
    def testHandlesModes(self):
        st = irclib.IrcState()
        st.addMsg(self.irc, ircmsgs.join('#foo', prefix=self.irc.prefix))
        self.failIf('bar' in st.channels['#foo'].ops)
        st.addMsg(self.irc, ircmsgs.op('#foo', 'bar'))
        self.failUnless('bar' in st.channels['#foo'].ops)
        st.addMsg(self.irc, ircmsgs.deop('#foo', 'bar'))
        self.failIf('bar' in st.channels['#foo'].ops)

        self.failIf('bar' in st.channels['#foo'].voices)
        st.addMsg(self.irc, ircmsgs.voice('#foo', 'bar'))
        self.failUnless('bar' in st.channels['#foo'].voices)
        st.addMsg(self.irc, ircmsgs.devoice('#foo', 'bar'))
        self.failIf('bar' in st.channels['#foo'].voices)

        self.failIf('bar' in st.channels['#foo'].halfops)
        st.addMsg(self.irc, ircmsgs.halfop('#foo', 'bar'))
        self.failUnless('bar' in st.channels['#foo'].halfops)
        st.addMsg(self.irc, ircmsgs.dehalfop('#foo', 'bar'))
        self.failIf('bar' in st.channels['#foo'].halfops)