Timeout for voicing
This commit is contained in:
parent
ed6f38afdc
commit
c57485583e
10
config.py
10
config.py
|
|
@ -94,6 +94,16 @@ conf.registerChannelValue(TriviaTime.general, 'waitTime',
|
|||
"""Time in between the end of one question and the start of another""")
|
||||
)
|
||||
|
||||
conf.registerChannelValue(TriviaTime.voice, 'enableVoice',
|
||||
registry.Boolean(True,
|
||||
"""Enable voicing of top players for week, month, and year""")
|
||||
)
|
||||
|
||||
conf.registerChannelValue(TriviaTime.voice, 'timeoutVoice',
|
||||
registry.Integer(60,
|
||||
"""The minimum amount of time between anouncing voicing of a user""")
|
||||
)
|
||||
|
||||
conf.registerChannelValue(TriviaTime.voice, 'numTopToVoice',
|
||||
registry.Integer(10,
|
||||
"""The number of top players who are elligible for voice""")
|
||||
|
|
|
|||
86
plugin.py
86
plugin.py
|
|
@ -39,6 +39,7 @@ class TriviaTime(callbacks.Plugin):
|
|||
|
||||
# games info
|
||||
self.games = {} # separate game for each channel
|
||||
self.voiceTimeouts = self.TimeoutList(self.registryValue('voice.timeoutVoice'))
|
||||
|
||||
#Database amend statements for outdated versions
|
||||
self.dbamends = {} #Formatted like this: <DBVersion>: "<ALTERSTATEMENT>; <ALTERSTATEMENT>;" (This IS valid SQL as long as we include the semicolons)
|
||||
|
|
@ -112,16 +113,15 @@ class TriviaTime(callbacks.Plugin):
|
|||
# check the answer
|
||||
self.games[channelCanonical].checkAnswer(msg)
|
||||
|
||||
def doJoin(self,irc,msg):
|
||||
username = msg.nick
|
||||
# is it a user?
|
||||
try:
|
||||
# rootcoma!~rootcomaa@unaffiliated/rootcoma
|
||||
user = ircdb.users.getUser(msg.prefix)
|
||||
username = user.name
|
||||
except KeyError:
|
||||
pass
|
||||
channel = msg.args[0]
|
||||
def voiceUser(self, irc, username, channel):
|
||||
irc.queueMsg(ircmsgs.voice(channel, username))
|
||||
|
||||
def handleVoice(self, irc, username, channel):
|
||||
if not self.registryValue('voice.enableVoice'):
|
||||
return
|
||||
timeoutVoice = self.registryValue('voice.timeoutVoice')
|
||||
self.voiceTimeouts.setTimeout(timeoutVoice)
|
||||
usernameCanonical = ircutils.toLower(username)
|
||||
dbLocation = self.registryValue('admin.sqlitedb')
|
||||
threadStorage = self.Storage(dbLocation)
|
||||
if self.registryValue('general.globalStats'):
|
||||
|
|
@ -134,26 +134,32 @@ class TriviaTime(callbacks.Plugin):
|
|||
minPointsVoiceWeek = self.registryValue('voice.minPointsVoiceWeek')
|
||||
if len(user) >= 1:
|
||||
if user[13] <= numTopToVoice and user[4] >= minPointsVoiceYear:
|
||||
irc.sendMsg(
|
||||
ircmsgs.privmsg(channel,
|
||||
'Giving MVP to %s for being top #%d this YEAR' % (username, user[13])
|
||||
)
|
||||
)
|
||||
irc.queueMsg(ircmsgs.voice(channel, username))
|
||||
if not self.voiceTimeouts.has(usernameCanonical):
|
||||
self.voiceTimeouts.append(usernameCanonical)
|
||||
irc.sendMsg(ircmsgs.privmsg(channel, 'Giving MVP to %s for being top #%d this YEAR' % (username, user[13])))
|
||||
self.voiceUser(irc,channel, username)
|
||||
elif user[14] <= numTopToVoice and user[6] >= minPointsVoiceMonth:
|
||||
irc.sendMsg(
|
||||
ircmsgs.privmsg(channel,
|
||||
'Giving MVP to %s for being top #%d this MONTH' % (username, user[14])
|
||||
)
|
||||
)
|
||||
irc.queueMsg(ircmsgs.voice(channel, username))
|
||||
if not self.voiceTimeouts.has(usernameCanonical):
|
||||
self.voiceTimeouts.append(usernameCanonical)
|
||||
irc.sendMsg(ircmsgs.privmsg(channel, 'Giving MVP to %s for being top #%d this MONTH' % (username, user[14])))
|
||||
self.voiceUser(irc,channel, username)
|
||||
elif user[15] <= numTopToVoice and user[8] >= minPointsVoiceWeek:
|
||||
irc.sendMsg(
|
||||
ircmsgs.privmsg(channel,
|
||||
'Giving MVP to %s for being top #%d this WEEK' % (username, user[15])
|
||||
)
|
||||
)
|
||||
irc.queueMsg(ircmsgs.voice(channel, username))
|
||||
if not self.voiceTimeouts.has(usernameCanonical):
|
||||
self.voiceTimeouts.append(usernameCanonical)
|
||||
irc.sendMsg(ircmsgs.privmsg(channel, 'Giving MVP to %s for being top #%d this WEEK' % (username, user[15])))
|
||||
self.voiceUser(irc,channel, username)
|
||||
|
||||
def doJoin(self,irc,msg):
|
||||
username = msg.nick
|
||||
# is it a user?
|
||||
try:
|
||||
# rootcoma!~rootcomaa@unaffiliated/rootcoma
|
||||
user = ircdb.users.getUser(msg.prefix)
|
||||
username = user.name
|
||||
except KeyError:
|
||||
pass
|
||||
channel = msg.args[0]
|
||||
self.handleVoice(irc, username, channel)
|
||||
|
||||
def doNotice(self,irc,msg):
|
||||
username = msg.nick
|
||||
|
|
@ -3619,5 +3625,29 @@ class TriviaTime(callbacks.Plugin):
|
|||
except:
|
||||
pass
|
||||
|
||||
class TimeoutList:
|
||||
def __init__(self, timeout):
|
||||
self.timeout = timeout
|
||||
self.dict = {}
|
||||
|
||||
def setTimeout(self, timeout):
|
||||
self.timeout = timeout
|
||||
|
||||
def clearTimeout(self):
|
||||
for k, t in self.dict.items():
|
||||
if t < (time.time() - self.timeout):
|
||||
del self.dict[k]
|
||||
|
||||
def append(self, value):
|
||||
self.clearTimeout()
|
||||
self.dict[value] = time.time()
|
||||
|
||||
def has(self, value):
|
||||
self.clearTimeout()
|
||||
if value in self.dict:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
Class = TriviaTime
|
||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||
|
|
|
|||
Loading…
Reference in New Issue