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 chats(update, context): all_chats = sql.get_all_chats() or [] chatfile = 'Daftar obrolan.\n' for chat in all_chats: chatfile += "{} - ({})\n".format(chat.chat_name, chat.chat_id) with BytesIO(str.encode(chatfile)) as output: output.name = "chatlist.txt" update.effective_message.reply_document( document=output, filename="chatlist.txt", caption="Berikut ini daftar obrolan dalam database saya.")
def chats(update, context): all_chats = sql.get_all_chats() or [] chatfile = "List of chats.\n" for chat in all_chats: chatfile += "{} - ({})\n".format(chat.chat_name, chat.chat_id) with BytesIO(str.encode(chatfile)) as output: output.name = "chatlist.txt" update.effective_message.reply_document( document=output, filename="chatlist.txt", caption="Here is the list of chats in my database.", )
def get_muted_chats(bot: Bot, update: Update, leave: bool = False): chat_id = update.effective_chat.id chats = user_sql.get_all_chats() muted_chats, progress = 0, 0 chat_list = [] progress_message = None for chat in chats: if ((100 * chats.index(chat)) / len(chats)) > progress: progress_bar = f"{progress}% completed in getting muted chats." if progress_message: try: bot.editMessageText(progress_bar, chat_id, progress_message.message_id) except: pass else: progress_message = bot.sendMessage(chat_id, progress_bar) progress += 5 cid = chat.chat_id sleep(0.1) try: bot.send_chat_action(cid, "TYPING", timeout=120) except (BadRequest, Unauthorized): muted_chats += +1 chat_list.append(cid) except: pass try: progress_message.delete() except: pass if not leave: return muted_chats else: for muted_chat in chat_list: sleep(0.1) try: bot.leaveChat(muted_chat, timeout=120) except: pass user_sql.rem_chat(muted_chat) return muted_chats
def broadcast(update, context): to_send = update.effective_message.text.split(None, 1) if len(to_send) >= 2: chats = sql.get_all_chats() or [] failed = 0 for chat in chats: try: context.bot.sendMessage(int(chat.chat_id), to_send[1]) sleep(0.1) except TelegramError: failed += 1 LOGGER.warning("Couldn't send broadcast to %s, group name %s", str(chat.chat_id), str(chat.chat_name)) send_message( update.effective_message, "Siaran selesai. {} grup gagal menerima pesan, mungkin " "karena ditendang.".format(failed))
def broadcast(update, context): to_send = update.effective_message.text.split(None, 1) if len(to_send) >= 2: chats = sql.get_all_chats() or [] failed = 0 for chat in chats: try: context.bot.sendMessage(int(chat.chat_id), to_send[1]) sleep(0.1) except TelegramError: failed += 1 LOGGER.warning( "Couldn't send broadcast to %s, group name %s", str(chat.chat_id), str(chat.chat_name), ) update.effective_message.reply_text( "Broadcast complete. {} groups failed to receive the message, probably " "due to being kicked.".format(failed) )
def ungban(update, context): message = update.effective_message args = context.args user_id = extract_user(message, args) if not user_id: message.reply_text("You don't seem to be referring to a user.") return user_chat = context.bot.get_chat(user_id) if user_chat.type != "private": message.reply_text("That's not a user!") return if not sql.is_user_gbanned(user_id): message.reply_text("This user is not gbanned!") return banner = update.effective_user # type: Optional[User] message.reply_text("I'll give {} a second chance, globally.".format( user_chat.first_name)) context.bot.sendMessage( MESSAGE_DUMP, "<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 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: message.reply_text("Could not un-gban due to: {}".format( excp.message)) context.bot.send_message( OWNER_ID, "Could not un-gban due to: {}".format(excp.message)) return except TelegramError: pass sql.ungban_user(user_id) context.bot.sendMessage( MESSAGE_DUMP, "User {} has been successfully un-gbanned!".format( mention_html(user_chat.id, user_chat.first_name)), parse_mode=ParseMode.HTML, ) message.reply_text("Person has been un-gbanned.")
def gban(update, context): message = update.effective_message # type: Optional[Message] args = context.args user_id, reason = extract_user_and_text(message, args) if user_id == "error": send_message(update.effective_message, tl(update.effective_message, reason)) return "" if not user_id: send_message(update.effective_message, tl(update.effective_message, "Anda sepertinya tidak mengacu pada pengguna.")) return if int(user_id) in SUDO_USERS: send_message(update.effective_message, tl(update.effective_message, "Saya memata-matai, dengan mata kecil saya... perang pengguna sudo! Mengapa kalian saling berpaling? 😱")) return if int(user_id) in SUPPORT_USERS: send_message(update.effective_message, tl(update.effective_message, "OOOH seseorang mencoba untuk memblokir secara global pengguna dukungan! 😄 *mengambil popcorn*")) return if user_id == context.bot.id: send_message(update.effective_message, tl(update.effective_message, "😑 Sangat lucu, mari kita blokir secara global diri saya sendiri? Usaha yang bagus 😒")) return try: user_chat = context.bot.get_chat(user_id) except BadRequest as excp: send_message(update.effective_message, excp.message) return if user_chat.type != 'private': send_message(update.effective_message, tl(update.effective_message, "Itu bukan pengguna!")) return if sql.is_user_gbanned(user_id): if not reason: send_message(update.effective_message, tl(update.effective_message, "Pengguna ini sudah dilarang secara global; Saya akan mengubah alasannya, tetapi Anda belum memberi saya satu...")) return old_reason = sql.update_gban_reason(user_id, user_chat.username or user_chat.first_name, reason) if old_reason: send_message(update.effective_message, tl(update.effective_message, "Pengguna ini sudah gbanned, karena alasan berikut:\n" "<code>{}</code>\n" "Saya telah melakukan dan memperbaruinya dengan alasan baru Anda!").format(html.escape(old_reason)), parse_mode=ParseMode.HTML) else: send_message(update.effective_message, tl(update.effective_message, "Pengguna ini sudah gbanned, tetapi tidak ada alasan yang ditetapkan; Saya telah melakukan dan memperbaruinya!")) return send_message(update.effective_message, tl(update.effective_message, "*It's global banned time* 😉")) banner = update.effective_user # type: Optional[User] send_to_list(context.bot, SUDO_USERS + SUPPORT_USERS, tl(update.effective_message, "{} melarang secara global pengguna {} " "karena:\n{}").format(mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name), reason or tl(update.effective_message, "Tidak ada alasan yang diberikan")), html=True) sql.gban_user(user_id, user_chat.username or user_chat.first_name, reason) 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: context.bot.kick_chat_member(chat_id, user_id) except BadRequest as excp: if excp.message in GBAN_ERRORS: pass else: send_message(update.effective_message, tl(update.effective_message, "Tidak dapat melarang secara global karena: {}").format(excp.message)) send_to_list(context.bot, SUDO_USERS + SUPPORT_USERS, tl(update.effective_message, "Tidak dapat melarang secara global karena: {}").format(excp.message)) sql.ungban_user(user_id) return except TelegramError: pass send_to_list(context.bot, SUDO_USERS + SUPPORT_USERS, tl(update.effective_message, "Melarang secara global selesai!")) send_message(update.effective_message, tl(update.effective_message, "Orang ini telah dilarang secara global."))