def remove_all_notes(update, context): chat = update.effective_chat user = update.effective_user message = update.effective_message if chat.type == "private": chat.title = tl(chat.id, "local notes") else: owner = chat.get_member(user.id) chat.title = chat.title if owner.status != 'creator': message.reply_text(tl(chat.id, "You must be this chat creator.")) return note_list = sql.get_all_chat_notes(chat.id) if not note_list: message.reply_text(tl(chat.id, "No notes in *{}*!").format(chat.title), parse_mode=ParseMode.MARKDOWN) return x = 0 a_note = [] for notename in note_list: x += 1 note = notename.name.lower() a_note.append(note) for note in a_note: sql.rm_note(chat.id, note) message.reply_text( tl(chat.id, "{} notes from this chat have been removed.").format(x))
def setlog(update, context): message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] if chat.type == chat.CHANNEL: send_message(update.effective_message, tl(update.effective_message, "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: context.bot.send_message(message.forward_from_chat.id, tl(update.effective_message, "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": context.bot.send_message(chat.id, tl(update.effective_message, "Gagal menyetel saluran log!\nSaya mungkin bukan admin di channel tersebut.")) sql.stop_chat_logging(chat.id) return else: LOGGER.exception("ERROR in setting the log channel.") context.bot.send_message(chat.id, tl(update.effective_message, "Berhasil mengatur saluran log!")) else: send_message(update.effective_message, tl(update.effective_message, "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 purge(update, context): args = context.args msg = update.effective_message # type: Optional[Message] if msg.reply_to_message: user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] if user_can_delete(chat, user, context.bot.id): message_id = msg.reply_to_message.message_id if args and args[0].isdigit(): delete_to = message_id + int(args[0]) else: delete_to = msg.message_id - 1 for m_id in range(delete_to, message_id - 1, -1): # Reverse iteration over message ids try: context.bot.deleteMessage(chat.id, m_id) except BadRequest as err: if err.message == "Message can't be deleted": send_message( update.effective_message, tl( update.effective_message, "Tidak dapat menghapus semua pesan. Pesannya mungkin terlalu lama, saya mungkin " "tidak memiliki hak menghapus, atau ini mungkin bukan supergrup." )) elif err.message != "Message to delete not found": LOGGER.exception("Error while purging chat messages.") try: msg.delete() except BadRequest as err: if err.message == "Message can't be deleted": send_message( update.effective_message, tl( update.effective_message, "Tidak dapat menghapus semua pesan. Pesannya mungkin terlalu lama, saya mungkin " "tidak memiliki hak menghapus, atau ini mungkin bukan supergrup." )) elif err.message != "Message to delete not found": LOGGER.exception("Error while purging chat messages.") send_message(update.effective_message, tl(update.effective_message, "Pembersihan selesai.")) return "<b>{}:</b>" \ "\n#PURGE" \ "\n<b>Admin:</b> {}" \ "\nPurged <code>{}</code> messages.".format(html.escape(chat.title), mention_html(user.id, user.first_name), delete_to - message_id) else: send_message( update.effective_message, tl(update.effective_message, "Balas pesan untuk memilih tempat mulai membersihkan.")) return ""
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, tl(update.effective_message, "Anda bisa lakukan command ini pada grup, bukan pada PM")) return "" chat = update.effective_chat chat_name = update.effective_message.chat.title res = build_lock_message(chat.id) if conn: res = res.replace(tl(update.effective_message, 'obrolan ini'), '*{}*'.format(chat_name)) send_message(update.effective_message, res, parse_mode=ParseMode.MARKDOWN)
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 reply_afk(update, context): message = update.effective_message # type: Optional[Message] entities = message.parse_entities([MessageEntity.TEXT_MENTION, MessageEntity.MENTION]) if message.entities and entities: for ent in entities: if ent.type == MessageEntity.TEXT_MENTION: user_id = ent.user.id fst_name = ent.user.first_name elif ent.type == MessageEntity.MENTION: user_id = get_user_id(message.text[ent.offset:ent.offset + ent.length]) if not user_id: # Should never happen, since for a user to become AFK they must have spoken. Maybe changed username? return try: chat = context.bot.get_chat(user_id) except BadRequest: print("Error: Could not fetch userid {} for AFK module".format(user_id)) return fst_name = chat.first_name else: return if sql.is_afk(user_id): valid, reason = sql.check_afk_status(user_id) if valid: if not reason: res = tl(update.effective_message, "{} is AFK!").format(fst_name) else: res = tl(update.effective_message, "{} is AFK! says its because of: {}").format(fst_name, reason) send_message(update.effective_message, res)
def leavechat(update, context): args = context.args if args: chat_id = int(args[0]) else: send_message( update.effective_message, tl(update.effective_message, "Anda sepertinya tidak mengacu pada obrolan")) try: chat = context.bot.getChat(chat_id) titlechat = context.bot.get_chat(chat_id).title context.bot.sendMessage( chat_id, tl(update.effective_message, "Selamat tinggal semua 😁")) context.bot.leaveChat(chat_id) send_message( update.effective_message, tl(update.effective_message, "Saya telah keluar dari grup {}").format(titlechat)) except BadRequest as excp: if excp.message == "Chat not found": send_message( update.effective_message, tl( update.effective_message, "Sepertinya saya sudah keluar atau di tendang di grup tersebut" )) else: return
def __chat_settings__(chat_id, user_id): log_channel = sql.get_chat_log_channel(chat_id) if log_channel: log_channel_info = dispatcher.bot.get_chat(log_channel) return tl(user_id, "Grup ini memiliki semua log yang dikirim ke: {} (`{}`)").format(escape_markdown(log_channel_info.title), log_channel) return tl(user_id, "Tidak ada saluran masuk yang ditetapkan untuk grup ini!")
def stickerid(update, context): msg = update.effective_message if msg.reply_to_message and msg.reply_to_message.sticker: send_message(update.effective_message, 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: send_message(update.effective_message, tl(update.effective_message, "Tolong balas pesan stiker untuk mendapatkan id stiker"), parse_mode=ParseMode.MARKDOWN)
def help_connect_chat(update, context): 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")
def __chat_settings__(chat_id, user_id): limit = sql.get_flood_limit(chat_id) if limit == 0: return tl(user_id, "Saat ini *Tidak* menegakkan pengendalian pesan beruntun.") else: return tl(user_id, "Anti Pesan Beruntun diatur ke `{}` pesan.").format(limit)
def pat(update, context): args = context.args chat_id = update.effective_chat.id msg = str(update.message.text) try: msg = msg.split(" ", 1)[1] except IndexError: msg = "" msg_id = update.effective_message.reply_to_message.message_id if update.effective_message.reply_to_message else update.effective_message.message_id pats = [] pats = json.loads( urllib.request.urlopen( urllib.request.Request('http://headp.at/js/pats.json', headers={ 'User-Agent': 'Mozilla/5.0 (X11; U; Linux i686) ' 'Gecko/20071127 Firefox/2.0.0.11' })).read().decode('utf-8')) if "@" in msg and len(msg) > 5: context.bot.send_photo( chat_id, f'https://headp.at/pats/{urllib.parse.quote(random.choice(pats))}', caption=msg) else: context.bot.send_photo( chat_id, f'https://headp.at/pats/{urllib.parse.quote(random.choice(pats))}', reply_to_message_id=msg_id) 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 and user_id != "error": slapped_user = context.bot.get_chat(user_id) user1 = curr_user user2 = "{}".format( mention_markdown(slapped_user.id, slapped_user.first_name)) # if no target found, bot targets the sender else: user1 = "{}".format( mention_markdown(context.bot.id, context.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 __user_info__(user_id, chat_id): if user_id == dispatcher.bot.id: return languages.tl( chat_id, """Saya telah melihatnya... Wow. Apakah mereka menguntit saya? Mereka ada di semua tempat yang sama dengan saya... oh. Ini aku.""" ) num_chats = sql.get_user_num_chats(user_id) return languages.tl( chat_id, """Saya telah melihatnya <code>{}</code> obrolan total.""").format( num_chats)
def unsetlog(update, context): 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: context.bot.send_message(log_channel, tl(update.effective_message, "Channel telah dibatalkan tautannya {}").format(chat.title)) send_message(update.effective_message, tl(update.effective_message, "Log saluran telah dinonaktifkan.")) else: send_message(update.effective_message, tl(update.effective_message, "Belum ada saluran log yang ditetapkan!"))
def disconnect_chat(update, context): if update.effective_chat.type == 'private': disconnection_status = sql.disconnect(update.effective_message.from_user.id) if disconnection_status: sql.disconnected_chat = send_message(update.effective_message, languages.tl(update.effective_message, "Terputus dari obrolan!")) else: send_message(update.effective_message, languages.tl(update.effective_message, "Anda tidak terkoneksi!")) else: send_message(update.effective_message, languages.tl(update.effective_message, "Penggunaan terbatas hanya untuk PM"))
def build_curr_disabled(chat_id: Union[str, int]) -> str: disabled = sql.get_all_disabled(chat_id) if not disabled: return languages.tl(chat_id, "Tidak ada perintah yang dinonaktifkan!") result = "" for cmd in disabled: result += " - `{}`\n".format(escape_markdown(cmd)) return languages.tl( chat_id, "Perintah-perintah berikut saat ini dibatasi:\n{}").format(result)
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 send_log(bot: Bot, log_chat_id: str, orig_chat_id: str, result: str): try: bot.send_message(log_chat_id, result, parse_mode=ParseMode.HTML) except BadRequest as excp: if excp.message == "Chat not found": bot.send_message(orig_chat_id, tl(update.effective_message, "Saluran log ini telah dihapus - tidak bisa dibuka.")) sql.stop_chat_logging(orig_chat_id) else: LOGGER.warning(excp.message) LOGGER.warning(result) LOGGER.exception("Could not parse") bot.send_message(log_chat_id, result + tl(update.effective_message, "\n\nMemformat telah dinonaktifkan karena kesalahan tak terduga."))
def locktypes(update, context): locklist = list(LOCK_TYPES) locklist.sort() perm = list(LOCK_CHAT_RESTRICTION) perm.sort() send_message(update.effective_message, "\n - ".join([ tl(update.effective_message, "*Jenis kunci yang tersedia adalah:* ") ] + locklist) + "\n\n" + "\n - ".join([ tl(update.effective_message, "*Jenis izin kunci yang tersedia adalah:* ") ] + perm), parse_mode="markdown")
def logging(update, context): 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 = context.bot.get_chat(log_channel) send_message(update.effective_message, tl(update.effective_message, "Grup ini memiliki semua log yang dikirim ke: {} (`{}`)").format(escape_markdown(log_channel_info.title), log_channel), parse_mode=ParseMode.MARKDOWN) else: send_message(update.effective_message, tl(update.effective_message, "Tidak ada saluran log yang telah ditetapkan untuk grup ini!"))
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 deepfryer(update, context): message = update.effective_message chat = update.effective_chat if message.reply_to_message: data = message.reply_to_message.photo data2 = message.reply_to_message.sticker else: data = [] data2 = [] # check if message does contain media and cancel when not if not data and not data2: message.reply_text(tl(chat.id, "What am I supposed to do with this?!")) return # download last photo (highres) as byte array if data: photodata = data[len(data) - 1].get_file().download_as_bytearray() image = Image.open(io.BytesIO(photodata)) elif data2: sticker = context.bot.get_file(data2.file_id) sticker.download('sticker.png') image = Image.open("sticker.png") # the following needs to be executed async (because dumb lib) bot = context.bot loop = asyncio.new_event_loop() loop.run_until_complete( process_deepfry(image, message.reply_to_message, bot, context)) loop.close()
def shout(update, context): message = update.effective_message chat = update.effective_chat # type: Optional[Chat] args = context.args noreply = False if message.reply_to_message: data = message.reply_to_message.text elif args: noreply = True data = " ".join(args) else: noreply = True data = tl(chat.id, "I need a message to meme.") msg = "```" result = [] result.append(' '.join([s for s in data])) for pos, symbol in enumerate(data[1:]): result.append(symbol + ' ' + ' ' * pos + symbol) result = list("\n".join(result)) result[0] = data[0] result = "".join(result) msg = "```\n" + result + "```" return update.effective_message.reply_text(msg, parse_mode="MARKDOWN")
def markdown_help(update, context): send_message(update.effective_message, tl(update.effective_message, "MARKDOWN_HELP").format(dispatcher.bot.first_name), parse_mode=ParseMode.HTML) send_message( update.effective_message, tl(update.effective_message, "Coba teruskan pesan berikut kepada saya, dan Anda akan lihat!")) send_message( update.effective_message, 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 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 list_cmds(update, context): if DISABLE_CMDS + DISABLE_OTHER: result = "" for cmd in set(DISABLE_CMDS + DISABLE_OTHER): result += " - `{}`\n".format(escape_markdown(cmd)) send_message( update.effective_message, languages.tl( update.effective_message, "Perintah berikut dapat diubah:\n{}").format(result), parse_mode=ParseMode.MARKDOWN) else: send_message( update.effective_message, languages.tl(update.effective_message, "Tidak ada perintah yang dapat dinonaktifkan."))
def log_user(update, context): chat = update.effective_chat # type: Optional[Chat] msg = update.effective_message # type: Optional[Message] """text = msg.text if msg.text else "" uid = msg.from_user.id uname = msg.from_user.name print("{} | {} | {} | {}".format(text, uname, uid, chat.title))""" fed_id = fedsql.get_fed_id(chat.id) if fed_id: user = update.effective_user if user: fban, fbanreason, fbantime = fedsql.get_fban_user(fed_id, user.id) if fban: send_message( update.effective_message, languages.tl( update.effective_message, "Pengguna ini dilarang di federasi saat ini!\nAlasan: `{}`" ).format(fbanreason), parse_mode="markdown") try: context.bot.kick_chat_member(chat.id, user.id) except: print("Fban: cannot banned this user") sql.update_user(msg.from_user.id, msg.from_user.username, chat.id, chat.title) if msg.reply_to_message: sql.update_user(msg.reply_to_message.from_user.id, msg.reply_to_message.from_user.username, chat.id, chat.title) if msg.forward_from: sql.update_user(msg.forward_from.id, msg.forward_from.username)
def get_settings(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) # ONLY send settings in PM if chat.type != chat.PRIVATE: if is_user_admin(chat, user.id): text = tl( update.effective_message, "Klik di sini untuk mendapatkan pengaturan obrolan ini, serta milik Anda." ) msg.reply_text(text, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton( text="Pengaturan", url="t.me/{}?start=stngs_{}".format( context.bot.username, chat.id)) ]])) # else: # text = tl(update.effective_message, "Klik di sini untuk memeriksa pengaturan Anda.") else: send_settings(chat.id, user.id, True)
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 blacklist(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 filter_list = tl( update.effective_message, "<b>Kata daftar hitam saat ini di {}:</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 == tl( update.effective_message, "<b>Kata daftar hitam saat ini di {}:</b>\n").format( chat_name): send_message( update.effective_message, tl(update.effective_message, "Tidak ada pesan daftar hitam di <b>{}</b>!").format( chat_name), parse_mode=ParseMode.HTML) return send_message(update.effective_message, text, parse_mode=ParseMode.HTML)