def about_me(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 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_me_info(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 + tl(update.effective_message, " belum mengatur pesan info tentang diri mereka!")) else: update.effective_message.reply_text( tl(update.effective_message, "Anda belum mengatur pesan info tentang diri Anda!"))
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 update.effective_message.reply_text( "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) update.effective_message.reply_text("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": update.effective_message.reply_text("Id Anda adalah `{}`.".format(chat.id), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text("Id grup ini adalah `{}`.".format(chat.id), parse_mode=ParseMode.MARKDOWN)
def about_bio(update, context): message = update.effective_message # type: Optional[Message] args = context.args user_id = extract_user(message, args) if user_id and user_id != "error": user = context.bot.get_chat(user_id) else: user = message.from_user info = sql.get_user_bio(user.id) if info: send_message(update.effective_message, "*{}*:\n{}".format(user.first_name, escape_markdown(info)), parse_mode=ParseMode.MARKDOWN) elif message.reply_to_message: username = user.first_name send_message( update.effective_message, tl(update.effective_message, "{} belum memiliki pesan tentang dirinya sendiri!").format( username)) else: send_message( update.effective_message, tl(update.effective_message, "Anda belum memiliki bio set tentang diri Anda!"))
def rsudo(update, context: List[str]): args = context.args 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 addsudo(update, context: List[str]): args = context.args 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 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(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 #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(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 about_bio(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 message = update.effective_message # type: Optional[Message] user_id = extract_user(message, args) if user_id and user_id != "error": user = bot.get_chat(user_id) else: user = message.from_user info = sql.get_user_bio(user.id) if info: send_message(update.effective_message, "*{}*:\n{}".format(user.first_name, escape_markdown(info)), parse_mode=ParseMode.MARKDOWN) elif message.reply_to_message: username = user.first_name send_message( update.effective_message, tl(update.effective_message, "{} belum memiliki pesan tentang dirinya sendiri!").format( username)) else: send_message( update.effective_message, tl(update.effective_message, "Anda belum memiliki bio set tentang diri Anda!"))
def mute(bot: Bot, update: Update, args: List[str]) -> str: spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id) if spam == True: return update.effective_message.reply_text("Saya kecewa dengan anda, saya tidak akan mendengar kata-kata anda sekarang!") chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] user_id = extract_user(message, args) if not user_id: message.reply_text("Anda harus memberi saya nama pengguna untuk membungkam, atau membalas seseorang untuk dibisukan.") return "" conn = connected(bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = dispatcher.bot.getChat(conn).title text = "Dia telah dibisukan pada *{}*! 😆".format(chat_name) else: if update.effective_message.chat.type == "private": update.effective_message.reply_text("Anda bisa lakukan command ini pada grup, bukan pada PM") return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title text = "Dia telah dibisukan! 😆" if user_id == bot.id: message.reply_text("Saya tidak akan membungkam diri saya sendiri!") return "" check = bot.getChatMember(chat.id, user.id) if check['can_restrict_members'] == False: message.reply_text("Anda tidak punya hak untuk membatasi seseorang.") return "" member = chat.get_member(int(user_id)) if member: if is_user_admin(chat, user_id, member=member): message.reply_text("Saya tidak bisa menghentikan seorang admin berbicara!") elif member.can_send_messages is None or member.can_send_messages: bot.restrict_chat_member(chat.id, user_id, can_send_messages=False) message.reply_text(text, parse_mode="markdown") return "<b>{}:</b>" \ "\n#MUTE" \ "\n<b>Admin:</b> {}" \ "\n<b>Pengguna:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name)) else: message.reply_text("Pengguna ini sudah dibungkam!") else: message.reply_text("Pengguna ini tidak ada dalam obrolan!") return ""
def info(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] chat = update.effective_chat # type: Optional[Chat] user_id = extract_user(update.effective_message, 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("Saya tidak dapat mengekstrak pengguna dari ini.") return else: return text = "<b>Info Pengguna</b>:" \ "\nID: <code>{}</code>" \ "\nNama depan: {}".format(user.id, html.escape(user.first_name)) if user.last_name: text += "\nNama belakang: {}".format(html.escape(user.last_name)) if user.username: text += "\nNama pengguna: @{}".format(html.escape(user.username)) text += "\nTautan pengguna permanen: {}".format(mention_html(user.id, "link")) if user.id == OWNER_ID: text += "\n\nOrang ini adalah pemilik saya - saya tidak akan pernah melakukan apa pun terhadap mereka!" else: if user.id in SUDO_USERS: text += "\nOrang ini adalah salah satu pengguna sudo saya! " \ "Hampir sama kuatnya dengan pemilik saya - jadi tontonlah." else: if user.id in SUPPORT_USERS: text += "\nOrang ini adalah salah satu pengguna dukungan saya! " \ "Tidak sekuat pengguna sudo, tetapi masih dapat menyingkirkan Anda dari peta." if user.id in WHITELIST_USERS: text += "\nOrang ini telah dimasukkan dalam daftar putih! " \ "Itu berarti saya tidak diizinkan untuk melarang/menendang mereka." for mod in USER_INFO: try: mod_info = mod.__user_info__(user.id).strip() except TypeError: 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 ungban(update, context): message = update.effective_message # type: Optional[Message] args = context.args user_id = extract_user(message, args) if not user_id: send_message(update.effective_message, tl(update.effective_message, "Anda sepertinya tidak mengacu pada pengguna.")) return if user_id == "error": send_message(update.effective_message, tl(update.effective_message, "Error: Unknown user!")) return "" user_chat = context.bot.get_chat(user_id) if user_chat.type != 'private': send_message(update.effective_message, tl(update.effective_message, "Itu bukan pengguna!")) return if not sql.is_user_gbanned(user_id): send_message(update.effective_message, tl(update.effective_message, "Pengguna ini tidak dilarang secara global!")) return banner = update.effective_user # type: Optional[User] send_message(update.effective_message, tl(update.effective_message, "Saya akan berikan {} kesempatan kedua, secara global.").format(user_chat.first_name)) send_to_list(context.bot, SUDO_USERS + SUPPORT_USERS, tl(update.effective_message, "{} telah menghapus larangan global untuk pengguna {}").format(mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name)), html=True) sql.ungban_user(user_id) 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 = context.bot.get_chat_member(chat_id, user_id) if member.status == 'kicked': context.bot.unban_chat_member(chat_id, user_id) except BadRequest as excp: if excp.message in UNGBAN_ERRORS: pass else: send_message(update.effective_message, tl(update.effective_message, "Tidak dapat menghapus larangan secara global karena: {}").format(excp.message)) context.bot.send_message(OWNER_ID, tl(update.effective_message, "Tidak dapat menghapus larangan secara global karena: {}").format(excp.message)) return except TelegramError: pass send_to_list(context.bot, SUDO_USERS + SUPPORT_USERS, tl(update.effective_message, "Menghapus larangan global selesai!")) send_message(update.effective_message, tl(update.effective_message, "Orang ini telah dihapus larangannya."))
def reset_warns(bot: Bot, update: Update, args: List[str]) -> str: spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id) if spam == True: return update.effective_message.reply_text( "Saya kecewa dengan anda, saya tidak akan mendengar kata-kata anda sekarang!" ) 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) conn = connected(bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: if update.effective_message.chat.type == "private": update.effective_message.reply_text( "Anda bisa lakukan command ini pada grup, bukan pada PM") return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title check = bot.getChatMember(chat_id, bot.id) if check.status == 'member' or check['can_restrict_members'] == False: if conn: text = "Saya tidak bisa membatasi orang di {}! Pastikan saya sudah menjadi admin.".format( chat_name) else: text = "Saya tidak bisa membatasi orang di sini! Pastikan saya sudah menjadi admin." message.reply_text(text, parse_mode="markdown") return "" if user_id: sql.reset_warns(user_id, chat.id) if conn: message.reply_text( "Peringatan telah disetel ulang pada *{}*!".format(chat_name), parse_mode="markdown") else: message.reply_text("Peringatan telah disetel ulang!") warned = chat.get_member(user_id).user return "<b>{}:</b>" \ "\n#RESETWARNS" \ "\n<b>Admin:</b> {}" \ "\n<b>Pengguna:</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("Tidak ada pengguna yang ditunjuk!") return ""
def mute(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] args = context.args user_id = extract_user(message, args) if not user_id or user_id == "error": send_message(update.effective_message, tl(update.effective_message, "Anda harus memberi saya nama pengguna untuk membungkam, atau membalas seseorang untuk dibisukan.")) return "" conn = connected(context.bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = dispatcher.bot.getChat(conn).title text = tl(update.effective_message, "Terbisukan pada *{}*! 😆").format(chat_name) else: if update.effective_message.chat.type == "private": update.effective_send_message(update.effective_message, tl(update.effective_message, "Anda bisa lakukan command ini pada grup, bukan pada PM")) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title text = tl(update.effective_message, "Terbisukan! 😆") if user_id == context.bot.id: send_message(update.effective_message, tl(update.effective_message, "Saya tidak akan membungkam diri saya sendiri!")) return "" check = context.bot.getChatMember(chat.id, user.id) if check['can_restrict_members'] == False: send_message(update.effective_message, tl(update.effective_message, "Anda tidak punya hak untuk membatasi seseorang.")) return "" member = chat.get_member(int(user_id)) if member: if is_user_admin(chat, user_id, member=member): send_message(update.effective_message, tl(update.effective_message, "Saya tidak bisa menghentikan seorang admin berbicara!")) elif member.can_send_messages is None or member.can_send_messages: context.bot.restrict_chat_member(chat.id, user_id, permissions=ChatPermissions(can_send_messages=False)) send_message(update.effective_message, text, parse_mode="markdown") return "<b>{}:</b>" \ "\n#MUTE" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name)) else: send_message(update.effective_message, tl(update.effective_message, "Pengguna ini sudah dibungkam!")) else: send_message(update.effective_message, tl(update.effective_message, "Pengguna ini tidak ada dalam obrolan!")) return ""
def warns(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 message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id, need_admin=False) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: if update.effective_message.chat.type == "private": update.effective_message.reply_text(tl(update.effective_message, "Anda bisa lakukan command ini pada grup, bukan pada PM")) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title 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, warn_mode = sql.get_warn_setting(chat.id) if reasons: if conn: text = tl(update.effective_message, "Pengguna ini memiliki {}/{} peringatan pada *{}*, untuk alasan berikut:").format(num_warns, limit, chat_name) else: text = tl(update.effective_message, "Pengguna ini memiliki {}/{} peringatan, untuk alasan berikut:").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, parse_mode="markdown") else: if conn: update.effective_message.reply_text( tl(update.effective_message, "Pengguna ini memiliki {}/{} peringatan pada *{}*, tetapi tidak ada alasan untuk itu.").format(num_warns, limit, chat_name), parse_mode="markdown") else: update.effective_message.reply_text( tl(update.effective_message, "Pengguna ini memiliki {}/{} peringatan, tetapi tidak ada alasan untuk itu.").format(num_warns, limit)) else: if conn: update.effective_message.reply_text(tl(update.effective_message, "Pengguna ini belum mendapatkan peringatan apa pun pada *{}*!").format(chat_name), parse_mode="markdown") else: update.effective_message.reply_text(tl(update.effective_message, "Pengguna ini belum mendapatkan peringatan apa pun!"))
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 reset_warns(update, context): message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] args = context.args user_id = extract_user(message, args) conn = connected(context.bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: if update.effective_message.chat.type == "private": send_message(update.effective_message, tl(update.effective_message, "Anda bisa lakukan command ini pada grup, bukan pada PM")) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title check = context.bot.getChatMember(chat_id, context.bot.id) if check.status == 'member' or check['can_restrict_members'] == False: if conn: text = tl(update.effective_message, "Saya tidak bisa membatasi orang di {}! Pastikan saya sudah menjadi admin.").format(chat_name) else: text = tl(update.effective_message, "Saya tidak bisa membatasi orang di sini! Pastikan saya sudah menjadi admin.") send_message(update.effective_message, text, parse_mode="markdown") return "" if user_id and user_id != "error": sql.reset_warns(user_id, chat.id) if conn: send_message(update.effective_message, tl(update.effective_message, "Peringatan telah disetel ulang pada *{}*!").format(chat_name), parse_mode="markdown") else: send_message(update.effective_message, tl(update.effective_message, "Peringatan telah disetel ulang!")) 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: send_message(update.effective_message, tl(update.effective_message, "Tidak ada pengguna yang ditunjuk!")) return ""
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) #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 and user_id != "error": slapped_user = context.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(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 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) reply_text(repl, parse_mode=ParseMode.MARKDOWN)
def get_id(update, context): args = context.args user_id = extract_user(update.effective_message, args) if user_id and user_id != "error": 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 text = 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) if update.effective_message.chat.type != "private": text += "\n" + tl(update.effective_message, "Id grup ini adalah `{}`.").format(update.effective_message.chat.id) send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN) else: user = context.bot.get_chat(user_id) text = tl(update.effective_message, "Id {} adalah `{}`.").format(escape_markdown(user.first_name), user.id) if update.effective_message.chat.type != "private": text += "\n" + tl(update.effective_message, "Id grup ini adalah `{}`.").format(update.effective_message.chat.id) send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN) elif user_id == "error": try: user = context.bot.get_chat(args[0]) except BadRequest: send_message(update.effective_message, "Error: Unknown User/Chat!") return text = tl(update.effective_message, "Id Anda adalah `{}`.").format(update.effective_message.from_user.id) text += "\n" + tl(update.effective_message, "Id grup tersebut adalah `{}`.").format(user.id) if update.effective_message.chat.type != "private": text += "\n" + tl(update.effective_message, "Id grup ini adalah `{}`.").format(update.effective_message.chat.id) send_message(update.effective_message, text, 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(update.effective_message.from_user.id), parse_mode=ParseMode.MARKDOWN) else: send_message(update.effective_message, tl(update.effective_message, "Id Anda adalah `{}`.").format(update.effective_message.from_user.id) + "\n" + tl(update.effective_message, "Id grup ini adalah `{}`.").format(chat.id), parse_mode=ParseMode.MARKDOWN)
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) if spam == True: return update.effective_message.reply_text("Saya kecewa dengan anda, saya tidak akan mendengar kata-kata anda sekarang!") 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: # 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(SLAP_TEMPLATES) item = random.choice(ITEMS) hit = random.choice(HIT) throw = random.choice(THROW) repl = temp.format(user1=user1, user2=user2, item=item, hits=hit, throws=throw) reply_text(repl, parse_mode=ParseMode.MARKDOWN)
def about_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 = user.first_name update.effective_message.reply_text( "{} belum memiliki pesan tentang dirinya sendiri!".format( username)) else: update.effective_message.reply_text( "Anda belum memiliki bio set tentang diri Anda!")
def unmute(bot: Bot, update: Update, args: List[str]) -> str: spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] user_id = extract_user(message, args) if not user_id: send_message( update.effective_message, tl( update.effective_message, "Anda harus memberi saya nama pengguna untuk menyuarakan, atau membalas seseorang untuk disuarakan." )) return "" conn = connected(bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = dispatcher.bot.getChat(conn).title text = tl(update.effective_message, "Pengguna ini sudah bisa untuk berbicara pada *{}*.").format( chat_name) text2 = tl(update.effective_message, "Dia telah disuarakan pada *{}*.").format(chat_name) else: if update.effective_message.chat.type == "private": update.effective_send_message( update.effective_message, tl(update.effective_message, "Anda bisa lakukan command ini pada grup, bukan pada PM")) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title text = tl(update.effective_message, "Pengguna ini sudah bisa untuk berbicara.") text2 = "Dia telah disuarakan." check = bot.getChatMember(chat.id, user.id) if check['can_restrict_members'] == False: send_message( update.effective_message, tl(update.effective_message, "Anda tidak punya hak untuk membatasi seseorang.")) return "" member = chat.get_member(int(user_id)) if member: if is_user_admin(chat, user_id, member=member): send_message( update.effective_message, tl(update.effective_message, "Dia adalah admin, apa yang Anda harapkan kepada saya?")) return "" elif 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: send_message(update.effective_message, text, parse_mode="markdown") return "" else: bot.restrict_chat_member(chat.id, int(user_id), can_send_messages=True, can_send_media_messages=True, can_send_other_messages=True, can_add_web_page_previews=True) send_message(update.effective_message, text2, parse_mode="markdown") return "<b>{}:</b>" \ "\n#UNMUTE" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name)) else: send_message( update.effective_message, tl( update.effective_message, "Pengguna ini bahkan tidak dalam obrolan, menyuarakannya tidak akan membuat mereka berbicara lebih dari " "yang sudah mereka lakukan!")) return ""
def promote(bot: Bot, update: Update, args: List[str]) -> str: chat_id = update.effective_chat.id message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return conn = connected(bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: if update.effective_message.chat.type == "private": update.effective_message.reply_text( tl(update.effective_message, "Anda bisa lakukan command ini pada grup, bukan pada PM")) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title user_id = extract_user(message, args) if not user_id: message.reply_text( tl(update.effective_message, "Anda sepertinya tidak mengacu pada pengguna.")) return "" user_member = chat.get_member(user_id) if user_member.status == 'administrator' or user_member.status == 'creator': message.reply_text( tl( update.effective_message, "Bagaimana saya ingin menaikan jabatan seseorang yang sudah menjadi admin?" )) return "" if user_id == bot.id: message.reply_text( tl( update.effective_message, "Saya tidak bisa menaikan jabatan diri saya sendiri! Hanya admin yang dapat melakukanya untuk saya." )) return "" # set same perms as bot - bot can't assign higher perms than itself! bot_member = chat.get_member(bot.id) try: bot.promoteChatMember( chat_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 ) except BadRequest: message.reply_text( tl( update.effective_message, "Tidak dapat mempromosikan pengguna, mungkin saya bukan admin atau tidak punya izin untuk mempromosikan pengguna." )) return message.reply_text( tl(update.effective_message, "💖 Berhasil dinaikan jabatannya!")) return "<b>{}:</b>" \ "\n#PROMOTED" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(user_member.user.id, user_member.user.first_name))
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] spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return conn = connected(bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: if update.effective_message.chat.type == "private": update.effective_message.reply_text( tl(update.effective_message, "Anda bisa lakukan command ini pada grup, bukan pada PM")) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title user_id = extract_user(message, args) if not user_id: message.reply_text( tl(update.effective_message, "Anda sepertinya tidak mengacu pada pengguna.")) return "" user_member = chat.get_member(user_id) if user_member.status == 'creator': message.reply_text( tl( update.effective_message, "Orang ini MENCIPTAKAN obrolan ini, bagaimana saya menurunkannya?" )) return "" if not user_member.status == 'administrator': message.reply_text( tl(update.effective_message, "Tidak dapat menurunkan jabatan apa yang belum dipromosikan!")) return "" if user_id == bot.id: message.reply_text( tl( update.effective_message, "Saya tidak bisa menurunkan jabatan diri saya sendiri! Hanya admin yang dapat melakukanya untuk saya." )) return "" try: bot.promoteChatMember(int(chat.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( tl(update.effective_message, "💔 Berhasil diturunkan jabatannya!")) return "<b>{}:</b>" \ "\n#DEMOTED" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(user_member.user.id, user_member.user.first_name)) except BadRequest: message.reply_text( tl( update.effective_message, "Tidak dapat menurunkan jabatannya. Saya mungkin bukan admin, atau status admin ditunjuk oleh " "orang lain, jadi saya tidak bisa bertindak atas hak mereka!")) return ""
def promote(update, context): chat_id = update.effective_chat.id message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] args = context.args conn = connected(context.bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: if update.effective_message.chat.type == "private": send_message(update.effective_message, tl(update.effective_message, "Anda bisa lakukan command ini pada grup, bukan pada PM")) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title user_id = extract_user(message, args) user_send = dispatcher.bot.getChatMember(chat_id, message.from_user.id) if (user_send.status == "administrator" and user_send.can_promote_members) or (user_send.status == "creator"): pass else: send_message(update.effective_message, "You don't have permission to do this command") return "" if not user_id: send_message(update.effective_message, tl(update.effective_message, "Anda sepertinya tidak mengacu pada pengguna.")) return "" if user_id == "error": send_message(update.effective_message, tl(update.effective_message, "Error: Unknown user!")) return "" user_member = chat.get_member(user_id) if user_member.status == 'administrator' or user_member.status == 'creator': send_message(update.effective_message, tl(update.effective_message, "Bagaimana saya ingin menaikan jabatan seseorang yang sudah menjadi admin?")) return "" if user_id == context.bot.id: send_message(update.effective_message, tl(update.effective_message, "Saya tidak bisa menaikan jabatan diri saya sendiri! Hanya admin yang dapat melakukanya untuk saya.")) return "" # set same perms as bot - bot can't assign higher perms than itself! bot_member = chat.get_member(context.bot.id) try: context.bot.promote_chat_member(chat_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 ) except BadRequest as error: if error.message == "Bot_groups_blocked": send_message(update.effective_message, tl(update.effective_message, "Gagal menaikan jabatan: Bot terkunci")) else: send_message(update.effective_message, tl(update.effective_message, "Tidak dapat mempromosikan pengguna, mungkin saya bukan admin atau tidak punya izin untuk mempromosikan pengguna.")) return send_message(update.effective_message, tl(update.effective_message, "💖 Berhasil dinaikan jabatannya!")) return "<b>{}:</b>" \ "\n#PROMOTED" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(user_member.user.id, user_member.user.first_name))
def ungban(update, context): message = update.effective_message # type: Optional[Message] args = context.args user_id = extract_user(message, args) if not user_id: send_message( update.effective_message, tl(update.effective_message, "You don't seem to be referring to a user.")) return if user_id == "error": send_message(update.effective_message, tl(update.effective_message, "Error: Unknown user!")) return "" user_chat = context.bot.get_chat(user_id) if user_chat.type != 'private': send_message(update.effective_message, tl(update.effective_message, "That's not a user!")) return if not sql.is_user_gbanned(user_id): send_message(update.effective_message, tl(update.effective_message, "This user is not gbanned!")) return banner = update.effective_user # type: Optional[User] send_message( update.effective_message, tl(update.effective_message, "I'll give {} a second chance, globally.").format( user_chat.first_name)) context.bot.send_message(MESSAGE_DUMP, tl(update.effective_message, "{} has ungbanned user {}").format( mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name)), parse_mode=ParseMode.HTML) sql.ungban_user(user_id) 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 = context.bot.get_chat_member(chat_id, user_id) if member.status == 'kicked': context.bot.unban_chat_member(chat_id, user_id) except BadRequest as excp: if excp.message in UNGBAN_ERRORS: pass else: send_message( update.effective_message, tl(update.effective_message, "Could not un-gban due to: {}").format(excp.message)) context.bot.send_message( OWNER_ID, tl(update.effective_message, "Could not un-gban due to: {}").format(excp.message)) return except TelegramError: pass context.bot.send_message(MESSAGE_DUMP, tl(update.effective_message, "un-gban complete!")) send_message(update.effective_message, tl(update.effective_message, "Person has been un-gbanned."))
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>Info Pengguna</b>:") \ + "\nID: <code>{}</code>".format(user.id) + \ tl(update.effective_message, "\nNama depan: {}").format(html.escape(user.first_name)) if user.last_name: text += tl(update.effective_message, "\nNama belakang: {}").format(html.escape(user.last_name)) if user.username: text += tl(update.effective_message, "\nNama pengguna: @{}").format(html.escape(user.username)) text += tl(update.effective_message, "\nTautan pengguna permanen: {}").format( mention_html(user.id, "link")) if user.id == OWNER_ID: text += tl( update.effective_message, "\n\nOrang ini adalah pemilik saya - saya tidak akan pernah melakukan apa pun terhadap mereka!" ) else: if user.id in SUDO_USERS: text += tl(update.effective_message, "\n\nOrang ini adalah salah satu pengguna sudo saya! " \ "Hampir sama kuatnya dengan pemilik saya - jadi tontonlah.") else: if user.id in SUPPORT_USERS: text += tl(update.effective_message, "\n\nOrang ini adalah salah satu pengguna dukungan saya! " \ "Tidak sekuat pengguna sudo, tetapi masih dapat menyingkirkan Anda dari peta.") if user.id in WHITELIST_USERS: text += tl(update.effective_message, "\n\nOrang ini telah dimasukkan dalam daftar putih! " \ "Itu berarti saya tidak diizinkan untuk melarang/menendang mereka.") fedowner = feds_sql.get_user_owner_fed_name(user.id) if fedowner: text += tl( update.effective_message, "\n\n<b>Pengguna ini adalah pemilik federasi ini:</b>\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)
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)