def cap_format(uid, resin=None): no_soft = False if resin is None: resin = db.get_warn(uid) if resin == -1: no_soft = True resin = RESIN_MAX cur_resin = db.get_resin(uid) hard, soft = resin_cap(uid, resin) soft_time = f"<code>{soft[0][0]}h+{soft[0][1]}m</code>" hard_time = f"<code>{hard[0][0]}h+{hard[0][1]}m</code>" hard_h = "" soft_h = "" if hard[1] is not None: soft_hour = f"<code>{soft[1][0]:02}:{soft[1][1]:02}h</code>" hard_hour = f"<code>{hard[1][0]:02}:{hard[1][1]:02}h</code>" soft_h = f" @ {soft_hour}" hard_h = f" @ {hard_hour}" soft_str = f"<b>Soft Cap (<code>{resin}</code>):</b> {soft_time}{soft_h}\n" return (f"<b>Current resin:</b> <code>{cur_resin}</code>\n\n" f"{soft_str if not no_soft else ''}" f"<b>Hard Cap (<code>{RESIN_MAX}</code>):</b> {hard_time}{hard_h}")
def warn_toggle(update): uid = update.effective_message.chat.id cur_warn = db.get_warn(uid) if cur_warn == -1: db.set_warn(uid, _warn_value(update)) else: db.unset_warn(uid) settings_warn_menu(update)
def run(self): while not self.flag.wait(self.timer): db.inc_resin(self.uid, 1) resin = db.get_resin(self.uid) warn = db.get_warn(self.uid) if warn != -1: if resin >= ut.RESIN_MAX: self.notify("‼ Hey, you have hit the resin cap!") self.flag.set() elif resin >= warn and not self.notified: self.notify(f"❗ Hey, your resin is: {resin}") self.notified = True elif resin < warn and self.notified: self.notified = False self.timer = ut.RESIN_REGEN * 60
def warn_updown(update, up=True): uid = update.effective_message.chat.id cur_warn = db.get_warn(uid) if cur_warn != -1: _state(uid, ut.CMD.WARN, [int(cw) for cw in f"{cur_warn:03d}"]) else: _state(uid, ut.CMD.WARN, [int(cw) for cw in f"{ut.RESIN_MAX-10:03d}"]) st_warn = STATE[uid][ut.CMD.WARN] txt = 'warn_down' if up: txt = 'warn_up' pos = int(update.callback_query.data.split(txt)[1]) if up: st_warn[pos] = (st_warn[pos] + 1) % 10 else: st_warn[pos] = (st_warn[pos] - 1) % 10 value = int(''.join(str(c) for c in st_warn)) if value > 159: STATE[uid][ut.CMD.WARN] = [1, 5, 9] settings_warn_menu(update)
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 settings_warn_menu(update): uid = update.effective_message.chat.id cur_warn = db.get_warn(uid) if cur_warn != -1: _state(uid, ut.CMD.WARN, [int(cw) for cw in f"{cur_warn:03d}"]) warn_icon = '🔔' else: _state(uid, ut.CMD.WARN, [int(cw) for cw in f"{ut.RESIN_MAX-10:03d}"]) cur_warn = 'disabled' warn_icon = '🔕' st_warn = STATE[uid][ut.CMD.WARN] kb = [ button([(f"Threshold: {cur_warn}", 'settings_warn_menu'), (f"Resin Warnings: {warn_icon}", 'warn_toggle')]), button([("˄", 'warn_up0'), ("˄", 'warn_up1'), ("˄", 'warn_up2')]), button([(st_warn[0], 'nop'), (st_warn[1], 'nop'), (st_warn[2], 'nop')]), button([("˅", 'warn_down0'), ("˅", 'warn_down1'), ("˅", 'warn_down2')]), button([("Set Warning Threshold", 'warn_threshold')]), button([("« Back to Settings", 'settings_menu'), ("« Back to Menu", 'main_menu')]) ] ut.edit(update, "Warnings Settings Menu", InlineKeyboardMarkup(kb))
def gui_cap_format(uid): no_soft = False resin = db.get_warn(uid) if resin == -1: no_soft = True resin = RESIN_MAX hard, soft = resin_cap(uid, resin) soft_time = f"{soft[0][0]}h+{soft[0][1]}m" hard_time = f"{hard[0][0]}h+{hard[0][1]}m" hard_h = "" soft_h = "" if hard[1] is not None: soft_hour = f"{soft[1][0]:02}:{soft[1][1]:02}h" hard_hour = f"{hard[1][0]:02}:{hard[1][1]:02}h" soft_h = f" @ {soft_hour}" hard_h = f" @ {hard_hour}" soft_str = f"{soft_time}{soft_h} ({resin})" hard_str = f"{hard_time}{hard_h} ({RESIN_MAX})" if not no_soft: return [(soft_str, 'resin_menu'), (hard_str, 'resin_menu')] else: return [(hard_str, 'resin_menu')]