mirror of
https://git.wownero.com/wownero/tippero.git
synced 2024-08-15 00:33:14 +00:00
Make idle and cleanup functions fields of the module object
This commit is contained in:
parent
9ab5db39e4
commit
1a6476d2f0
2 changed files with 14 additions and 25 deletions
|
@ -15,8 +15,6 @@ from tipbot.utils import *
|
||||||
modules = dict()
|
modules = dict()
|
||||||
commands = dict()
|
commands = dict()
|
||||||
calltable=dict()
|
calltable=dict()
|
||||||
idles = []
|
|
||||||
cleanup = dict()
|
|
||||||
|
|
||||||
def SendToProxy(link,msg):
|
def SendToProxy(link,msg):
|
||||||
link.send(msg)
|
link.send(msg)
|
||||||
|
@ -122,12 +120,6 @@ def RegisterCommand(command):
|
||||||
commands[command['name']] = []
|
commands[command['name']] = []
|
||||||
commands[command['name']].append(command)
|
commands[command['name']].append(command)
|
||||||
|
|
||||||
def RegisterIdleFunction(module,function):
|
|
||||||
idles.append((module,function))
|
|
||||||
|
|
||||||
def RegisterCleanupFunction(module,function):
|
|
||||||
cleanup.append((module,function))
|
|
||||||
|
|
||||||
def OnCommand(link,cmd,check_admin,check_registered):
|
def OnCommand(link,cmd,check_admin,check_registered):
|
||||||
cmdparts = cmd[0].split(':')
|
cmdparts = cmd[0].split(':')
|
||||||
log_log('cmdparts: %s' % str(cmdparts))
|
log_log('cmdparts: %s' % str(cmdparts))
|
||||||
|
@ -178,11 +170,13 @@ def OnCommand(link,cmd,check_admin,check_registered):
|
||||||
link.send("Invalid command, try !help")
|
link.send("Invalid command, try !help")
|
||||||
|
|
||||||
def RunIdleFunctions(param=None):
|
def RunIdleFunctions(param=None):
|
||||||
for f in idles:
|
for module in modules:
|
||||||
try:
|
if 'idle' in modules[module]:
|
||||||
f[1](param)
|
f=modules[module]['idle']
|
||||||
except Exception,e:
|
try:
|
||||||
log_error("Exception running idle function %s from module %s: %s" % (str(f[1]),str(f[2]),str(e)))
|
f(param)
|
||||||
|
except Exception,e:
|
||||||
|
log_error("Exception running idle function %s from module %s: %s" % (str(f),module,str(e)))
|
||||||
|
|
||||||
def RunModuleHelpFunction(module,link):
|
def RunModuleHelpFunction(module,link):
|
||||||
if module in modules:
|
if module in modules:
|
||||||
|
@ -197,18 +191,12 @@ def UnregisterModule(module):
|
||||||
global commands
|
global commands
|
||||||
global idles
|
global idles
|
||||||
|
|
||||||
if module in cleanup:
|
if not module in modules:
|
||||||
cleanup[module]()
|
log_error('Trying to unregister module %s, which is not registered' % module)
|
||||||
del cleanup[module]
|
return
|
||||||
|
|
||||||
if module in modules:
|
if 'cleanup' in modules[module]:
|
||||||
del modules[module]
|
modules[module]['cleanup']()
|
||||||
|
|
||||||
new_idles = []
|
|
||||||
for f in idles:
|
|
||||||
if f[0] != module:
|
|
||||||
new_idles.append(f)
|
|
||||||
idles = new_idles
|
|
||||||
|
|
||||||
new_commands = dict()
|
new_commands = dict()
|
||||||
for cmd in commands:
|
for cmd in commands:
|
||||||
|
@ -220,3 +208,4 @@ def UnregisterModule(module):
|
||||||
new_commands[cmd] = newlist
|
new_commands[cmd] = newlist
|
||||||
commands = new_commands
|
commands = new_commands
|
||||||
|
|
||||||
|
del modules[module]
|
||||||
|
|
|
@ -114,6 +114,7 @@ def Help(link):
|
||||||
RegisterModule({
|
RegisterModule({
|
||||||
'name': __name__,
|
'name': __name__,
|
||||||
'help': Help,
|
'help': Help,
|
||||||
|
'idle': UpdateCoin
|
||||||
})
|
})
|
||||||
RegisterCommand({
|
RegisterCommand({
|
||||||
'module': __name__,
|
'module': __name__,
|
||||||
|
@ -121,5 +122,4 @@ RegisterCommand({
|
||||||
'function': Deposit,
|
'function': Deposit,
|
||||||
'help': "Show instructions about depositing %s" % coinspecs.name
|
'help': "Show instructions about depositing %s" % coinspecs.name
|
||||||
})
|
})
|
||||||
RegisterIdleFunction(__name__,UpdateCoin)
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue