def refuse(msg: catbot.Message): try: operator = bot.get_chat_member(config['group'], msg.from_.id) except catbot.UserNotFoundError: return if not (operator.status == 'creator' or operator.status == 'administrator'): return if msg.reply: refused_id = msg.reply_to_message.from_.id else: user_input_token = msg.text.split() if len(user_input_token) < 2: bot.send_message(msg.chat.id, text=config['messages']['general_prompt'], reply_to_message_id=msg.id) return try: refused_id = int(user_input_token[1]) except ValueError: bot.send_message(msg.chat.id, text=config['messages']['telegram_id_error'], reply_to_message_id=msg.id) return try: refused_user = bot.get_chat_member(config['group'], refused_id) except catbot.UserNotFoundError: restricted_until = 0 else: if refused_user.status == 'restricted': restricted_until = refused_user.until_date if restricted_until == 0: restricted_until = -1 else: restricted_until = 0 with t_lock: ac_list, rec = bot.secure_record_fetch('ac', list) for i in range(len(ac_list)): entry = Ac.from_dict(ac_list[i]) if entry.telegram_id == refused_id: refused_index = i break else: entry = Ac(refused_id) ac_list.append(entry) refused_index = -1 if restricted_until != -1: entry.restricted_until = restricted_until entry.confirmed = False entry.confirming = False entry.refused = True ac_list[refused_index] = entry.to_dict() rec['ac'] = ac_list json.dump(rec, open(config['record'], 'w', encoding='utf-8'), indent=2, ensure_ascii=False) log(config['messages']['refuse_log'].format(tg_id=refused_id, refuser=html_refer(operator.name))) silence_trial(entry)
def confirm(msg: catbot.Message): with t_lock: ac_list, rec = bot.secure_record_fetch('ac', list) entry_index = -1 for i in range(len(ac_list)): entry = Ac.from_dict(ac_list[i]) if entry.telegram_id == msg.from_.id: if entry.confirmed: bot.send_message(msg.chat.id, text=config['messages']['confirm_already'].format( wp_name=get_mw_username(entry.mw_id) )) return elif entry.confirming: bot.send_message(msg.chat.id, text=config['messages']['confirm_confirming']) return elif entry.refused: bot.send_message(msg.chat.id, text=config['messages']['confirm_ineligible']) return else: entry_index = i else: if entry_index == -1: entry = Ac(msg.from_.id) ac_list.append(entry.to_dict()) entry = Ac.from_dict(ac_list[entry_index]) entry.confirming = True ac_list[entry_index] = entry.to_dict() rec['ac'] = ac_list json.dump(rec, open(config['record'], 'w', encoding='utf-8'), indent=2, ensure_ascii=False) button = catbot.InlineKeyboardButton(config['messages']['confirm_button'], callback_data=f'confirm') keyboard = catbot.InlineKeyboard([[button]]) bot.send_message(msg.chat.id, text=config['messages']['confirm_wait'].format( link=config['oauth_auth_url'].format(telegram_id=msg.from_.id), ), parse_mode='HTML', disable_web_page_preview=True, reply_markup=keyboard)