add debug mode option to disable the bot when developing locally

This commit is contained in:
lza_menace 2020-08-06 13:40:03 -07:00
parent eca06caf75
commit 928f7b00af
8 changed files with 29 additions and 7 deletions

View file

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

View file

@ -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 from tipbot.helpers.utils import is_tg_admin
@wallet_rpc_required @wallet_rpc_required
@log_event @log_event
@check_debug
def debug(update, context): def debug(update, context):
if is_tg_admin(update.message.from_user['id']): if is_tg_admin(update.message.from_user['id']):
pass pass

View file

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

View file

@ -1,11 +1,12 @@
import logging import logging
from tipbot import wownero from tipbot import wownero
from tipbot import db 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 @wallet_rpc_required
@log_event @log_event
@check_debug
def register(update, context): def register(update, context):
uid = update.message.from_user['id'] uid = update.message.from_user['id']
un = update.message.from_user['first_name'] un = update.message.from_user['first_name']

View file

@ -3,12 +3,13 @@ from decimal import Decimal
from telegram import ParseMode from telegram import ParseMode
from tipbot import wownero from tipbot import wownero
from tipbot import db 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 @wallet_rpc_required
@registration_required @registration_required
@log_event @log_event
@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.reply_text('Not enough arguments passed.')

View file

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

View file

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

View file

@ -1,9 +1,24 @@
import logging import logging
from functools import wraps
from tipbot import wownero from tipbot import wownero
from tipbot import db 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): def log_event(f):
@wraps(f) @wraps(f)
def decorated_function(*args, **kwargs): def decorated_function(*args, **kwargs):