def reload_command(update, context): message = update.message chat = message.chat user = message.from_user if user.id not in get_chat_admins( context.bot, chat.id, context.bot_data.get("config").get("SUPER_ADMIN")): logger.info(f"Reload: User {user.id} is unauthorized, blocking") message.reply_text( context.bot_data.get("config").get("START_UNAUTHORIZED_PRIVATE")) return message.reply_text(reload_config(context))
def reload_command(update, context): message = update.message chat = message.chat user = message.from_user if user.id not in get_chat_admins(context.bot, chat.id, config.get("SUPER_ADMIN")): logger.info(f"Reload: User {user.id} is unauthorized, blocking") message.reply_text(config.get("START_UNAUTHORIZED_PRIVATE")) return message.reply_text( config.get("RELOAD").format(num=config.get("number")) if reload_config(context) else config.get("PENDING"), )
def start_private(update, context): message = update.message callback_query = update.callback_query if callback_query: callback_query.answer() user = callback_query.from_user else: user = message.from_user if user.id not in get_chat_admins(context.bot, config.get("CHAT"), config.get("SUPER_ADMIN")): logger.info(f"Private: User {user.id} is unauthorized, blocking") message.reply_text(config.get("START_UNAUTHORIZED_PRIVATE")) return ConversationHandler.END keyboard = [ [ InlineKeyboardButton(config.get("SAVE_QUESTION_BTN"), callback_data="save") ], [ InlineKeyboardButton( config.get("ADD_NEW_QUESTION_BTN"), callback_data=f'edit_question_private|{config.get("number")}', ) ], [ InlineKeyboardButton( config.get("LIST_ALL_QUESTION_BTN"), callback_data="list_question_private", ) ], ] markup = InlineKeyboardMarkup(keyboard) if callback_query: callback_query.edit_message_text( config.get("START_PRIVATE").format(link=config.get("CHAT")), reply_markup=markup, ) else: message.reply_text( config.get("START_PRIVATE").format(link=config.get("CHAT")), reply_markup=markup, ) logger.info("Private: Start") logger.debug(callback_query) return CHOOSING
def admin(update: Update, context: CallbackContext) -> None: def admin_callback(rawstr: str) -> Tuple[bool, int]: data = rawstr.split("|") logger.info(f"Parse Callback: {data}") if data[1] == "pass": result = True else: result = False user_id = int(data[2]) logger.info( f"New admin parse callback:\nuser_id: {user_id}\nresult: {result}") return result, user_id callback_query = update.callback_query user = callback_query.from_user message = callback_query.message chat = message.chat if user.id not in get_chat_admins( context.bot, chat.id, extra_user=context.bot_data.get("config").get("SUPER_ADMIN"), ): callback_query.answer( text=context.bot_data.get("config").get("OTHER"), show_alert=True, ) return result, user_id = admin_callback(callback_query.data) cqconf = (context.bot_data.get("config").get("PASS_BTN") if result else context.bot_data.get("config").get("KICK_BTN")) conf = (context.bot_data.get("config").get("ADMIN_PASS") if result else context.bot_data.get("config").get("ADMIN_KICK")) callback_query.answer( text=cqconf, show_alert=False, ) if result: restore(context, chat.id, user_id) if schedule := context.job_queue.scheduler.get_job( f"{chat.id}|{user_id}|clean_join"): schedule.remove()
def admin(update, context): callback_query = update.callback_query user = callback_query.from_user message = callback_query.message chat = message.chat if user.id not in get_chat_admins( context.bot, chat.id, extra_user=context.bot_data.get("config").get("SUPER_ADMIN"), ): callback_query.answer( text=context.bot_data.get("config").get("OTHER"), show_alert=True, ) return result, user_id = parse_callback(context, callback_query.data) cqconf = (context.bot_data.get("config").get("PASS_BTN") if result else context.bot_data.get("config").get("KICK_BTN")) conf = (context.bot_data.get("config").get("ADMIN_PASS") if result else context.bot_data.get("config").get("ADMIN_KICK")) callback_query.answer( text=cqconf, show_alert=False, ) if result: restore(context, chat.id, user_id) for job in context.job_queue.get_jobs_by_name( f"{chat.id}|{user_id}|clean_join"): job.schedule_removal() else: kick(context, chat.id, user_id) message.edit_text( escape_markdown(conf).format( admin=user.mention_markdown_v2(), user=mention_markdown(user_id, str(user_id), version=2), ), parse_mode=ParseMode.MARKDOWN_V2, ) for job in context.job_queue.get_jobs_by_name(f"{chat.id}|{user_id}|kick"): job.schedule_removal()
def newmem(update, context): message = update.message chat = message.chat if message.from_user.id in get_chat_admins( context.bot, chat.id, context.bot_data.get("config").get("SUPER_ADMIN")): return for user in message.new_chat_members: if user.is_bot: continue num = SystemRandom().randint( 0, len(context.bot_data.get("config").get("CHALLENGE")) - 1) flag = context.bot_data.get("config").get("CHALLENGE")[num] if context.bot.restrict_chat_member( chat_id=chat.id, user_id=user.id, permissions=ChatPermissions(can_send_messages=False), ): logger.info( f"New member: Successfully restricted user {user.id} at group {chat.id}" ) else: logger.warning( f"New member: No enough permissions to restrict user {user.id} at group {chat.id}" ) buttons = [[ InlineKeyboardButton( flag.get("WRONG")[t], callback_data= f"challenge|{user.id}|{num}|{flag.get('wrong')[t]}", ) ] for t in range(len(flag.get("WRONG")))] buttons.append([ InlineKeyboardButton( flag.get("ANSWER"), callback_data=f"challenge|{user.id}|{num}|{flag.get('answer')}", ) ]) SystemRandom().shuffle(buttons) buttons.append([ InlineKeyboardButton( context.bot_data.get("config").get("PASS_BTN"), callback_data=f"admin|pass|{user.id}", ), InlineKeyboardButton( context.bot_data.get("config").get("KICK_BTN"), callback_data=f"admin|kick|{user.id}", ), ]) question_message = message.reply_text( context.bot_data.get("config").get("GREET").format( question=flag.get("QUESTION"), time=context.bot_data.get("config").get("TIME"), ), reply_markup=InlineKeyboardMarkup(buttons), parse_mode=ParseMode.MARKDOWN, ) context.job_queue.run_once( kick_queue, context.bot_data.get("config").get("TIME"), context={ "chat_id": chat.id, "user_id": user.id, }, name=f"{chat.id}|{user.id}|kick", ) context.job_queue.run_once( clean_queue, context.bot_data.get("config").get("TIME"), context={ "chat_id": chat.id, "user_id": user.id, "message_id": message.message_id, }, name=f"{chat.id}|{user.id}|clean_join", ) context.job_queue.run_once( clean_queue, context.bot_data.get("config").get("TIME"), context={ "chat_id": chat.id, "user_id": user.id, "message_id": question_message.message_id, }, name=f"{chat.id}|{user.id}|clean_question", )
def newmem(update: Update, context: CallbackContext) -> None: message = update.message chat = message.chat if message.from_user.id in get_chat_admins( context.bot, chat.id, extra_user=context.bot_data.get("config").get("SUPER_ADMIN"), ): return for user in message.new_chat_members: if user.is_bot: continue num = SystemRandom().randint( 0, len(context.bot_data.get("config").get("CHALLENGE")) - 1) flag = context.bot_data.get("config").get("CHALLENGE")[num] if context.bot.restrict_chat_member( chat_id=chat.id, user_id=user.id, permissions=ChatPermissions(can_send_messages=False), ): logger.info( f"New member: Successfully restricted user {user.id} at group {chat.id}" ) else: logger.warning( f"New member: No enough permissions to restrict user {user.id} at group {chat.id}" ) buttons = [[ InlineKeyboardButton( flag.get("WRONG")[t], callback_data= f"challenge|{user.id}|{num}|{flag.get('wrong')[t]}", ) ] for t in range(len(flag.get("WRONG")))] buttons.append([ InlineKeyboardButton( flag.get("ANSWER"), callback_data=f"challenge|{user.id}|{num}|{flag.get('answer')}", ) ]) SystemRandom().shuffle(buttons) buttons.append([ InlineKeyboardButton( context.bot_data.get("config").get("PASS_BTN"), callback_data=f"admin|pass|{user.id}", ), InlineKeyboardButton( context.bot_data.get("config").get("KICK_BTN"), callback_data=f"admin|kick|{user.id}", ), ]) question_message = message.reply_text( escape_markdown( context.bot_data.get("config").get("GREET")).format( question=escape_markdown(flag.get("QUESTION")), time=context.bot_data.get("config").get("TIME"), ), reply_markup=InlineKeyboardMarkup(buttons), parse_mode=ParseMode.MARKDOWN_V2, ) context.job_queue.scheduler.add_job( kick, "date", id=f"{chat.id}|{user.id}|kick", name=f"{chat.id}|{user.id}|kick", args=[context, chat.id, user.id], run_date=context.job_queue._tz_now() + datetime.timedelta( seconds=context.bot_data.get("config").get("TIME")), replace_existing=True, ) context.job_queue.scheduler.add_job( clean, "date", id=f"{chat.id}|{user.id}|clean_join", name=f"{chat.id}|{user.id}|clean_join", args=[context, chat.id, user.id, message.message_id], run_date=context.job_queue._tz_now() + datetime.timedelta( seconds=context.bot_data.get("config").get("TIME")), replace_existing=True, ) context.job_queue.scheduler.add_job( clean, "date", id=f"{chat.id}|{user.id}|clean_question", name=f"{chat.id}|{user.id}|clean_question", args=[context, chat.id, user.id, question_message.message_id], run_date=context.job_queue._tz_now() + datetime.timedelta( seconds=context.bot_data.get("config").get("TIME")), replace_existing=True, )
def admin_command(update, context): message = update.message message.reply_text( get_chat_admins(context.bot, message.chat.id, username=True))