def menu(update, context): uid = update.effective_message.chat.id if not db.banned(uid): if not db.cached(uid): ut.not_started(update) else: main_menu(update)
def notifications(update, context): uid = update.effective_message.chat.id if not db.banned(uid): if not db.cached(uid): ut.not_started(update) else: msg = ("❗ Argument must be 1 or -1, " "e.g. /notifications 1, /notifications -1") if context.args: try: value = int(context.args[0]) except ValueError: msg = ut.strike_user(uid, msg) else: if abs(value) == 1: if value == -1: db.unset_notifications(uid) value = "disabled" else: db.set_notifications(uid) value = "enabled" msg = ut.text_format("Current notifications status", value) db.dec_strikes(uid) else: msg = ut.strike_user(uid, msg) else: status = ('enabled' if db.get_notifications(uid) == 1 else 'disabled') msg = ut.text_format("Current notifications status", status) db.dec_strikes(uid) ut.send(update, msg)
def resin(update, context): uid = update.effective_message.chat.id if not db.banned(uid): if not db.cached(uid): ut.not_started(update) else: cur_resin = db.get_resin(uid) msg = (f"❗ Argument must be an integer greater than " f"{cur_resin} and lower than {ut.RESIN_MAX}, " f"e.g. /resin, /resin 135") if context.args: try: value = int(context.args[0]) except ValueError: msg = ut.strike_user(uid, msg) else: if cur_resin < value < ut.RESIN_MAX: msg = ut.cap_format(uid, value) msg = _synchronized(uid, msg) db.dec_strikes(uid) else: msg = ut.strike_user(uid, msg) else: msg = ut.cap_format(uid) msg = _synchronized(uid, msg) db.dec_strikes(uid) _state(uid) ut.send(update, msg)
def stop(update, context): uid = update.effective_message.chat.id if not db.banned(uid): msg = "Bot doesn't have information about you." if db.cached(uid): ut.blocked(uid) msg = "Your information has been removed from the bot." ut.send(update, msg)
def codes(update, context): uid = update.effective_message.chat.id if not db.banned(uid): if not db.cached(uid): ut.not_started(update) else: unexpired = db.unexpired_codes() ut.send(update, ut.codes_format(unexpired))
def start(update, context): uid = update.effective_message.chat.id if not db.banned(uid): msg = "I'm glad to see you again, Traveler!" if not db.cached(uid): _state(uid) db.add_user(uid) msg = f"Hi Traveler, I'm Paimon!\n\n{HELP}" ut.send(update, msg)
def cancel(update, context): uid = update.effective_message.chat.id if not db.banned(uid): if not db.cached(uid): ut.not_started(update) else: if uid in STATE and STATE[uid] != ut.CMD.NOP: msg = (f"The command <code>{STATE[uid].value}</code> " f"has been cancelled. Anything else I can do for you?" f"\n\n" f"Send /help for a list of commands.") else: msg = ("No active command to cancel. " "I wasn't doing anything anyway.\nZzzzz...") ut.send(update, msg) _state(uid)
def set_resin(update, context): uid = update.effective_message.chat.id if not db.banned(uid): if not db.cached(uid): ut.not_started(update) else: msg = (f"❗ Argument must be an integer lower than {ut.RESIN_MAX}, " f"e.g. /set, /set 12") if context.args: msg = _set_resin(context.args, uid, msg) else: msg = (f"Tell me your current resin " f"(max: <code>{ut.RESIN_MAX}</code>)") _state(uid, ut.CMD.SET) db.dec_strikes(uid) ut.send(update, msg)
def track(update, context): uid = update.effective_message.chat.id if not db.banned(uid): if not db.cached(uid): ut.not_started(update) else: msg = ("❗ Argument must have format: mm:ss, " "e.g. /track, /track 5:35m /track -1") if context.args: msg = _track(context.args, context.bot, uid, msg) else: msg = ("Tell me your genshin timer " "in format <code>mm:ss</code>, " "or <code>-1</code> to disable") _state(uid, ut.CMD.TRACK) db.dec_strikes(uid) ut.send(update, msg)
def spend(update, context): uid = update.effective_message.chat.id if not db.banned(uid): if not db.cached(uid): ut.not_started(update) else: cur_resin = db.get_resin(uid) msg = (f"❗ Argument must be an integer greater than 0 " f"and lower than {cur_resin}, " f"e.g. /spend, /spend 20") if context.args: msg = _spend(context.args, uid, msg, cur_resin) else: msg = (f"Tell me how much resin to spend " f"(max: <code>{cur_resin}</code>)") _state(uid, ut.CMD.SPEND) db.dec_strikes(uid) ut.send(update, msg)
def refill(update, context): uid = update.effective_message.chat.id if not db.banned(uid): if not db.cached(uid): ut.not_started(update) else: cur_resin = db.get_resin(uid) max_resin = ut.RESIN_MAX - cur_resin msg = (f"❗ Argument must be an integer greater than 0 " f"and lower than {max_resin}, " f"e.g. /refill, /refill 20") if context.args: msg = _refill(context.args, uid, msg, cur_resin, max_resin) else: msg = (f"Tell me how much resin to refill " f"(max: <code>{max_resin}</code>)") _state(uid, ut.CMD.REFILL) db.dec_strikes(uid) ut.send(update, msg)
def text(update, context): uid = update.effective_message.chat.id if not db.banned(uid): if not db.cached(uid): ut.not_started(update) else: msg = "❗ Send only one argument, following the format." args = update.message.text.split() if len(args) == 1: if uid in STATE: if STATE[uid] == ut.CMD.SET: msg = (f"❗ Value must be an integer lower " f"than {ut.RESIN_MAX}.") msg = _set_resin(args, uid, msg) elif STATE[uid] == ut.CMD.SPEND: cur_resin = db.get_resin(uid) msg = (f"❗ Value must be an integer greater than 0 " f"and lower than {cur_resin}.") msg = _spend(args, uid, msg, cur_resin) elif STATE[uid] == ut.CMD.REFILL: cur_resin = db.get_resin(uid) max_resin = ut.RESIN_MAX - cur_resin msg = (f"❗ Value must be an integer greater than 0 " f"and lower than {max_resin}.") msg = _refill(args, uid, msg, cur_resin, max_resin) elif STATE[uid] == ut.CMD.TRACK: msg = "❗ Timer must have format: <code>mm:ss</code>." msg = _track(args, context.bot, uid, msg) elif STATE[uid] == ut.CMD.WARN: msg = (f"❗ Value must be an integer greater than 0 " f"and lower than {ut.RESIN_MAX}, " f"or <code>-1</code>.") msg = _warnings(args, uid, msg) elif STATE[uid] == ut.CMD.TZ: msg = ("❗ Hour must have format(24h): " "<code>hh:mm</code> " "or <code>-1</code>.") msg = _timezone(args, uid, msg) else: _state(uid) ut.send(update, msg)
def warnings(update, context): uid = update.effective_message.chat.id if not db.banned(uid): if not db.cached(uid): ut.not_started(update) else: msg = (f"❗ Argument must be an integer greater than 0 " f"and lower than {ut.RESIN_MAX}, or -1, " f"e.g. /warnings, /warnings -1, /warning 140") if context.args: msg = _warnings(context.args, uid, msg) else: cur_warn = db.get_warn(uid) if cur_warn == -1: cur_warn = "disabled" msg = (f"{ut.text_format('Warning threshold', cur_warn)}\n\n" f"Tell me resin value to be warned at, " f"or <code>-1</code> to disable") _state(uid, ut.CMD.WARN) db.dec_strikes(uid) ut.send(update, msg)
def timezone(update, context): uid = update.effective_message.chat.id if not db.banned(uid): if not db.cached(uid): ut.not_started(update) else: msg = ("❗ Argument must have format(24h): hh:mm or -1, " "e.g. /timezone, /timezone -1, /timezone 18:30") if context.args: msg = _timezone(context.args, uid, msg) else: tz_hour, tz_minutes = db.get_timezone(uid).split(':') if tz_hour == 'null': tz = "disabled" else: tz = ut.normalize_timezone(tz_hour, tz_minutes) msg = (f"{ut.text_format('Current timezone', tz)}\n\n" f"Tell me your current hour " f"in format(24h): <code>hh:mm</code>, " f"or <code>-1</code> to disable") _state(uid, ut.CMD.TZ) db.dec_strikes(uid) ut.send(update, msg)
def bot_help(update, context): uid = update.effective_message.chat.id if not db.banned(uid): ut.send(update, HELP)
def button_handler(update, context): uid = update.effective_message.chat.id query = update.callback_query try: query.answer() except BadRequest: pass if not db.banned(uid): if not db.cached(uid): ut.not_started_gui(update) else: if query.data == 'main_menu': gui.main_menu(update) elif query.data == 'resin_menu': gui.resin_menu(update) elif query.data == 'tracking_menu': gui.tracking_menu(update) elif query.data == 'tracking_start': gui.tracking_start(update, context) elif query.data == 'tracking_stop': gui.tracking_stop(update) elif query.data.startswith('tracking_up'): gui.tracking_updown(update) elif query.data.startswith('tracking_down'): gui.tracking_updown(update, up=False) elif query.data == 'spend_menu': gui.spend_menu(update) elif query.data.startswith('spend_r'): gui.spend_resin(update) elif query.data == 'refill_menu': gui.refill_menu(update) elif query.data.startswith('refill_up'): gui.refill_updown(update) elif query.data.startswith('refill_down'): gui.refill_updown(update, up=False) elif query.data == 'refill_r': gui.refill_resin(update) elif query.data == 'codes_menu': gui.codes_menu(update) elif query.data.startswith('code_desc'): ctype, cdata = query.data.split(':')[1:] gui.code_menu(update, ctype, cdata) elif query.data == 'codes_redeem': gui.redeem_menu(update) elif query.data == 'settings_menu': gui.settings_menu(update) elif query.data == 'settings_warn_menu': gui.settings_warn_menu(update) elif query.data == 'warn_toggle': gui.warn_toggle(update) elif query.data == 'warn_threshold': gui.warn_threshold(update) elif query.data.startswith('warn_up'): gui.warn_updown(update) elif query.data.startswith('warn_down'): gui.warn_updown(update, up=False) elif query.data == 'settings_promo_menu': gui.settings_promo_menu(update) elif query.data == 'promo_toggle': gui.promo_toggle(update) elif query.data == 'settings_timezone_menu': gui.settings_timezone_menu(update) elif query.data == 'timezone_menu': gui.timezone_menu(update) elif query.data == 'timezone_disable': gui.timezone_disable(update) elif query.data == 'timezone_set': gui.timezone_set(update) elif query.data.startswith('timezone_up'): gui.timezone_updown(update) elif query.data.startswith('timezone_down'): gui.timezone_updown(update, up=False)