|
|
@ -11,7 +11,8 @@ from tipbot.helpers.decorators import wallet_rpc_required, log_event, registrati
|
|
|
|
@check_debug
|
|
|
|
@check_debug
|
|
|
|
def tip(update, context):
|
|
|
|
def tip(update, context):
|
|
|
|
if len(context.args) < 2:
|
|
|
|
if len(context.args) < 2:
|
|
|
|
update.message.reply_text('Not enough arguments passed.')
|
|
|
|
update.message.from_user.send_message('Not enough arguments passed.')
|
|
|
|
|
|
|
|
update.message.delete()
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
elif len(context.args) == 2:
|
|
|
|
elif len(context.args) == 2:
|
|
|
|
message = ""
|
|
|
|
message = ""
|
|
|
@ -25,7 +26,8 @@ def tip(update, context):
|
|
|
|
target_un = context.args[0]
|
|
|
|
target_un = context.args[0]
|
|
|
|
|
|
|
|
|
|
|
|
if target_un == update.message.from_user['first_name']:
|
|
|
|
if target_un == update.message.from_user['first_name']:
|
|
|
|
update.message.reply_text('You cannot tip yourself!')
|
|
|
|
update.message.from_user.send_message('You cannot tip yourself!')
|
|
|
|
|
|
|
|
update.message.delete()
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
if not db.User.filter(telegram_user=target_un):
|
|
|
|
if not db.User.filter(telegram_user=target_un):
|
|
|
@ -33,24 +35,28 @@ def tip(update, context):
|
|
|
|
'That user has not registered and cannot receive tips yet.',
|
|
|
|
'That user has not registered and cannot receive tips yet.',
|
|
|
|
'If they would like to receive a tip, have them /register with the bot.'
|
|
|
|
'If they would like to receive a tip, have them /register with the bot.'
|
|
|
|
]
|
|
|
|
]
|
|
|
|
update.message.reply_text(' '.join(reply_text))
|
|
|
|
update.message.from_user.send_message(' '.join(reply_text))
|
|
|
|
|
|
|
|
update.message.delete()
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
# validate amount
|
|
|
|
# validate amount
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
amount = Decimal(context.args[1])
|
|
|
|
amount = Decimal(context.args[1])
|
|
|
|
except:
|
|
|
|
except:
|
|
|
|
update.message.reply_text(f'Bad Wownero amount specified; not a valid number.')
|
|
|
|
update.message.from_user.send_message(f'Bad Wownero amount specified; not a valid number.')
|
|
|
|
|
|
|
|
update.message.delete()
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
if amount < 1:
|
|
|
|
if amount < 1:
|
|
|
|
update.message.reply_text('Bad Wownero amount specified. Provide only positive integers or decimals greater than or equal to 1.')
|
|
|
|
update.message.from_user.send_message('Bad Wownero amount specified. Provide only positive integers or decimals greater than or equal to 1.')
|
|
|
|
|
|
|
|
update.message.delete()
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
tipper = db.User.get(telegram_id=update.message.from_user['id'])
|
|
|
|
tipper = db.User.get(telegram_id=update.message.from_user['id'])
|
|
|
|
tipper_balances = wownero.Wallet().balances(account=tipper.account_index)
|
|
|
|
tipper_balances = wownero.Wallet().balances(account=tipper.account_index)
|
|
|
|
if amount >= tipper_balances[1]:
|
|
|
|
if amount >= tipper_balances[1]:
|
|
|
|
update.message.reply_text(f'You do not have sufficient funds to send {amount} WOW. Check your /balance')
|
|
|
|
update.message.from_user.send_message(f'You do not have sufficient funds to send {amount} WOW. Check your /balance')
|
|
|
|
|
|
|
|
update.message.delete()
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
# get target user details
|
|
|
|
# get target user details
|
|
|
@ -63,10 +69,13 @@ def tip(update, context):
|
|
|
|
if 'tx_hash' in tx:
|
|
|
|
if 'tx_hash' in tx:
|
|
|
|
h = tx['tx_hash']
|
|
|
|
h = tx['tx_hash']
|
|
|
|
msg = f'Tipped @{target_un} {amount} WOW! Tx: {h}'
|
|
|
|
msg = f'Tipped @{target_un} {amount} WOW! Tx: {h}'
|
|
|
|
update.message.reply_text(msg)
|
|
|
|
update.message.from_user.send_message(msg)
|
|
|
|
|
|
|
|
update.message.delete()
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
logging.error(f'Transaction failure details for {tipper.telegram_user} ({tipper.telegram_id}): {tx}')
|
|
|
|
logging.error(f'Transaction failure details for {tipper.telegram_user} ({tipper.telegram_id}): {tx}')
|
|
|
|
update.message.reply_text(f'Failed to send a tip. Reason: "{tx["message"]}"')
|
|
|
|
update.message.from_user.send_message(f'Failed to send a tip. Reason: "{tx["message"]}"')
|
|
|
|
|
|
|
|
update.message.delete()
|
|
|
|
except Exception as e:
|
|
|
|
except Exception as e:
|
|
|
|
logging.error(f'Unable to send transfer: {e}. Debug: {update.message}')
|
|
|
|
logging.error(f'Unable to send transfer: {e}. Debug: {update.message}')
|
|
|
|
update.message.reply_text('Failed to send a tip. Ask for help.')
|
|
|
|
update.message.from_user.send_message('Failed to send a tip. Ask for help.')
|
|
|
|
|
|
|
|
update.message.delete()
|
|
|
|