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 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 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 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 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 = "ഇയാൾക്ക് {}/{} warnings ഉണ്ട്, കാരണങ്ങൾ താഴെ പറയുന്നു:".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( "ഇയാൾക്ക് {}/{} warnings ഉണ്ട്, കാരണം ലഭ്യമല്ല.".format( num_warns, limit)) else: update.effective_message.reply_text( "ഇയാൾക്ക് warnings ഒന്നും കിട്ടിയിട്ടില്ല!")
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 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 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 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 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 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 admin and can appoint new admins.") 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 who'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 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 user_can_promote(chat, user, bot.id) is False: message.reply_text(tld(chat.id, "admin_no_promote_perm")) return "" if not chatD.get_member(bot.id).can_promote_members: 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 == '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 pat(update, context): args = context.args chat_id = update.effective_chat.id msg = str(update.message.text) try: msg = msg.split(" ", 1)[1] except IndexError: msg = "" msg_id = update.effective_message.reply_to_message.message_id if update.effective_message.reply_to_message else update.effective_message.message_id pats = [] pats = json.loads( urllib.request.urlopen( urllib.request.Request('http://headp.at/js/pats.json', headers={ 'User-Agent': 'Mozilla/5.0 (X11; U; Linux i686) ' 'Gecko/20071127 Firefox/2.0.0.11' })).read().decode('utf-8')) if "@" in msg and len(msg) > 5: context.bot.send_photo( chat_id, f'https://headp.at/pats/{urllib.parse.quote(random.choice(pats))}', caption=msg) else: context.bot.send_photo( chat_id, f'https://headp.at/pats/{urllib.parse.quote(random.choice(pats))}', reply_to_message_id=msg_id) curr_user = "******".format( mention_markdown(msg.from_user.id, msg.from_user.first_name)) user_id = extract_user(update.effective_message, args) if user_id and user_id != "error": slapped_user = context.bot.get_chat(user_id) user1 = curr_user user2 = "{}".format( mention_markdown(slapped_user.id, slapped_user.first_name)) # if no target found, bot targets the sender else: user1 = "{}".format( mention_markdown(context.bot.id, context.bot.first_name)) user2 = curr_user temp = random.choice(tl(update.effective_message, "SLAP_TEMPLATES")) item = random.choice(tl(update.effective_message, "ITEMS")) hit = random.choice(tl(update.effective_message, "HIT")) throw = random.choice(tl(update.effective_message, "THROW")) repl = temp.format(user1=user1, user2=user2, item=item, hits=hit, throws=throw) send_message(update.effective_message, repl, parse_mode=ParseMode.MARKDOWN)
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: {}").format(mention_html(user.id, "link")) if user.id == OWNER_ID: text += tld(chat.id, "\n\nThis person is my owner - I would never do anything against them!") else: if user.id == int(918317361): text += tld(chat.id, "\n\nThis person.... He is my god.") if user.id in SUDO_USERS: text += tld(chat.id, "\n\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, "\n\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, "\n\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, disable_web_page_preview=True)
def about_me(bot: Bot, update: Update, args: List[str]): message = update.effective_message user_id = extract_user(message, args) chat = update.effective_chat user = bot.get_chat(user_id) if user_id else message.from_user if info := sql.get_user_me_info(user.id): update.effective_message.reply_text("*{}*:\n{}".format( user.first_name, escape_markdown(info)), parse_mode=ParseMode.MARKDOWN)
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 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 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 "" 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, "{} is 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 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 slap(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat msg = update.effective_message # reply to correct message reply_text = msg.reply_to_message.reply_text if msg.reply_to_message else msg.reply_text # get user who sent message if msg.from_user.username: curr_user = "******" + escape_markdown(msg.from_user.username) else: curr_user = "******".format(msg.from_user.first_name, msg.from_user.id) user_id = extract_user(update.effective_message, args) if user_id: slapped_user = bot.get_chat(user_id) user1 = curr_user if slapped_user.username == "RealAkito": reply_text(tld(chat.id, "memes_not_doing_that")) return if slapped_user.username: user2 = "@" + escape_markdown(slapped_user.username) else: user2 = "[{}](tg://user?id={})".format(slapped_user.first_name, slapped_user.id) # if no target found, bot targets the sender else: user1 = "[{}](tg://user?id={})".format(bot.first_name, bot.id) user2 = curr_user temp = random.choice(tld_list(chat.id, "memes_slaps_templates_list")) item = random.choice(tld_list(chat.id, "memes_items_list")) hit = random.choice(tld_list(chat.id, "memes_hit_list")) throw = random.choice(tld_list(chat.id, "memes_throw_list")) itemp = random.choice(tld_list(chat.id, "memes_items_list")) itemr = random.choice(tld_list(chat.id, "memes_items_list")) repl = temp.format(user1=user1, user2=user2, item=item, hits=hit, throws=throw, itemp=itemp, itemr=itemr) reply_text(repl, parse_mode=ParseMode.MARKDOWN)
def slap(update, context): args = context.args msg = update.effective_message # type: Optional[Message] # reply to correct message reply_text = msg.reply_to_message.reply_text if msg.reply_to_message else msg.reply_text # get user who sent message if msg.from_user.username: curr_user = "******" + escape_markdown(msg.from_user.username) else: curr_user = "******".format(msg.from_user.first_name, msg.from_user.id) user_id = extract_user(update.effective_message, args) if user_id == context.bot.id or user_id == 777000: user1 = "[{}](tg://user?id={})".format(context.bot.first_name, context.bot.id) user2 = curr_user elif user_id: slapped_user = context.bot.get_chat(user_id) user1 = curr_user if slapped_user.username: user2 = "@" + escape_markdown(slapped_user.username) else: user2 = "[{}](tg://user?id={})".format(slapped_user.first_name, slapped_user.id) # if no target found, bot targets the sender else: user1 = "[{}](tg://user?id={})".format(context.bot.first_name, context.bot.id) user2 = curr_user temp = random.choice(SLAP_TEMPLATES) item = random.choice(ITEMS) hit = random.choice(HIT) throw = random.choice(THROW) emoji = random.choice(EMOJI) repl = temp.format(user1=user1, user2=user2, item=item, hits=hit, throws=throw, emoji=emoji) reply_text(repl, parse_mode=ParseMode.MARKDOWN)
def user_join_fed(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat user = update.effective_user msg = update.effective_message fed_id = sql.get_fed_id(chat.id) if is_user_fed_owner(fed_id, user.id): 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, "common_err_no_user")) return else: LOGGER.warning('error') getuser = sql.search_user_in_fed(fed_id, user_id) fed_id = sql.get_fed_id(chat.id) info = sql.get_fed_info(fed_id) get_owner = eval(info['fusers'])['owner'] get_owner = bot.get_chat(get_owner).id if user_id == get_owner: update.effective_message.reply_text( tld(chat.id, "feds_promote_owner")) return if getuser: update.effective_message.reply_text( tld(chat.id, "feds_promote_owner")) return if user_id == bot.id: update.effective_message.reply_text( tld(chat.id, "feds_promote_bot")) return res = sql.user_join_fed(fed_id, user_id) if res: update.effective_message.reply_text( tld(chat.id, "feds_promote_success")) else: update.effective_message.reply_text("") else: update.effective_message.reply_text(tld(chat.id, "feds_owner_only"))
def reset_warns(bot: Bot, update: Update, args: List[str]) -> str: message = update.effective_message chat = update.effective_chat user = update.effective_user user_id = extract_user(message, args) if user_id: sql.reset_warns(user_id, chat.id) message.reply_text(tld(chat.id, 'warns_reset_success')) warned = chat.get_member(user_id).user return tld(chat.id, 'warns_reset_log_channel').format( html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(warned.id, warned.first_name), warned.id) else: message.reply_text(tld(chat.id, 'common_err_no_user')) return ""
def slap(bot: Bot, update: Update, args: List[str]): spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return msg = update.effective_message # type: Optional[Message] # reply to correct message reply_text = msg.reply_to_message.reply_text if msg.reply_to_message else msg.reply_text # get user who sent message #if msg.from_user.username: # curr_user = "******" + escape_markdown(msg.from_user.username) #else: curr_user = "******".format( mention_markdown(msg.from_user.id, msg.from_user.first_name)) user_id = extract_user(update.effective_message, args) if user_id: slapped_user = bot.get_chat(user_id) user1 = curr_user #if slapped_user.username: # user2 = "@" + escape_markdown(slapped_user.username) #else: user2 = "{}".format( mention_markdown(slapped_user.id, slapped_user.first_name)) # if no target found, bot targets the sender else: user1 = "{}".format(mention_markdown(bot.id, bot.first_name)) user2 = curr_user temp = random.choice(tl(update.effective_message, "SLAP_TEMPLATES")) item = random.choice(tl(update.effective_message, "ITEMS")) hit = random.choice(tl(update.effective_message, "HIT")) throw = random.choice(tl(update.effective_message, "THROW")) repl = temp.format(user1=user1, user2=user2, item=item, hits=hit, throws=throw) send_message(update.effective_message, repl, parse_mode=ParseMode.MARKDOWN)
def user_demote_fed(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat user = update.effective_user fed_id = sql.get_fed_id(chat.id) if is_user_fed_owner(fed_id, user.id): msg = update.effective_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, "common_err_no_user")) return else: LOGGER.warning('error') if user_id == bot.id: update.effective_message.reply_text(tld(chat.id, "feds_demote_bot")) return if sql.search_user_in_fed(fed_id, user_id) is False: update.effective_message.reply_text( tld(chat.id, "feds_demote_target_not_admin")) return res = sql.user_demote_fed(fed_id, user_id) if res is True: update.effective_message.reply_text( tld(chat.id, "feds_demote_success")) else: update.effective_message.reply_text( tld(chat.id, "feds_demote_failed")) else: update.effective_message.reply_text(tld(chat.id, "feds_owner_only")) return
def my_bio(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id = extract_user(message, args) if user_id: user = bot.get_chat(user_id) else: user = message.from_user info = sql.get_user_bio(user.id) if info: update.effective_message.reply_text("*{}*:\n{}".format(user.first_name, escape_markdown(info)), parse_mode=ParseMode.MARKDOWN) elif message.reply_to_message: username = message.reply_to_message.from_user.first_name update.effective_message.reply_text(username + " hasn't set an info message about themselves yet!") else: update.effective_message.reply_text("You haven't set an info message about yourself yet!")
def slap(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] msg = update.effective_message # type: Optional[Message] # reply to correct message reply_text = msg.reply_to_message.reply_text if msg.reply_to_message else msg.reply_text # get user who sent message if msg.from_user.username: curr_user = "******" + escape_markdown(msg.from_user.username) else: curr_user = "******".format(msg.from_user.first_name, msg.from_user.id) user_id = extract_user(update.effective_message, args) if user_id: slapped_user = bot.get_chat(user_id) user1 = curr_user if slapped_user.username == "HitaloSama": reply_text("Nah, Not doing that") return if slapped_user.username: user2 = "@" + escape_markdown(slapped_user.username) else: user2 = "[{}](tg://user?id={})".format(slapped_user.first_name, slapped_user.id) # if no target found, bot targets the sender else: user1 = "[{}](tg://user?id={})".format(bot.first_name, bot.id) user2 = curr_user temp = random.choice(tld(chat.id, "SLAP_TEMPLATES-K")) item = random.choice(tld(chat.id, "ITEMS-K")) hit = random.choice(tld(chat.id, "HIT-K")) throw = random.choice(tld(chat.id, "THROW-K")) itemp = random.choice(tld(chat.id, "ITEMP-K")) itemr = random.choice(tld(chat.id, "ITEMR-K")) repl = temp.format(user1=user1, user2=user2, item=item, hits=hit, throws=throw, itemp=itemp, itemr=itemr) # user1=user1, user2=user2, item=item_ru, hits=hit_ru, throws=throw_ru, itemp=itemp_ru, itemr=itemr_ru reply_text(repl, parse_mode=ParseMode.MARKDOWN)
def reset_warns(bot: Bot, update: Update, args: List[str]) -> str: message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] user_id = extract_user(message, args) if user_id: sql.reset_warns(user_id, chat.id) message.reply_text("Warnings have been reset!") warned = chat.get_member(user_id).user return "<b>{}:</b>" \ "\n#RESETWARNS" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(warned.id, warned.first_name), warned.id) else: message.reply_text("No user has been designated!") return ""
def reset_warns(bot: Bot, update: Update, args: List[str]) -> str: message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] user_id = extract_user(message, args) if user_id: sql.reset_warns(user_id, chat.id) message.reply_text("Warnings ഒക്കെ reset ചെയ്തിട്ടുണ്ട്!") warned = chat.get_member(user_id).user return "<b>{}:</b>" \ "\n#RESETWARNS" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(warned.id, warned.first_name), warned.id) else: message.reply_text( "ആരുടെ warnings ആണ് reset ചെയ്യേണ്ടത് എന്നു പറഞ്ഞില്ലല്ലോ?") return ""
def get_id(bot: Bot, update: Update, args: List[str]): spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return user_id = extract_user(update.effective_message, args) 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 send_message( update.effective_message, tl( update.effective_message, "Pengirim asli, {}, memiliki ID `{}`.\nSi penerus pesan, {}, memiliki ID `{}`." ).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) send_message(update.effective_message, tl(update.effective_message, "Id {} adalah `{}`.").format( escape_markdown(user.first_name), user.id), parse_mode=ParseMode.MARKDOWN) else: chat = update.effective_chat # type: Optional[Chat] if chat.type == "private": send_message(update.effective_message, tl(update.effective_message, "Id Anda adalah `{}`.").format(chat.id), parse_mode=ParseMode.MARKDOWN) else: send_message(update.effective_message, tl(update.effective_message, "Id grup ini adalah `{}`.").format(chat.id), parse_mode=ParseMode.MARKDOWN)
def about_bio(bot: Bot, update: Update, args: List[str]): message = update.effective_message chat = update.effective_chat user_id = extract_user(message, args) if user_id: user = bot.get_chat(user_id) else: user = message.from_user info = sql.get_user_bio(user.id) if info: update.effective_message.reply_text("*{}*:\n{}".format( user.first_name, escape_markdown(info)), parse_mode=ParseMode.MARKDOWN) elif message.reply_to_message: username = user.first_name update.effective_message.reply_text( tld(chat.id, 'userinfo_bio_none_they').format(username)) else: update.effective_message.reply_text( tld(chat.id, 'userinfo_bio_none_you'))
def info(update, context): args = context.args msg = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] user_id = extract_user(update.effective_message, args) if user_id and user_id != "error": user = context.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]))): send_message( update.effective_message, tl(update.effective_message, "Saya tidak dapat mengekstrak pengguna dari ini.")) return else: return text = tl(update.effective_message, "<b>User info:</b>") \ + "\nID: <code>{}</code>".format(user.id) + \ tl(update.effective_message, "\nFirst Name: {}").format(html.escape(user.first_name)) if user.last_name: text += tl(update.effective_message, "\nLast Name: {}").format(html.escape(user.last_name)) if user.username: text += tl(update.effective_message, "\nUsername: @{}").format(html.escape(user.username)) text += tl(update.effective_message, "\nUser link: {}").format(mention_html(user.id, "link")) if user.id == OWNER_ID: text += tl( update.effective_message, "\n\nThis person is my owner - I would never do anything against them!" ) else: if user.id in SUDO_USERS: text += tl( update.effective_message, "\n\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 += tl( update.effective_message, "\n\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 += tl( update.effective_message, "\n\nThis person has been whitelisted!" "That means I'm not allowed to ban/kick them.") fedowner = feds_sql.get_user_owner_fed_name(user.id) if fedowner: text += tl(update.effective_message, "\n\nThis user owns the following federations:\n<code>") text += "</code>, <code>".join(fedowner) text += "</code>" # fedadmin = feds_sql.get_user_admin_fed_name(user.id) # if fedadmin: # text += tl(update.effective_message, "\n\nThis user is a fed admin in the current federation:\n") # text += ", ".join(fedadmin) for mod in USER_INFO: mod_info = mod.__user_info__(user.id, chat.id).strip() if mod_info: text += "\n\n" + mod_info send_message(update.effective_message, text, parse_mode=ParseMode.HTML)