mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 12:42:34 +01:00
Added an "irc" argument to callbacks.Privmsg.__init__, so now plugins get an Irc on instantiation.
This commit is contained in:
parent
fe82ad63e0
commit
381a42d863
@ -42,9 +42,9 @@ import supybot.schedule as schedule
|
||||
import supybot.callbacks as callbacks
|
||||
|
||||
class Admin(callbacks.Privmsg):
|
||||
def __init__(self):
|
||||
def __init__(self, irc):
|
||||
self.__parent = super(Admin, self)
|
||||
self.__parent.__init__()
|
||||
self.__parent.__init__(irc)
|
||||
self.joins = {}
|
||||
self.pendingNickChanges = {}
|
||||
|
||||
|
@ -40,8 +40,9 @@ import supybot.ircutils as ircutils
|
||||
import supybot.callbacks as callbacks
|
||||
|
||||
class Channel(callbacks.Privmsg):
|
||||
def __init__(self):
|
||||
callbacks.Privmsg.__init__(self)
|
||||
def __init__(self, irc):
|
||||
self.__parent = super(Channel, self)
|
||||
self.__parent.__init__(irc)
|
||||
self.invites = {}
|
||||
|
||||
def doKick(self, irc, msg):
|
||||
|
@ -53,9 +53,10 @@ class Filter(callbacks.Privmsg):
|
||||
output of the bot -- for instance, you could make everything the bot says
|
||||
be in leetspeak, or Morse code, or any number of other kinds of filters.
|
||||
Not very useful, but definitely quite fun :)"""
|
||||
def __init__(self):
|
||||
def __init__(self, irc):
|
||||
self.__parent = super(Filter, self)
|
||||
self.__parent.__init__(irc)
|
||||
self.outFilters = ircutils.IrcDict()
|
||||
callbacks.Privmsg.__init__(self)
|
||||
|
||||
def outFilter(self, irc, msg):
|
||||
if msg.command == 'PRIVMSG':
|
||||
|
@ -55,9 +55,9 @@ class HeraldDB(plugins.ChannelUserDB):
|
||||
return L[0]
|
||||
|
||||
class Herald(callbacks.Privmsg):
|
||||
def __init__(self):
|
||||
def __init__(self, irc):
|
||||
self.__parent = super(Herald, self)
|
||||
self.__parent.__init__()
|
||||
self.__parent.__init__(irc)
|
||||
self.db = HeraldDB(filename)
|
||||
world.flushers.append(self.db.flush)
|
||||
self.lastParts = plugins.ChannelUserDictionary()
|
||||
|
@ -45,8 +45,9 @@ import supybot.callbacks as callbacks
|
||||
from supybot.utils.iter import ifilter
|
||||
|
||||
class Misc(callbacks.Privmsg):
|
||||
def __init__(self):
|
||||
super(Misc, self).__init__()
|
||||
def __init__(self, irc):
|
||||
self.__parent = super(Misc, self)
|
||||
self.__parent.__init__(irc)
|
||||
self.invalidCommands = ircutils.FloodQueue(60)
|
||||
|
||||
def callPrecedence(self, irc):
|
||||
|
@ -124,9 +124,9 @@ class LogProxy(object):
|
||||
class Owner(callbacks.Privmsg):
|
||||
# This plugin must be first; its priority must be lowest; otherwise odd
|
||||
# things will happen when adding callbacks.
|
||||
def __init__(self, *args, **kwargs):
|
||||
def __init__(self, irc):
|
||||
self.__parent = super(Owner, self)
|
||||
self.__parent.__init__()
|
||||
self.__parent.__init__(irc)
|
||||
# Setup log object/command.
|
||||
self.log = LogProxy(self.log)
|
||||
# Setup command flood detection.
|
||||
|
@ -45,8 +45,9 @@ import supybot.registry as registry
|
||||
import supybot.callbacks as callbacks
|
||||
|
||||
class Status(callbacks.Privmsg):
|
||||
def __init__(self):
|
||||
callbacks.Privmsg.__init__(self)
|
||||
def __init__(self, irc):
|
||||
self.__parent = super(Status, self)
|
||||
self.__parent.__init__(irc)
|
||||
self.sentMsgs = 0
|
||||
self.recvdMsgs = 0
|
||||
self.sentBytes = 0
|
||||
|
@ -1030,7 +1030,7 @@ class Privmsg(irclib.IrcCallback):
|
||||
def isDisabled(self, command):
|
||||
return self._disabled.disabled(command, self.name())
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, irc):
|
||||
self.__parent = super(Privmsg, self)
|
||||
myName = self.name()
|
||||
self.log = log.getPluginLogger(myName)
|
||||
@ -1274,9 +1274,9 @@ class PrivmsgRegexp(Privmsg):
|
||||
flags = re.I
|
||||
Proxy = SimpleProxy
|
||||
commandArgs = ['self', 'irc', 'msg', 'match']
|
||||
def __init__(self):
|
||||
def __init__(self, irc):
|
||||
self.__parent = super(PrivmsgRegexp, self)
|
||||
self.__parent.__init__()
|
||||
self.__parent.__init__(irc)
|
||||
self.res = []
|
||||
#for name, value in self.__class__.__dict__.iteritems():
|
||||
for name, value in self.__class__.__dict__.items():
|
||||
@ -1328,9 +1328,9 @@ class PrivmsgCommandAndRegexp(Privmsg):
|
||||
regexps = ()
|
||||
addressedRegexps = ()
|
||||
Proxy = SimpleProxy
|
||||
def __init__(self):
|
||||
def __init__(self, irc):
|
||||
self.__parent = super(PrivmsgCommandAndRegexp, self)
|
||||
self.__parent.__init__()
|
||||
self.__parent.__init__(irc)
|
||||
self.res = []
|
||||
self.addressedRes = []
|
||||
for name in self.regexps:
|
||||
|
@ -81,7 +81,7 @@ def loadPluginModule(name, ignoreDeprecation=False):
|
||||
def loadPluginClass(irc, module, register=None):
|
||||
"""Loads the plugin Class from the given module into the given Irc."""
|
||||
try:
|
||||
cb = module.Class()
|
||||
cb = module.Class(irc)
|
||||
except AttributeError, e:
|
||||
if 'Class' in str(e):
|
||||
raise callbacks.Error, \
|
||||
|
@ -85,7 +85,9 @@ class TestPlugin(callbacks.Privmsg):
|
||||
irc.reply(repr(eval(' '.join(args))))
|
||||
except Exception, e:
|
||||
irc.reply(utils.exnToString(e))
|
||||
TestInstance = TestPlugin()
|
||||
# Since we know we don't now need the Irc object, we just give None. This
|
||||
# might break if callbacks.Privmsg ever *requires* the Irc object.
|
||||
TestInstance = TestPlugin(None)
|
||||
conf.registerPlugin('TestPlugin', True, public=False)
|
||||
|
||||
class SupyTestCase(unittest.TestCase):
|
||||
|
@ -389,17 +389,17 @@ class PrivmsgTestCase(ChannelPluginTestCase):
|
||||
ChannelPluginTestCase.tearDown(self)
|
||||
|
||||
def testDispatching(self):
|
||||
self.irc.addCallback(self.First())
|
||||
self.irc.addCallback(self.Second())
|
||||
self.irc.addCallback(self.First(self.irc))
|
||||
self.irc.addCallback(self.Second(self.irc))
|
||||
self.assertResponse('firstcmd', 'foo')
|
||||
self.assertResponse('secondcmd', 'bar')
|
||||
self.assertResponse('first firstcmd', 'foo')
|
||||
self.assertResponse('second secondcmd', 'bar')
|
||||
|
||||
def testAmbiguousError(self):
|
||||
self.irc.addCallback(self.First())
|
||||
self.irc.addCallback(self.First(self.irc))
|
||||
self.assertNotError('firstcmd')
|
||||
self.irc.addCallback(self.FirstRepeat())
|
||||
self.irc.addCallback(self.FirstRepeat(self.irc))
|
||||
self.assertError('firstcmd')
|
||||
self.assertError('firstcmd [firstcmd]')
|
||||
self.assertNotRegexp('firstcmd', '(foo.*baz|baz.*foo)')
|
||||
@ -407,15 +407,15 @@ class PrivmsgTestCase(ChannelPluginTestCase):
|
||||
self.assertResponse('firstrepeat firstcmd', 'baz')
|
||||
|
||||
def testAmbiguousHelpError(self):
|
||||
self.irc.addCallback(self.First())
|
||||
self.irc.addCallback(self.FirstRepeat())
|
||||
self.irc.addCallback(self.First(self.irc))
|
||||
self.irc.addCallback(self.FirstRepeat(self.irc))
|
||||
self.assertError('help first')
|
||||
|
||||
def testHelpDispatching(self):
|
||||
self.irc.addCallback(self.First())
|
||||
self.irc.addCallback(self.First(self.irc))
|
||||
self.assertHelp('help firstcmd')
|
||||
self.assertHelp('help first firstcmd')
|
||||
self.irc.addCallback(self.FirstRepeat())
|
||||
self.irc.addCallback(self.FirstRepeat(self.irc))
|
||||
self.assertError('help firstcmd')
|
||||
self.assertRegexp('help first firstcmd', 'First', 0) # no re.I flag.
|
||||
self.assertRegexp('help firstrepeat firstcmd', 'FirstRepeat', 0)
|
||||
@ -426,7 +426,7 @@ class PrivmsgTestCase(ChannelPluginTestCase):
|
||||
irc.reply('bar') # We're going to check that this isn't an action.
|
||||
|
||||
def testNotActionSecondReply(self):
|
||||
self.irc.addCallback(self.TwoRepliesFirstAction())
|
||||
self.irc.addCallback(self.TwoRepliesFirstAction(self.irc))
|
||||
self.assertAction('testactionreply', 'foo')
|
||||
m = self.getMsg(' ')
|
||||
self.failIf(m.args[1].startswith('\x01ACTION'))
|
||||
@ -445,8 +445,8 @@ class PrivmsgTestCase(ChannelPluginTestCase):
|
||||
self.assertNotRegexp('help first', r'%s')
|
||||
|
||||
def testDefaultCommand(self):
|
||||
self.irc.addCallback(self.First())
|
||||
self.irc.addCallback(self.Third())
|
||||
self.irc.addCallback(self.First(self.irc))
|
||||
self.irc.addCallback(self.Third(self.irc))
|
||||
self.assertError('first blah')
|
||||
self.assertResponse('third foo bar baz', 'foo bar baz')
|
||||
|
||||
@ -466,7 +466,7 @@ class PrivmsgTestCase(ChannelPluginTestCase):
|
||||
original = str(conf.supybot.reply.whenNotCommand)
|
||||
conf.supybot.reply.whenNotCommand.set('True')
|
||||
self.assertRegexp('asdfjkl', 'not a valid command')
|
||||
self.irc.addCallback(self.InvalidCommand())
|
||||
self.irc.addCallback(self.InvalidCommand(self.irc))
|
||||
self.assertResponse('asdfjkl', 'foo')
|
||||
self.assertNoResponse(' ', 2)
|
||||
finally:
|
||||
@ -481,7 +481,7 @@ class PrivmsgTestCase(ChannelPluginTestCase):
|
||||
try:
|
||||
original = str(conf.supybot.reply.whenNotCommand)
|
||||
conf.supybot.reply.whenNotCommand.set('True')
|
||||
self.irc.addCallback(self.BadInvalidCommand())
|
||||
self.irc.addCallback(self.BadInvalidCommand(self.irc))
|
||||
self.assertRegexp('asdfjkl', 'not a valid command')
|
||||
finally:
|
||||
conf.supybot.reply.whenNotCommand.set(original)
|
||||
@ -494,7 +494,7 @@ class PrivmsgCommandAndRegexpTestCase(PluginTestCase):
|
||||
"<foo>"
|
||||
raise callbacks.ArgumentError
|
||||
def testNoEscapingArgumentError(self):
|
||||
self.irc.addCallback(self.PCAR())
|
||||
self.irc.addCallback(self.PCAR(self.irc))
|
||||
self.assertResponse('test', 'test <foo>')
|
||||
|
||||
class RichReplyMethodsTestCase(PluginTestCase):
|
||||
@ -503,7 +503,7 @@ class RichReplyMethodsTestCase(PluginTestCase):
|
||||
def error(self, irc, msg, args):
|
||||
irc.errorNoCapability('admin')
|
||||
def testErrorNoCapability(self):
|
||||
self.irc.addCallback(self.NoCapability())
|
||||
self.irc.addCallback(self.NoCapability(self.irc))
|
||||
self.assertRegexp('error', 'admin')
|
||||
|
||||
|
||||
@ -519,7 +519,7 @@ class WithPrivateNoticeTestCase(ChannelPluginTestCase):
|
||||
irc.reply('should be with notice due to private',
|
||||
private=True)
|
||||
def test(self):
|
||||
self.irc.addCallback(self.WithPrivateNotice())
|
||||
self.irc.addCallback(self.WithPrivateNotice(self.irc))
|
||||
# Check normal behavior.
|
||||
m = self.assertNotError('normal')
|
||||
self.failIf(m.command == 'NOTICE')
|
||||
|
Loading…
Reference in New Issue
Block a user