def add_blacklist(update, context): 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) conn = connected(context.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_blacklist = list(set(trigger.strip() for trigger in text.split("\n") if trigger.strip())) for trigger in to_blacklist: sql.add_to_blacklist(chat_id, trigger.lower()) if len(to_blacklist) == 1: send_message(update.effective_message, tl(update.effective_message, "<code>{}</code> ditambahkan ke daftar hitam di <b>{}</b>!").format(html.escape(to_blacklist[0]), chat_name), parse_mode=ParseMode.HTML) else: send_message(update.effective_message, tl(update.effective_message, "<code>{}</code> Pemicu ditambahkan ke daftar hitam di <b>{}</b>!").format(len(to_blacklist), chat_name), parse_mode=ParseMode.HTML) else: send_message(update.effective_message, tl(update.effective_message, "Beri tahu saya kata-kata apa yang ingin Anda hapus dari daftar hitam."))
def clear_rules(update, context): chat = update.effective_chat chat_id = update.effective_chat.id user = update.effective_user 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 chat_id = update.effective_chat.id sql.set_rules(chat_id, "") send_message(update.effective_message, tl(update.effective_message, "Berhasil membersihkan aturan!"))
def permapin(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 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 text, data_type, content, buttons = get_message_type(message) tombol = build_keyboard_alternate(buttons) try: message.delete() except BadRequest: pass if str(data_type) in ('Types.BUTTON_TEXT', 'Types.TEXT'): try: sendingmsg = context.bot.send_message( chat_id, text, parse_mode="markdown", disable_web_page_preview=True, reply_markup=InlineKeyboardMarkup(tombol)) except BadRequest: context.bot.send_message( chat_id, tl( update.effective_message, "Teks markdown salah!\nJika anda tidak tahu apa itu markdown, silahkan ketik `/markdownhelp` pada PM." ), parse_mode="markdown") return else: sendingmsg = ENUM_FUNC_MAP[str(data_type)]( chat_id, content, caption=text, parse_mode="markdown", disable_web_page_preview=True, reply_markup=InlineKeyboardMarkup(tombol)) try: context.bot.pinChatMessage(chat_id, sendingmsg.message_id) except BadRequest: send_message( update.effective_message, tl(update.effective_message, "Saya tidak punya akses untuk pin pesan!"))
def commands(update, context): chat = update.effective_chat user = update.effective_user 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, languages.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 = build_curr_disabled(chat.id) send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN)
def clear(update, context): args = context.args chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] msg = update.effective_message conn = connected(context.bot, update, chat, user.id) note_name, text, data_type, content, buttons = get_note_type(msg) if user_can_changeinfo(chat, user, context.bot.id) is False: msg.reply_text("You don't have enough rights to Remove Notes !") return "" 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 = "local notes" else: chat_name = chat.title if len(args) >= 1: notename = args[0].lower() if sql.rm_note(chat_id, notename): update.effective_message.reply_text( "Successfully deleted '`{note_name}`' from {chat_name}!". format(note_name=note_name, chat_name=chat_name), parse_mode=ParseMode.MARKDOWN, ) else: update.effective_message.reply_text( "There is no such notes saved in {chat_name}!".format( chat_name=chat_name))
def invite(update, context): user = update.effective_user msg = update.effective_message chat = update.effective_chat args = context.args conn = connected(context.bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) else: if msg.chat.type == "private": msg.reply_text("This command is meant to use in chat not in PM") return "" chat = update.effective_chat if chat.username: msg.reply_text(chat.username) elif chat.type == chat.SUPERGROUP or chat.type == chat.CHANNEL: bot_member = chat.get_member(context.bot.id) if bot_member.can_invite_users: invitelink = context.bot.exportChatInviteLink(chat.id) msg.reply_text(invitelink) else: msg.reply_text( "I don't have access to the invite link, try changing my permissions!" ) else: msg.reply_text( "I can only give you invite links for supergroups and channels, sorry!" )
def disable(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_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, languages.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 len(args) >= 1: disable_cmd = args[0] if disable_cmd.startswith(CMD_STARTERS): disable_cmd = disable_cmd[1:] if disable_cmd in set(DISABLE_CMDS + DISABLE_OTHER): sql.disable_command(chat.id, disable_cmd) if conn: text = languages.tl( update.effective_message, "Menonaktifkan penggunaan `{}` pada *{}*").format( disable_cmd, chat_name) else: text = languages.tl( update.effective_message, "Menonaktifkan penggunaan `{}`").format(disable_cmd) send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN) else: send_message( update.effective_message, languages.tl(update.effective_message, "Perintah itu tidak bisa dinonaktifkan")) else: send_message( update.effective_message, languages.tl(update.effective_message, "Apa yang harus saya nonaktifkan?"))
def list_notes(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(context.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 unblacklist(update, context): 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) conn = connected(context.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: send_message(update.effective_message, tl(update.effective_message, "<code>{}</code> dihapus dari daftar hitam di <b>{}</b>!").format(html.escape(to_unblacklist[0]), chat_name), parse_mode=ParseMode.HTML) else: send_message(update.effective_message, "Ini bukan pemicu daftar hitam...!") elif successful == len(to_unblacklist): send_message(update.effective_message, tl(update.effective_message, "<code>{}</code> Pemicu dihapus dari daftar hitam di <b>{}</b>!").format( successful, chat_name), parse_mode=ParseMode.HTML) elif not successful: send_message(update.effective_message, tl(update.effective_message, "Tidak satu pun pemicu ini ada, sehingga tidak dapat dihapus.").format( successful, len(to_unblacklist) - successful), parse_mode=ParseMode.HTML) else: send_message(update.effective_message, tl(update.effective_message, "Pemicu <code>{}</code> dihapus dari daftar hitam. {} Tidak ada, " "jadi tidak dihapus.").format(successful, len(to_unblacklist) - successful), parse_mode=ParseMode.HTML) else: send_message(update.effective_message, tl(update.effective_message, "Beri tahu saya kata-kata apa yang ingin Anda hapus dari daftar hitam."))
def save(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(context.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 stop_filter(update, context): chat = update.effective_chat user = update.effective_user args = update.effective_message.text.split msg = update.effective_message args = msg.text.split(None, 1) 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 = "Local filters" else: chat_name = chat.title if len(args) < 2: send_message(update.effective_message, "What should i stop?") return chat_filters = sql.get_chat_triggers(chat_id) if user_can_changeinfo(chat, user, context.bot.id) is False: msg.reply_text("You don't have enough rights to Remove Filters !") return "" if not chat_filters: send_message(update.effective_message, "No filters active here!") return for keyword in chat_filters: if keyword == args[1]: sql.remove_filter(chat_id, args[1]) send_message( update.effective_message, "Okay, I'll stop replying to that filter in *{}*.".format( chat_name), parse_mode=telegram.ParseMode.MARKDOWN, ) raise DispatcherHandlerStop send_message( update.effective_message, "That's not a filter - Click: /filters to get currently active filters.", )
def private_rules(update, context): args = context.args chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(context.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"): sql.private_rules(str(chat_id), True) send_message( update.effective_message, tl( update.effective_message, "Private Rules di *aktifkan*, pesan peraturan akan di kirim di PM." ), parse_mode="markdown") elif args[0] in ("no", "off"): sql.private_rules(str(chat_id), False) send_message( update.effective_message, tl( update.effective_message, "Private Rules di *non-aktifkan*, pesan peraturan 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 = sql.get_private_rules(chat_id) send_message(update.effective_message, tl(update.effective_message, "Pengaturan Private Rules di {}: *{}*").format( chat_name, "Enabled" if is_private else "Disabled"), parse_mode="markdown")
def add_blacklist(update, context): msg = update.effective_message chat = update.effective_chat user = update.effective_user words = msg.text.split(None, 1) conn = connected(context.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_blacklist = list( set(trigger.strip() for trigger in text.split("\n") if trigger.strip())) for trigger in to_blacklist: sql.add_to_blacklist(chat_id, trigger.lower()) if len(to_blacklist) == 1: send_message( update.effective_message, "Added blacklist <code>{}</code> in chat: <b>{}</b>!".format( html.escape(to_blacklist[0]), chat_name), parse_mode=ParseMode.HTML, ) else: send_message( update.effective_message, "Added blacklist trigger: <code>{}</code> in <b>{}</b>!". format(len(to_blacklist), chat_name), parse_mode=ParseMode.HTML, ) else: send_message( update.effective_message, "Tell me which words you would like to add in blacklist.", )
def blackliststicker(update, context): msg = 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=False) if conn: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: if chat.type == "private": return else: chat_id = update.effective_chat.id chat_name = chat.title sticker_list = tl( update.effective_message, "<b>Daftar hitam stiker saat saat ini di {}:</b>\n").format(chat_name) all_stickerlist = sql.get_chat_stickers(chat_id) if len(args) > 0 and args[0].lower() == 'copy': for trigger in all_stickerlist: sticker_list += "<code>{}</code>\n".format(html.escape(trigger)) elif len(args) == 0: for trigger in all_stickerlist: sticker_list += " - <code>{}</code>\n".format(html.escape(trigger)) split_text = split_message(sticker_list) for text in split_text: if sticker_list == tl( update.effective_message, "<b>Daftar hitam stiker saat saat ini di {}:</b>\n").format( chat_name).format(chat_name): send_message( update.effective_message, tl(update.effective_message, "Tidak ada stiker daftar hitam stiker di <b>{}</b>!"). format(chat_name), parse_mode=ParseMode.HTML) return send_message(update.effective_message, text, parse_mode=ParseMode.HTML)
def stop_filter(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] args = update.effective_message.text.split(None, 1) 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 len(args) < 2: send_message( update.effective_message, tl(update.effective_message, "Apa yang harus saya hentikan?")) return chat_filters = sql.get_chat_triggers(chat_id) if not chat_filters: send_message( update.effective_message, tl(update.effective_message, "Tidak ada filter aktif di sini!")) return for keyword in chat_filters: if keyword == args[1]: sql.remove_filter(chat_id, args[1]) send_message( update.effective_message, tl(update.effective_message, "Ya, saya akan berhenti menjawabnya di *{}*.").format( chat_name), parse_mode=telegram.ParseMode.MARKDOWN) raise DispatcherHandlerStop send_message( update.effective_message, "Itu bukan filter aktif - jalankan /filter untuk semua filter aktif.")
def flood(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(context.bot, update, chat, user.id, need_admin=False) if conn: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: if 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 limit = sql.get_flood_limit(chat_id) if limit == 0: if conn: text = tl( update.effective_message, "Saat ini saya tidak memberlakukan pengendalian pesan beruntun pada *{}*!" ).format(chat_name) else: text = tl( update.effective_message, "Saat ini saya tidak memberlakukan pengendalian pesan beruntun" ) send_message(update.effective_message, text, parse_mode="markdown") else: if conn: text = tl( update.effective_message, "Saat ini saya melarang pengguna jika mereka mengirim lebih dari *{}* pesan berturut-turut pada *{}*." ).format(limit, chat_name) else: text = tl( update.effective_message, "Saat ini saya melarang pengguna jika mereka mengirim lebih dari *{}* pesan berturut-turut." ).format(limit) send_message(update.effective_message, text, parse_mode="markdown")
def list_handlers(update, context): chat = update.effective_chat user = update.effective_user conn = connected(context.bot, update, chat, user.id, need_admin=False) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title filter_list = "*Filter in {}:*\n" else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "Local filters" filter_list = "*local filters:*\n" else: chat_name = chat.title filter_list = "*Filters in {}*:\n" all_handlers = sql.get_chat_triggers(chat_id) if not all_handlers: send_message(update.effective_message, "No filters saved in {}!".format(chat_name)) return for keyword in all_handlers: entry = " ✗ `{}`\n".format(escape_markdown(keyword)) if len(entry) + len(filter_list) > telegram.MAX_MESSAGE_LENGTH: send_message( update.effective_message, filter_list.format(chat_name), parse_mode=telegram.ParseMode.MARKDOWN, ) filter_list = entry else: filter_list += entry send_message( update.effective_message, filter_list.format(chat_name), parse_mode=telegram.ParseMode.MARKDOWN, )
def invite(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=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 chat.username: send_message(update.effective_message, chat.username) elif chat.type == chat.SUPERGROUP or chat.type == chat.CHANNEL: bot_member = chat.get_member(context.bot.id) if bot_member.can_invite_users: invitelink = context.bot.exportChatInviteLink(chat.id) send_message(update.effective_message, invitelink) else: send_message( update.effective_message, tl( update.effective_message, "Saya tidak memiliki akses ke tautan undangan, coba ubah izin saya!" )) else: send_message( update.effective_message, tl( update.effective_message, "Saya hanya dapat memberi Anda tautan undangan untuk supergroup dan saluran, maaf!" ))
def flood(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] msg = update.effective_message conn = connected(context.bot, update, chat, user.id, need_admin=False) if conn: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: if update.effective_message.chat.type == "private": send_message( update.effective_message, "This command is meant to use in group not in PM", ) return chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title limit = sql.get_flood_limit(chat_id) if limit == 0: if conn: text = msg.reply_text( "I'm not enforcing any flood control in {}!".format(chat_name) ) else: text = msg.reply_text("I'm not enforcing any flood control here!") send_message(update.effective_message, text, parse_mode="markdown") else: if conn: text = msg.reply_text( "I'm currently restricting members after {} consecutive messages in {}.".format( limit, chat_name ) ) else: text = msg.reply_text( "I'm currently restricting members after {} consecutive messages.".format( limit ) ) send_message(update.effective_message, text, parse_mode="markdown")
def save(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] 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 = "local notes" else: chat_name = chat.title msg = update.effective_message note_name, text, data_type, content, buttons = get_note_type(msg) note_name = note_name.lower() if user_can_changeinfo(chat, user, context.bot.id) is False: msg.reply_text("You don't have enough rights to Add Notes !") return "" if data_type is None: msg.reply_text("Bruh! there's no note") 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) msg.reply_text( "Saved '`{note_name}`' in *{chat_name}*.\nGet it with `/get {note_name}`, or `#{note_name}`!" .format(note_name=note_name, chat_name=chat_name), parse_mode=ParseMode.MARKDOWN, )
def blacklist(update, context): chat = update.effective_chat user = update.effective_user args = context.args conn = connected(context.bot, update, chat, user.id, need_admin=False) if conn: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: if chat.type == "private": return else: chat_id = update.effective_chat.id chat_name = chat.title filter_list = "Current blacklisted words in <b>{}</b>:\n".format(chat_name) all_blacklisted = sql.get_chat_blacklist(chat_id) if len(args) > 0 and args[0].lower() == "copy": for trigger in all_blacklisted: filter_list += "<code>{}</code>\n".format(html.escape(trigger)) else: for trigger in all_blacklisted: filter_list += " - <code>{}</code>\n".format(html.escape(trigger)) # for trigger in all_blacklisted: # filter_list += " - <code>{}</code>\n".format(html.escape(trigger)) split_text = split_message(filter_list) for text in split_text: if filter_list == "Current blacklisted words in <b>{}</b>:\n".format( chat_name): send_message( update.effective_message, "No blacklisted words in <b>{}</b>!".format(chat_name), parse_mode=ParseMode.HTML, ) return send_message(update.effective_message, text, parse_mode=ParseMode.HTML)
def list_handlers(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(context.bot, update, chat, user.id, need_admin=False) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title filter_list = "*Filter di {}:*\n" else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = tl(update.effective_message, "filter lokal") filter_list = tl(update.effective_message, "*filter lokal:*\n") else: chat_name = chat.title filter_list = tl(update.effective_message, "*Filter di {}*:\n") all_handlers = sql.get_chat_triggers(chat_id) if not all_handlers: send_message( update.effective_message, tl(update.effective_message, "Tidak ada filter di {}!").format(chat_name)) return for keyword in all_handlers: entry = " - {}\n".format(escape_markdown(keyword)) if len(entry) + len(filter_list) > telegram.MAX_MESSAGE_LENGTH: send_message(update.effective_message, filter_list.format(chat_name), parse_mode=telegram.ParseMode.MARKDOWN) filter_list = entry else: filter_list += entry send_message(update.effective_message, filter_list.format(chat_name), parse_mode=telegram.ParseMode.MARKDOWN)
def list_notes(update, context): chat_id = update.effective_chat.id chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(context.bot, update, chat, user.id, need_admin=False) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title msg = "*Notes in {}:*\n" else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "" msg = "*Local Notes:*\n" else: chat_name = chat.title msg = "*Notes saved in {}:*\n" note_list = sql.get_all_chat_notes(chat_id) des = "You can get notes by using `/get notename`, or `#notename`.\n" for note in note_list: note_name = " ✗ `{}`\n".format(note.name.lower()) if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name if not note_list: update.effective_message.reply_text("No notes saved here!") elif len(msg) != 0: try: update.effective_message.reply_text(msg.format(chat_name) + des, parse_mode=ParseMode.MARKDOWN) except ValueError: update.effective_message.reply_text( "There was a problem in showing notes list, maybe due to some invalid character in note names. Ask in @MeikoSupport if you're unable to figure it out!" )
def set_blue_text_must_click(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 conn = connected(context.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": sql.set_cleanbt(chat_id, False) if conn: text = tl(update.effective_message, "Penghapus pesan biru telah di *non-aktifka*n di *{}*.").format(chat_name) else: text = tl(update.effective_message, "Penghapus pesan biru telah di *non-aktifkan*.") send_message(update.effective_message, text, parse_mode="markdown") elif val == "yes" or val == "ya" or val == "on": sql.set_cleanbt(chat_id, True) if conn: text = tl(update.effective_message, "Penghapus pesan biru telah di *aktifkan* di *{}*.").format(chat_name) else: text = tl(update.effective_message, "Penghapus pesan biru telah di *aktifkan*.") send_message(update.effective_message, text, parse_mode="markdown") else: send_message(update.effective_message, tl(update.effective_message, "Argumen tidak dikenal - harap gunakan 'yes', atau 'no'.")) else: send_message(update.effective_message, tl(update.effective_message, "Pengaturan untuk penghapus pesan biru saat ini di {}: *{}*").format(chat_name, "Enabled" if sql.is_enable(chat_id) else "Disabled"), parse_mode="markdown")
def unpin(update, context): chat = update.effective_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 try: context.bot.unpinChatMessage(chat.id) if conn: send_message( update.effective_message, tl(update.effective_message, "Saya sudah unpin pesan dalam grup {}").format(chat_name)) except BadRequest as excp: if excp.message == "Chat_not_modified": pass else: raise return "<b>{}:</b>" \ "\n#UNPINNED" \ "\n<b>Admin:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name))
def private_note(update, context): args = context.args chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(context.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 list_locks(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # Connection check conn = connected(context.bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_name = chat.title else: if update.effective_message.chat.type == "private": send_message( update.effective_message, "This command is meant to use in group not in PM", ) return "" chat = update.effective_chat chat_name = update.effective_message.chat.title res = build_lock_message(chat.id) if conn: res = res.replace("Locks in", "*{}*".format(chat_name)) send_message(update.effective_message, res, parse_mode=ParseMode.MARKDOWN)
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 send_rules(update, chat_id, from_pm=False): bot = dispatcher.bot user = update.effective_user # type: Optional[User] try: chat = bot.get_chat(chat_id) except BadRequest as excp: if excp.message == "Chat not found" and from_pm: bot.send_message( user.id, tl( update.effective_message, "Pintasan aturan untuk obrolan ini belum diatur dengan benar! Mintalah admin untuk " "perbaiki ini.")) return else: raise conn = connected(bot, update, chat, user.id, need_admin=False) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = dispatcher.bot.getChat(conn).title rules, buttons = button_markdown_parser(sql.get_rules(chat_id)) try: text = tl(update.effective_message, "Peraturan untuk *{}* adalah:\n\n{}").format( escape_markdown(chat.title), rules) except TypeError: send_message( update.effective_message, tl(update.effective_message, "Anda bisa lakukan command ini pada grup, bukan pada PM")) return "" is_private = sql.get_private_rules(chat_id) if from_pm and rules: bot.send_message(user.id, text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( build_keyboard_alternate(buttons))) elif from_pm: if conn: bot.send_message( user.id, tl( update.effective_message, "Admin grup belum menetapkan aturan apa pun untuk *{}*. " "Bukan berarti obrolan ini tanpa hukum...!").format( chat_name), parse_mode="markdown") else: bot.send_message( user.id, tl( update.effective_message, "Admin grup belum menetapkan aturan apa pun untuk obrolan ini. " "Bukan berarti obrolan ini tanpa hukum...!")) elif rules: if (update.effective_message.chat.type == "private" or not is_private) and rules: if not is_private: send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( build_keyboard_alternate(buttons))) else: bot.send_message(user.id, text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( build_keyboard_alternate(buttons))) else: send_message( update.effective_message, tl(update.effective_message, "Hubungi saya di PM untuk mendapatkan aturan grup ini"), reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton(text=tl(update.effective_message, "Peraturan"), url="t.me/{}?start={}".format( bot.username, chat_id)) ]])) else: if conn: send_message( update.effective_message, tl( update.effective_message, "Admin grup belum menetapkan aturan apa pun untuk *{}*. " "Bukan berarti obrolan ini tanpa hukum...!").format( chat_name), parse_mode="markdown") else: send_message( update.effective_message, tl( update.effective_message, "Admin grup belum menetapkan aturan apa pun untuk obrolan ini. " "Bukan berarti obrolan ini tanpa hukum...!"))
def set_rules(update, context): chat = update.effective_chat chat_id = update.effective_chat.id user = update.effective_user msg = update.effective_message # type: Optional[Message] raw_text = msg.text args = raw_text.split(None, 1) # use python's maxsplit to separate cmd and 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 if len(args) == 2: txt = args[1] offset = len(txt) - len( raw_text) # set correct offset relative to command markdown_rules = markdown_parser(txt, entities=msg.parse_entities(), offset=offset) sql.set_rules(chat_id, markdown_rules) if conn: send_message( update.effective_message, tl(update.effective_message, "Berhasil mengatur aturan untuk *{}*.").format(chat_name), parse_mode="markdown") else: send_message( update.effective_message, tl(update.effective_message, "Berhasil mengatur aturan untuk grup ini.")) elif msg.reply_to_message and len(args) == 1: txt = msg.reply_to_message.text offset = len(txt) - len( raw_text) # set correct offset relative to command markdown_rules = markdown_parser(txt, entities=msg.parse_entities(), offset=offset) sql.set_rules(chat_id, markdown_rules) if conn: send_message( update.effective_message, tl(update.effective_message, "Berhasil mengatur aturan untuk *{}*.").format(chat_name), parse_mode="markdown") else: send_message( update.effective_message, tl(update.effective_message, "Berhasil mengatur aturan untuk grup ini."))