def demote(update, context): chat = update.effective_chat message = update.effective_message user = update.effective_user args = context.args if user_can_promote(chat, user, context.bot.id) is False: message.reply_text("Anda tidak memiliki cukup hak untuk menurunkan seseorang!") return "" user_id = extract_user(message, args) if not user_id: message.reply_text("mention one.... π€·π»ββ.") return "" user_member = chat.get_member(user_id) if user_member.status == "creator": message.reply_text("Saya tidak akan menurunkan Kreator dari grup ini.... π") return "" if not user_member.status == "administrator": message.reply_text( "Bagaimana saya bisa menurunkan seseorang yang bahkan bukan admin!" ) return "" if user_id == context.bot.id: message.reply_text("Yah ... Tidak akan menurunkan diriku sendiri!") return "" try: context.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, ) message.reply_text("Berhasil diturunkan!") return ( "<b>{}:</b>" "\n#DEMOTED" "\n<b>Admin:</b> {}" "\n<b>Pengguna:</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( "Gagal menurunkan. Saya mungkin bukan admin, atau status admin diangkat oleh orang lain " "pengguna, jadi saya tidak bisa menindaklanjutinya!" ) return ""
def unmute(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 if user_can_ban(chat, user, context.bot.id) == False: message.reply_text( "Anda tidak memiliki cukup hak untuk menyuarakan orang") return "" user_id = extract_user(message, args) if not user_id: message.reply_text( "Anda harus memberi saya nama pengguna untuk menyuarakan, atau membalas seseorang untuk dibungkam." ) return "" member = chat.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( "Pengguna ini sudah memiliki hak untuk berbicara.") else: context.bot.restrict_chat_member( chat.id, int(user_id), permissions=ChatPermissions( can_send_messages=True, can_invite_users=True, can_pin_messages=True, can_send_polls=True, can_change_info=True, can_send_media_messages=True, can_send_other_messages=True, can_add_web_page_previews=True, ), ) message.reply_text( "Ya! pengguna ini dapat mulai berbicara lagi...") 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: message.reply_text( "Pengguna ini bahkan tidak ada dalam obrolan, mengaktifkannya tidak akan membuat mereka berbicara lebih banyak daripada mereka " "sudah lakukan!") return ""
def promote(update, context): chat_id = update.effective_chat.id message = update.effective_message chat = update.effective_chat user = update.effective_user args = context.args if user_can_promote(chat, user, context.bot.id) is False: message.reply_text("Anda tidak memiliki cukup hak untuk mempromosikan seseorang!") return "" user_id = extract_user(message, args) if not user_id: message.reply_text("mention one.... π€·π»ββ.") return "" user_member = chat.get_member(user_id) if ( user_member.status == "administrator" or user_member.status == "creator" ): message.reply_text("Orang ini sudah menjadi admin...!") return "" if user_id == context.bot.id: message.reply_text("Saya berharap, jika saya bisa mempromosikan diri saya sendiri!") return "" # set same perms as bot - bot can't assign higher perms than itself! bot_member = chat.get_member(context.bot.id) context.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, ) message.reply_text("Promotedπ§‘") 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 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 if user_can_ban(chat, user, context.bot.id) == False: message.reply_text( "Anda tidak memiliki cukup hak untuk membatasi seseorang agar tidak berbicara!" ) return "" 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 dibungkam." ) return "" if user_id == context.bot.id: message.reply_text("Yah... Aku tidak membungkam diriku sendiri!") return "" member = chat.get_member(int(user_id)) if member: if is_user_admin(chat, user_id, member=member): message.reply_text( "Yah, saya tidak akan menghentikan admin untuk 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), ) message.reply_text("ππ» dibisukan! π€") 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: message.reply_text("Pengguna ini sudah dibisukan π€") else: message.reply_text("Pengguna ini tidak sedang mengobrol!") return ""
def warns(update, context): message = update.effective_message chat = update.effective_chat args = context.args user = update.effective_user user_id = extract_user(message, args) or update.effective_user.id conn = connected(context.bot, update, chat, user.id, need_admin=False) if conn: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: if chat.type == "private": return else: chat_id = update.effective_chat.id chat_name = chat.title result = sql.get_warns(user_id, chat_id) num = 1 if result and result[0] != 0: num_warns, reasons = result limit, _ = sql.get_warn_setting(chat_id) if reasons: if conn: text = "Pengguna ini memiliki {}/{} peringatan, dalam * {} * karena alasan berikut:".format( num_warns, limit, chat_name) else: text = "Pengguna ini memiliki {}/{} peringatan, karena alasan berikut:".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, parse_mode="markdown") else: update.effective_message.reply_text( "Pengguna memiliki peringatan {}/{}, tapi tidak ada alasan untuk itu." .format(num_warns, limit), parse_mode="markdown", ) else: update.effective_message.reply_text( "Pengguna ini tidak mendapat peringatan apa pun!")
def warns(update, context): message = update.effective_message chat = update.effective_chat args = context.args user = update.effective_user user_id = extract_user(message, args) or update.effective_user.id conn = connected(context.bot, update, chat, user.id, need_admin=False) if conn: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: if chat.type == "private": return else: chat_id = update.effective_chat.id chat_name = chat.title result = sql.get_warns(user_id, chat_id) num = 1 if result and result[0] != 0: num_warns, reasons = result limit, _ = sql.get_warn_setting(chat_id) if reasons: if conn: text = "This user has {}/{} warnings, in *{}* for the following reasons:".format( num_warns, limit, chat_name) else: text = "This user has {}/{} warnings, for the following reasons:".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, parse_mode="markdown") else: update.effective_message.reply_text( "User has {}/{} warnings, but no reasons for any of them.". format(num_warns, limit), parse_mode="markdown", ) else: update.effective_message.reply_text( "This user hasn't got any warnings!")
def caschecker(update, context) -> str: #/info logic bot = context.bot args = context.args msg = update.effective_message # type: Optional[Message] user_id = extract_user(update.effective_message, args) if user_id and int(user_id) != 777000: user = bot.get_chat(user_id) elif user_id and int(user_id) == 777000: msg.reply_text( "Ini Telegram. Kecuali Anda memasukkan ID akun yang dipesan ini secara manual, kemungkinan besar itu adalah siaran dari saluran tertaut." ) return 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>CAS Check</b>:" \ "\nID: <code>{}</code>" \ "\nFirst Name: {}".format(user.id, html.escape(user.first_name)) if user.last_name: text += "\nLast Name: {}".format(html.escape(user.last_name)) if user.username: text += "\nUsername: @{}".format(html.escape(user.username)) text += "\n\nCAS Banned: " result = cas.banchecker(user.id) text += str(result) if result: parsing = cas.offenses(user.id) if parsing: text += "\nTotal of Offenses: " text += str(parsing) parsing = cas.timeadded(user.id) if parsing: parseArray = str(parsing).split(", ") text += "\nDay added: " text += str(parseArray[1]) text += "\nTime added: " text += str(parseArray[0]) text += "\n\nAll times are in UTC" update.effective_message.reply_text(text, parse_mode=ParseMode.HTML)
def slap(update, context): args = context.args 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 = 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(fun.SLAP_TEMPLATES) item = random.choice(fun.ITEMS) hit = random.choice(fun.HIT) throw = random.choice(fun.THROW) repl = temp.format( user1=user1, user2=user2, item=item, hits=hit, throws=throw ) reply_text(repl, parse_mode=ParseMode.MARKDOWN)
def punch(update, context): args = context.args 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: punched_user = context.bot.get_chat(user_id) user1 = curr_user if punched_user.username: user2 = "@" + escape_markdown(punched_user.username) else: user2 = "[{}](tg://user?id={})".format( punched_user.first_name, punched_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(fun.PUNCH_TEMPLATES) item = random.choice(fun.ITEMS) punch = random.choice(fun.PUNCH) repl = temp.format(user1=user1, user2=user2, item=item, punches=punch) 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: 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 `{}`.\nPenerusan, {}, memiliki ID dari `{}`." .format( escape_markdown(user2.first_name), user2.id, escape_markdown(user1.first_name), user1.id, ), parse_mode=ParseMode.MARKDOWN, ) else: user = context.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 kamu `{}`.".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 reset_warns(update, context): message = update.effective_message chat = update.effective_chat user = update.effective_user args = context.args user_id = extract_user(message, args) if user_id: sql.reset_warns(user_id, chat.id) 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>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("Tidak ada pengguna yang telah ditunjuk!") return ""
def reset_warns(update, context): message = update.effective_message chat = update.effective_chat user = update.effective_user args = context.args 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 about_bio(update, context): message = update.effective_message # type: Optional[Message] args = context.args user_id = extract_user(message, args) if user_id: user = context.bot.get_chat(user_id) else: user = message.from_user info = USER_BIO.find_one({'_id': user.id}) if info: update.effective_message.reply_text( "*{}*:\n{}".format(user.first_name, escape_markdown(info["bio"])), parse_mode=ParseMode.MARKDOWN, ) elif message.reply_to_message: username = user.first_name update.effective_message.reply_text( "{} Belum ada detail tentang dia yang disimpan !".format(username)) else: update.effective_message.reply_text( " Biografi Anda tentang Anda telah disimpan !")
def about_me(update, context): message = update.effective_message # type: Optional[Message] args = context.args user_id = extract_user(message, args) if user_id: user = context.bot.get_chat(user_id) else: user = message.from_user info = USER_INFO.find_one({'_id': user.id})["info"] 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 + "Informasi tentang dia saat ini tidak tersedia !") else: update.effective_message.reply_text( "Anda belum menambahkan informasi apa pun tentang diri Anda !")
def about_bio(update, context): message = update.effective_message # type: Optional[Message] args = context.args user_id = extract_user(message, args) if user_id: user = context.bot.get_chat(user_id) else: user = message.from_user info = USER_BIO.find_one({'_id': user.id})["bio"] 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( "{} No details about him have been saved yet !".format(username)) else: update.effective_message.reply_text( " Your bio about you has been saved !")
def remove_warns(update, context): message = update.effective_message chat = update.effective_chat user = update.effective_user args = context.args user_id = extract_user(message, args) if user_id: sql.remove_warn(user_id, chat.id) message.reply_text("Last warn has been removed!") warned = chat.get_member(user_id).user return ("<b>{}:</b>" "\n#UNWARN" "\n<b>β’ Admin:</b> {}" "\n<b>β’ User:</b> {}" "\n<b>β’ ID:</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 about_me(update, context): message = update.effective_message # type: Optional[Message] args = context.args user_id = extract_user(message, args) if user_id: user = context.bot.get_chat(user_id) else: user = message.from_user info = USER_INFO.find_one({'_id': user.id})["info"] 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 + "Information about him is currently unavailable !") else: update.effective_message.reply_text( "You have not added any information about yourself yet !")
def info(update, context): args = context.args msg = update.effective_message # type: Optional[Message] user_id = extract_user(update.effective_message, args) chat = update.effective_chat if user_id: 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]))): msg.reply_text("Saya tidak dapat mengekstrak pengguna dari ini.") return else: return del_msg = msg.reply_text( "Tunggu sebentar sementara saya mencuri beberapa data dari <b>Database FBI</b>...", parse_mode=ParseMode.HTML, ) text = ("<b>USER INFO</b>:" "\n<b>ID:</b> <code>{}</code>" "\n<b>Nama Depan:</b> <code>{}</code>".format( user.id, html.escape(user.first_name))) if user.last_name: text += "\n<b>Nama Belakang:</b> <code>{}</code>".format( html.escape(user.last_name)) if user.username: text += "\n<b>Nama pengguna:</b> @{}".format(html.escape( user.username)) text += "\n<b>Tautan pengguna permanen:</b> {}".format( mention_html(user.id, "link")) text += "\n<b>Jumlah foto profil:</b> <code>{}</code>".format( context.bot.get_user_profile_photos(user.id).total_count) if chat.type != "private": status = context.bot.get_chat_member(chat.id, user.id).status if status: _stext = "\n<b>Status:</b> <code>{}</code>" afk_st = is_afk(user.id) if afk_st: text += _stext.format("Away From Keyboard") else: status = context.bot.get_chat_member(chat.id, user.id).status if status: if status in {"left", "kicked"}: text += _stext.format("Absent") elif status == "member": text += _stext.format("Present") elif status in {"administrator", "creator"}: text += _stext.format("Admin") try: sw = spamwtc.get_ban(int(user.id)) if sw: text += "\n\n<b>Orang ini dilarang di Spamwatch!</b>" text += f"\n<b>Alasan:</b> <pre>{sw.reason}</pre>" text += "\nAda yang salah coba tanyakan di @SpamWatchSupport" else: pass except BaseException: pass # don't crash if api is down somehow... cas_banned = check_cas(user.id) if cas_banned: text += "\n\n<b>Orang ini Dilarang di CAS!</b>" text += f"\n<b>Alasan: </b> <a href='{cas_banned}'>CAS Banned</a>" text += "\nAda yang salah coba tanyakan di @cas_discussion" if user.id == OWNER_ID: text += "\n\nAye, orang ini adalah pemilikku.\nSaya tidak akan pernah melakukan apa pun untuk melawannya!" elif user.id in DEV_USERS: text += ( "\n\nOrang ini adalah salah satu pengguna dev saya! " "\nDia memiliki perintah paling banyak untuk saya setelah pemilik saya." ) elif user.id in SUDO_USERS: text += ("\n\nOrang ini adalah salah satu pengguna sudo saya! " "Hampir sekuat pemilik saya - jadi tontonlah.") elif user.id in SUPPORT_USERS: text += ( "\n\nOrang ini adalah salah satu pengguna dukungan saya! " "Bukan pengguna sudo, tetapi masih bisa membuat Anda keluar dari peta." ) elif user.id in WHITELIST_USERS: text += ("\n\nOrang ini telah masuk daftar putih! " "Itu artinya saya tidak boleh melarang / menendang mereka.") elif user.id == int(1087968824): text += "\n\nIni adalah admin anonim di grup ini. " try: memstatus = chat.get_member(user.id).status if memstatus == "administrator" or memstatus == "creator": result = context.bot.get_chat_member(chat.id, user.id) if result.custom_title: text += f"\n\nPengguna ini memiliki judul khusus <b>{result.custom_title}</b> di obrolan ini." except BadRequest: pass 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 try: profile = context.bot.get_user_profile_photos(user.id).photos[0][-1] context.bot.sendChatAction(chat.id, "upload_photo") context.bot.send_photo( chat.id, photo=profile, caption=(text), parse_mode=ParseMode.HTML, ) except IndexError: context.bot.sendChatAction(chat.id, "typing") msg.reply_text(text, parse_mode=ParseMode.HTML, disable_web_page_preview=True) finally: del_msg.delete()
def ungban(update, context): message = update.effective_message args = context.args user_id = extract_user(message, args) if not user_id: message.reply_text("Anda sepertinya tidak mengacu pada pengguna.") return user_chat = context.bot.get_chat(user_id) if user_chat.type != "private": message.reply_text("Itu bukan pengguna!") return if not gban_db.is_user_gbanned(user_id): message.reply_text("Pengguna ini tidak dilarang!") return banner = update.effective_user message.reply_text( "Saya akan memberi {} kesempatan kedua, secara global.".format( user_chat.first_name)) context.bot.sendMessage( GBAN_LOGS, "<b>Regression of Global Ban</b>" "\n#UNGBAN" "\n<b>Status:</b> <code>Ceased</code>" "\n<b>Sudo Admin:</b> {}" "\n<b>User:</b> {}" "\n<b>ID:</b> <code>{}</code>".format( mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name), user_chat.id, ), 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 gban_db.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: message.reply_text( "Tidak dapat membatalkan gban karena: {}".format( excp.message)) context.bot.send_message( OWNER_ID, "Tidak dapat membatalkan gban karena: {}".format( excp.message), ) return except TelegramError: pass gban_db.ungban_user(user_id) message.reply_text("Tidak di larang lagi.")