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 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 _timezone(args, uid, msg): try: datetime.strptime(args[0], "%H:%M") except ValueError: try: value = int(args[0]) except ValueError: msg = ut.strike_user(uid, msg) else: if value == -1: db.unset_timezone(uid) msg = ut.text_format("Current timezone", "disabled") db.dec_strikes(uid) else: msg = ut.strike_user(uid, msg) else: hour, minutes = map(int, args[0].split(':')) bot_hour, bot_minutes = map( int, datetime.now().strftime("%H:%M").split(':')) tz_hour = hour - bot_hour tz_minutes = minutes - bot_minutes db.set_timezone(uid, tz_hour, tz_minutes) tz = ut.normalize_timezone(tz_hour, tz_minutes) msg = ( f"{ut.text_format('Bot hour', f'{bot_hour:02}:{bot_minutes:02}')}\n\n" # noqa f"{ut.text_format('Current timezone', f'{tz}')}") db.dec_strikes(uid) return msg
def _refill(args, uid, msg, current, max_resin): try: value = int(args[0]) except ValueError: msg = ut.strike_user(uid, msg) else: if 0 < value < max_resin: db.inc_resin(uid, value) msg = ut.text_format("Current resin", current + value) msg = _synchronized(uid, msg) db.dec_strikes(uid) else: msg = ut.strike_user(uid, msg) return msg
def _spend(args, uid, msg, current): try: value = int(args[0]) except ValueError: msg = ut.strike_user(uid, msg) else: if 0 < value < current: db.dec_resin(uid, value) msg = ut.text_format("Current resin", current - value) msg = _synchronized(uid, msg) db.dec_strikes(uid) else: msg = ut.strike_user(uid, msg) return msg
def _set_resin(args, uid, msg): try: value = int(args[0]) except ValueError: msg = ut.strike_user(uid, msg) else: if 0 < value < ut.RESIN_MAX: db.set_resin(uid, value) msg = ut.text_format("Current resin", value) msg = _synchronized(uid, msg) db.dec_strikes(uid) else: msg = ut.strike_user(uid, msg) return msg
def _warnings(args, uid, msg): try: value = int(args[0]) except ValueError: msg = ut.strike_user(uid, msg) else: if value == -1 or 0 < value < ut.RESIN_MAX: if value == -1: value = "disabled" db.unset_warn(uid) else: db.set_warn(uid, value) msg = ut.text_format("Current warning threshold", value) msg = _synchronized(uid, msg) db.dec_strikes(uid) else: msg = ut.strike_user(uid, msg) return msg
def _track(args, bot, uid, msg): try: datetime.strptime(args[0], "%M:%S") except ValueError: try: value = int(args[0]) except ValueError: msg = ut.strike_user(uid, msg) else: if value == -1: th.del_thread(uid) msg = ut.text_format("Current tracking status", "disabled") db.dec_strikes(uid) else: msg = ut.strike_user(uid, msg) else: minutes, seconds = map(int, args[0].split(':')) timer = minutes * 60 + seconds th.new_thread(bot, uid, timer) msg = "Bot timer synchronized." db.dec_strikes(uid) return msg