add debug mode option to disable the bot when developing locally

master
lza_menace 4 years ago
parent eca06caf75
commit 928f7b00af

@ -1,12 +1,13 @@
import logging
from tipbot import wownero
from tipbot import db
from tipbot.helpers.decorators import wallet_rpc_required, log_event, registration_required
from tipbot.helpers.decorators import wallet_rpc_required, log_event, registration_required, check_debug
@wallet_rpc_required
@registration_required
@log_event
@check_debug
def balance(update, context):
u = db.User.get(telegram_id=update.message.from_user['id'])
balances = wownero.Wallet().balances(account=u.account_index)

@ -1,9 +1,10 @@
from tipbot.helpers.decorators import wallet_rpc_required, log_event
from tipbot.helpers.decorators import wallet_rpc_required, log_event, check_debug
from tipbot.helpers.utils import is_tg_admin
@wallet_rpc_required
@log_event
@check_debug
def debug(update, context):
if is_tg_admin(update.message.from_user['id']):
pass

@ -1,12 +1,13 @@
import logging
from tipbot import wownero
from tipbot import db
from tipbot.helpers.decorators import wallet_rpc_required, log_event, registration_required
from tipbot.helpers.decorators import wallet_rpc_required, log_event, registration_required, check_debug
@wallet_rpc_required
@registration_required
@log_event
@check_debug
def deposit(update, context):
u = db.User.get(telegram_id=update.message.from_user['id'])
address = wownero.Wallet().addresses(account=u.account_index)[0]

@ -1,11 +1,12 @@
import logging
from tipbot import wownero
from tipbot import db
from tipbot.helpers.decorators import wallet_rpc_required, log_event
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']

@ -3,12 +3,13 @@ from decimal import Decimal
from telegram import ParseMode
from tipbot import wownero
from tipbot import db
from tipbot.helpers.decorators import wallet_rpc_required, log_event, registration_required
from tipbot.helpers.decorators import wallet_rpc_required, log_event, registration_required, check_debug
@wallet_rpc_required
@registration_required
@log_event
@check_debug
def tip(update, context):
if len(context.args) < 2:
update.message.reply_text('Not enough arguments passed.')

@ -3,12 +3,13 @@ from decimal import Decimal
from telegram import ParseMode
from tipbot import wownero
from tipbot import db
from tipbot.helpers.decorators import wallet_rpc_required, log_event, registration_required
from tipbot.helpers.decorators import wallet_rpc_required, log_event, registration_required, check_debug
@wallet_rpc_required
@registration_required
@log_event
@check_debug
def withdraw(update, context):
if len(context.args) < 2:
update.message.reply_text('Not enough arguments passed.')

@ -1,3 +1,4 @@
DEBUG = True
TG_TOKEN = 'tttttttttttt'
TG_ADMIN_ID = 0000000000
WALLET_PROTO = 'http'

@ -1,8 +1,23 @@
import logging
from functools import wraps
from tipbot import wownero
from tipbot import db
from functools import wraps
from tipbot import config
from tipbot.helpers.utils import is_tg_admin
def check_debug(f):
@wraps(f)
def decorated_function(*args, **kwargs):
msg = args[0].message
is_admin = is_tg_admin(msg.from_user["id"])
is_debug = getattr(config, 'DEBUG', True) == True
if is_debug:
if not is_admin:
msg.reply_text('I am in debug mode by my admin. Commands are disabled at the moment. Try again later.')
return False
return f(*args, **kwargs)
return decorated_function
def log_event(f):
@wraps(f)

Loading…
Cancel
Save