mirror of
https://git.wownero.com/wownero/tippero.git
synced 2024-08-15 00:33:14 +00:00
Modules can now be reloaded
This commit is contained in:
parent
800e1d754c
commit
a59e883626
3 changed files with 49 additions and 5 deletions
|
@ -16,6 +16,7 @@ from tipbot.irc import *
|
|||
commands = dict()
|
||||
calltable=dict()
|
||||
idles = []
|
||||
cleanup = dict()
|
||||
|
||||
def RunRegisteredCommand(nick,chan,ifyes,yesdata,ifno,nodata):
|
||||
if nick not in calltable:
|
||||
|
@ -91,8 +92,11 @@ def Commands(nick,chan,cmd):
|
|||
def RegisterCommand(command):
|
||||
commands[command['name']] = command
|
||||
|
||||
def RegisterIdleFunction(function):
|
||||
idles.append(function)
|
||||
def RegisterIdleFunction(module,function):
|
||||
idles.append((module,function))
|
||||
|
||||
def RegisterCleanupFunction(module,function):
|
||||
cleanup.append((module,function))
|
||||
|
||||
def OnCommand(cmd,chan,who,check_admin,check_registered):
|
||||
if cmd[0] in commands:
|
||||
|
@ -109,8 +113,28 @@ def OnCommand(cmd,chan,who,check_admin,check_registered):
|
|||
def RunIdleFunctions(param):
|
||||
for f in idles:
|
||||
try:
|
||||
f(param)
|
||||
f[1](param)
|
||||
except Exception,e:
|
||||
log_error("Exception running idle function %s: %s" % (str(f),str(e)))
|
||||
log_error("Exception running idle function %s from module %s: %s" % (str(f[1]),str(f[2]),str(e)))
|
||||
|
||||
def UnregisterCommands(module):
|
||||
global commands
|
||||
global idles
|
||||
|
||||
if module in cleanup:
|
||||
cleanup[module]()
|
||||
del cleanup[module]
|
||||
|
||||
new_idles = []
|
||||
for f in idles:
|
||||
if f[0] != module:
|
||||
new_idles.append(f)
|
||||
idles = new_idles
|
||||
|
||||
new_commands = dict()
|
||||
for cmd in commands:
|
||||
c = commands[cmd]
|
||||
if c['module'] != module:
|
||||
new_commands[cmd] = c
|
||||
commands = new_commands
|
||||
|
||||
|
|
|
@ -89,5 +89,5 @@ def UpdateCoin(param):
|
|||
log_error('UpdateCoin: Failed to get bulk payments: %s' % str(e))
|
||||
last_wallet_update_time = time.time()
|
||||
|
||||
RegisterIdleFunction(UpdateCoin)
|
||||
RegisterIdleFunction("payment",UpdateCoin)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue