Added an "irc" argument to callbacks.Privmsg.__init__, so now plugins get an Irc on instantiation.

This commit is contained in:
Jeremy Fincher 2005-01-29 19:16:29 +00:00
parent fe82ad63e0
commit 381a42d863
11 changed files with 43 additions and 37 deletions

View File

@ -42,9 +42,9 @@ import supybot.schedule as schedule
import supybot.callbacks as callbacks import supybot.callbacks as callbacks
class Admin(callbacks.Privmsg): class Admin(callbacks.Privmsg):
def __init__(self): def __init__(self, irc):
self.__parent = super(Admin, self) self.__parent = super(Admin, self)
self.__parent.__init__() self.__parent.__init__(irc)
self.joins = {} self.joins = {}
self.pendingNickChanges = {} self.pendingNickChanges = {}

View File

@ -40,8 +40,9 @@ import supybot.ircutils as ircutils
import supybot.callbacks as callbacks import supybot.callbacks as callbacks
class Channel(callbacks.Privmsg): class Channel(callbacks.Privmsg):
def __init__(self): def __init__(self, irc):
callbacks.Privmsg.__init__(self) self.__parent = super(Channel, self)
self.__parent.__init__(irc)
self.invites = {} self.invites = {}
def doKick(self, irc, msg): def doKick(self, irc, msg):

View File

