Show the coins a user has in a specified wallet when a wallet is specified to

!wallet
This commit is contained in:
jesopo 2018-10-18 15:24:33 +01:00
parent 79c4a357d7
commit d2557cbc4f

View file

@ -70,6 +70,8 @@ class Module(ModuleManager.BaseModule):
user.set_setting("wallets", wallets) user.set_setting("wallets", wallets)
def _reset_user_wallets(self, user): def _reset_user_wallets(self, user):
user.del_setting("wallets") user.del_setting("wallets")
def _user_has_wallet(self, user, wallet):
return wallet.lower() in self._get_user_wallets(user)
def _get_user_coins(self, user, wallet=WALLET_DEFAULT): def _get_user_coins(self, user, wallet=WALLET_DEFAULT):
wallets = self._get_user_wallets(user) wallets = self._get_user_wallets(user)
@ -172,10 +174,18 @@ class Module(ModuleManager.BaseModule):
:help: Show your wallets and their balances :help: Show your wallets and their balances
:usage: [wallet] :usage: [wallet]
""" """
if event["args_split"]: if not event["args_split"]:
wallets = self._get_user_wallets(event["user"]).keys() wallets = self._get_user_wallets(event["user"]).keys()
event["stdout"].write("%s: your available wallets are: %s" % event["stdout"].write("%s: your available wallets are: %s" %
(event["user"].nickname, ", ".join(wallets))) (event["user"].nickname, ", ".join(wallets)))
else:
wallet = event["args"]
if not self._user_has_wallet(wallet):
raise utils.EventError("%s: you don't have a '%s' wallet" %
(event["user"].nickname, wallet))
coins = self._get_user_coins(user, wallet)
event["stdout"].write("%s: you have %s coins in your '%s' wallet" %
(event["user"].nickname, self._coin_str(coins), wallet))
@utils.hook("received.command.resetcoins", min_args=1) @utils.hook("received.command.resetcoins", min_args=1)
def reset_coins(self, event): def reset_coins(self, event):