def lock_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 chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # Connection check conn = connected(bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = chat.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 if args: if args[0] == "on" or args[0] == "yes": sql.set_lockconf(chat_id, True) try: send_message( update.effective_message, tl( update.effective_message, "Saya *akan* memperingati pengguna jika dia mengirim pesan yang dikunci" ), parse_mode="markdown") except BadRequest: send_message( update.effective_message, tl(update.effective_message, "Saya *akan* memperingati pengguna jika dia mengirim pesan yang dikunci", parse_mode="markdown", quote=False)) elif args[0] == "off" or args[0] == "no": sql.set_lockconf(chat_id, False) try: send_message( update.effective_message, tl( update.effective_message, "Saya *tidak akan* memperingati pengguna jika dia mengirim pesan yang dikunci" ), parse_mode="markdown") except BadRequest: send_message( update.effective_message, tl(update.effective_message, "Saya *tidak akan* memperingati pengguna jika dia mengirim pesan yang dikunci", parse_mode="markdown", quote=False)) else: try: send_message( update.effective_message, tl(update.effective_message, "Saya hanya mengerti 'on/yes' atau 'off/no' saja!"), parse_mode="markdown") except BadRequest: send_message( update.effective_message, tl(update.effective_message, "Saya hanya mengerti 'on/yes' atau 'off/no' saja!"), parse_mode="markdown", quote=False) else: getconf = sql.get_lockconf(chat_id) if getconf: try: send_message( update.effective_message, tl( update.effective_message, "Saat ini saya *akan* memperingati pengguna jika dia mengirim pesan yang dikunci" ), parse_mode="markdown") except BadRequest: send_message( update.effective_message, tl( update.effective_message, "Saat ini saya *akan* memperingati pengguna jika dia mengirim pesan yang dikunci" ), parse_mode="markdown", quote=False) else: try: send_message( update.effective_message, tl( update.effective_message, "Saat ini saya *tidak akan* memperingati pengguna jika dia mengirim pesan yang dikunci" ), parse_mode="markdown") except BadRequest: send_message( update.effective_message, tl( update.effective_message, "Saat ini saya *tidak akan* memperingati pengguna jika dia mengirim pesan yang dikunci" ), parse_mode="markdown", quote=False)
def temp_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, 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 "" 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": 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 try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": send_message( update.effective_message, tl(update.effective_message, "Saya tidak dapat menemukan pengguna ini")) return "" else: raise if is_user_admin(chat, user_id, member): send_message( update.effective_message, tl(update.effective_message, "Saya benar-benar berharap dapat membisukan admin...")) return "" if user_id == context.bot.id: send_message( update.effective_message, tl( update.effective_message, "Saya tidak akan membisukan diri saya sendiri, apakah kamu gila?" )) 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 "" if not reason: send_message( update.effective_message, tl( update.effective_message, "Anda belum menetapkan waktu untuk menonaktifkan pengguna ini!" )) return "" split_reason = reason.split(None, 1) time_val = split_reason[0].lower() if len(split_reason) > 1: reason = split_reason[1] else: reason = "" mutetime = extract_time(message, time_val) if not mutetime: return "" log = "<b>{}:</b>" \ "\n#TMUTE" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {}" \ "\n<b>Time:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), time_val) if reason: log += "\n<b>Reason:</b> {}".format(reason) try: if member.can_send_messages is None or member.can_send_messages: context.bot.restrict_chat_member( chat.id, user_id, until_date=mutetime, permissions=ChatPermissions(can_send_messages=False)) if conn: text = tl(update.effective_message, "Dibisukan untuk *{}* pada *{}*!").format( time_val, chat_name) else: text = tl(update.effective_message, "Dibisukan untuk *{}*!").format(time_val) send_message(update.effective_message, text, parse_mode="markdown") return log else: send_message( update.effective_message, tl(update.effective_message, "Pengguna ini sudah dibungkam.")) except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply send_message(update.effective_message, tl(update.effective_message, "Dibisukan untuk *{}*!").format(time_val), quote=False) return log else: LOGGER.warning(update) LOGGER.exception("ERROR muting user %s in chat %s (%s) due to %s", user_id, chat.title, chat.id, excp.message) send_message( update.effective_message, tl(update.effective_message, "Yah sial, aku tidak bisa membisukan pengguna itu.")) return ""
def remove_warn_filter(bot: Bot, update: Update): 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] msg = update.effective_message # type: Optional[Message] user = update.effective_user # type: Optional[User] 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 args = msg.text.split(None, 1) # use python's maxsplit to separate Cmd, keyword, and reply_text if len(args) < 2: return extracted = split_quotes(args[1]) if len(extracted) < 1: return chat_filters = sql.get_chat_warn_triggers(chat.id) if not chat_filters: if conn: text = tl(update.effective_message, "Tidak ada filter peringatan aktif di *{}*!").format(chat_name) else: text = tl(update.effective_message, "Tidak ada filter peringatan aktif di sini!") msg.reply_text(text) return nowarn = 0 inwarn = 0 success = "" fail = "" teks = args[1].split(" ") for x in range(len(teks)): to_remove = teks[x] if to_remove not in chat_filters: fail += "`{}` ".format(to_remove) nowarn += 1 for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat.id, to_remove) success += "`{}` ".format(to_remove) inwarn += 1 if nowarn == 0: if conn: text = tl(update.effective_message, "Ya, saya akan berhenti memperingatkan orang-orang untuk {} pada *{}*.").format(success, chat_name) else: text = tl(update.effective_message, "Ya, saya akan berhenti memperingatkan orang-orang untuk {}.").format(success) msg.reply_text(text, parse_mode=ParseMode.MARKDOWN) raise DispatcherHandlerStop elif inwarn == 0: if conn: text = tl(update.effective_message, "Gagal menghapus filter warn untuk {} pada *{}*.").format(fail, chat_name) else: text = tl(update.effective_message, "Gagal menghapus filter warn untuk {}.").format(fail) msg.reply_text(text, parse_mode=ParseMode.MARKDOWN) raise DispatcherHandlerStop else: if conn: text = tl(update.effective_message, "Ya, saya akan berhenti memperingatkan orang-orang untuk {}.\nDan gagal menghapus filter warn untuk {}.\nPada *{}*").format(success, fail, chat_name) else: text = tl(update.effective_message, "Ya, saya akan berhenti memperingatkan orang-orang untuk {}.\nDan gagal menghapus filter warn untuk {}.").format(success, fail) msg.reply_text(text, parse_mode=ParseMode.MARKDOWN) raise DispatcherHandlerStop """ if not chat_filters: msg.reply_text("Tidak ada filter peringatan aktif di sini!") return for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat.id, to_remove) msg.reply_text("Ya, saya akan berhenti memperingatkan orang-orang untuk {}.".format(to_remove)) raise DispatcherHandlerStop """ if conn: text = tl(update.effective_message, "Itu bukan filter peringatan saat ini - jalankan /warnlist untuk semua filter peringatan aktif pada *{}*.") else: text = tl(update.effective_message, "Itu bukan filter peringatan saat ini - jalankan /warnlist untuk semua filter peringatan aktif.") msg.reply_text(text, parse_mode="markdown")
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) 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 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 = "Pengguna ini sudah bisa untuk berbicara pada *{}*.".format(chat_name) text2 = "Dia telah disuarakan 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 = "Pengguna ini sudah bisa untuk berbicara." text2 = "Dia telah disuarakan." 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("Ini 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: message.reply_text(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) message.reply_text(text2, parse_mode="markdown") return "<b>{}:</b>" \ "\n#UNMUTE" \ "\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 bahkan tidak dalam obrolan, menyuarakannya tidak akan membuat mereka berbicara lebih dari " "yang sudah mereka lakukan!") return ""
def filters(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] msg = update.effective_message # type: Optional[Message] args = msg.text.split(None, 1) # use python's maxsplit to separate Cmd, keyword, and reply_text conn = connected(context.bot, update, chat, user.id) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = tl(update.effective_message, "catatan lokal") else: chat_name = chat.title if not msg.reply_to_message and len(args) < 2: send_message(update.effective_message, tl(update.effective_message, "Anda harus memberi nama untuk filter ini!")) return if msg.reply_to_message: if len(args) < 2: send_message(update.effective_message, tl(update.effective_message, "Anda harus memberi nama untuk filter ini!")) return else: keyword = args[1] else: extracted = split_quotes(args[1]) if len(extracted) < 1: return # set trigger -> lower, so as to avoid adding duplicate filters with different cases keyword = extracted[0].lower() # Add the filter # Note: perhaps handlers can be removed somehow using sql.get_chat_filters for handler in dispatcher.handlers.get(HANDLER_GROUP, []): if handler.filters == (keyword, chat_id): dispatcher.remove_handler(handler, HANDLER_GROUP) text, file_type, file_id = get_filter_type(msg) if not msg.reply_to_message and len(extracted) >= 2: offset = len(extracted[1]) - len(msg.text) # set correct offset relative to command + notename text, buttons = button_markdown_parser(extracted[1], entities=msg.parse_entities(), offset=offset) text = text.strip() if not text: send_message(update.effective_message, tl(update.effective_message, "Tidak ada pesan catatan - Anda tidak bisa HANYA menekan tombol, Anda perlu pesan untuk melakukannya!")) return elif msg.reply_to_message and len(args) >= 2: if msg.reply_to_message.text: text_to_parsing = msg.reply_to_message.text elif msg.reply_to_message.caption: text_to_parsing = msg.reply_to_message.caption else: text_to_parsing = "" offset = len(text_to_parsing) # set correct offset relative to command + notename text, buttons = button_markdown_parser(text_to_parsing, entities=msg.parse_entities(), offset=offset) text = text.strip() elif not text and not file_type: send_message(update.effective_message, tl(update.effective_message, "Anda harus memberi nama untuk filter ini!")) return elif msg.reply_to_message: if msg.reply_to_message.text: text_to_parsing = msg.reply_to_message.text elif msg.reply_to_message.caption: text_to_parsing = msg.reply_to_message.caption else: text_to_parsing = "" offset = len(text_to_parsing) # set correct offset relative to command + notename text, buttons = button_markdown_parser(text_to_parsing, entities=msg.parse_entities(), offset=offset) text = text.strip() if (msg.reply_to_message.text or msg.reply_to_message.caption) and not text: send_message(update.effective_message, tl(update.effective_message, "Tidak ada pesan catatan - Anda tidak bisa HANYA menekan tombol, Anda perlu pesan untuk melakukannya!")) return else: send_message(update.effective_message, tl(update.effective_message, "Invalid filter!")) return sql.new_add_filter(chat_id, keyword, text, file_type, file_id, buttons) # This is an old method # sql.add_filter(chat_id, keyword, content, is_sticker, is_document, is_image, is_audio, is_voice, is_video, buttons) send_message(update.effective_message, tl(update.effective_message, "Handler '{}' ditambahkan di *{}*!").format(keyword, chat_name), parse_mode=telegram.ParseMode.MARKDOWN) raise DispatcherHandlerStop
def blacklist_mode(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!" ) chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] msg = update.effective_message # type: Optional[Message] 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 if args: if args[0].lower() == 'off' or args[0].lower( ) == 'nothing' or args[0].lower() == 'no': settypeblacklist = 'dimatikan' sql.set_blacklist_strength(chat_id, 0, "0") elif args[0].lower() == 'del' or args[0].lower() == 'delete': settypeblacklist = 'hapus' sql.set_blacklist_strength(chat_id, 1, "0") elif args[0].lower() == 'warn': settypeblacklist = 'peringati' sql.set_blacklist_strength(chat_id, 2, "0") elif args[0].lower() == 'mute': settypeblacklist = 'bisukan' sql.set_blacklist_strength(chat_id, 3, "0") elif args[0].lower() == 'kick': settypeblacklist = 'tendang' sql.set_blacklist_strength(chat_id, 4, "0") elif args[0].lower() == 'ban': settypeblacklist = 'blokir' sql.set_blacklist_strength(chat_id, 5, "0") elif args[0].lower() == 'tban': if len(args) == 1: teks = """Sepertinya Anda mencoba menetapkan nilai sementara untuk anti-banjir, tetapi belum menentukan waktu; gunakan `/setfloodmode tban <timevalue>`. Contoh nilai waktu: 4m = 4 menit, 3h = 3 jam, 6d = 6 hari, 5w = 5 minggu.""" msg.reply_text(teks, parse_mode="markdown") return settypeblacklist = 'blokir sementara selama {}'.format(args[1]) sql.set_blacklist_strength(chat_id, 6, str(args[1])) elif args[0].lower() == 'tmute': if len(args) == 1: teks = """Sepertinya Anda mencoba menetapkan nilai sementara untuk anti-banjir, tetapi belum menentukan waktu; gunakan `/setfloodmode tmute <timevalue>`. Contoh nilai waktu: 4m = 4 menit, 3h = 3 jam, 6d = 6 hari, 5w = 5 minggu.""" msg.reply_text(teks, parse_mode="markdown") return settypeblacklist = 'bisukan sementara selama {}'.format(args[1]) sql.set_blacklist_strength(chat_id, 7, str(args[1])) else: msg.reply_text( "Saya hanya mengerti off/del/warn/ban/kick/mute/tban/tmute!") return if conn: text = "Mode blacklist diubah menjadi `{}` pada *{}*!".format( settypeblacklist, chat_name) else: text = "Mode blacklist diubah menjadi `{}`!".format( settypeblacklist) msg.reply_text(text, parse_mode="markdown") return "<b>{}:</b>\n" \ "<b>Admin:</b> {}\n" \ "Telah mengubah mode blacklist. Pengguna akan di{}.".format(settypeblacklist, html.escape(chat.title), mention_html(user.id, user.first_name)) else: getmode, getvalue = sql.get_blacklist_setting(chat.id) if getmode == 0: settypeblacklist = 'tidak aktif' elif getmode == 1: settypeblacklist = 'hapus' elif getmode == 2: settypeblacklist = 'warn' elif getmode == 3: settypeblacklist = 'mute' elif getmode == 4: settypeblacklist = 'kick' elif getmode == 5: settypeblacklist = 'ban' elif getmode == 6: settypeblacklist = 'banned sementara selama {}'.format(getvalue) elif getmode == 7: settypeblacklist = 'mute sementara selama {}'.format(getvalue) if conn: text = "Mode blacklist saat ini disetel ke *{}* pada *{}*.".format( settypeblacklist, chat_name) else: text = "Mode antiflood saat ini disetel ke *{}*.".format( settypeblacklist) msg.reply_text(text, parse_mode=ParseMode.MARKDOWN) return ""
def set_flood(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] 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_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_id = update.effective_chat.id chat_name = update.effective_message.chat.title if len(args) >= 1: val = args[0].lower() if val == "off" or val == "no" or val == "0": sql.set_flood(chat_id, 0) if conn: text = tl( update.effective_message, "Antiflood telah dinonaktifkan di *{}*.").format(chat_name) else: text = tl(update.effective_message, "Antiflood telah dinonaktifkan.") send_message(update.effective_message, text, parse_mode="markdown") elif val.isdigit(): amount = int(val) if amount <= 0: sql.set_flood(chat_id, 0) if conn: text = tl(update.effective_message, "Antiflood telah dinonaktifkan di *{}*.").format( chat_name) else: text = tl(update.effective_message, "Antiflood telah dinonaktifkan.") return "<b>{}:</b>" \ "\n#SETFLOOD" \ "\n<b>Admin:</b> {}" \ "\nDisable antiflood.".format(html.escape(chat_name), mention_html(user.id, user.first_name)) elif amount < 3: send_message( update.effective_message, tl( update.effective_message, "Antiflood harus baik 0 (dinonaktifkan), atau nomor lebih besar dari 3!" )) return "" else: sql.set_flood(chat_id, amount) if conn: text = tl( update.effective_message, "Antiflood telah diperbarui dan diatur menjadi *{}* pada *{}*" ).format(amount, chat_name) else: text = tl( update.effective_message, "Antiflood telah diperbarui dan diatur menjadi *{}*" ).format(amount) send_message(update.effective_message, text, parse_mode="markdown") return "<b>{}:</b>" \ "\n#SETFLOOD" \ "\n<b>Admin:</b> {}" \ "\nSet antiflood to <code>{}</code>.".format(html.escape(chat_name), mention_html(user.id, user.first_name), amount) else: send_message( update.effective_message, tl( update.effective_message, "Argumen tidak dikenal - harap gunakan angka, 'off', atau 'no'." )) else: send_message( update.effective_message, tl( update.effective_message, "Gunakan `/setflood nomor` untuk menyetel anti pesan beruntun.\nAtau gunakan `/setflood off` untuk menonaktifkan anti pesan beruntun." ), parse_mode="markdown") return ""
def permanent_pin_set(update, context): user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] 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 if not args: get_permapin = sql.get_permapin(chat_id) text_maker = tl(update.effective_message, "Permanen pin saat ini di atur: `{}`").format( bool(int(get_permapin))) if get_permapin: if chat.username: old_pin = "https://t.me/{}/{}".format( chat.username, get_permapin) else: old_pin = "https://t.me/c/{}/{}".format( str(chat.id)[4:], get_permapin) text_maker += tl( update.effective_message, "\nUntuk menonaktifkan permanen pin: `/permanentpin off`") text_maker += tl( update.effective_message, "\n\n[Pesan permanen pin ada disini]({})").format(old_pin) send_message(update.effective_message, tl(update.effective_message, text_maker), parse_mode="markdown") return "" prev_message = args[0] if prev_message == "off": sql.set_permapin(chat_id, 0) send_message( update.effective_message, tl(update.effective_message, "Permanen pin telah di nonaktifkan!")) return if "/" in prev_message: prev_message = prev_message.split("/")[-1] 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 if update.effective_message.reply_to_message: prev_message = update.effective_message.reply_to_message.message_id elif len(args) >= 1 and args[0] == "off": sql.set_permapin(chat.id, 0) send_message( update.effective_message, tl(update.effective_message, "Permanen pin telah di nonaktifkan!")) return else: get_permapin = sql.get_permapin(chat_id) text_maker = tl(update.effective_message, "Permanen pin saat ini di atur: `{}`").format( bool(int(get_permapin))) if get_permapin: if chat.username: old_pin = "https://t.me/{}/{}".format( chat.username, get_permapin) else: old_pin = "https://t.me/c/{}/{}".format( str(chat.id)[4:], get_permapin) text_maker += tl( update.effective_message, "\nUntuk menonaktifkan permanen pin: `/permanentpin off`") text_maker += tl( update.effective_message, "\n\n[Pesan permanen pin ada disini]({})").format(old_pin) send_message(update.effective_message, text_maker, parse_mode="markdown") return "" is_group = chat.type != "private" and chat.type != "channel" if prev_message and is_group: sql.set_permapin(chat.id, prev_message) send_message( update.effective_message, tl(update.effective_message, "Permanent pin berhasil di atur!")) return "<b>{}:</b>" \ "\n#PERMANENT_PIN" \ "\n<b>Admin:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name)) return ""
def save(bot: Bot, update: Update): 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] conn = connected(bot, update, chat, user.id) if conn: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "catatan lokal" else: chat_name = chat.title msg = update.effective_message # type: Optional[Message] checktext = msg.text.split() if msg.reply_to_message: if len(checktext) <= 1: send_message( update.effective_message, tl(update.effective_message, "Anda harus memberi nama untuk catatan ini!")) return else: if len(checktext) <= 2: send_message( update.effective_message, tl(update.effective_message, "Anda harus memberi nama untuk catatan ini!")) return note_name, text, data_type, content, buttons = get_note_type(msg) if data_type is None: send_message(update.effective_message, tl(update.effective_message, "Tidak ada catatan!")) return if len(text.strip()) == 0: text = "`" + note_name + "`" sql.add_note_to_db(chat_id, note_name, text, data_type, buttons=buttons, file=content) if conn: savedtext = tl( update.effective_message, "Ok, catatan `{note_name}` disimpan di *{chat_name}*.").format( note_name=note_name, chat_name=chat_name) else: savedtext = tl( update.effective_message, "Ok, catatan `{note_name}` disimpan.").format(note_name=note_name) try: send_message(update.effective_message, savedtext, parse_mode=ParseMode.MARKDOWN) except BadRequest: if conn: savedtext = tl( update.effective_message, "Ok, catatan <code>{note_name}</code> disimpan di <b>{chat_name}</b>." ).format(note_name=note_name, chat_name=chat_name) else: savedtext = tl( update.effective_message, "Ok, catatan <code>{note_name}</code> disimpan.").format( note_name=note_name) send_message(update.effective_message, savedtext, parse_mode=ParseMode.HTML)
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 adminlist(update, context): 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=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": 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 administrators = context.bot.getChatAdministrators(chat_id) text = tl(update.effective_message, "Admin di *{}*:").format( update.effective_chat.title or tl(update.effective_message, "chat ini")) for admin in administrators: user = admin.user status = admin.status if user.first_name == '': name = tl(update.effective_message, "Γ’ΛΒ Akun Terhapus") else: name = "{}".format( mention_markdown( user.id, user.first_name + " " + (user.last_name or ""))) #if user.username: # name = escape_markdown("@" + user.username) if status == "creator": text += "\n Γ°ΕΈββ Creator:" text += "\n` Γ’β¬Β’ `{} \n\n Γ°ΕΈβΒ± Admins:".format(name) for admin in administrators: user = admin.user status = admin.status if user.first_name == '': name = tl(update.effective_message, "Γ’ΛΒ Akun Terhapus") else: name = "{}".format( mention_markdown( user.id, user.first_name + " " + (user.last_name or ""))) #if user.username: # name = escape_markdown("@" + user.username) if status == "administrator": text += "\n` Γ’β¬Β’ `{}".format(name) try: send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN) except BadRequest: send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN, quote=False)
def pin(update, context): user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] 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 if len(args) <= 1: send_message( update.effective_message, tl(update.effective_message, "Gunakan /pin <notify/loud/silent/violent> <link pesan>")) return "" prev_message = args[1] if "/" in prev_message: prev_message = prev_message.split("/")[-1] 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 if update.effective_message.reply_to_message: prev_message = update.effective_message.reply_to_message.message_id else: send_message( update.effective_message, tl(update.effective_message, "Balas pesan untuk pin pesan tersebut pada grup ini")) return "" is_group = chat.type != "private" and chat.type != "channel" is_silent = True if len(args) >= 1: is_silent = not (args[0].lower() == 'silent' or args[0].lower() == 'off' or args[0].lower() == 'mute') if prev_message and is_group: try: context.bot.pinChatMessage(chat.id, prev_message, disable_notification=is_silent) if conn: send_message( update.effective_message, tl(update.effective_message, "Saya sudah pin pesan dalam grup {}").format(chat_name)) except BadRequest as excp: if excp.message == "Chat_not_modified": pass else: raise return "<b>{}:</b>" \ "\n#PINNED" \ "\n<b>Admin:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name)) return ""
def demote(update, context): chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] 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) 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 == 'creator': send_message( update.effective_message, tl( update.effective_message, "Orang ini MENCIPTAKAN obrolan ini, bagaimana saya menurunkannya?" )) return "" if not user_member.status == 'administrator': send_message( update.effective_message, tl(update.effective_message, "Tidak dapat menurunkan jabatan apa yang belum dipromosikan!")) return "" if user_id == context.bot.id: send_message( update.effective_message, tl( update.effective_message, "Saya tidak bisa menurunkan jabatan diri saya sendiri! Hanya admin yang dapat melakukanya untuk saya." )) 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, can_promote_members=False) send_message( update.effective_message, 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: send_message( update.effective_message, 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 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, 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: 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 unban(update, context): message = update.effective_message # type: Optional[Message] user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] 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 "" 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 if not user_id: return "" check = context.bot.getChatMember(chat_id, context.bot.id) if check.status == 'member': if conn: text = tl( update.effective_message, "Saya tidak bisa membatasi orang di {}! Pastikan saya admin dan dapat menunjuk admin baru." ).format(chat_name) else: text = tl( update.effective_message, "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru." ) send_message(update.effective_message, text, parse_mode="markdown") return "" else: if check['can_restrict_members'] == False: if conn: text = tl( update.effective_message, "Saya tidak bisa membatasi orang di {}! Pastikan saya admin dan dapat menunjuk admin baru." ).format(chat_name) else: text = tl( update.effective_message, "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru." ) send_message(update.effective_message, text, parse_mode="markdown") return "" try: if conn: member = context.bot.getChatMember(chat_id, user_id) else: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": send_message( update.effective_message, tl(update.effective_message, "Saya tidak dapat menemukan pengguna ini")) return "" else: raise if user_id == context.bot.id: send_message( update.effective_message, tl( update.effective_message, "Bagaimana saya akan unban diri saya sendiri jika saya tidak ada di sini...? π€" )) return "" if is_user_in_chat(chat, user_id): send_message( update.effective_message, tl( update.effective_message, "Mengapa Anda mencoba unban seseorang yang sudah ada di obrolan? π" )) 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 "" if conn: context.bot.unbanChatMember(chat_id, user_id) send_message( update.effective_message, tl(update.effective_message, "Ya, pengguna ini dapat bergabung pada {}! π").format( chat_name)) else: chat.unban_member(user_id) send_message( update.effective_message, tl(update.effective_message, "Ya, pengguna ini dapat bergabung! π")) log = "<b>{}:</b>" \ "\n#UNBANNED" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), member.user.id) if reason: log += "\n<b>Reason:</b> {}".format(reason) return log
def clear(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 chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id) if conn: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "local notes" else: chat_name = chat.title if len(args) >= 1: catatan = [] catatangagal = [] for x in range(len(args)): notename = args[x] if sql.rm_note(chat_id, notename): catatan.append(notename) else: catatangagal.append(notename) if len(catatan) >= 1 and len(catatangagal) == 0: if conn: rtext = tl( update.effective_message, "Catatan di *{chat_name}* untuk `{note_name}` dihapus π" ).format(chat_name=chat_name, note_name=", ".join(catatan)) else: rtext = tl(update.effective_message, "Catatan `{note_name}` dihapus π").format( note_name=", ".join(catatan)) try: send_message(update.effective_message, rtext, parse_mode=ParseMode.MARKDOWN) except BadRequest: if conn: rtext = tl( update.effective_message, "Catatan di <b>{chat_name}</b> untuk <code>{note_name}</code> dihapus π" ).format(chat_name=chat_name, note_name=", ".join(catatan)) else: rtext = tl( update.effective_message, "Catatan <code>{note_name}</code> dihapus π").format( note_name=", ".join(catatan)) send_message(update.effective_message, rtext, parse_mode=ParseMode.HTML) elif len(catatangagal) >= 0 and len(catatan) == 0: if conn: rtext = tl( update.effective_message, "Catatan di *{chat_name}* untuk `{fnote_name}` gagal dihapus!" ).format(chat_name=chat_name, fnote_name=", ".join(catatangagal)) else: rtext = tl(update.effective_message, "Catatan `{fnote_name}` gagal dihapus!").format( fnote_name=", ".join(catatangagal)) try: send_message(update.effective_message, rtext, parse_mode=ParseMode.MARKDOWN) except BadRequest: if conn: rtext = tl( update.effective_message, "Catatan di <b>{chat_name}</b> untuk <code>{fnote_name}</code> gagal dihapus!" ).format(chat_name=chat_name, fnote_name=", ".join(catatangagal)) else: rtext = tl( update.effective_message, "Catatan <code>{fnote_name}</code> gagal dihapus!" ).format(fnote_name=", ".join(catatangagal)) send_message(update.effective_message, tl(update.effective_message, rtext), parse_mode=ParseMode.HTML) else: if conn: rtext = tl( update.effective_message, "Catatan di *{chat_name}* untuk `{note_name}` dihapus π\nCatatan `{fnote_name}` gagal dihapus!" ).format(chat_name=chat_name, note_name=", ".join(catatan), fnote_name=", ".join(catatangagal)) else: rtext = tl( update.effective_message, "Catatan `{note_name}` dihapus π\nCatatan `{fnote_name}` gagal dihapus!" ).format(note_name=", ".join(catatan), fnote_name=", ".join(catatangagal)) try: send_message(update.effective_message, rtext, parse_mode=ParseMode.MARKDOWN) except BadRequest: if conn: rtext = tl( update.effective_message, "Catatan di <b>{chat_name}</b> untuk <code>{note_name}</code> dihapus π\nCatatan <code>{fnote_name}</code> gagal dihapus!" ).format(chat_name=chat_name, note_name=", ".join(catatan), fnote_name=", ".join(catatangagal)) else: rtext = tl( update.effective_message, "Catatan <code>{note_name}</code> dihapus π\nCatatan <code>{fnote_name}</code> gagal dihapus!" ).format(note_name=", ".join(catatan), fnote_name=", ".join(catatangagal)) send_message(update.effective_message, tl(update.effective_message, rtext), parse_mode=ParseMode.HTML) else: send_message(update.effective_message, tl(update.effective_message, "Apa yang ingin dihapus?"))
def unblacklist(bot: Bot, update: Update): msg = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] words = msg.text.split(None, 1) 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!" ) conn = connected(bot, update, chat, user.id) if conn: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": return else: chat_name = chat.title if len(words) > 1: text = words[1] to_unblacklist = list( set(trigger.strip() for trigger in text.split("\n") if trigger.strip())) successful = 0 for trigger in to_unblacklist: success = sql.rm_from_blacklist(chat_id, trigger.lower()) if success: successful += 1 if len(to_unblacklist) == 1: if successful: msg.reply_text( "<code>{}</code> dihapus dari daftar hitam di <b>{}</b>!". format(html.escape(to_unblacklist[0]), chat_name), parse_mode=ParseMode.HTML) else: msg.reply_text("Ini bukan pemicu daftar hitam...!") elif successful == len(to_unblacklist): msg.reply_text( "Pemicu <code>{}</code> dihapus dari daftar hitam di <b>{}</b>!" .format(successful, chat_name), parse_mode=ParseMode.HTML) elif not successful: msg.reply_text( "Tidak satu pun pemicu ini ada, sehingga tidak dapat dihapus.". format(successful, len(to_unblacklist) - successful), parse_mode=ParseMode.HTML) else: msg.reply_text( "Pemicu <code>{}</code> dihapus dari daftar hitam. {} Tidak ada, " "jadi tidak dihapus.".format(successful, len(to_unblacklist) - successful), parse_mode=ParseMode.HTML) else: msg.reply_text( "Beri tahu saya kata-kata apa yang ingin Anda hapus dari daftar hitam." )
def get(bot, update, notename, show_none=True, no_format=False): 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_id = conn send_id = user.id else: chat_id = update.effective_chat.id send_id = chat_id note = sql.get_note(chat_id, notename) message = update.effective_message # type: Optional[Message] if note: # If we're replying to a message, reply to that message (unless it's an error) if message.reply_to_message: reply_id = message.reply_to_message.message_id else: reply_id = message.message_id if note.is_reply: if MESSAGE_DUMP: try: bot.forward_message(chat_id=chat_id, from_chat_id=MESSAGE_DUMP, message_id=note.value) except BadRequest as excp: if excp.message == "Message to forward not found": send_message( update.effective_message, tl( update.effective_message, "Pesan ini tampaknya telah hilang - saya akan menghapusnya " "dari daftar catatan Anda.")) sql.rm_note(chat_id, notename) else: raise else: try: bot.forward_message(chat_id=chat_id, from_chat_id=chat_id, message_id=note.value) except BadRequest as excp: if excp.message == "Message to forward not found": send_message( update.effective_message, tl( update.effective_message, "Sepertinya pengirim asli dari catatan ini telah dihapus " "pesan mereka - maaf! Dapatkan admin bot Anda untuk mulai menggunakan " "pesan dump untuk menghindari ini. Saya akan menghapus catatan ini dari " "catatan tersimpan Anda.")) sql.rm_note(chat_id, notename) else: raise else: VALID_WELCOME_FORMATTERS = [ 'first', 'last', 'fullname', 'username', 'id', 'chatname', 'mention' ] valid_format = escape_invalid_curly_brackets( note.value, VALID_WELCOME_FORMATTERS) if valid_format: text = valid_format.format( first=escape_markdown(message.from_user.first_name), last=escape_markdown(message.from_user.last_name or message.from_user.first_name), fullname=escape_markdown( " ".join([ message.from_user.first_name, message.from_user. last_name ] if message.from_user.last_name else [message.from_user.first_name])), username="******" + message.from_user.username if message.from_user.username else mention_markdown( message.from_user.id, message.from_user.first_name), mention=mention_markdown(message.from_user.id, message.from_user.first_name), chatname=escape_markdown( message.chat.title if message.chat.type != "private" else message.from_user.first_name), id=message.from_user.id) else: text = "" keyb = [] parseMode = ParseMode.MARKDOWN buttons = sql.get_buttons(chat_id, notename) if no_format: parseMode = None text += revert_buttons(buttons) else: keyb = build_keyboard(buttons) keyboard = InlineKeyboardMarkup(keyb) try: is_private, is_delete = sql.get_private_note(chat.id) if note.msgtype in (sql.Types.BUTTON_TEXT, sql.Types.TEXT): try: if is_delete: update.effective_message.delete() if is_private: bot.send_message(user.id, text, parse_mode=parseMode, disable_web_page_preview=True, reply_markup=keyboard) else: bot.send_message(send_id, text, reply_to_message_id=reply_id, parse_mode=parseMode, disable_web_page_preview=True, reply_markup=keyboard) except BadRequest as excp: if excp.message == "Wrong http url": failtext = tl( update.effective_message, "Kesalahan: URL pada tombol tidak valid! Harap perbaruhi catatan ini." ) failtext += "\n\n```\n{}```".format( note.value + revert_buttons(buttons)) send_message(update.effective_message, failtext, parse_mode="markdown") elif excp.message == "Button_url_invalid": failtext = tl( update.effective_message, "Kesalahan: URL pada tombol tidak valid! Harap perbaruhi catatan ini." ) failtext += "\n\n```\n{}```".format( note.value + revert_buttons(buttons)) send_message(update.effective_message, failtext, parse_mode="markdown") elif excp.message == "Message can't be deleted": pass elif excp.message == "Have no rights to send a message": pass except Unauthorized as excp: send_message( update.effective_message, tl( update.effective_message, "Hubungi saya di PM dulu untuk mendapatkan catatan ini." ), parse_mode="markdown") pass else: try: if is_delete: update.effective_message.delete() if is_private: ENUM_FUNC_MAP[note.msgtype]( user.id, note.file, caption=text, parse_mode=parseMode, disable_web_page_preview=True, reply_markup=keyboard) else: ENUM_FUNC_MAP[note.msgtype]( send_id, note.file, caption=text, reply_to_message_id=reply_id, parse_mode=parseMode, disable_web_page_preview=True, reply_markup=keyboard) except BadRequest as excp: if excp.message == "Message can't be deleted": pass elif excp.message == "Have no rights to send a message": pass except Unauthorized as excp: send_message( update.effective_message, tl( update.effective_message, "Hubungi saya di PM dulu untuk mendapatkan catatan ini." ), parse_mode="markdown") pass except BadRequest as excp: if excp.message == "Entity_mention_user_invalid": send_message( update.effective_message, tl( update.effective_message, "Sepertinya Anda mencoba menyebutkan seseorang yang belum pernah saya lihat sebelumnya. " "Jika kamu benar-benar ingin menyebutkannya, meneruskan salah satu pesan mereka kepada saya, " "dan saya akan dapat untuk menandai mereka!")) elif FILE_MATCHER.match(note.value): send_message( update.effective_message, tl( update.effective_message, "Catatan ini adalah file yang salah diimpor dari bot lain - saya tidak bisa menggunakan " "ini. Jika Anda benar-benar membutuhkannya, Anda harus menyimpannya lagi. " "Sementara itu, saya akan menghapusnya dari daftar catatan Anda." )) sql.rm_note(chat_id, notename) else: send_message( update.effective_message, tl( update.effective_message, "Catatan ini tidak dapat dikirim karena formatnya salah." )) LOGGER.exception( "Tidak dapat menguraikan pesan #%s di obrolan %s", notename, str(chat_id)) LOGGER.warning("Pesan itu: %s", str(note.value)) return elif show_none: send_message(update.effective_message, tl(update.effective_message, "Catatan ini tidak ada"))
def set_flood_mode(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 chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] msg = update.effective_message # type: Optional[Message] 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": 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 if args: if args[0].lower() == 'ban': settypeflood = tl(update.effective_message, 'blokir') sql.set_flood_strength(chat_id, 1, "0") elif args[0].lower() == 'kick': settypeflood = tl(update.effective_message, 'tendang') sql.set_flood_strength(chat_id, 2, "0") elif args[0].lower() == 'mute': settypeflood = tl(update.effective_message, 'bisukan') sql.set_flood_strength(chat_id, 3, "0") elif args[0].lower() == 'tban': if len(args) == 1: teks = tl( update.effective_message, """Sepertinya Anda mencoba menetapkan nilai sementara untuk anti-banjir, tetapi belum menentukan waktu; gunakan `/setfloodmode tban <timevalue>`. Contoh nilai waktu: 4m = 4 menit, 3h = 3 jam, 6d = 6 hari, 5w = 5 minggu.""") send_message(update.effective_message, teks, parse_mode="markdown") return settypeflood = tl(update.effective_message, "blokir sementara selama {}").format(args[1]) sql.set_flood_strength(chat_id, 4, str(args[1])) elif args[0].lower() == 'tmute': if len(args) == 1: teks = tl( update.effective_message, """Sepertinya Anda mencoba menetapkan nilai sementara untuk anti-banjir, tetapi belum menentukan waktu; gunakan `/setfloodmode tban <timevalue>`. Contoh nilai waktu: 4m = 4 menit, 3h = 3 jam, 6d = 6 hari, 5w = 5 minggu.""") send_message(update.effective_message, teks, parse_mode="markdown") return settypeflood = tl(update.effective_message, 'bisukan sementara selama {}').format(args[1]) sql.set_flood_strength(chat_id, 5, str(args[1])) else: send_message( update.effective_message, tl(update.effective_message, "Saya hanya mengerti ban/kick/mute/tban/tmute!")) return if conn: text = tl( update.effective_message, "Terlalu banyak mengirim pesan sekarang akan menghasilkan `{}` pada *{}*!" ).format(settypeflood, chat_name) else: text = tl( update.effective_message, "Terlalu banyak mengirim pesan sekarang akan menghasilkan `{}`!" ).format(settypeflood) send_message(update.effective_message, text, parse_mode="markdown") return "<b>{}:</b>\n" \ "<b>Admin:</b> {}\n" \ "Has changed antiflood mode. User will {}.".format(settypeflood, html.escape(chat.title), mention_html(user.id, user.first_name)) else: getmode, getvalue = sql.get_flood_setting(chat.id) if getmode == 1: settypeflood = tl(update.effective_message, 'blokir') elif getmode == 2: settypeflood = tl(update.effective_message, 'tendang') elif getmode == 3: settypeflood = tl(update.effective_message, 'bisukan') elif getmode == 4: settypeflood = tl(update.effective_message, 'blokir sementara selama {}').format(getvalue) elif getmode == 5: settypeflood = tl(update.effective_message, 'bisukan sementara selama {}').format(getvalue) if conn: text = tl( update.effective_message, "Jika member mengirim pesan beruntun, maka dia akan *di {}* pada *{}*." ).format(settypeflood, chat_name) else: text = tl( update.effective_message, "Jika member mengirim pesan beruntun, maka dia akan *di {}*." ).format(settypeflood) send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN) return ""
def private_note(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 chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id) if conn: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = chat.title else: chat_name = chat.title if len(args) >= 1: if args[0] in ("yes", "on", "ya"): if len(args) >= 2: if args[1] == "del": sql.private_note(str(chat_id), True, True) send_message( update.effective_message, tl( update.effective_message, "Private Note di *aktifkan*, ketika pengguna mengambil catatan, pesan catatan akan dikirim ke PM dan pesan pengguna akan segera di hapus." ), parse_mode="markdown") else: sql.private_note(str(chat_id), True, False) send_message( update.effective_message, tl( update.effective_message, "Private Note di *aktifkan*, ketika pengguna mengambil catatan, pesan catatan akan dikirim ke PM." ), parse_mode="markdown") else: sql.private_note(str(chat_id), True, False) send_message( update.effective_message, tl( update.effective_message, "Private Note di *aktifkan*, ketika pengguna mengambil catatan, pesan catatan akan dikirim ke PM." ), parse_mode="markdown") elif args[0] in ("no", "off"): sql.private_note(str(chat_id), False, False) send_message( update.effective_message, tl( update.effective_message, "Private Note di *non-aktifkan*, pesan catatan akan di kirim di grup." ), parse_mode="markdown") else: send_message( update.effective_message, tl(update.effective_message, "Argumen tidak dikenal - harap gunakan 'yes', atau 'no'.")) else: is_private, is_delete = sql.get_private_note(chat_id) print(is_private, is_delete) send_message(update.effective_message, tl(update.effective_message, "Pengaturan Private Note di {}: *{}*{}").format( chat_name, "Enabled" if is_private else "Disabled", " - *Hash will be deleted*" if is_delete else ""), parse_mode="markdown")
def temp_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, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("Anda sepertinya tidak mengacu pada pengguna.") 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("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 try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": message.reply_text("Saya tidak dapat menemukan pengguna ini") return "" else: raise if is_user_admin(chat, user_id, member): message.reply_text("Saya benar-benar berharap dapat membisukan admin...") return "" if user_id == bot.id: message.reply_text("Saya tidak akan membisukan diri saya sendiri, apakah kamu gila?") 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 "" if not reason: message.reply_text("Anda belum menetapkan waktu untuk menonaktifkan pengguna ini!") return "" split_reason = reason.split(None, 1) time_val = split_reason[0].lower() if len(split_reason) > 1: reason = split_reason[1] else: reason = "" mutetime = extract_time(message, time_val) if not mutetime: return "" log = "<b>{}:</b>" \ "\n#BISU SEMENTARA" \ "\n<b>Admin:</b> {}" \ "\n<b>Pengguna:</b> {}" \ "\n<b>Waktu:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), time_val) if reason: log += "\n<b>Alasan:</b> {}".format(reason) try: if member.can_send_messages is None or member.can_send_messages: bot.restrict_chat_member(chat.id, user_id, until_date=mutetime, can_send_messages=False) if conn: text = "Dibisukan untuk *{}* pada *{}*!".format(time_val, chat_name) else: text = "Dibisukan untuk *{}*!".format(time_val) message.reply_text(text, parse_mode="markdown") return log else: message.reply_text("Pengguna ini sudah dibungkam.") except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text("Dibisukan untuk {}!".format(time_val), quote=False) return log else: LOGGER.warning(update) LOGGER.exception("ERROR muting user %s in chat %s (%s) due to %s", user_id, chat.title, chat.id, excp.message) message.reply_text("Yah sial, aku tidak bisa membisukan pengguna itu.") return ""
def list_notes(bot: Bot, update: Update): 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] conn = connected(bot, update, chat, user.id, need_admin=False) if conn: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title msg = tl(update.effective_message, "*Catatan di {}:*\n").format(chat_name) else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "" msg = tl(update.effective_message, "*Catatan lokal:*\n") else: chat_name = chat.title msg = tl(update.effective_message, "*Catatan di {}:*\n").format(chat_name) note_list = sql.get_all_chat_notes(chat_id) for note in note_list: note_name = " - `{}`\n".format(note.name) if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: send_message(update.effective_message, msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name if msg == tl(update.effective_message, "*Catatan di {}:*\n").format(chat_name) or msg == tl( update.effective_message, "*Catatan lokal:*\n"): if conn: send_message( update.effective_message, tl(update.effective_message, "Tidak ada catatan di obrolan *{}*!").format(chat_name), parse_mode="markdown") else: send_message( update.effective_message, tl(update.effective_message, "Tidak ada catatan di obrolan ini!")) elif len(msg) != 0: msg += tl( update.effective_message, "\nAnda dapat mengambil catatan ini dengan menggunakan `/get notename`, atau `#notename`" ) try: send_message(update.effective_message, msg, parse_mode=ParseMode.MARKDOWN) except BadRequest: if chat.type == "private": chat_name = "" msg = tl(update.effective_message, "<b>Catatan lokal:</b>\n") else: chat_name = chat.title msg = tl(update.effective_message, "<b>Catatan di {}:</b>\n").format(chat_name) for note in note_list: note_name = " - <code>{}</code>\n".format(note.name) if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: send_message(update.effective_message, msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name msg += tl( update.effective_message, "\nAnda dapat mengambil catatan ini dengan menggunakan <code>/get notename</code>, atau <code>#notename</code>" ) send_message(update.effective_message, msg, parse_mode=ParseMode.HTML)
def filters(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] msg = update.effective_message # type: Optional[Message] args = msg.text.split( None, 1) # use python's maxsplit to separate Cmd, keyword, and reply_text 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) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "catatan lokal" else: chat_name = chat.title if len(args) < 2: msg.reply_text("Anda harus memberi nama untuk filter ini!") return extracted = split_quotes(args[1]) if len(extracted) < 1: return # set trigger -> lower, so as to avoid adding duplicate filters with different cases keyword = extracted[0].lower() is_sticker = False is_document = False is_image = False is_voice = False is_audio = False is_video = False buttons = [] # determine what the contents of the filter are - text, image, sticker, etc if len(extracted) >= 2: offset = len(extracted[1]) - len( msg.text) # set correct offset relative to command + notename content, buttons = button_markdown_parser( extracted[1], entities=msg.parse_entities(), offset=offset) content = content.strip() if not content: msg.reply_text( "Tidak ada pesan catatan - Anda tidak bisa HANYA menekan tombol, Anda perlu pesan untuk melakukannya!" ) return elif msg.reply_to_message and msg.reply_to_message.sticker: content = msg.reply_to_message.sticker.file_id is_sticker = True elif msg.reply_to_message and msg.reply_to_message.document: content = msg.reply_to_message.document.file_id is_document = True elif msg.reply_to_message and msg.reply_to_message.photo: content = msg.reply_to_message.photo[ -1].file_id # last elem = best quality is_image = True elif msg.reply_to_message and msg.reply_to_message.audio: content = msg.reply_to_message.audio.file_id is_audio = True elif msg.reply_to_message and msg.reply_to_message.voice: content = msg.reply_to_message.voice.file_id is_voice = True elif msg.reply_to_message and msg.reply_to_message.video: content = msg.reply_to_message.video.file_id is_video = True else: msg.reply_text("Anda tidak menentukan apa yang harus dibalas!") return # Add the filter # Note: perhaps handlers can be removed somehow using sql.get_chat_filters for handler in dispatcher.handlers.get(HANDLER_GROUP, []): if handler.filters == (keyword, chat_id): dispatcher.remove_handler(handler, HANDLER_GROUP) sql.add_filter(chat_id, keyword, content, is_sticker, is_document, is_image, is_audio, is_voice, is_video, buttons) msg.reply_text("Handler '{}' ditambahkan di *{}*!".format( keyword, chat_name), parse_mode=telegram.ParseMode.MARKDOWN) raise DispatcherHandlerStop
def temp_ban(update, context): currentchat = update.effective_chat # type: Optional[Chat] 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, reason = extract_user_and_text(message, args) if user_id == "error": send_message(update.effective_message, tl(update.effective_message, reason)) 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 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': if conn: text = tl( update.effective_message, "Saya tidak bisa membatasi orang di *{}*! Pastikan saya admin dan dapat menunjuk admin baru." ).format(chat_name) else: text = tl( update.effective_message, "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru." ) send_message(update.effective_message, text, parse_mode="markdown") return "" else: if check['can_restrict_members'] == False: if conn: text = tl( update.effective_message, "Saya tidak bisa membatasi orang di *{}*! Pastikan saya admin dan dapat menunjuk admin baru." ).format(chat_name) else: text = tl( update.effective_message, "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru." ) send_message(update.effective_message, text, parse_mode="markdown") return "" if not user_id: send_message( update.effective_message, tl(update.effective_message, "Anda sepertinya tidak mengacu pada pengguna.")) return "" try: if conn: member = context.bot.getChatMember(chat_id, user_id) else: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": send_message( update.effective_message, tl(update.effective_message, "Saya tidak dapat menemukan pengguna ini π£")) return "" else: raise if user_id == context.bot.id: send_message( update.effective_message, tl(update.effective_message, "Saya tidak akan BAN diri saya sendiri, apakah kamu gila? π ")) return "" if is_user_ban_protected(chat, user_id, member): send_message( update.effective_message, tl(update.effective_message, "Saya tidak bisa banned orang ini karena dia adalah admin π")) return "" if member['can_restrict_members'] == False: send_message( update.effective_message, tl(update.effective_message, "Anda tidak punya hak untuk membatasi seseorang.")) return "" if not reason: send_message( update.effective_message, tl(update.effective_message, "Anda belum menetapkan waktu untuk banned pengguna ini!")) return "" split_reason = reason.split(None, 1) time_val = split_reason[0].lower() if len(split_reason) > 1: reason = split_reason[1] else: reason = "" bantime = extract_time(message, time_val) if not bantime: return "" log = "<b>{}:</b>" \ "\n#TEMPBAN" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {} (<code>{}</code>)" \ "\n<b>Time:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), member.user.id, time_val) if reason: log += "\n<b>Reason:</b> {}".format(reason) try: if conn: context.bot.kickChatMember(chat_id, user_id, until_date=bantime) context.bot.send_sticker(currentchat.id, BAN_STICKER) # banhammer marie sticker send_message( update.effective_message, tl(update.effective_message, "Banned! Pengguna diblokir untuk *{}* pada *{}*.").format( time_val, chat_name), parse_mode="markdown") else: chat.kick_member(user_id, until_date=bantime) context.bot.send_sticker(chat.id, BAN_STICKER) # banhammer marie sticker send_message( update.effective_message, tl(update.effective_message, "Banned! Pengguna diblokir untuk {}.").format(time_val)) return log except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply send_message( update.effective_message, tl(update.effective_message, "Banned! Pengguna diblokir untuk {}.").format(time_val), quote=False) return log else: LOGGER.warning(update) LOGGER.exception("ERROR banning user %s in chat %s (%s) due to %s", user_id, chat.title, chat.id, excp.message) send_message( update.effective_message, tl(update.effective_message, "Well damn, I can't ban that user. π")) 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 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 menyuarakan, atau membalas seseorang untuk disuarakan." )) 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, "Pengguna ini sudah bisa untuk berbicara pada *{}*.").format( chat_name) text2 = tl(update.effective_message, "Unmuted! *{}*.").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 = "Unmuted!" 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, "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: context.bot.restrict_chat_member( chat.id, int(user_id), permissions=ChatPermissions( 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 ban(update, context): currentchat = update.effective_chat # type: Optional[Chat] 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, reason = extract_user_and_text(message, args) if user_id == "error": send_message(update.effective_message, tl(update.effective_message, reason)) 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 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, "I can not restrict people on {}! Make sure that I am the admin and can appoint a new admin." ).format(chat_name) else: text = tl( update.effective_message, "I can not restrict people here! Make sure that I am the admin and can appoint a new admin." ) send_message(update.effective_message, text, parse_mode="markdown") return "" if not user_id: send_message( update.effective_message, tl(update.effective_message, "You don't seem to be referring to a user.")) return "" try: if conn: member = context.bot.getChatMember(chat_id, user_id) else: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": if conn: text = tl( update.effective_message, "I can not find this user in *{}* π£").format(chat_name) else: text = tl(update.effective_message, "I can not find this user π£") send_message(update.effective_message, text, parse_mode="markdown") return "" else: raise if user_id == context.bot.id: send_message( update.effective_message, tl(update.effective_message, "Saya tidak akan BAN diri saya sendiri, apakah kamu gila? π ")) return "" if is_user_ban_protected(chat, user_id, member): send_message( update.effective_message, tl(update.effective_message, "Saya tidak bisa banned orang ini karena dia adalah admin π")) return "" if member['can_restrict_members'] == False: if conn: text = tl( update.effective_message, "Anda tidak punya hak untuk membatasi seseorang pada *{}*." ).format(chat_name) else: text = tl(update.effective_message, "Anda tidak punya hak untuk membatasi seseorang.") send_message(update.effective_message, text, parse_mode="markdown") return "" log = "<b>{}:</b>" \ "\n#BANNED" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), member.user.id) if reason: log += "\n<b>Reason:</b> {}".format(reason) try: if conn: context.bot.kickChatMember(chat_id, user_id) context.bot.send_sticker(currentchat.id, BAN_STICKER) # banhammer marie sticker send_message(update.effective_message, tl(update.effective_message, "Banned on *{}*! π").format(chat_name), parse_mode="markdown") else: chat.kick_member(user_id) if message.text.split(None, 1)[0][1:] == "sban": update.effective_message.delete() else: context.bot.send_sticker( chat.id, BAN_STICKER) # banhammer marie sticker send_message(update.effective_message, tl(update.effective_message, "Banned! π")) return log except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply send_message(update.effective_message, tl(update.effective_message, "Banned! π"), quote=False) return log elif excp.message == "Message can't be deleted": pass else: LOGGER.warning(update) LOGGER.exception("ERROR banning user %s in chat %s (%s) due to %s", user_id, chat.title, chat.id, excp.message) send_message( update.effective_message, tl(update.effective_message, "Well damn, I can't ban that User. π")) 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 kick(update, context): currentchat = update.effective_chat # type: Optional[Chat] 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, 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 "" 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': if conn: text = tl( update.effective_message, "Saya tidak bisa membatasi orang di {}! Pastikan saya admin dan dapat menunjuk admin baru." ).format(chat_name) else: text = tl( update.effective_message, "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru." ) send_message(update.effective_message, text, parse_mode="markdown") return "" else: if check['can_restrict_members'] == False: if conn: text = tl( update.effective_message, "Saya tidak bisa membatasi orang di *{}*! Pastikan saya admin dan dapat menunjuk admin baru." ).format(chat_name) else: text = tl( update.effective_message, "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru." ) send_message(update.effective_message, text, parse_mode="markdown") return "" if not user_id: return "" try: if conn: member = context.bot.getChatMember(chat_id, user_id) else: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": send_message( update.effective_message, tl(update.effective_message, "I can not find this user π£")) return "" else: raise if user_id == context.bot.id: send_message( update.effective_message, tl(update.effective_message, "I'm not going to kick myself, are you crazy? π ")) return "" if is_user_ban_protected(chat, user_id): send_message( update.effective_message, tl(update.effective_message, "I can not kick this guy because he is admin")) return "" if user_id == context.bot.id: send_message(update.effective_message, tl(update.effective_message, "Yahhh I will not do it π")) return "" check = context.bot.getChatMember(chat.id, user.id) if check['can_restrict_members'] == False: send_message( update.effective_message, tl(update.effective_message, "You have no right to restrict a person.")) return "" if conn: res = context.bot.unbanChatMember( chat_id, user_id) # unban on current user = kick else: res = chat.unban_member(user_id) # unban on current user = kick if res: if conn: context.bot.send_sticker(currentchat.id, BAN_STICKER) # banhammer marie sticker text = tl(update.effective_message, "Kicked in *{}*! π").format(chat_name) send_message(update.effective_message, text, parse_mode="markdown") else: if message.text.split(None, 1)[0][1:] == "skick": update.effective_message.delete() else: context.bot.send_sticker( chat.id, BAN_STICKER) # banhammer marie sticker text = tl(update.effective_message, "Kicked! π") send_message(update.effective_message, text, parse_mode="markdown") log = "<b>{}:</b>" \ "\n#KICKED" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), member.user.id) log += "\n<b>Reason:</b> {}".format(reason) return log else: send_message( update.effective_message, tl(update.effective_message, "Yah sial, aku tidak bisa menendang pengguna itu π")) return ""
def set_warn_strength(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 chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] msg = update.effective_message # type: Optional[Message] 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 if args: if args[0].lower() in ("on", "yes"): sql.set_warn_strength(chat.id, False) if conn: text = "Terlalu banyak peringatan sekarang akan menghasilkan blokir pada *{}*!".format(chat_name) else: text = "Terlalu banyak peringatan sekarang akan menghasilkan blokir!" msg.reply_text(text, parse_mode="markdown") return "<b>{}:</b>\n" \ "<b>Admin:</b> {}\n" \ "Telah mengaktifkan peringatan yang kuat. Pengguna akan diblokir.".format(html.escape(chat.title), mention_html(user.id, user.first_name)) elif args[0].lower() in ("off", "no"): sql.set_warn_strength(chat.id, True) if conn: text = "Terlalu banyak peringatan akan menghasilkan tendangan pada *{}*! Pengguna akan dapat bergabung lagi.".format(chat_name) else: text = "Terlalu banyak peringatan akan menghasilkan tendangan! Pengguna akan dapat bergabung lagi." msg.reply_text(text, parse_mode="markdown") return "<b>{}:</b>\n" \ "<b>Admin:</b> {}\n" \ "Telah menonaktifkan peringatan kuat. Pengguna hanya akan ditendang.".format(html.escape(chat.title), mention_html(user.id, user.first_name)) else: msg.reply_text("Saya hanya mengerti on/yes/no/off!") else: limit, soft_warn, warn_mode = sql.get_warn_setting(chat.id) if soft_warn: if conn: text = "Peringatan saat ini disetel ke *tendangan* pengguna saat melampaui batas pada *{}*.".format(chat_name) else: text = "Peringatan saat ini disetel ke *tendangan* pengguna saat melampaui batas." msg.reply_text(text, parse_mode=ParseMode.MARKDOWN) else: if conn: text = "Peringatan saat ini disetel untuk *diblokir* pengguna saat melampaui batas pada *{}*.".format(chat_name) else: text = "Peringatan saat ini disetel untuk *diblokir* pengguna saat melampaui batas." msg.reply_text(text, parse_mode=ParseMode.MARKDOWN) return ""
def unlock(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] if is_user_admin(chat, message.from_user.id): if len(args) >= 1: if args[0] in LOCK_TYPES: # Connection check conn = connected(bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = chat.title text = tl( update.effective_message, "Tidak terkunci *{}* untuk semua orang pada *{}*!" ).format(args[0], chat_name) 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 text = tl(update.effective_message, "Tidak terkunci *{}* untuk semua orang!").format( args[0]) sql.update_lock(chat.id, args[0], locked=False) send_message(update.effective_message, text, parse_mode="markdown") return "<b>{}:</b>" \ "\n#UNLOCK" \ "\n<b>Admin:</b> {}" \ "\nUnlocked <code>{}</code>.".format(html.escape(chat.title), mention_html(user.id, user.first_name), args[0]) elif args[0] in RESTRICTION_TYPES: # Connection check conn = connected(bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = chat.title text = tl( update.effective_message, "Tidak terkunci *{}* untuk semua orang pada *{}*!" ).format(args[0], chat_name) 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 text = tl(update.effective_message, "Tidak terkunci *{}* untuk semua orang!").format( args[0]) sql.update_restriction(chat.id, args[0], locked=False) """ members = users_sql.get_chat_members(chat.id) if args[0] == "messages": unrestr_members(bot, chat.id, members, media=False, other=False, previews=False) elif args[0] == "media": unrestr_members(bot, chat.id, members, other=False, previews=False) elif args[0] == "other": unrestr_members(bot, chat.id, members, previews=False) elif args[0] == "previews": unrestr_members(bot, chat.id, members) elif args[0] == "all": unrestr_members(bot, chat.id, members, True, True, True, True) """ send_message(update.effective_message, text, parse_mode="markdown") return "<b>{}:</b>" \ "\n#UNLOCK" \ "\n<b>Admin:</b> {}" \ "\nUnlocked <code>{}</code>.".format(html.escape(chat.title), mention_html(user.id, user.first_name), args[0]) else: send_message( update.effective_message, tl( update.effective_message, "Apa yang Anda coba untuk membuka kunci...? Coba /locktypes untuk daftar kunci yang dapat dikunci" )) else: send_message( update.effective_message, tl(update.effective_message, "Apa yang Anda coba untuk buka kunci...?")) return ""