@ -53,9 +53,10 @@ class Filter(callbacks.Privmsg):
output of the bot -- for instance, you could make everything the bot says 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. be in leetspeak, or Morse code, or any number of other kinds of filters.
Not very useful, but definitely quite fun :)""" 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() self.outFilters = ircutils.IrcDict()
callbacks.Privmsg.__init__(self)
def outFilter(self, irc, msg): def outFilter(self, irc, msg):
if msg.command == 'PRIVMSG': if msg.command == 'PRIVMSG':

View File

@ -55,9 +55,9 @@ class HeraldDB(plugins.ChannelUserDB):
return L[0] return L[0]
class Herald(callbacks.Privmsg): class Herald(callbacks.Privmsg):
def __init__(self): def __init__(self, irc):
self.__parent = super(Herald, self) self.__parent = super(Herald, self)
self.__parent.__init__() self.__parent.__init__(irc)
self.db = HeraldDB(filename) self.db = HeraldDB(filename)
world.flushers.append(self.db.flush) world.flushers.append(self.db.flush)
self.lastParts = plugins.ChannelUserDictionary() self.lastParts = plugins.ChannelUserDictionary()

View File

@ -45,8 +45,9 @@ import supybot.callbacks as callbacks
from supybot.utils.iter import ifilter from supybot.utils.iter import ifilter
class Misc(callbacks.Privmsg): class Misc(callbacks.Privmsg):
def __init__(self): def __init__(self, irc):
super(Misc, self).__init__() self.__parent = super(Misc, self)
self.__parent.__init__(irc)
self.invalidCommands = ircutils.FloodQueue(60) self.invalidCommands = ircutils.FloodQueue(60)
def callPrecedence(self, irc): def callPrecedence(self, irc):

View File

@ -124,9 +124,9 @@ class LogProxy(object):
class Owner(callbacks.Privmsg): class Owner(callbacks.Privmsg):
# This plugin must be first; its priority must be lowest; otherwise odd # This plugin must be first; its priority must be lowest; otherwise odd
# things will happen when adding callbacks. # things will happen when adding callbacks.
def __init__(self, *args, **kwargs): def __init__(self, irc):
self.__parent = super(Owner, self) self.__parent = super(Owner, self)
self.__parent.__init__() self.__parent.__init__(irc)
# Setup log object/command. # Setup log object/command.
self.log = LogProxy(self.log) self.log = LogProxy(self.log)
# Setup command flood detection. # Setup command flood detection.

View File

@ -45,8 +45,9 @@ import supybot.registry as registry
import supybot.callbacks as callbacks import supybot.callbacks as callbacks
class Status(callbacks.Privmsg): class Status(callbacks.Privmsg):
def __init__(self): def __init__(self, irc):
callbacks.Privmsg.__init__(self) self.__parent = super(Status, self)
self.__parent.__init__(irc)
self.sentMsgs = 0 self.sentMsgs = 0
self.recvdMsgs = 0 self.recvdMsgs = 0
self.sentBytes = 0 self.sentBytes = 0

View File

@ -1030,7 +1030,7 @@ class Privmsg(irclib.IrcCallback):
def isDisabled(self, command): def isDisabled(self, command):
return self._disabled.disabled(command, self.name()) return self._disabled.disabled(command, self.name())
def __init__(self): def __init__(self, irc):
self.__parent = super(Privmsg, self) self.__parent = super(Privmsg, self)
myName = self.name() myName = self.name()
self.log = log.getPluginLogger(myName) self.log = log.getPluginLogger(myName)
@ -1274,9 +1274,9 @@ class PrivmsgRegexp(Privmsg):
flags = re.I flags = re.I
Proxy = SimpleProxy Proxy = SimpleProxy
commandArgs = ['self', 'irc', 'msg', 'match'] commandArgs = ['self', 'irc', 'msg', 'match']
def __init__(self): def __init__(self, irc):
self.__parent = super(PrivmsgRegexp, self) self.__parent = super(PrivmsgRegexp, self)
self.__parent.__init__() self.__parent.__init__(irc)
self.res = [] self.res = []
#for name, value in self.__class__.__dict__.iteritems(): #for name, value in self.__class__.__dict__.iteritems():
for name, value in self.__class__.__dict__.items(): for name, value in self.__class__.__dict__.items():
@ -1328,9 +1328,9 @@ class PrivmsgCommandAndRegexp(Privmsg):
regexps = () regexps = ()
addressedRegexps = () addressedRegexps = ()
Proxy = SimpleProxy Proxy = SimpleProxy
def __init__(self): def __init__(self, irc):
self.__parent = super(PrivmsgCommandAndRegexp, self) self.__parent = super(PrivmsgCommandAndRegexp, self)
self.__parent.__init__() self.__parent.__init__(irc)
self.res = [] self.res = []
self.addressedRes = [] self.addressedRes = []
for name in self.regexps: for name in self.regexps:

View File

@ -81,7 +81,7 @@ def loadPluginModule(name, ignoreDeprecation=False):
def loadPluginClass(irc, module, register=None): def loadPluginClass(irc, module, register=None):
"""Loads the plugin Class from the given module into the given Irc.""" """Loads the plugin Class from the given module into the given Irc."""
try: try:
cb = module.Class() cb = module.Class(irc)
except AttributeError, e: except AttributeError, e:
if 'Class' in str(e): if 'Class' in str(e):
raise callbacks.Error, \ raise callbacks.Error, \

View File

@ -85,7 +85,9 @@ class TestPlugin(callbacks.Privmsg):
irc.reply(repr(eval(' '.join(args)))) irc.reply(repr(eval(' '.join(args))))
except Exception, e: except Exception, e:
irc.reply(utils.exnToString(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) conf.registerPlugin('TestPlugin', True, public=False)
class SupyTestCase(unittest.TestCase): class SupyTestCase(unittest.TestCase):

View File

@ -389,17 +389,17 @@ class PrivmsgTestCase(ChannelPluginTestCase):
ChannelPluginTestCase.tearDown(self) ChannelPluginTestCase.tearDown(self)
def testDispatching(self): def testDispatching(self):
self.irc.addCallback(self.First()) self.irc.addCallback(self.First(self.irc))
self.irc.addCallback(self.Second()) self.irc.addCallback(self.Second(self.irc))
self.assertResponse('firstcmd', 'foo') self.assertResponse('firstcmd', 'foo')
self.assertResponse('secondcmd', 'bar') self.assertResponse('secondcmd', 'bar')
self.assertResponse('first firstcmd', 'foo') self.assertResponse('first firstcmd', 'foo')
self.assertResponse('second secondcmd', 'bar') self.assertResponse('second secondcmd', 'bar')
def testAmbiguousError(self): def testAmbiguousError(self):
self.irc.addCallback(self.First()) self.irc.addCallback(self.First(self.irc))
self.assertNotError('firstcmd') self.assertNotError('firstcmd')
self.irc.addCallback(self.FirstRepeat()) self.irc.addCallback(self.FirstRepeat(self.irc))
self.assertError('firstcmd') self.assertError('firstcmd')
self.assertError('firstcmd [firstcmd]') self.assertError('firstcmd [firstcmd]')
self.assertNotRegexp('firstcmd', '(foo.*baz|baz.*foo)') self.assertNotRegexp('firstcmd', '(foo.*baz|baz.*foo)')
@ -407,15 +407,15 @@ class PrivmsgTestCase(ChannelPluginTestCase):
self.assertResponse('firstrepeat firstcmd', 'baz') self.assertResponse('firstrepeat firstcmd', 'baz')
def testAmbiguousHelpError(self): def testAmbiguousHelpError(self):
self.irc.addCallback(self.First()) self.irc.addCallback(self.First(self.irc))
self.irc.addCallback(self.FirstRepeat()) self.irc.addCallback(self.FirstRepeat(self.irc))
self.assertError('help first') self.assertError('help first')
def testHelpDispatching(self): def testHelpDispatching(self):
self.irc.addCallback(self.First()) self.irc.addCallback(self.First(self.irc))
self.assertHelp('help firstcmd') self.assertHelp('help firstcmd')
self.assertHelp('help first firstcmd') self.assertHelp('help first firstcmd')
self.irc.addCallback(self.FirstRepeat()) self.irc.addCallback(self.FirstRepeat(self.irc))
self.assertError('help firstcmd') self.assertError('help firstcmd')
self.assertRegexp('help first firstcmd', 'First', 0) # no re.I flag. self.assertRegexp('help first firstcmd', 'First', 0) # no re.I flag.
self.assertRegexp('help firstrepeat firstcmd', 'FirstRepeat', 0) 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. irc.reply('bar') # We're going to check that this isn't an action.
def testNotActionSecondReply(self): def testNotActionSecondReply(self):
self.irc.addCallback(self.TwoRepliesFirstAction()) self.irc.addCallback(self.TwoRepliesFirstAction(self.irc))
self.assertAction('testactionreply', 'foo') self.assertAction('testactionreply', 'foo')
m = self.getMsg(' ') m = self.getMsg(' ')
self.failIf(m.args[1].startswith('\x01ACTION')) self.failIf(m.args[1].startswith('\x01ACTION'))
@ -445,8 +445,8 @@ class PrivmsgTestCase(ChannelPluginTestCase):
self.assertNotRegexp('help first', r'%s') self.assertNotRegexp('help first', r'%s')
def testDefaultCommand(self): def testDefaultCommand(self):
self.irc.addCallback(self.First()) self.irc.addCallback(self.First(self.irc))
self.irc.addCallback(self.Third()) self.irc.addCallback(self.Third(self.irc))
self.assertError('first blah') self.assertError('first blah')
self.assertResponse('third foo bar baz', 'foo bar baz') self.assertResponse('third foo bar baz', 'foo bar baz')
@ -466,7 +466,7 @@ class PrivmsgTestCase(ChannelPluginTestCase):
original = str(conf.supybot.reply.whenNotCommand) original = str(conf.supybot.reply.whenNotCommand)
conf.supybot.reply.whenNotCommand.set('True') conf.supybot.reply.whenNotCommand.set('True')
self.assertRegexp('asdfjkl', 'not a valid command') self.assertRegexp('asdfjkl', 'not a valid command')
self.irc.addCallback(self.InvalidCommand()) self.irc.addCallback(self.InvalidCommand(self.irc))
self.assertResponse('asdfjkl', 'foo') self.assertResponse('asdfjkl', 'foo')
self.assertNoResponse(' ', 2) self.assertNoResponse(' ', 2)
finally: finally:
@ -481,7 +481,7 @@ class PrivmsgTestCase(ChannelPluginTestCase):
try: try:
original = str(conf.supybot.reply.whenNotCommand) original = str(conf.supybot.reply.whenNotCommand)
conf.supybot.reply.whenNotCommand.set('True') 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') self.assertRegexp('asdfjkl', 'not a valid command')
finally: finally:
conf.supybot.reply.whenNotCommand.set(original) conf.supybot.reply.whenNotCommand.set(original)
@ -494,7 +494,7 @@ class PrivmsgCommandAndRegexpTestCase(PluginTestCase):
"<foo>" "<foo>"
raise callbacks.ArgumentError raise callbacks.ArgumentError
def testNoEscapingArgumentError(self): def testNoEscapingArgumentError(self):
self.irc.addCallback(self.PCAR()) self.irc.addCallback(self.PCAR(self.irc))
self.assertResponse('test', 'test <foo>') self.assertResponse('test', 'test <foo>')
class RichReplyMethodsTestCase(PluginTestCase): class RichReplyMethodsTestCase(PluginTestCase):
@ -503,7 +503,7 @@ class RichReplyMethodsTestCase(PluginTestCase):
def error(self, irc, msg, args): def error(self, irc, msg, args):
irc.errorNoCapability('admin') irc.errorNoCapability('admin')
def testErrorNoCapability(self): def testErrorNoCapability(self):
self.irc.addCallback(self.NoCapability()) self.irc.addCallback(self.NoCapability(self.irc))
self.assertRegexp('error', 'admin') self.assertRegexp('error', 'admin')
@ -519,7 +519,7 @@ class WithPrivateNoticeTestCase(ChannelPluginTestCase):
irc.reply('should be with notice due to private', irc.reply('should be with notice due to private',
private=True) private=True)
def test(self): def test(self):
self.irc.addCallback(self.WithPrivateNotice()) self.irc.addCallback(self.WithPrivateNotice(self.irc))
# Check normal behavior. # Check normal behavior.
m = self.assertNotError('normal') m = self.assertNotError('normal')
self.failIf(m.command == 'NOTICE') self.failIf(m.command == 'NOTICE')