From a754eb416376e89477a52fbf03e94fb2aefd9b4c Mon Sep 17 00:00:00 2001 From: lza_menace Date: Mon, 20 Jul 2020 23:41:57 -0700 Subject: [PATCH] setup some admin commands with click for management/troubleshooting --- requirements.txt | 1 + tipbot/admin.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ tipbot/wownero.py | 2 +- 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tipbot/admin.py diff --git a/requirements.txt b/requirements.txt index 5dd1898..57cf7a0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ certifi==2020.6.20 cffi==1.14.0 chardet==3.0.4 +click==7.1.2 cryptography==2.9.2 decorator==4.4.2 idna==2.10 diff --git a/tipbot/admin.py b/tipbot/admin.py new file mode 100644 index 0000000..f282c31 --- /dev/null +++ b/tipbot/admin.py @@ -0,0 +1,45 @@ +import click +import db +import wownero +import commands + + +@click.group() +def cli(): + pass + +@click.command() +def get_users(): + users = db.User.select() + wallet = wownero.Wallet() + for u in users: + balances = wallet.balances(account=u.account_index) + address = wallet.addresses(account=u.account_index)[0] + click.echo(f'{u.account_index} - {u.telegram_user} ({u.telegram_id}) - {float(balances[0])} locked, {float(balances[1])} unlocked - {address}') + +@click.command() +@click.argument('account_index') +def get_address(account_index): + address = wownero.Wallet().addresses(account=int(account_index))[0] + click.echo(address) + +@click.command() +@click.argument('dest_address') +@click.argument('amount') +def transfer(dest_address, amount): + tx = wownero.Wallet().transfer(dest_address=dest_address, amount=amount, priority=2, account=0) + +@click.command() +def generate_bot_help(): + for cmd in commands.all_commands: + c = commands.all_commands[cmd] + if not 'admin' in c: + click.echo(f'{cmd} - {commands.all_commands[cmd]["help"]}') + +cli.add_command(get_users) +cli.add_command(get_address) +cli.add_command(transfer) +cli.add_command(generate_bot_help) + +if __name__ == '__main__': + cli() diff --git a/tipbot/wownero.py b/tipbot/wownero.py index 1c4a75b..9cdc992 100644 --- a/tipbot/wownero.py +++ b/tipbot/wownero.py @@ -85,7 +85,7 @@ class Wallet(object): def balances(self, account): data = {'account_index': account} - _balance = self.make_wallet_rpc('getbalance', data) + _balance = self.make_wallet_rpc('get_balance', data) return (from_atomic(_balance['balance']), from_atomic(_balance['unlocked_balance'])) def transfer(self, dest_address, amount, priority, account):