From 44d6f0137888d15db5dd5a085e41ae3cbf604098 Mon Sep 17 00:00:00 2001 From: moneromooo Date: Thu, 1 Jan 2015 14:23:34 +0000 Subject: [PATCH] Move module specific help to modules --- tipbot.py | 26 +------------------------- tipbot/command_manager.py | 15 +++++++++++++++ tipbot/modules/payment.py | 23 ++++++++++++++++++++++- tipbot/modules/withdraw.py | 7 +++++++ 4 files changed, 45 insertions(+), 26 deletions(-) diff --git a/tipbot.py b/tipbot.py index 6e7facc..62ec0ac 100644 --- a/tipbot.py +++ b/tipbot.py @@ -80,21 +80,6 @@ for modulename in modulenames: -def GetTipbotAddress(): - try: - j = SendWalletJSONRPCCommand("getaddress",None) - if not "result" in j: - log_error('GetTipbotAddress: No result found in getaddress reply') - return ERROR - result = j["result"] - if not "address" in result: - log_error('GetTipbotAddress: No address found in getaddress reply') - return ERROR - return result["address"] - except Exception,e: - log_error("GetTipbotAddress: Error retrieving %s's address: %s" % (config.tipbot_name, str(e))) - return "ERROR" - def GetBalance(nick,chan,cmd): sendto=GetSendTo(nick,chan) log_log("GetBalance: checking %s" % nick) @@ -179,16 +164,7 @@ def DumpUsers(nick,chan,cmd): def Help(nick,chan,cmd): SendTo(nick, "See available commands with !commands or !commands ") - if 'payment' in modulenames: - SendTo(nick, "You can send %s to your account:" % coinspecs.name); - SendTo(nick, " Address: %s" % GetTipbotAddress()) - SendTo(nick, " Payment ID: %s" % GetPaymentID(nick)) - SendTo(nick, "NO WARRANTY, YOU MAY LOSE YOUR COINS") - if 'withdraw' in modulenames: - fee = config.withdrawal_fee or coinspecs.min_withdrawal_fee - min_amount = config.min_withdraw_amount or fee - SendTo(nick, "Minimum withdrawal: %s" % AmountToString(min_amount)) - SendTo(nick, "Withdrawal fee: %s" % AmountToString(fee)) + RunHelpFunctions(nick) if coinspecs.web_wallet_url: SendTo(nick, "No %s address ? You can use %s" % (coinspecs.name, coinspecs.web_wallet_url)) diff --git a/tipbot/command_manager.py b/tipbot/command_manager.py index e5f5a58..3bdec29 100644 --- a/tipbot/command_manager.py +++ b/tipbot/command_manager.py @@ -17,6 +17,7 @@ commands = dict() calltable=dict() idles = [] cleanup = dict() +helps = dict() def RunRegisteredCommand(nick,chan,ifyes,yesdata,ifno,nodata): if nick not in calltable: @@ -101,6 +102,9 @@ def RegisterIdleFunction(module,function): def RegisterCleanupFunction(module,function): cleanup.append((module,function)) +def RegisterHelpFunction(module,function): + helps[module]=function + def OnCommand(cmd,chan,who,check_admin,check_registered): if cmd[0] in commands: c = commands[cmd[0]] @@ -120,9 +124,17 @@ def RunIdleFunctions(param): except Exception,e: log_error("Exception running idle function %s from module %s: %s" % (str(f[1]),str(f[2]),str(e))) +def RunHelpFunctions(param): + for f in helps: + try: + helps[f](param) + except Exception,e: + log_error("Exception running help function %s from module %s: %s" % (str(helps[f]),str(f),str(e))) + def UnregisterCommands(module): global commands global idles + global helps if module in cleanup: cleanup[module]() @@ -134,6 +146,9 @@ def UnregisterCommands(module): new_idles.append(f) idles = new_idles + if module in helps: + del helps[module] + new_commands = dict() for cmd in commands: c = commands[cmd] diff --git a/tipbot/modules/payment.py b/tipbot/modules/payment.py index e116fff..bcedcc8 100644 --- a/tipbot/modules/payment.py +++ b/tipbot/modules/payment.py @@ -20,6 +20,21 @@ from tipbot.command_manager import * last_wallet_update_time = None +def GetTipbotAddress(): + try: + j = SendWalletJSONRPCCommand("getaddress",None) + if not "result" in j: + log_error('GetTipbotAddress: No result found in getaddress reply') + return ERROR + result = j["result"] + if not "address" in result: + log_error('GetTipbotAddress: No address found in getaddress reply') + return ERROR + return result["address"] + except Exception,e: + log_error("GetTipbotAddress: Error retrieving %s's address: %s" % (config.tipbot_name, str(e))) + return "ERROR" + def UpdateCoin(param): irc = param[0] redisdb = param[1] @@ -89,5 +104,11 @@ def UpdateCoin(param): log_error('UpdateCoin: Failed to get bulk payments: %s' % str(e)) last_wallet_update_time = time.time() -RegisterIdleFunction(__name__,UpdateCoin) +def Help(nick): + SendTo(nick, "You can send %s to your account:" % coinspecs.name); + SendTo(nick, " Address: %s" % GetTipbotAddress()) + SendTo(nick, " Payment ID: %s" % GetPaymentID(nick)) + +RegisterIdleFunction(__name__,UpdateCoin) +RegisterHelpFunction(__name__,Help) diff --git a/tipbot/modules/withdraw.py b/tipbot/modules/withdraw.py index a18436d..514a173 100644 --- a/tipbot/modules/withdraw.py +++ b/tipbot/modules/withdraw.py @@ -144,6 +144,12 @@ def Withdraw(nick,chan,cmd): log_error('Withdraw: FAILED TO SUBTRACT BALANCE: exception: %s' % str(e)) CheckDisableWithdraw() +def Help(nick): + fee = config.withdrawal_fee or coinspecs.min_withdrawal_fee + min_amount = config.min_withdraw_amount or fee + SendTo(nick, "Minimum withdrawal: %s" % AmountToString(min_amount)) + SendTo(nick, "Withdrawal fee: %s" % AmountToString(fee)) + RegisterCommand({ @@ -168,3 +174,4 @@ RegisterCommand({ 'admin': True, 'help': "Disable withdrawals" }) +RegisterHelpFunction(__name__,Help)