mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 19:19:32 +01:00
Updated to use the registry.
This commit is contained in:
parent
dbcbdb76fa
commit
ca094203f5
@ -47,16 +47,6 @@ import ircmsgs
|
|||||||
import ircutils
|
import ircutils
|
||||||
import privmsgs
|
import privmsgs
|
||||||
import callbacks
|
import callbacks
|
||||||
import configurable
|
|
||||||
|
|
||||||
|
|
||||||
def configure(onStart, afterConnect, advanced):
|
|
||||||
# This will be called by setup.py to configure this module. onStart and
|
|
||||||
# afterConnect are both lists. Append to onStart the commands you would
|
|
||||||
# like to be run when the bot is started; append to afterConnect the
|
|
||||||
# commands you would like to be run when the bot has finished connecting.
|
|
||||||
from questions import expect, anything, something, yn
|
|
||||||
onStart.append('load Herald')
|
|
||||||
|
|
||||||
|
|
||||||
class HeraldDB(object):
|
class HeraldDB(object):
|
||||||
@ -100,21 +90,22 @@ class HeraldDB(object):
|
|||||||
del self.heralds[(id, channel)]
|
del self.heralds[(id, channel)]
|
||||||
|
|
||||||
|
|
||||||
class Herald(callbacks.Privmsg, configurable.Mixin):
|
conf.registerPlugin('Herald')
|
||||||
configurables = configurable.Dictionary(
|
conf.registerChannelValue(conf.supybot.plugins.Herald, 'heralding',
|
||||||
[('heralding', configurable.BoolType, True,
|
registry.Boolean(True, """Determines whether messages will be sent to the
|
||||||
"""Determines whether messages will be sent to the channel when
|
channel when a recognized user joins; basically enables or disables the
|
||||||
a recognized user joins; basically enables or disables the
|
plugin."""))
|
||||||
plugin."""),
|
conf.registerChannelValue(conf.supybot.plugins.Herald, 'throttleTime',
|
||||||
('throttle-time', configurable.PositiveIntType, 600,
|
registry.PositiveInteger(600, """Determines the minimum number of seconds
|
||||||
"""Determines the minimum number of seconds between heralds."""),
|
between heralds."""))
|
||||||
('throttle-after-part', configurable.IntType, 60,
|
conf.registerChannelValue(conf.supybot.plugins.Herald, 'throttleTimeAfterPart',
|
||||||
"""Determines the minimum number of seconds after parting that the
|
registry.PositiveInteger(60, """Determines the minimum number of seconds
|
||||||
bot will not herald the person when he or she rejoins."""),]
|
after parting that the bot will not herald the person when he or she
|
||||||
)
|
rejoins."""))
|
||||||
|
|
||||||
|
class Herald(callbacks.Privmsg):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
callbacks.Privmsg.__init__(self)
|
callbacks.Privmsg.__init__(self)
|
||||||
configurable.Mixin.__init__(self)
|
|
||||||
self.db = HeraldDB()
|
self.db = HeraldDB()
|
||||||
self.lastParts = {}
|
self.lastParts = {}
|
||||||
self.lastHerald = {}
|
self.lastHerald = {}
|
||||||
@ -122,21 +113,20 @@ class Herald(callbacks.Privmsg, configurable.Mixin):
|
|||||||
def die(self):
|
def die(self):
|
||||||
self.db.close()
|
self.db.close()
|
||||||
callbacks.Privmsg.die(self)
|
callbacks.Privmsg.die(self)
|
||||||
configurable.Mixin.die(self)
|
|
||||||
|
|
||||||
def doJoin(self, irc, msg):
|
def doJoin(self, irc, msg):
|
||||||
channel = msg.args[0]
|
channel = msg.args[0]
|
||||||
if self.configurables.get('heralding', channel):
|
if self.registryValue('heralding', channel):
|
||||||
try:
|
try:
|
||||||
id = ircdb.users.getUserId(msg.prefix)
|
id = ircdb.users.getUserId(msg.prefix)
|
||||||
herald = self.db.getHerald(id, channel)
|
herald = self.db.getHerald(id, channel)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return
|
return
|
||||||
now = time.time()
|
now = time.time()
|
||||||
throttle = self.configurables.get('throttle-time', channel)
|
throttle = self.registryValue('throttleTime', channel)
|
||||||
if now - self.lastHerald.get((id, channel), 0) > throttle:
|
if now - self.lastHerald.get((id, channel), 0) > throttle:
|
||||||
if (id, channel) in self.lastParts:
|
if (id, channel) in self.lastParts:
|
||||||
i = self.configurables.get('throttle-after-part', channel)
|
i = self.registryValue('throttleTimeAfterPart', channel)
|
||||||
if now - self.lastParts[(id, channel)] < i:
|
if now - self.lastParts[(id, channel)] < i:
|
||||||
return
|
return
|
||||||
self.lastHerald[(id, channel)] = now
|
self.lastHerald[(id, channel)] = now
|
||||||
|
Loading…
Reference in New Issue
Block a user