def list_handlers(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id) 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, 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 = "filter lokal" filter_list = "*filter lokal:*\n" else: chat_name = chat.title filter_list = "*Filter di {}*:\n" all_handlers = sql.get_chat_triggers(chat_id) if not all_handlers: update.effective_message.reply_text( "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: update.effective_message.reply_text( filter_list.format(chat_name), parse_mode=telegram.ParseMode.MARKDOWN) filter_list = entry else: filter_list += entry update.effective_message.reply_text(filter_list.format(chat_name), parse_mode=telegram.ParseMode.MARKDOWN)
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 = "*Catatan di {}:*\n".format(chat_name) else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "" msg = "*Catatan lokal:*\n" else: chat_name = chat.title msg = "*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: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name if msg == "*Catatan di {}:*\n".format( chat_name) or msg == "*Catatan Lokal:*\n": if conn: update.effective_message.reply_text( "Tidak ada catatan di obrolan *{}*!".format(chat_name), parse_mode="markdown") else: update.effective_message.reply_text( "Tidak ada catatan di obrolan ini!") elif len(msg) != 0: msg += "\nAnda dapat mengambil catatan ini dengan menggunakan `/get notename`, atau `#notename`" update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN)
def report_alt(bot: Bot, update: Update) -> str: spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] if chat and message.reply_to_message and sql.chat_should_report(chat.id): reported_user = message.reply_to_message.from_user # type: Optional[User] chat_name = chat.title or chat.first or chat.username admin_list = chat.get_administrators() msg = tl(update.effective_message, "<b>{}:</b>" \ "\n<b>Pengguna yang dilaporkan:</b> {} (<code>{}</code>)" \ "\n<b>Dilaporkan oleh:</b> {} (<code>{}</code>)").format(html.escape(chat.title), mention_html( reported_user.id, reported_user.first_name), reported_user.id, mention_html(user.id, user.first_name), user.id) all_admins = [] for admin in admin_list: if admin.user.is_bot: # don't tag bot continue if sql.user_should_report(admin.user.id): all_admins.append("<a href='tg://user?id={}'></a>".format( admin.user.id)) bot.send_message( chat.id, tl(update.effective_message, "⚠️ {} <b>telah di laporkan ke admin!</b>{}").format( mention_html(reported_user.id, reported_user.first_name), "".join(all_admins)), parse_mode=ParseMode.HTML, reply_to_message_id=message.reply_to_message.message_id) return msg return ""
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 += "{}, ".format(notename) else: catatangagal += "{}, ".format(notename) if catatan != "" and catatangagal == "": update.effective_message.reply_text( "Catatan di *{}* untuk {}berhasil dihapus 😁".format( chat_name, catatan), parse_mode=ParseMode.MARKDOWN) elif catatangagal != "" and catatan == "": update.effective_message.reply_text( "Catatan di *{}* untuk {}gagal dihapus!".format( chat_name, catatangagal), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text( "Catatan di *{}* untuk {}berhasil dihapus 😁\nCatatan {}gagal dihapus!" .format(chat_name, catatan, catatangagal), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text("Apa yang ingin dihapus?")
def enable(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user 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, 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 len(args) >= 1: enable_cmd = args[0] if enable_cmd.startswith(CMD_STARTERS): enable_cmd = enable_cmd[1:] if sql.enable_command(chat.id, enable_cmd): if conn: text = "Diaktifkan penggunaan `{}` pada *{}*".format( enable_cmd, chat_name) else: text = "Diaktifkan penggunaan `{}`".format(enable_cmd) update.effective_message.reply_text( text, parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text( "Apakah itu bahkan dinonaktifkan?") else: update.effective_message.reply_text( "Apa yang harus saya aktifkan?")
def add_url(bot, update, args): spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return if len(args) >= 1: chat = update.effective_chat tg_chat_id = str(update.effective_chat.id) tg_feed_link = args[0] link_processed = parse(tg_feed_link) # check if link is a valid RSS Feed link if link_processed.bozo == 0: if len(link_processed.entries[0]) >= 1: tg_old_entry_link = link_processed.entries[0].link else: tg_old_entry_link = "" # gather the row which contains exactly that telegram group ID and link for later comparison row = sql.check_url_availability(tg_chat_id, tg_feed_link) # check if there's an entry already added to DB by the same user in the same group with the same link if row: send_message( update.effective_message, tl(update.effective_message, "URL ini sudah ditambahkan")) else: sql.add_url(tg_chat_id, tg_feed_link, tg_old_entry_link) send_message( update.effective_message, tl(update.effective_message, "URL ditambahkan ke langganan")) else: send_message( update.effective_message, tl(update.effective_message, "Tautan ini bukan tautan Umpan RSS")) else: send_message(update.effective_message, tl(update.effective_message, "URL hilang"))
def slap(bot: Bot, update: Update, args: List[str]): spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return msg = update.effective_message # type: Optional[Message] # reply to correct message reply_text = msg.reply_to_message.reply_text if msg.reply_to_message else msg.reply_text # get user who sent message #if msg.from_user.username: # curr_user = "******" + escape_markdown(msg.from_user.username) #else: curr_user = "******".format( mention_markdown(msg.from_user.id, msg.from_user.first_name)) user_id = extract_user(update.effective_message, args) if user_id: slapped_user = bot.get_chat(user_id) user1 = curr_user #if slapped_user.username: # user2 = "@" + escape_markdown(slapped_user.username) #else: user2 = "{}".format( mention_markdown(slapped_user.id, slapped_user.first_name)) # if no target found, bot targets the sender else: user1 = "{}".format(mention_markdown(bot.id, bot.first_name)) user2 = curr_user temp = random.choice(tl(update.effective_message, "SLAP_TEMPLATES")) item = random.choice(tl(update.effective_message, "ITEMS")) hit = random.choice(tl(update.effective_message, "HIT")) throw = random.choice(tl(update.effective_message, "THROW")) repl = temp.format(user1=user1, user2=user2, item=item, hits=hit, throws=throw) send_message(update.effective_message, repl, parse_mode=ParseMode.MARKDOWN)
def afk(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 args = update.effective_message.text.split(None, 1) if len(args) >= 2: reason = args[1] else: reason = "" sql.set_afk(update.effective_user.id, reason) send_message( update.effective_message, tl(update.effective_message, "{} sekarang AFK!").format(update.effective_user.first_name))
def unsetlog(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 message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] log_channel = sql.stop_chat_logging(chat.id) if log_channel: bot.send_message( log_channel, "Channel telah dibatalkan tautannya {}".format(chat.title)) message.reply_text("Log saluran telah dinonaktifkan.") else: message.reply_text("Belum ada saluran log yang ditetapkan!")
def afk(bot: Bot, update: Update): 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!" ) args = update.effective_message.text.split(None, 1) if len(args) >= 2: reason = args[1] else: reason = "" sql.set_afk(update.effective_user.id, reason) update.effective_message.reply_text("{} sekarang AFK!".format( update.effective_user.first_name))
def stop_filter(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] args = update.effective_message.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 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) < 2: return chat_filters = sql.get_chat_triggers(chat_id) if not chat_filters: update.effective_message.reply_text("Tidak ada filter aktif di sini!") return for keyword in chat_filters: if keyword == args[1]: sql.remove_filter(chat_id, args[1]) update.effective_message.reply_text( "Ya, saya akan berhenti menjawabnya di *{}*.".format( chat_name), parse_mode=telegram.ParseMode.MARKDOWN) raise DispatcherHandlerStop update.effective_message.reply_text( "Itu bukan filter aktif - jalankan /filter untuk semua filter aktif.")
def disable(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return conn = connected(bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: if update.effective_message.chat.type == "private": update.effective_message.reply_text( "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 = "Menonaktifkan penggunaan `{}` pada *{}*".format( disable_cmd, chat_name) else: text = "Menonaktifkan penggunaan `{}`".format(disable_cmd) update.effective_message.reply_text( text, parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text( "Perintah itu tidak bisa dinonaktifkan") else: update.effective_message.reply_text( "Apa yang harus saya nonaktifkan?")
def setlog(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 message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] if chat.type == chat.CHANNEL: message.reply_text( "Sekarang, teruskan /setlog ke grup yang Anda ingin ikat saluran ini!" ) elif message.forward_from_chat: sql.set_chat_log_channel(chat.id, message.forward_from_chat.id) try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception( "Error deleting message in log channel. Should work anyway though." ) try: bot.send_message( message.forward_from_chat.id, "Saluran ini telah ditetapkan sebagai saluran log untuk {}." .format(chat.title or chat.first_name)) except Unauthorized as excp: if excp.message == "Forbidden: bot is not a member of the channel chat": bot.send_message(chat.id, "Successfully set log channel!") else: LOGGER.exception("ERROR in setting the log channel.") bot.send_message(chat.id, "Berhasil mengatur saluran log!") else: message.reply_text( "Langkah-langkah untuk mengatur saluran log adalah:\n" " - tambahkan bot ke saluran yang diinginkan\n" " - Kirimkan /setlog ke saluran\n" " - Teruskan /setlog ke grup\n")
def invite(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return conn = connected(bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: if update.effective_message.chat.type == "private": update.effective_message.reply_text( tl(update.effective_message, "Anda bisa lakukan command ini pada grup, bukan pada PM")) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title if chat.username: update.effective_message.reply_text(chat.username) elif chat.type == chat.SUPERGROUP or chat.type == chat.CHANNEL: bot_member = chat.get_member(bot.id) if bot_member.can_invite_users: invitelink = bot.exportChatInviteLink(chat.id) update.effective_message.reply_text(invitelink) else: update.effective_message.reply_text( tl( update.effective_message, "Saya tidak memiliki akses ke tautan undangan, coba ubah izin saya!" )) else: update.effective_message.reply_text( tl( update.effective_message, "Saya hanya dapat memberi Anda tautan undangan untuk supergroup dan saluran, maaf!" ))
def blackliststicker(bot: Bot, update: Update, args: List[str]): msg = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return conn = connected(bot, update, chat, user.id, need_admin=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 = "<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 == "<b>Daftar hitam stiker saat saat ini di {}:</b>\n".format( chat_name): msg.reply_text( "Tidak ada stiker daftar hitam stiker di <b>{}</b>!".format( chat_name), parse_mode=ParseMode.HTML) return msg.reply_text(text, parse_mode=ParseMode.HTML)
def del_message(bot: Bot, update: Update) -> str: spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return if update.effective_message.reply_to_message: user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] if can_delete(chat, bot.id): update.effective_message.reply_to_message.delete() update.effective_message.delete() return "<b>{}:</b>" \ "\n#DEL" \ "\n<b>Admin:</b> {}" \ "\nMessage deleted.".format(html.escape(chat.title), mention_html(user.id, user.first_name)) else: send_message(update.effective_message, tl(update.effective_message, "Apa yang ingin di hapus?")) return ""
def file(bot: Bot, update: Update): 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_id = update.effective_chat.id args = update.effective_message.text.split(None, 1) message = update.effective_message message.delete() if message.reply_to_message: bot.sendDocument( chat_id, args[1], reply_to_message_id=message.reply_to_message.message_id) else: bot.sendDocument(chat_id, args[1])
def markdown_help(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 update.effective_message.reply_text(tl(update.effective_message, "MARKDOWN_HELP").format( dispatcher.bot.first_name), parse_mode=ParseMode.HTML) update.effective_message.reply_text( tl(update.effective_message, "Coba teruskan pesan berikut kepada saya, dan Anda akan lihat!")) update.effective_message.reply_text( tl( update.effective_message, "/save test Ini adalah tes markdown. _miring_, *tebal*, `kode`, " "[URL](contoh.com) [tombol](buttonurl:github.com) " "[tombol2](buttonurl:google.com:same)"))
def get_time(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 location = " ".join(args) if location.lower() == bot.first_name.lower(): update.effective_message.reply_text("Selalu ada waktu banned untukku!") bot.send_sticker(update.effective_chat.id, BAN_STICKER) return res = requests.get(GMAPS_LOC, params=dict(address=location, key=MAPS_API)) print(res.text) if res.status_code == 200: loc = json.loads(res.text) if loc.get('status') == 'OK': lat = loc['results'][0]['geometry']['location']['lat'] long = loc['results'][0]['geometry']['location']['lng'] country = None city = None address_parts = loc['results'][0]['address_components'] for part in address_parts: if 'country' in part['types']: country = part.get('long_name') if 'administrative_area_level_1' in part['types'] and not city: city = part.get('long_name') if 'locality' in part['types']: city = part.get('long_name') if city and country: location = "{}, {}".format(city, country) elif country: location = country timenow = int(datetime.utcnow().timestamp()) res = requests.get(GMAPS_TIME, params=dict(location="{},{}".format(lat, long), timestamp=timenow)) if res.status_code == 200: offset = json.loads(res.text)['dstOffset'] timestamp = json.loads(res.text)['rawOffset'] time_there = datetime.fromtimestamp(timenow + timestamp + offset).strftime("%H:%M:%S hari %A %d %B") update.message.reply_text("Sekarang pukul {} di {}".format(time_there, location))
def del_message(bot: Bot, update: Update) -> 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!") if update.effective_message.reply_to_message: user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] if can_delete(chat, bot.id): update.effective_message.reply_to_message.delete() update.effective_message.delete() return "<b>{}:</b>" \ "\n#DEL" \ "\n<b>Admin:</b> {}" \ "\nPesan dihapus.".format(html.escape(chat.title), mention_html(user.id, user.first_name)) else: update.effective_message.reply_text("Apa yang ingin di hapus?") return ""
def kickme(bot: Bot, update: Update): user_id = update.effective_message.from_user.id if is_user_admin(update.effective_chat, user_id): update.effective_message.reply_text( "Saya berharap saya bisa... tetapi Anda seorang admin 😒") return spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return res = update.effective_chat.unban_member( user_id) # unban on current user = kick if res: update.effective_message.reply_text("Tidak masalah 😊") else: update.effective_message.reply_text("Hah? Aku tidak bisa 🙄")
def gbanstat(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 if len(args) > 0: if args[0].lower() in ["on", "yes"]: sql.enable_gbans(update.effective_chat.id) update.effective_send_message(update.effective_message, tl(update.effective_message, "Saya telah mengaktifkan larangan global dalam grup ini. Ini akan membantu melindungi Anda " "dari spammer, karakter tidak menyenangkan, dan troll terbesar.")) elif args[0].lower() in ["off", "no"]: sql.disable_gbans(update.effective_chat.id) update.effective_send_message(update.effective_message, tl(update.effective_message, "Saya telah menonaktifkan larangan global dalam grup ini. Larangan global tidak akan memengaruhi pengguna Anda " "lagi. Anda akan kurang terlindungi dari troll dan spammer sekalipun")) else: update.effective_send_message(update.effective_message, tl(update.effective_message, "Berikan saya beberapa argumen untuk memilih pengaturan! on/off, yes/no!\n\n" "Pengaturan Anda saat ini: {}\n" "Ketika Benar, setiap larangan global yang terjadi juga akan terjadi di grup Anda. " "Ketika Salah, mereka tidak akan meninggalkan Anda pada belas kasihan yang mungkin dari " "spammer.").format(sql.does_chat_gban(update.effective_chat.id)))
def list_warn_filters(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 = 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 all_handlers = sql.get_chat_warn_triggers(chat.id) if not all_handlers: 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!") update.effective_message.reply_text(text, parse_mode="markdown") return filter_list = tl(update.effective_message, "CURRENT_WARNING_FILTER_STRING") if conn: filter_list = filter_list.replace(tl(update.effective_message, 'obrolan ini'), tl(update.effective_message, 'obrolan *{}*').format(chat_name)) for keyword in all_handlers: entry = " - {}\n".format(html.escape(keyword)) if len(entry) + len(filter_list) > telegram.MAX_MESSAGE_LENGTH: update.effective_message.reply_text(filter_list, parse_mode=ParseMode.HTML) filter_list = entry else: filter_list += entry if not filter_list == tl(update.effective_message, "CURRENT_WARNING_FILTER_STRING"): update.effective_message.reply_text(filter_list, parse_mode=ParseMode.HTML)
def unpin(bot: Bot, update: Update) -> str: chat = update.effective_chat user = update.effective_user # type: Optional[User] spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return conn = connected(bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: if update.effective_message.chat.type == "private": 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: 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 list_cmds(bot: Bot, update: Update): 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!" ) if DISABLE_CMDS + DISABLE_OTHER: result = "" for cmd in set(DISABLE_CMDS + DISABLE_OTHER): result += " - `{}`\n".format(escape_markdown(cmd)) update.effective_message.reply_text( "Perintah berikut dapat diubah:\n{}".format(result), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text( "Tidak ada perintah yang dapat dinonaktifkan.")
def disconnect_chat(bot, update): spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return if update.effective_chat.type == 'private': disconnection_status = sql.disconnect( update.effective_message.from_user.id) if disconnection_status: sql.disconnected_chat = update.effective_message.reply_text( "Terputus dari obrolan!") else: update.effective_message.reply_text( "Memutus sambungan tidak berhasil!") else: update.effective_message.reply_text( "Penggunaan terbatas hanya untuk PM")
def stickerid(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 msg = update.effective_message if msg.reply_to_message and msg.reply_to_message.sticker: update.effective_message.reply_text(tl( update.effective_message, "Hai {}, Id stiker yang anda balas adalah :\n```{}```").format( mention_markdown(msg.from_user.id, msg.from_user.first_name), msg.reply_to_message.sticker.file_id), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text(tl( update.effective_message, "Tolong balas pesan stiker untuk mendapatkan id stiker"), parse_mode=ParseMode.MARKDOWN)
def logging(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 message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] log_channel = sql.get_chat_log_channel(chat.id) if log_channel: log_channel_info = bot.get_chat(log_channel) message.reply_text( "Grup ini memiliki semua log yang dikirim ke: {} (`{}`)". format(escape_markdown(log_channel_info.title), log_channel), parse_mode=ParseMode.MARKDOWN) else: message.reply_text( "Tidak ada saluran log yang telah ditetapkan untuk grup ini!")
def stickerid(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 msg = update.effective_message if msg.reply_to_message and msg.reply_to_message.sticker: update.effective_message.reply_text( "Hai " + "[{}](tg://user?id={})".format(msg.from_user.first_name, msg.from_user.id) + ", Id stiker yang anda balas adalah :\n" + "```{}```".format(msg.reply_to_message.sticker.file_id), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text( "Hai " + "[{}](tg://user?id={})".format(msg.from_user.first_name, msg.from_user.id) + ", Tolong balas pesan stiker untuk mendapatkan id stiker", parse_mode=ParseMode.MARKDOWN)
def help_connect_chat(bot, update, args): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return if update.effective_message.chat.type != "private": send_message( update.effective_message, languages. tl(update.effective_message, "PM saya dengan command itu untuk mendapatkan bantuan Koneksi")) return else: send_message(update.effective_message, languages.tl(update.effective_message, "supportcmd"), parse_mode="markdown")