def warns(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] user_id = extract_user(message, args) or update.effective_user.id result = sql.get_warns(user_id, chat.id) if result and result[0] != 0: num_warns, reasons = result limit, soft_warn = sql.get_warn_setting(chat.id) if reasons: text = "This user has {}/{} warnings, for the following reasons:".format( num_warns, limit) for reason in reasons: text += "\n • {}".format(reason) msgs = split_message(text) for msg in msgs: update.effective_message.reply_text(msg) else: update.effective_message.reply_text( "User has {}/{} warnings, but no reasons for any of them.". format(num_warns, limit)) else: update.effective_message.reply_text( "This user hasn't got any warnings!")
def sudopromote(bot: Bot, update: Update, args: List[str]): message = update.effective_message banner = update.effective_user user_id = extract_user(message, args) if not user_id: message.reply_text("Refer a user first....") return "" if int(user_id) == OWNER_ID: message.reply_text( "The specified user is my owner! No need add him to SUDO_USERS list!" ) return "" if int(user_id) in SUDO_USERS: message.reply_text("Buddy this user is already a sudo user.") return "" with open("sudo_users.txt", "a") as file: file.write(str(user_id) + "\n") SUDO_USERS.append(user_id) message.reply_text("Succefully Added To SUDO List!") return ""
def sudodemote(bot: Bot, update: Update, args: List[str]): message = update.effective_message user_id = extract_user(message, args) if not user_id: message.reply_text("Refer the user first.") return "" if int(user_id) == OWNER_ID: message.reply_text( "The specified user is my owner! I won't remove him from SUDO_USERS list!" ) return "" if user_id not in SUDO_USERS: message.reply_text("{} is not a sudo user".format(user_id)) return "" users = [line.rstrip('\n') for line in open("sudo_users.txt")] with open("sudo_users.txt", "w") as file: for user in users: if not int(user) == user_id: file.write(str(user) + "\n") SUDO_USERS.remove(user_id) message.reply_text("Yep Succefully removed from SUDO List!") return ""
def get_id(bot: Bot, update: Update, args: List[str]): user_id = extract_user(update.effective_message, args) chat = update.effective_chat # type: Optional[Chat] if user_id: if update.effective_message.reply_to_message and update.effective_message.reply_to_message.forward_from: user1 = update.effective_message.reply_to_message.from_user user2 = update.effective_message.reply_to_message.forward_from update.effective_message.reply_text(tld( chat.id, "The original sender, {}, has an ID of `{}`.\nThe forwarder, {}, has an ID of `{}`." ).format(escape_markdown(user2.first_name), user2.id, escape_markdown(user1.first_name), user1.id), parse_mode=ParseMode.MARKDOWN) else: user = bot.get_chat(user_id) update.effective_message.reply_text(tld( chat.id, "{}'s id is `{}`.").format(escape_markdown(user.first_name), user.id), parse_mode=ParseMode.MARKDOWN) else: chat = update.effective_chat # type: Optional[Chat] if chat.type == "private": update.effective_message.reply_text(tld( chat.id, "Your id is `{}`.").format(chat.id), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text(tld( chat.id, "This group's id is `{}`.").format(chat.id), parse_mode=ParseMode.MARKDOWN)
def get_id(bot: Bot, update: Update, args: List[str]): user_id = extract_user(update.effective_message, args) chat = update.effective_chat # type: Optional[Chat] if user_id: if update.effective_message.reply_to_message and update.effective_message.reply_to_message.forward_from: user1 = update.effective_message.reply_to_message.from_user user2 = update.effective_message.reply_to_message.forward_from update.effective_message.reply_markdown( tld(chat.id, "misc_get_id_1").format(escape_markdown(user2.first_name), user2.id, escape_markdown(user1.first_name), user1.id)) else: user = bot.get_chat(user_id) update.effective_message.reply_markdown( tld(chat.id, "misc_get_id_2").format(escape_markdown(user.first_name), user.id)) else: chat = update.effective_chat # type: Optional[Chat] if chat.type == "private": update.effective_message.reply_markdown( tld(chat.id, "misc_id_1").format(chat.id)) else: update.effective_message.reply_markdown( tld(chat.id, "misc_id_2").format(chat.id))
def warns(bot: Bot, update: Update, args: List[str]): message = update.effective_message chat = update.effective_chat user_id = extract_user(message, args) or update.effective_user.id result = sql.get_warns(user_id, chat.id) num = 1 if result and result[0] != 0: num_warns, reasons = result limit, soft_warn = sql.get_warn_setting(chat.id) if reasons: text = tld(chat.id, 'warns_list_warns').format(num_warns, limit) for reason in reasons: text += "\n {}. {}".format(num, reason) num += 1 msgs = split_message(text) for msg in msgs: update.effective_message.reply_text(msg) else: update.effective_message.reply_text( tld(chat.id, 'warns_list_warns_no_reason').format(num_warns, limit)) else: update.effective_message.reply_text( tld(chat.id, 'warns_list_warns_none'))
def promote(bot: Bot, update: Update, args: List[str]) -> str: message = update.effective_message # type: Optional[Message] user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] conn = connected(bot, update, chat, user.id) if not conn == False: chatD = dispatcher.bot.getChat(conn) else: chatD = update.effective_chat if chat.type == "private": exit(1) if not chatD.get_member(bot.id).can_promote_members: update.effective_message.reply_text( "Saya tidak bisa promote/demote orang disini! " "Jadikan saya admin agar saya bisa menambahkan admin baru.") exit(1) user_id = extract_user(message, args) if not user_id: message.reply_text(tld(chat.id, "Tag orangnya, jangan bikin bingung!")) return "" user_member = chatD.get_member(user_id) if user_member.status == 'administrator' or user_member.status == 'creator': message.reply_text( tld(chat.id, "Dia sudah jadi admin, ngapain di promosiin lagi?")) return "" if user_id == bot.id: message.reply_text( tld( chat.id, "Saya tidak bisa promote diri sendiri, jadikan admin jangan pelit!" )) return "" # set same perms as bot - bot can't assign higher perms than itself! bot_member = chatD.get_member(bot.id) bot.promoteChatMember( chatD.id, user_id, can_change_info=bot_member.can_change_info, can_post_messages=bot_member.can_post_messages, can_edit_messages=bot_member.can_edit_messages, can_delete_messages=bot_member.can_delete_messages, #can_invite_users=bot_member.can_invite_users, can_restrict_members=bot_member.can_restrict_members, can_pin_messages=bot_member.can_pin_messages, can_promote_members=bot_member.can_promote_members) message.reply_text(tld( chat.id, f"Berhasil promote menjadi admin di *{chatD.title}*!"), parse_mode=ParseMode.MARKDOWN) return f"<b>{html.escape(chatD.title)}:</b>" \ "\n#PROMOTED" \ f"\n<b>Admin:</b> {mention_html(user.id, user.first_name)}" \ f"\n<b>User:</b> {mention_html(user_member.user.id, user_member.user.first_name)}"
def promote(bot: Bot, update: Update, args: List[str]) -> str: message = update.effective_message # type: Optional[Message] user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] conn = connected(bot, update, chat, user.id) if not conn == False: chatD = dispatcher.bot.getChat(conn) else: chatD = update.effective_chat if chat.type == "private": exit(1) if not chatD.get_member(bot.id).can_promote_members: update.effective_message.reply_text( "I can't promote/demote people here! " "Make sure I'm admin and can appoint new admins.") exit(1) user_id = extract_user(message, args) if not user_id: message.reply_text( tld(chat.id, "You don't seem to be referring to a user.")) return "" user_member = chatD.get_member(user_id) if user_member.status == 'administrator' or user_member.status == 'creator': message.reply_text( tld(chat.id, "How am I meant to promote someone that's already an admin?")) return "" if user_id == bot.id: message.reply_text( tld(chat.id, "I can't promote myself! Get an admin to do it for me.")) return "" # set same perms as bot - bot can't assign higher perms than itself! bot_member = chatD.get_member(bot.id) bot.promoteChatMember( chatD.id, user_id, can_change_info=bot_member.can_change_info, can_post_messages=bot_member.can_post_messages, can_edit_messages=bot_member.can_edit_messages, can_delete_messages=bot_member.can_delete_messages, #can_invite_users=bot_member.can_invite_users, can_restrict_members=bot_member.can_restrict_members, can_pin_messages=bot_member.can_pin_messages, can_promote_members=bot_member.can_promote_members) message.reply_text(tld(chat.id, f"Successfully promoted in *{chatD.title}*!"), parse_mode=ParseMode.MARKDOWN) return f"<b>{html.escape(chatD.title)}:</b>" \ "\n#PROMOTED" \ f"\n<b>Admin:</b> {mention_html(user.id, user.first_name)}" \ f"\n<b>User:</b> {mention_html(user_member.user.id, user_member.user.first_name)}"
def info(bot: Bot, update: Update, args: List[str]): msg = update.effective_message # type: Optional[Message] user_id = extract_user(update.effective_message, args) chat = update.effective_chat # type: Optional[Chat] if user_id: user = bot.get_chat(user_id) elif not msg.reply_to_message and not args: user = msg.from_user elif not msg.reply_to_message and ( not args or (len(args) >= 1 and not args[0].startswith("@") and not args[0].isdigit() and not msg.parse_entities([MessageEntity.TEXT_MENTION]))): msg.reply_text(tld(chat.id, "I can't extract a user from this.")) return else: return text = tld(chat.id, "misc_info_1") text += tld(chat.id, "misc_info_id").format(user.id) text += tld(chat.id, "misc_info_first").format(html.escape(user.first_name)) if user.last_name: text += tld(chat.id, "misc_info_name").format(html.escape(user.last_name)) if user.username: text += tld(chat.id, "misc_info_username").format(html.escape(user.username)) text += tld(chat.id, "misc_info_user_link").format(mention_html(user.id, "link")) if user.id == OWNER_ID: text += tld(chat.id, "misc_info_is_owner") else: if user.id == int(254318997): text += tld(chat.id, "misc_info_is_original_owner") if user.id in SUDO_USERS: text += tld(chat.id, "misc_info_is_sudo") else: if user.id in SUPPORT_USERS: text += tld(chat.id, "misc_info_is_support") if user.id in WHITELIST_USERS: text += tld(chat.id, "misc_info_is_whitelisted") for mod in USER_INFO: mod_info = mod.__user_info__(user.id, chat.id).strip() if mod_info: text += "\n\n" + mod_info update.effective_message.reply_text(text, parse_mode=ParseMode.HTML)
def mute(bot: Bot, update: Update, args: List[str]) -> str: chat = update.effective_chat user = update.effective_user message = update.effective_message conn = connected(bot, update, chat, user.id) if conn: chatD = dispatcher.bot.getChat(conn) else: if chat.type == "private": return else: chatD = chat user_id = extract_user(message, args) if not user_id: message.reply_text(tld(chat.id, "mute_invalid")) return "" if user_id == bot.id: message.reply_text(tld(chat.id, "mute_not_myself")) return "" member = chatD.get_member(int(user_id)) if member: if user_id in SUDO_USERS: message.reply_text(tld(chat.id, "mute_not_sudo")) elif is_user_admin(chatD, user_id, member=member): message.reply_text(tld(chat.id, "mute_not_m_admin")) elif member.can_send_messages is None or member.can_send_messages: bot.restrict_chat_member(chatD.id, user_id, can_send_messages=False) keyboard = [] reply = tld(chat.id, "mute_success").format( mention_html(member.user.id, member.user.first_name), chatD.title) message.reply_text(reply, reply_markup=keyboard, parse_mode=ParseMode.HTML) return "<b>{}:</b>" \ "\n#MUTE" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {}".format(html.escape(chatD.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name)) else: message.reply_text( tld(chat.id, "mute_already_mute").format(chatD.title)) else: message.reply_text( tld(chat.id, "mute_not_in_chat").format(chatD.title)) return ""
def promote(bot: Bot, update: Update, args: List[str]) -> str: message = update.effective_message user = update.effective_user chat = update.effective_chat conn = connected(bot, update, chat, user.id) if conn: chatD = dispatcher.bot.getChat(conn) else: chatD = update.effective_chat if chat.type == "private": return "" if not chatD.get_member(bot.id).can_promote_members: update.effective_message.reply_text(tld(chat.id, "admin_err_no_perm")) return "" member = chatD.get_member(user.id) if not member.can_promote_members and member.status != 'creator': update.effective_message.reply_text( tld(chat.id, "admin_err_user_no_perm")) return "" user_id = extract_user(message, args) if not user_id: message.reply_text(tld(chat.id, "common_err_no_user")) return "" user_member = chatD.get_member(user_id) if user_member.status == 'administrator' or user_member.status == 'creator': message.reply_text(tld(chat.id, "admin_err_user_admin")) return "" if user_id == bot.id: message.reply_text(tld(chat.id, "admin_err_self_promote")) return "" # set same perms as bot - bot can't assign higher perms than itself! bot_member = chatD.get_member(bot.id) bot.promoteChatMember(chatD.id, user_id, can_change_info=bot_member.can_change_info, can_post_messages=bot_member.can_post_messages, can_edit_messages=bot_member.can_edit_messages, can_delete_messages=bot_member.can_delete_messages, can_invite_users=bot_member.can_invite_users, can_restrict_members=bot_member.can_restrict_members, can_pin_messages=bot_member.can_pin_messages, can_promote_members=bot_member.can_promote_members) message.reply_text(tld(chat.id, "admin_promote_success").format( mention_html(user.id, user.first_name), mention_html(user_member.user.id, user_member.user.first_name), html.escape(chatD.title)), parse_mode=ParseMode.HTML) return f"<b>{html.escape(chatD.title)}:</b>" \ "\n#PROMOTED" \ f"\n<b>Admin:</b> {mention_html(user.id, user.first_name)}" \ f"\n<b>User:</b> {mention_html(user_member.user.id, user_member.user.first_name)}"
def ungban(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id = extract_user(message, args) if not user_id: message.reply_text("You don't seem to be referring to a user.") return user_chat = bot.get_chat(user_id) if user_chat.type != 'private': message.reply_text("That's not a user!") return if not sql.is_user_gbanned(user_id): message.reply_text("This user is not gbanned!") return banner = update.effective_user # type: Optional[User] message.reply_text("I'll give {} a second chance, globally.".format( user_chat.first_name)) bot.send_message(MESSAGE_DUMP, "{} has ungbanned user {}".format( mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name)), parse_mode=ParseMode.HTML) chats = get_all_chats() for chat in chats: chat_id = chat.chat_id # Check if this group has disabled gbans if not sql.does_chat_gban(chat_id): continue try: member = bot.get_chat_member(chat_id, user_id) if member.status == 'kicked': bot.unban_chat_member(chat_id, user_id) except BadRequest as excp: if excp.message in UNGBAN_ERRORS: pass else: message.reply_text("Could not un-gban due to: {}".format( excp.message)) bot.send_message( OWNER_ID, "Could not un-gban due to: {}".format(excp.message)) return except TelegramError: pass sql.ungban_user(user_id) bot.send_message(MESSAGE_DUMP, "un-gban complete!") message.reply_text("Person has been un-gbanned.")
def user_join_fed(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] fed_id = sql.get_fed_id(chat.id) if is_user_fed_owner(fed_id, user.id) == False: update.effective_message.reply_text(tld(chat.id, "Only fed owner can do this!")) return msg = update.effective_message # type: Optional[Message] user_id = extract_user(msg, args) if user_id: user = bot.get_chat(user_id) elif not msg.reply_to_message and not args: user = msg.from_user elif not msg.reply_to_message and (not args or ( len(args) >= 1 and not args[0].startswith("@") and not args[0].isdigit() and not msg.parse_entities( [MessageEntity.TEXT_MENTION]))): msg.reply_text(tld(chat.id, "I can't extract a user from this.")) return else: return print(sql.search_user_in_fed(fed_id, user_id)) #if user_id == user_id: # update.effective_message.reply_text(tld(chat.id, "Are you gonna promote yourself?")) # return fed_id = sql.get_fed_id(chat.id) info = sql.get_fed_info(fed_id) OW = bot.get_chat(info.owner_id) HAHA = OW.id if user_id == HAHA: update.effective_message.reply_text(tld(chat.id, "Why are you trying to promote federation owner!?")) return if not sql.search_user_in_fed(fed_id, user_id) == False: update.effective_message.reply_text(tld(chat.id, "I can't promote user which is already a fed admin! But I can demote them.")) return if user_id == bot.id: update.effective_message.reply_text(tld(chat.id, "I am already the federation admin and the one that manage it!")) return #else: # return res = sql.user_join_fed(fed_id, user_id) if not res: update.effective_message.reply_text(tld(chat.id, "Failed to promoted! It might be because you are admin in another federation! Our code is still buggy, We are sorry for that!")) return update.effective_message.reply_text(tld(chat.id, "Promoted Successfully!"))
def nomedia(bot: Bot, update: Update, args: List[str]) -> str: chat = update.effective_chat user = update.effective_user message = update.effective_message conn = connected(bot, update, chat, user.id) if conn: chatD = dispatcher.bot.getChat(conn) else: if chat.type == "private": return else: chatD = chat user_id = extract_user(message, args) if not user_id: message.reply_text(tld(chat.id, "restrict_invalid")) return "" if user_id == bot.id: message.reply_text(tld(chat.id, "restrict_is_bot")) return "" member = chatD.get_member(int(user_id)) if member: if is_user_admin(chatD, user_id, member=member): message.reply_text(tld(chat.id, "restrict_is_admin")) elif member.can_send_messages is None or member.can_send_messages: bot.restrict_chat_member(chatD.id, user_id, can_send_messages=True, can_send_media_messages=False, can_send_other_messages=False, can_add_web_page_previews=False) keyboard = [] reply = tld(chat.id, "restrict_success").format( mention_html(member.user.id, member.user.first_name), chatD.title) message.reply_text(reply, reply_markup=keyboard, parse_mode=ParseMode.HTML) return "<b>{}:</b>" \ "\n#RESTRICTED" \ "\n<b>• Admin:</b> {}" \ "\n<b>• User:</b> {}" \ "\n<b>• ID:</b> <code>{}</code>".format(html.escape(chatD.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), user_id) else: message.reply_text(tld(chat.id, "restrict_already_restricted")) else: message.reply_text( tld(chat.id, "mute_not_in_chat").format(chatD.title)) return ""
def user_join_fed(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] fed_id = sql.get_fed_id(chat.id) if is_user_fed_owner(fed_id, user.id) == False: update.effective_message.reply_text( tld(chat.id, "Only fed owner can do this!")) return msg = update.effective_message # type: Optional[Message] user_id = extract_user(msg, args) if user_id: user = bot.get_chat(user_id) elif not msg.reply_to_message and not args: user = msg.from_user elif not msg.reply_to_message and ( not args or (len(args) >= 1 and not args[0].startswith("@") and not args[0].isdigit() and not msg.parse_entities([MessageEntity.TEXT_MENTION]))): msg.reply_text(tld(chat.id, "I can't extract a user from this.")) return else: return print(sql.search_user_in_fed(fed_id, user_id)) if is_user_fed_owner(fed_id, user.id) == True: update.effective_message.reply_text( tld(chat.id, "Are you gonna promote yourself?")) return elif not sql.search_user_in_fed(fed_id, user_id) == False: update.effective_message.reply_text( tld( chat.id, "I can't promote user which is already a fed admin! But I can demote them." )) return if user_id == bot.id: update.effective_message.reply_text( tld( chat.id, "I am already the federation admin and the one that manage it!" )) return #else: # return res = sql.user_join_fed(fed_id, user_id) update.effective_message.reply_text(tld(chat.id, "Promoted Successfully!"))
def demote(bot: Bot, update: Update, args: List[str]) -> str: chat = update.effective_chat message = update.effective_message user = update.effective_user conn = connected(bot, update, chat, user.id) if conn: chatD = dispatcher.bot.getChat(conn) else: chatD = update.effective_chat if chat.type == "private": return if not chatD.get_member(bot.id).can_promote_members: update.effective_message.reply_text(tld(chat.id, "admin_err_no_perm")) return user_id = extract_user(message, args) if not user_id: message.reply_text(tld(chat.id, "common_err_no_user")) return "" user_member = chatD.get_member(user_id) if user_member.status == 'creator': message.reply_text(tld(chat.id, "admin_err_demote_creator")) return "" if not user_member.status == 'administrator': message.reply_text(tld(chat.id, "admin_err_demote_noadmin")) return "" if user_id == bot.id: message.reply_text(tld(chat.id, "admin_err_self_demote")) return "" try: bot.promoteChatMember(int(chatD.id), int(user_id), can_change_info=False, can_post_messages=False, can_edit_messages=False, can_delete_messages=False, can_invite_users=False, can_restrict_members=False, can_pin_messages=False, can_promote_members=False) message.reply_text(tld(chat.id, "admin_demote_success").format( mention_html(user.id, user.first_name), mention_html(user_member.user.id, user_member.user.first_name), html.escape(chatD.title)), parse_mode=ParseMode.HTML) return f"<b>{html.escape(chatD.title)}:</b>" \ "\n#DEMOTED" \ f"\n<b>Admin:</b> {mention_html(user.id, user.first_name)}" \ f"\n<b>User:</b> {mention_html(user_member.user.id, user_member.user.first_name)}" except BadRequest: message.reply_text(tld(chat.id, "admin_err_cant_demote")) return ""
def demote(bot: Bot, update: Update, args: List[str]) -> str: chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id) if conn: chatD = dispatcher.bot.getChat(conn) else: chatD = update.effective_chat if chat.type == "private": exit(1) if not chatD.get_member(bot.id).can_promote_members: update.effective_message.reply_text("I can't promote/demote people here! " "Make sure I'm an admin and can appoint new admins.") exit(1) user_id = extract_user(message, args) if not user_id: message.reply_text(tld(chat.id, "You don't seem to be referring to a user.")) return "" user_member = chatD.get_member(user_id) if user_member.status == 'creator': message.reply_text(tld(chat.id, "This person is the CREATOR of the chat, how would I demote them?")) return "" if not user_member.status == 'administrator': message.reply_text(tld(chat.id, "Can't demote those who weren't promoted!")) return "" if user_id == bot.id: message.reply_text(tld(chat.id, "I can't demote myself!")) return "" try: bot.promoteChatMember(int(chatD.id), int(user_id), can_change_info=False, can_post_messages=False, can_edit_messages=False, can_delete_messages=False, can_invite_users=False, can_restrict_members=False, can_pin_messages=False, can_promote_members=False) message.reply_text(tld(chat.id, f"Successfully demoted in *{chatD.title}*!"), parse_mode=ParseMode.MARKDOWN) return f"<b>{html.escape(chatD.title)}:</b>" \ "\n#DEMOTED" \ f"\n<b>Admin:</b> {mention_html(user.id, user.first_name)}" \ f"\n<b>User:</b> {mention_html(user_member.user.id, user_member.user.first_name)}" except BadRequest: message.reply_text( tld(chat.id, "Could not demote. I might not be admin, or the admin status was appointed by another user, so I can't act upon them!") ) return ""
def info(bot: Bot, update: Update, args: List[str]): msg = update.effective_message # type: Optional[Message] user_id = extract_user(update.effective_message, args) chat = update.effective_chat # type: Optional[Chat] if user_id: user = bot.get_chat(user_id) elif not msg.reply_to_message and not args: user = msg.from_user elif not msg.reply_to_message and (not args or ( len(args) >= 1 and not args[0].startswith("@") and not args[0].isdigit() and not msg.parse_entities( [MessageEntity.TEXT_MENTION]))): msg.reply_text(tld(chat.id, "I can't extract a user from this.")) return else: return text = tld(chat.id, "<b>User info</b>:") text += "\nID: <code>{}</code>".format(user.id) text += tld(chat.id, "\nFirst Name: {}").format(html.escape(user.first_name)) if user.last_name: text += tld(chat.id, "\nLast Name: {}").format(html.escape(user.last_name)) if user.username: text += tld(chat.id, "\nUsername: @{}").format(html.escape(user.username)) text += tld(chat.id, "\nUser link: {}\n").format(mention_html(user.id, "link")) if user.id == OWNER_ID: text += tld(chat.id, "\n\nAy, This guy is my owner. I would never do anything against him!") else: if user.id == int(254318997): text += tld(chat.id, "\nThis person.... He is my god.") if user.id in SUDO_USERS: text += tld(chat.id, "\nThis person is one of my sudo users! " \ "Nearly as powerful as my owner - so watch it.") else: if user.id in SUPPORT_USERS: text += tld(chat.id, "\nThis person is one of my support users! " \ "Not quite a sudo user, but can still gban you off the map.") if user.id in WHITELIST_USERS: text += tld(chat.id, "\nThis person has been whitelisted! " \ "That means I'm not allowed to ban/kick them.") for mod in USER_INFO: mod_info = mod.__user_info__(user.id, chat.id).strip() if mod_info: text += "\n\n" + mod_info update.effective_message.reply_text(text, parse_mode=ParseMode.HTML)
def promote(bot: Bot, update: Update, args: List[str]) -> str: message = update.effective_message # type: Optional[Message] user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] conn = connected(bot, update, chat, user.id) if not conn == False: chatD = dispatcher.bot.getChat(conn) else: chatD = update.effective_chat if chat.type == "private": exit(1) if not chatD.get_member(bot.id).can_promote_members: update.effective_message.reply_text("gabisa promot weh.") exit(1) user_id = extract_user(message, args) if not user_id: message.reply_text( tld(chat.id, "gabisa, kasih username atau reply ke pesannya!")) return "" user_member = chatD.get_member(user_id) if user_member.status == 'administrator' or user_member.status == 'creator': message.reply_text( tld(chat.id, "dia udah jadi admin, ngapain mau dipromote lagi?")) return "" if user_id == bot.id: message.reply_text( tld(chat.id, "mana bisa gua promote diri sendiri wkwk.")) return "" # set same perms as bot - bot can't assign higher perms than itself! bot_member = chatD.get_member(bot.id) bot.promoteChatMember( chatD.id, user_id, can_change_info=bot_member.can_change_info, can_post_messages=bot_member.can_post_messages, can_edit_messages=bot_member.can_edit_messages, can_delete_messages=bot_member.can_delete_messages, #can_invite_users=bot_member.can_invite_users, can_restrict_members=bot_member.can_restrict_members, can_pin_messages=bot_member.can_pin_messages, can_promote_members=bot_member.can_promote_members) message.reply_text(tld(chat.id, f"ok dia udah gua promote di *{chatD.title}*!"), parse_mode=ParseMode.MARKDOWN) return f"<b>{html.escape(chatD.title)}:</b>" \ "\n#PROMOTED" \ f"\n<b>Admin:</b> {mention_html(user.id, user.first_name)}" \ f"\n<b>User:</b> {mention_html(user_member.user.id, user_member.user.first_name)}"
def gkick(bot: Bot, update: Update, args: List[str]): message = update.effective_message user_id = extract_user(message, args) try: user_chat = bot.get_chat(user_id) except BadRequest as excp: if excp.message in GKICK_ERRORS: pass else: message.reply_text( "User cannot be Globally kicked because: {}".format( excp.message)) return except TelegramError: pass if not user_id: message.reply_text("You do not seems to be referring to a person") return if int(user_id) in SUDO_USERS or int(user_id) in SUPPORT_USERS: message.reply_text( "OHHH! Someone's trying to gkick a sudo/support user! *Grabs popcorn*" ) return if int(user_id) == OWNER_ID: message.reply_text( "Wow! Some's trying to gkick my owner! Go and f**k your self Bitch! *Grabs Potato Chips*" ) return if user_id == bot.id: message.reply_text("Well, I'm not gonna gkick myself!") return if int(user_id) in SUDO_USERS: message.reply_text("") return chats = get_all_chats() message.reply_text("Globally kicking person @{}".format( user_chat.username)) for chat in chats: try: bot.unban_chat_member(chat.chat_id, user_id) # Unban_member = kick (and not ban) except BadRequest as excp: if excp.message in GKICK_ERRORS: pass else: message.reply_text( "Person cannot be Globally kicked because: {}".format( excp.message)) return except TelegramError: pass
def gkick(bot: Bot, update: Update, args: List[str]): message = update.effective_message user_id = extract_user(message, args) try: user_chat = bot.get_chat(user_id) except BadRequest as excp: if excp.message in GKICK_ERRORS: pass else: message.reply_text("User cannot be Globally kicked because: {}".format(excp.message)) return except TelegramError: pass if not user_id: message.reply_text("You do not seems to be referring to a user") return if int(user_id) in SUDO_USERS or int(user_id) in SUPPORT_USERS: message.reply_text("OHHH! Someone's trying to gkick a sudo/support user! *Grabs popcorn*") return if int(user_id) == OWNER_ID: message.reply_text("Wow! Some's trying to gkick my owner! *Grabs Potato Chips*") return if user_id == bot.id: message.reply_text("Welp, I'm not gonna gkick myself!") return if user_chat.first_name == '': message.reply_text("That's a deleted account! Why u even bother gkicking dem") return if os.environ['GPROCESS'] == '1': message.reply_text("Leave me alone, I'm busy, Someone is using global stuff.") return os.environ['GPROCESS'] = '1' chats = get_all_chats() message.reply_text("Globally kicking user @{}".format(user_chat.username)) for chat in chats: try: bot.unban_chat_member(chat.chat_id, user_id) # Unban_member = kick (and not ban) except BadRequest as excp: if excp.message in GKICK_ERRORS: pass else: message.reply_text("User cannot be Globally kicked because: {}".format(excp.message)) os.environ['GPROCESS'] = '0' return except TelegramError: pass os.environ['GPROCESS'] = '0'
def promote(bot: Bot, update: Update, args: List[str]) -> str: message = update.effective_message # type: Optional[Message] user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] conn = connected(bot, update, chat, user.id) if not conn == False: chatD = dispatcher.bot.getChat(conn) else: chatD = update.effective_chat if chat.type == "private": exit(1) if not chatD.get_member(bot.id).can_promote_members: update.effective_message.reply_text( "لا يمكنني ترقية / تخفيض رتبة الناس هنا! " "تأكد من أنني مشرف ويمكنني تعيين مشرفين جدد.") exit(1) user_id = extract_user(message, args) if not user_id: message.reply_text(tld(chat.id, "لا يبدو أنك تشير إلى مستخدم.")) return "" user_member = chatD.get_member(user_id) if user_member.status == 'administrator' or user_member.status == 'creator': message.reply_text( tld(chat.id, "كيف أقوم بترقية شخص يعمل كمشرف بالفعل؟")) return "" if user_id == bot.id: message.reply_text( tld(chat.id, "لا يمكنني ترقية نفسي! اجعل مشرف يقوم بذلك من أجلي.")) return "" # set same perms as bot - bot can't assign higher perms than itself! bot_member = chatD.get_member(bot.id) bot.promoteChatMember( chatD.id, user_id, can_change_info=bot_member.can_change_info, can_post_messages=bot_member.can_post_messages, can_edit_messages=bot_member.can_edit_messages, can_delete_messages=bot_member.can_delete_messages, #can_invite_users=bot_member.can_invite_users, can_restrict_members=bot_member.can_restrict_members, can_pin_messages=bot_member.can_pin_messages, can_promote_members=bot_member.can_promote_members) message.reply_text(tld(chat.id, f"تمت الترقية بنجاح في *{chatD.title}*!"), parse_mode=ParseMode.MARKDOWN) return f"<b>{html.escape(chatD.title)}:</b>" \ "\n#PROMOTED" \ f"\n<b>Admin:</b> {mention_html(user.id, user.first_name)}" \ f"\n<b>User:</b> {mention_html(user_member.user.id, user_member.user.first_name)}"
def nomedia(bot: Bot, update: Update, args: List[str]) -> str: chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] conn = connected(bot, update, chat, user.id) if conn: chatD = dispatcher.bot.getChat(conn) else: if chat.type == "private": exit(1) else: chatD = chat user_id = extract_user(message, args) if not user_id: message.reply_text( tld(chat.id, "You'll need to either give me a username to restrict, or reply to someone to be restricted.")) return "" if user_id == bot.id: message.reply_text(tld(chat.id, "I'm not restricting myself!")) return "" member = chatD.get_member(int(user_id)) if member: if is_user_admin(chatD, user_id, member=member): message.reply_text(tld(chat.id, "Afraid I can't restrict admins!")) elif member.can_send_messages is None or member.can_send_messages: bot.restrict_chat_member(chatD.id, user_id, can_send_messages=True, can_send_media_messages=False, can_send_other_messages=False, can_add_web_page_previews=False) keyboard = [] reply = tld(chat.id, "{} is restricted from sending media in {}!").format( mention_html(member.user.id, member.user.first_name), chatD.title) message.reply_text(reply, reply_markup=keyboard, parse_mode=ParseMode.HTML) return "<b>{}:</b>" \ "\n#RESTRICTED" \ "\n<b>• Admin:</b> {}" \ "\n<b>• User:</b> {}" \ "\n<b>• ID:</b> <code>{}</code>".format(html.escape(chatD.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), user_id) else: message.reply_text(tld(chat.id, "This user is already restricted in {}!")) else: message.reply_text(tld(chat.id, "This user isn't in the {}!").format(chatD.title)) return ""
def mute(bot: Bot, update: Update, args: List[str]) -> str: chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] conn = connected(bot, update, chat, user.id) if not conn == False: chatD = dispatcher.bot.getChat(conn) else: if chat.type == "private": exit(1) else: chatD = chat user_id = extract_user(message, args) if not user_id: message.reply_text(tld(chat.id, "You'll need to either give me a username to mute, or reply to someone to be muted.")) return "" if user_id == bot.id: message.reply_text(tld(chat.id, "I'm not muting myself!")) return "" if user_id == 777000: message.reply_text(tld(chat.id, "I can't mute tg from tg u need to install whatsapp for thta lmao 😂")) return "" member = chatD.get_member(int(user_id)) if member: if user_id in SUDO_USERS: message.reply_text(tld(chat.id, "No! I'm not muting bot sudoers! That would be a pretty dumb idea.")) elif is_user_admin(chatD, user_id, member=member): message.reply_text(tld(chat.id, "No! I'm not muting chat administrator! That would be a pretty dumb idea.")) elif member.can_send_messages is None or member.can_send_messages: bot.restrict_chat_member(chatD.id, user_id, can_send_messages=False) keyboard = [] reply = tld(chat.id, "Shh! Quite now{}\nis muted in {}").format(mention_html(member.user.id, member.user.first_name), chatD.title) message.reply_text(reply, reply_markup=keyboard, parse_mode=ParseMode.HTML) return "<b>{}:</b>" \ "\n#MUTE" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {}".format(html.escape(chatD.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name)) else: message.reply_text(tld(chat.id, "This user is already muted in {}!").format(chatD.title)) else: message.reply_text(tld(chat.id, "This user isn't in the {}!").format(chatD.title)) return ""
def gkick(bot: Bot, update: Update, args: List[str]): message = update.effective_message user_id = extract_user(message, args) try: user_chat = bot.get_chat(user_id) except BadRequest as excp: if excp.message in GKICK_ERRORS: pass else: message.reply_text("User cannot be Globally kicked because: {}".format(excp.message)) return except TelegramError: pass if not user_id: message.reply_text("You do not seems to be referring to a user") return if int(user_id) in SUDO_USERS: message.reply_text("OHHH! Someone's trying to gkick a sudo user! *Grabs popcorn*") return if int(user_id) in WHITELIST_USERS: message.reply_text( "This person is whitelisted, so they can't be gkicked!") return if int(user_id) == OWNER_ID: message.reply_text("Wow! Some's trying to gkick my owner! *Grabs Potato Chips*") return if user_id == bot.id: message.reply_text("Welp, I'm not gonna gkick myself!") return if user_chat.first_name == '': message.reply_text("That's a deleted account! Why u even bother gkicking dem") return chats = get_all_chats() message.reply_text("Globally kicking user @{}".format(user_chat.username)) for chat in chats: try: bot.unban_chat_member(chat.chat_id, user_id) # Unban_member = kick (and not ban) except BadRequest as excp: if excp.message in GKICK_ERRORS: pass else: message.reply_text("User cannot be Globally kicked because: {}".format(excp.message)) return except TelegramError: pass
def user_demote_fed(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] fed_id = sql.get_fed_id(chat.id) if is_user_fed_owner(fed_id, user.id) == False: update.effective_message.reply_text( tld(chat.id, "Only fed owner can do this!")) return msg = update.effective_message # type: Optional[Message] user_id = extract_user(msg, args) if user_id: user = bot.get_chat(user_id) elif not msg.reply_to_message and not args: user = msg.from_user elif not msg.reply_to_message and ( not args or (len(args) >= 1 and not args[0].startswith("@") and not args[0].isdigit() and not msg.parse_entities([MessageEntity.TEXT_MENTION]))): msg.reply_text(tld(chat.id, "I can't extract a user from this.")) return #else: # return if user_id == bot.id: update.effective_message.reply_text( tld( chat.id, "What are you trying to do? Demoting me from your federation?") ) return if sql.search_user_in_fed(fed_id, user_id) == False: update.effective_message.reply_text( tld( chat.id, "I can't demote user which not a fed admin! If you wanna bring him to tears, promote him first!" )) return res = sql.user_demote_fed(fed_id, user_id) if res == True: update.effective_message.reply_text(tld(chat.id, "Get out of here!")) else: update.effective_message.reply_text( tld(chat.id, "I can not remove him, I am powerless!"))
def unmute(bot: Bot, update: Update, args: List[str]) -> str: chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] conn = connected(bot, update, chat, user.id) if conn: chatD = dispatcher.bot.getChat(conn) else: if chat.type == "private": return else: chatD = chat user_id = extract_user(message, args) if not user_id: message.reply_text(tld(chat.id, "unmute_invalid")) return "" member = chatD.get_member(int(user_id)) if member.status != 'kicked' and member.status != 'left': if member.can_send_messages and member.can_send_media_messages \ and member.can_send_other_messages and member.can_add_web_page_previews: message.reply_text( tld(chat.id, "unmute_not_muted").format(chatD.title)) else: bot.restrict_chat_member(chatD.id, int(user_id), can_send_messages=True, can_send_media_messages=True, can_send_other_messages=True, can_add_web_page_previews=True) keyboard = [] reply = tld(chat.id, "unmute_success").format( mention_html(member.user.id, member.user.first_name), chatD.title) message.reply_text(reply, reply_markup=keyboard, parse_mode=ParseMode.HTML) return "<b>{}:</b>" \ "\n#UNMUTE" \ "\n<b>• Admin:</b> {}" \ "\n<b>• User:</b> {}" \ "\n<b>• ID:</b> <code>{}</code>".format(html.escape(chatD.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), user_id) else: message.reply_text(tld(chat.id, "unmute_not_in_chat")) return ""
def media(bot: Bot, update: Update, args: List[str]) -> str: chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] conn = connected(bot, update, chat, user.id) if conn: chatD = dispatcher.bot.getChat(conn) else: if chat.type == "private": exit(1) else: chatD = chat user_id = extract_user(message, args) if not user_id: message.reply_text(tld(chat.id, "You'll need to either give me a username to unrestrict, or reply to someone to be unrestricted.")) return "" member = chatD.get_member(int(user_id)) if member.status != 'kicked' and member.status != 'left': if member.can_send_messages and member.can_send_media_messages \ and member.can_send_other_messages and member.can_add_web_page_previews: message.reply_text( tld(chat.id, "This user already has the rights to send anything in {}.").format(chatD.title)) else: bot.restrict_chat_member(chatD.id, int(user_id), can_send_messages=True, can_send_media_messages=True, can_send_other_messages=True, can_add_web_page_previews=True) keyboard = [] reply = tld(chat.id, "Yep, {} can send media again in {}!").format( mention_html(member.user.id, member.user.first_name), chatD.title) message.reply_text(reply, reply_markup=keyboard, parse_mode=ParseMode.HTML) return "<b>{}:</b>" \ "\n#UNRESTRICTED" \ "\n<b>• Admin:</b> {}" \ "\n<b>• User:</b> {}" \ "\n<b>• ID:</b> <code>{}</code>".format(html.escape(chatD.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), user_id) else: message.reply_text( tld(chat.id, "This user isn't even in the chat, unrestricting them won't make them send anything than they " "already do!")) return ""
def mute(bot: Bot, update: Update, args: List[str]) -> str: chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] conn = connected(bot, update, chat, user.id) if not conn == False: chatD = dispatcher.bot.getChat(conn) else: if chat.type == "private": exit(1) else: chatD = chat user_id = extract_user(message, args) if not user_id: message.reply_text(tld(chat.id, "Reply atau tag orangnya!")) return "" if user_id == bot.id: message.reply_text(tld(chat.id, "I'm not muting myself!")) return "" member = chatD.get_member(int(user_id)) if member: if user_id in SUDO_USERS: message.reply_text(tld(chat.id, "No! I'm not muting bot sudoers! That would be a pretty dumb idea.")) elif is_user_admin(chatD, user_id, member=member): message.reply_text(tld(chat.id, "Admin tidak bisa di mute bodoh! That would be a pretty dumb idea.")) elif member.can_send_messages is None or member.can_send_messages: bot.restrict_chat_member(chatD.id, user_id, can_send_messages=False) keyboard = [] reply = tld(chat.id, "{} di mute dari {}!").format(mention_html(member.user.id, member.user.first_name), chatD.title) message.reply_text(reply, reply_markup=keyboard, parse_mode=ParseMode.HTML) return "<b>{}:</b>" \ "\n#MUTE" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {}".format(html.escape(chatD.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name)) else: message.reply_text(tld(chat.id, "Orang ini telah di mute dari {}!").format(chatD.title)) else: message.reply_text(tld(chat.id, "Dia tidak ada di {}!").format(chatD.title)) return ""
def slap(bot: Bot, update: Update, args: List[str]): message = update.effective_message chat = update.effective_chat reply_text = message.reply_to_message.reply_text if message.reply_to_message else message.reply_text curr_user = html.escape(message.from_user.first_name) user_id = extract_user(message, args) if user_id == bot.id: temp = random.choice(fun_strings.SLAP_SAITAMA_TEMPLATES) if isinstance(temp, list): if temp[2] == "tmute": if is_user_admin(chat, message.from_user.id): reply_text(temp[1]) return mutetime = int(time.time() + 60) bot.restrict_chat_member(chat.id, message.from_user.id, until_date=mutetime, can_send_messages=False) reply_text(temp[0]) else: reply_text(temp) return if user_id: slapped_user = bot.get_chat(user_id) user1 = curr_user user2 = html.escape(slapped_user.first_name) else: user1 = bot.first_name user2 = curr_user temp = random.choice(fun_strings.SLAP_TEMPLATES) item = random.choice(fun_strings.ITEMS) hit = random.choice(fun_strings.HIT) throw = random.choice(fun_strings.THROW) reply = temp.format(user1=user1, user2=user2, item=item, hits=hit, throws=throw) reply_text(reply, parse_mode=ParseMode.HTML)