fix some bugs with message routing and prettify balance output

master
lza_menace 4 years ago
parent 8534b3dbc4
commit 219e2491e3

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

Loading…
Cancel
Save