async def remove_warn(client: PyroBot, c_q: CallbackQuery, user_id: str, warner: int): chat_id = str(c_q.message.chat.id) if chat_id not in client.warndatastore: client.warndatastore[chat_id] = {} DATA = client.warndatastore[chat_id] if c_q.from_user.id == warner: if DATA.get(user_id): up_l = DATA[user_id]["limit"] - 1 # up_l = updated limit if up_l > 0: DATA[user_id]["limit"] = up_l del DATA[user_id]["reason"][-1] else: DATA.pop(user_id) mention = f"<a href='tg://user?id={c_q.from_user.id}'>" mention += c_q.from_user.first_name mention += "</a>" text = f"{mention} removed this Warn." await c_q.edit_message_text(text) else: await c_q.edit_message_text( "😕😕 This User does not have any Warn.") await c_q.answer() # ensure no spinny circle -_- else: await c_q.answer(("Only " f"{(await client.get_users(warner)).first_name} " "Can Remove this Warn"), show_alert=True) client.warndatastore[chat_id] = DATA await client.save_public_store(WARN_DATA_ID, json.dumps(client.warndatastore))
async def set_warn_mode_and_limit(client: PyroBot, msg: Message): if len(msg.command) <= 1: await msg.reply("Input not found!") return chat_id = str(msg.chat.id) WARN_MODE = "kick" WARN_LIMIT = 5 _, args = msg.text.split(maxsplit=1) if "ban" in args.lower(): WARN_MODE = "ban" await msg.reply("Warning Mode Updated to <u>Ban</u>") elif "kick" in args.lower(): WARN_MODE = "kick" await msg.reply("Warning Mode Updated to <u>Kick</u>") elif "mute" in args.lower(): WARN_MODE = "mute" await msg.reply("Warning Mode Updated to <u>Mute</u>") elif args.isnumeric(): input_ = int(args) WARN_LIMIT = input_ await msg.reply(f'Warn limit Updated to <u>{WARN_LIMIT}</u> Warns.') else: await msg.reply("Invalid arguments, Exiting...") client.warnsettingsstore[chat_id] = { "WARN_LIMIT": WARN_LIMIT, "WARN_MODE": WARN_MODE } await client.save_public_store(WARN_SETTINGS_ID, json.dumps(client.warnsettingsstore))
async def check_warns_of_user(client: PyroBot, msg: Message): replied = msg.reply_to_message if not replied: return chat_id = str(msg.chat.id) if chat_id not in client.warndatastore: client.warndatastore[chat_id] = {} DATA = client.warndatastore[chat_id] W_S = client.warnsettingsstore[chat_id] WARN_LIMIT = W_S["WARN_LIMIT"] user_id = str(replied.from_user.id) mention = f"<a href='tg://user?id={user_id}'>" mention += replied.from_user.first_name mention += "</a>" if replied.from_user.is_self: return if DATA.get(user_id): w_c = DATA[user_id]["limit"] # warn counts reason = "\n".join(DATA[user_id]["reason"]) reply_msg = ("#WARNINGS\n" f"User: {mention}\n" f"Warn Counts: {w_c}/{WARN_LIMIT} Warnings\n" f"Reason: {reason}") await msg.reply(reply_msg) else: await msg.reply("Warnings not Found.")
async def reset_all_warns(client: PyroBot, msg: Message): replied = msg.reply_to_message if not replied: return user_id = str(replied.from_user.id) if replied.from_user.is_self: return chat_id = str(msg.chat.id) if chat_id not in client.warndatastore: client.warndatastore[chat_id] = {} DATA = client.warndatastore[chat_id] if DATA.get(user_id): DATA.pop(user_id) await msg.reply("All Warns are removed for this User.") else: await msg.reply("User already not have any warn.") client.warndatastore[chat_id] = DATA await client.save_public_store(WARN_DATA_ID, json.dumps(client.warndatastore))
async def warn_user(client: PyroBot, msg: Message): chat_id = str(msg.chat.id) replied = msg.reply_to_message if not replied: return if chat_id not in client.warndatastore: client.warndatastore[chat_id] = {} DATA = client.warndatastore[chat_id] user_id = str(replied.from_user.id) mention = f"<a href='tg://user?id={user_id}'>" mention += replied.from_user.first_name mention += "</a>" if replied.from_user.is_self: await msg.reply_text("ഞാൻ സ്വയം താക്കീത് നൽകാൻ പോകുന്നില്ല") return if await admin_check(replied): await msg.reply("User is Admin, Cannot Warn.") return if len(msg.command) < 2: await msg.reply("Give a reason to warn him.") return _, reason = msg.text.split(maxsplit=1) if chat_id not in client.warnsettingsstore: client.warnsettingsstore[chat_id] = { "WARN_LIMIT": 5, "WARN_MODE": "kick" } w_s = client.warnsettingsstore[chat_id] w_l = w_s["WARN_LIMIT"] w_m = w_s["WARN_MODE"] keyboard = InlineKeyboardMarkup([[ InlineKeyboardButton( "ഈ താക്കീത് നീക്കംചെയ്യുക", callback_data=f"rmwarn_{user_id}_{msg.from_user.id}") ]]) if not DATA.get(user_id): w_d = {"limit": 1, "reason": [reason]} DATA[user_id] = w_d # warning data reply_text = f"#Warned\n{mention} has 1/{w_l} warnings.\n" reply_text += f"<u>Reason</u>: {reason}" await replied.reply_text(reply_text, reply_markup=keyboard) else: p_l = DATA[user_id]["limit"] # previous limit nw_l = p_l + 1 # new limit if nw_l >= w_l: if w_m == "ban": await msg.chat.kick_member(int(user_id)) exec_str = "BANNED" elif w_m == "kick": await msg.chat.kick_member(int(user_id), until_date=time.time() + 61) exec_str = "KICKED" elif w_m == "mute": await msg.chat.restrict_member(int(user_id), ChatPermissions()) exec_str = "MUTED" reason = ("\n".join(DATA[user_id]["reason"]) + "\n" + str(reason)) await msg.reply(f"#WARNED_{exec_str}\n" f"{exec_str} User: {mention}\n" f"Warn Counts: {w_l}/{w_l} Warnings\n" f"Reason: {reason}") DATA.pop(user_id) else: DATA[user_id]["limit"] = nw_l DATA[user_id]["reason"].append(reason) r_t = f"#Warned\n{mention} has {nw_l}/{w_l} warnings.\n" r_t += f"<u>Reason</u>: {reason}" # r_t = reply text await replied.reply_text(r_t, reply_markup=keyboard) client.warndatastore[chat_id] = DATA await client.save_public_store(WARN_DATA_ID, json.dumps(client.warndatastore)) client.warnsettingsstore[chat_id] = w_s await client.save_public_store(WARN_SETTINGS_ID, json.dumps(client.warnsettingsstore))
async def save_filter(client: PyroBot, message): status_message = await message.reply_text("checking 🤔🙄🙄", quote=True) if (message.reply_to_message and message.reply_to_message.reply_markup is not None): fwded_mesg = await message.reply_to_message.forward( chat_id=TG_URI, disable_notification=True) chat_id = message.chat.id filter_kw = " ".join(message.command[1:]) fm_id = fwded_mesg.message_id client.filterstore[str(chat_id)][filter_kw] = fm_id await client.save_public_store(TG_IRU_S_M_ID, json.dumps(client.filterstore)) await status_message.edit_text( f"filter <u>{filter_kw}</u> added" # f"<a href='https://'>{message.chat.title}</a>" ) else: filter_kw, text, data_type, content, buttons = get_note_type( message, 2) if data_type is None: await status_message.edit_text("🤔 maybe note text is empty") return if not filter_kw: await status_message.edit_text( "എന്തിന്ന് ഉള്ള മറുപടി ആണ് എന്ന് വ്യക്തം ആക്കിയില്ല 🤔") return # construct message using the above parameters fwded_mesg = None reply_markup = None if len(buttons) > 0: reply_markup = InlineKeyboardMarkup(buttons) if data_type in (Types.BUTTON_TEXT, Types.TEXT): fwded_mesg = await client.send_message( chat_id=TG_URI, text=text, parse_mode="md", disable_web_page_preview=True, disable_notification=True, reply_to_message_id=1, reply_markup=reply_markup) elif data_type is not None: fwded_mesg = await client.send_cached_media( chat_id=TG_URI, file_id=content, caption=text, parse_mode="md", disable_notification=True, reply_to_message_id=1, reply_markup=reply_markup) # save to db 🤔 if fwded_mesg is not None: chat_id = message.chat.id fm_id = fwded_mesg.message_id client.filterstore[str(chat_id)][filter_kw] = fm_id await client.save_public_store(TG_IRU_S_M_ID, json.dumps(client.filterstore)) await status_message.edit_text( f"filter <u>{filter_kw}</u> added" # f"<a href='https://'>{message.chat.title}</a>" ) else: await status_message.edit_text("🥺 this might be an error 🤔")
async def save_filter(client: PyroBot, message): status_message = await message.reply_text("Wait a Sec", quote=True) if (message.reply_to_message and message.reply_to_message.reply_markup is not None): fwded_mesg = await message.reply_to_message.forward( chat_id=TG_URI, disable_notification=True) chat_id = message.chat.id filter_kw = " ".join(message.command[1:]) fm_id = fwded_mesg.message_id client.filterstore[str(chat_id)][filter_kw] = fm_id await client.save_public_store(TG_IRU_S_M_ID, json.dumps(client.filterstore)) await status_message.edit_text( f"filter <u>{filter_kw}</u> added" # f"<a href='https://'>{message.chat.title}</a>" ) else: filter_kw, text, data_type, content, buttons = get_note_type( message, 2) if data_type is None: await status_message.edit_text("🤔 Note Text is empty") return if not filter_kw: await status_message.edit_text("It is Not Clear 🤔") return # construct message using the above parameters fwded_mesg = None reply_markup = None if len(buttons) > 0: reply_markup = InlineKeyboardMarkup(buttons) if data_type in (Types.BUTTON_TEXT, Types.TEXT): fwded_mesg = await client.send_message( chat_id=TG_URI, text=text, parse_mode="md", disable_web_page_preview=True, disable_notification=True, reply_to_message_id=1, reply_markup=reply_markup) elif data_type is not None: fwded_mesg = await client.send_cached_media( chat_id=TG_URI, file_id=content, caption=text, parse_mode="md", disable_notification=True, reply_to_message_id=1, reply_markup=reply_markup) # save to db 🤔 if fwded_mesg is not None: chat_id = message.chat.id fm_id = fwded_mesg.message_id client.filterstore[str(chat_id)][filter_kw] = fm_id await client.save_public_store(TG_IRU_S_M_ID, json.dumps(client.filterstore)) await status_message.edit_text( f"Filter <u>{filter_kw}</u> Added Successfully" # f"<a href='https://'>{message.chat.title}</a>" ) else: await status_message.edit_text("🥺 This Might Be an Error 🤔")