mirror of
https://git.wownero.com/lza_menace/tg-bot.git
synced 2024-08-15 00:23:12 +00:00
50 lines
2.1 KiB
Python
50 lines
2.1 KiB
Python
import logging
|
|
from tipbot import wownero
|
|
from tipbot import db
|
|
from tipbot.helpers.decorators import wallet_rpc_required, log_event, check_debug
|
|
|
|
|
|
@wallet_rpc_required
|
|
@log_event
|
|
@check_debug
|
|
def register(update, context):
|
|
uid = update.message.from_user['id']
|
|
un = update.message.from_user['first_name']
|
|
|
|
if db.User.filter(telegram_id=uid):
|
|
if db.User.filter(telegram_id=uid, telegram_user=un):
|
|
update.message.reply_text('You are already registered. Use /help to see available bot commands.')
|
|
else:
|
|
try:
|
|
u = db.User.get(telegram_id=uid)
|
|
u.telegram_user = un
|
|
u.save()
|
|
update.message.reply_text(f'You have been registered again as Telegram ID {uid} but with username {un}.')
|
|
except Exception as e:
|
|
logging.error(f'Unable to update user in DB: {e}. Debug: {update.message}')
|
|
update.message.reply_text('Unable to update your existing account. Ask for help.')
|
|
return False
|
|
else:
|
|
try:
|
|
wallet = wownero.Wallet()
|
|
account_index = wallet.new_account(label=un)
|
|
except Exception as e:
|
|
logging.error(f'Unable to create a new account in wallet RPC: {e}. Debug: {update.message}')
|
|
update.message.reply_text('Unable to create a new account for you. Ask for help.')
|
|
return False
|
|
try:
|
|
u = db.User(
|
|
telegram_id=uid,
|
|
telegram_user=un,
|
|
account_index=account_index,
|
|
)
|
|
u.save()
|
|
reply_text = [
|
|
f'You have been registered as Telegram ID {uid} and username {un} and can now send and receive tips.',
|
|
'Ask for /help to see all available bot commands. Maybe start with /deposit to get your deposit address.'
|
|
]
|
|
update.message.reply_text(' '.join(reply_text))
|
|
except Exception as e:
|
|
logging.error(f'Unable to register user in DB: {e}. Debug: {update.message}')
|
|
update.message.reply_text('Unable to create a new account for you. Ask for help.')
|
|
return False
|