From 219e2491e3879ba8172bc68befb68dfc708af0b3 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Mon, 20 Jul 2020 23:59:06 -0700 Subject: [PATCH] fix some bugs with message routing and prettify balance output --- tipbot/commands.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tipbot/commands.py b/tipbot/commands.py index 4c81ac0..cf9f0e0 100644 --- a/tipbot/commands.py +++ b/tipbot/commands.py @@ -10,7 +10,8 @@ from decimal import Decimal def log_event(f): @wraps(f) def decorated_function(*args, **kwargs): - logging.info(f'"{f.__name__}" called by {args[0].message.from_user["username"]}') + msg = args[0].message + logging.info(f'"{f.__name__}" invoked from {msg.from_user["username"]} - Full command: "{msg.text}"') return f(*args, **kwargs) return decorated_function @@ -29,7 +30,7 @@ def registration_required(f): @wraps(f) def decorated_function(*args, **kwargs): wallet = wownero.Wallet() - if not db.User.filter(telegram_id=args[0].effective_chat.id): + if not db.User.filter(telegram_id=args[0].message.from_user['id']): args[0].message.reply_text('You are not yet registered. Issue the /register command.') return False return f(*args, **kwargs) @@ -97,7 +98,7 @@ def tip(update, context): else: target_un = context.args[0] - if target_un == update.effective_chat.username: + if target_un == update.message.from_user['username']: update.message.reply_text('You cannot tip yourself!') return False @@ -134,7 +135,7 @@ def tip(update, context): try: tx = wownero.Wallet().transfer(dest_address=address, amount=amount, priority=2, account=u.account_index) print(tx) - update.message.reply_text(f'@{update.effective_chat.username} has tipped @{target_un} {amount} WOW!') + update.message.reply_text(f'@{update.message.from_user["username"]} has tipped @{target_un} {amount} WOW!') except Exception as e: logging.error(f'Unable to send transfer: {e}. Debug: {update.message}') update.message.reply_text('Failed to send a tip. Ask for help.') @@ -177,7 +178,7 @@ def send(update, context): try: tx = wownero.Wallet().transfer(dest_address=address, amount=amount, priority=2, account=u.account_index) print(tx) - update.message.reply_text(f'@{update.effective_chat.username} has tipped @{target_un} {amount} WOW!') + update.message.reply_text(f'@{update.message.from_user["username"]} has tipped @{target_un} {amount} WOW!') except Exception as e: logging.error(f'Unable to send transfer: {e}. Debug: {update.message}') update.message.reply_text('Failed to send a tip. Ask for help.') @@ -188,7 +189,7 @@ def send(update, context): def balance(update, context): u = db.User.get(telegram_id=update.message.from_user['id']) balances = wownero.Wallet().balances(account=u.account_index) - update.message.reply_text(f'Available balance for {update.effective_chat.username}: {balances[1]} ({balances[0]} locked)') + update.message.reply_text(f'Available balance for {update.message.from_user["username"]}: {float(balances[1])} ({float(balances[0])} locked)') @wallet_rpc_required @registration_required @@ -196,7 +197,7 @@ def balance(update, context): def deposit(update, context): u = db.User.get(telegram_id=update.message.from_user['id']) address = wownero.Wallet().addresses(account=u.account_index)[0] - update.message.reply_text(f'Deposit address for {update.effective_chat.username}: {address}') + update.message.reply_text(f'Deposit address for {update.message.from_user["username"]}: {address}') @wallet_rpc_required @log_event