setup some admin commands with click for management/troubleshooting

This commit is contained in:
lza_menace 2020-07-20 23:41:57 -07:00
parent a8c5e5ea59
commit a754eb4163
3 changed files with 47 additions and 1 deletions

View file

@ -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

45
tipbot/admin.py Normal file
View file

@ -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()

View file

@ -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):