def remove_warn_filter(update, context): chat = update.effective_chat # type: Optional[Chat] msg = update.effective_message # type: Optional[Message] user = update.effective_user # type: Optional[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 args = msg.text.split(None, 1) # use python's maxsplit to separate Cmd, keyword, and reply_text if len(args) < 2: return extracted = split_quotes(args[1]) if len(extracted) < 1: return chat_filters = sql.get_chat_warn_triggers(chat.id) if not chat_filters: if conn: text = tl(update.effective_message, "Tidak ada filter peringatan aktif di *{}*!").format(chat_name) else: text = tl(update.effective_message, "Tidak ada filter peringatan aktif di sini!") send_message(update.effective_message, text) return nowarn = 0 inwarn = 0 success = "" fail = "" teks = args[1].split(" ") for x in range(len(teks)): to_remove = teks[x] if to_remove not in chat_filters: fail += "`{}` ".format(to_remove) nowarn += 1 for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat.id, to_remove) success += "`{}` ".format(to_remove) inwarn += 1 if nowarn == 0: if conn: text = tl(update.effective_message, "Ya, saya akan berhenti memperingatkan orang-orang untuk {} pada *{}*.").format(success, chat_name) else: text = tl(update.effective_message, "Ya, saya akan berhenti memperingatkan orang-orang untuk {}.").format(success) send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN) raise DispatcherHandlerStop elif inwarn == 0: if conn: text = tl(update.effective_message, "Gagal menghapus filter warn untuk {} pada *{}*.").format(fail, chat_name) else: text = tl(update.effective_message, "Gagal menghapus filter warn untuk {}.").format(fail) send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN) raise DispatcherHandlerStop else: if conn: text = tl(update.effective_message, "Ya, saya akan berhenti memperingatkan orang-orang untuk {}.\nDan gagal menghapus filter warn untuk {}.\nPada *{}*").format(success, fail, chat_name) else: text = tl(update.effective_message, "Ya, saya akan berhenti memperingatkan orang-orang untuk {}.\nDan gagal menghapus filter warn untuk {}.").format(success, fail) send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN) raise DispatcherHandlerStop """ if not chat_filters: send_message(update.effective_message, "Tidak ada filter peringatan aktif di sini!") return for filt in chat_filters: if filt == to_remove: sql.remove_warn_filter(chat.id, to_remove) send_message(update.effective_message, "Ya, saya akan berhenti memperingatkan orang-orang untuk {}.".format(to_remove)) raise DispatcherHandlerStop """ if conn: text = tl(update.effective_message, "Itu bukan filter peringatan saat ini - jalankan /warnlist untuk semua filter peringatan aktif pada *{}*.") else: text = tl(update.effective_message, "Itu bukan filter peringatan saat ini - jalankan /warnlist untuk semua filter peringatan aktif.") 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 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 get(bot, update, notename, show_none=True, no_format=False): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id, need_admin=False) if conn: chat_id = conn send_id = user.id else: chat_id = update.effective_chat.id send_id = chat_id note = sql.get_note(chat_id, notename) message = update.effective_message # type: Optional[Message] if note: # If we're replying to a message, reply to that message (unless it's an error) if message.reply_to_message: reply_id = message.reply_to_message.message_id else: reply_id = message.message_id if note.is_reply: if MESSAGE_DUMP: try: bot.forward_message(chat_id=chat_id, from_chat_id=MESSAGE_DUMP, message_id=note.value) except BadRequest as excp: if excp.message == "Message to forward not found": send_message( update.effective_message, tl( update.effective_message, "Pesan ini tampaknya telah hilang - saya akan menghapusnya " "dari daftar catatan Anda.")) sql.rm_note(chat_id, notename) else: raise else: try: bot.forward_message(chat_id=chat_id, from_chat_id=chat_id, message_id=note.value) except BadRequest as excp: if excp.message == "Message to forward not found": send_message( update.effective_message, tl( update.effective_message, "Sepertinya pengirim asli dari catatan ini telah dihapus " "pesan mereka - maaf! Dapatkan admin bot Anda untuk mulai menggunakan " "pesan dump untuk menghindari ini. Saya akan menghapus catatan ini dari " "catatan tersimpan Anda.")) sql.rm_note(chat_id, notename) else: raise else: VALID_WELCOME_FORMATTERS = [ 'first', 'last', 'fullname', 'username', 'id', 'chatname', 'mention', 'rules' ] valid_format = escape_invalid_curly_brackets( note.value, VALID_WELCOME_FORMATTERS) if valid_format: text = valid_format.format( first=escape_markdown(message.from_user.first_name), last=escape_markdown(message.from_user.last_name or message.from_user.first_name), fullname=escape_markdown( " ".join([ message.from_user.first_name, message.from_user. last_name ] if message.from_user.last_name else [message.from_user.first_name])), username="******" + message.from_user.username if message.from_user.username else mention_markdown( message.from_user.id, message.from_user.first_name), mention=mention_markdown(message.from_user.id, message.from_user.first_name), chatname=escape_markdown( message.chat.title if message.chat.type != "private" else message.from_user.first_name), id=message.from_user.id, rules="http://t.me/{}?start={}".format( bot.username, chat_id)) else: text = "" keyb = [] parseMode = ParseMode.MARKDOWN buttons = sql.get_buttons(chat_id, notename) if no_format: parseMode = None text += revert_buttons(buttons) else: keyb = build_keyboard_parser(bot, chat_id, buttons) keyboard = InlineKeyboardMarkup(keyb) try: is_private, is_delete = sql.get_private_note(chat.id) if note.msgtype in (sql.Types.BUTTON_TEXT, sql.Types.TEXT): try: if is_delete: update.effective_message.delete() if is_private: bot.send_message(user.id, text, parse_mode=parseMode, disable_web_page_preview=True, reply_markup=keyboard) else: bot.send_message(send_id, text, reply_to_message_id=reply_id, parse_mode=parseMode, disable_web_page_preview=True, reply_markup=keyboard) except BadRequest as excp: if excp.message == "Wrong http url": failtext = tl( update.effective_message, "Kesalahan: URL pada tombol tidak valid! Harap perbaruhi catatan ini." ) failtext += "\n\n```\n{}```".format( note.value + revert_buttons(buttons)) send_message(update.effective_message, failtext, parse_mode="markdown") elif excp.message == "Button_url_invalid": failtext = tl( update.effective_message, "Kesalahan: URL pada tombol tidak valid! Harap perbaruhi catatan ini." ) failtext += "\n\n```\n{}```".format( note.value + revert_buttons(buttons)) send_message(update.effective_message, failtext, parse_mode="markdown") elif excp.message == "Message can't be deleted": pass elif excp.message == "Have no rights to send a message": pass except Unauthorized as excp: send_message( update.effective_message, tl( update.effective_message, "Hubungi saya di PM dulu untuk mendapatkan catatan ini." ), parse_mode="markdown") pass else: try: if is_delete: update.effective_message.delete() if is_private: ENUM_FUNC_MAP[note.msgtype]( user.id, note.file, caption=text, parse_mode=parseMode, disable_web_page_preview=True, reply_markup=keyboard) else: ENUM_FUNC_MAP[note.msgtype]( send_id, note.file, caption=text, reply_to_message_id=reply_id, parse_mode=parseMode, disable_web_page_preview=True, reply_markup=keyboard) except BadRequest as excp: if excp.message == "Message can't be deleted": pass elif excp.message == "Have no rights to send a message": pass except Unauthorized as excp: send_message( update.effective_message, tl( update.effective_message, "Hubungi saya di PM dulu untuk mendapatkan catatan ini." ), parse_mode="markdown") pass except BadRequest as excp: if excp.message == "Entity_mention_user_invalid": send_message( update.effective_message, tl( update.effective_message, "Sepertinya Anda mencoba menyebutkan seseorang yang belum pernah saya lihat sebelumnya. " "Jika kamu benar-benar ingin menyebutkannya, meneruskan salah satu pesan mereka kepada saya, " "dan saya akan dapat untuk menandai mereka!")) elif FILE_MATCHER.match(note.value): send_message( update.effective_message, tl( update.effective_message, "Catatan ini adalah file yang salah diimpor dari bot lain - saya tidak bisa menggunakan " "ini. Jika Anda benar-benar membutuhkannya, Anda harus menyimpannya lagi. " "Sementara itu, saya akan menghapusnya dari daftar catatan Anda." )) sql.rm_note(chat_id, notename) else: send_message( update.effective_message, tl( update.effective_message, "Catatan ini tidak dapat dikirim karena formatnya salah." )) LOGGER.exception( "Tidak dapat menguraikan pesan #%s di obrolan %s", notename, str(chat_id)) LOGGER.warning("Pesan itu: %s", str(note.value)) return elif show_none: send_message(update.effective_message, tl(update.effective_message, "Catatan ini tidak ada"))
def set_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."))
def __stats__(): return tl(OWNER_ID, "{} obrolan memiliki aturan yang ditetapkan.").format( sql.num_chats())
def wiki(update, context): msg = update.effective_message chat_id = update.effective_chat.id args = update.effective_message.text.split(None, 1) teks = args[1] message = update.effective_message getlang = langsql.get_lang(chat_id) if str(getlang) == "id": wikipedia.set_lang("id") else: wikipedia.set_lang("en") try: pagewiki = wikipedia.page(teks) except wikipedia.exceptions.PageError: send_message(update.effective_message, tl(update.effective_message, "Hasil tidak ditemukan")) return except wikipedia.exceptions.DisambiguationError as refer: rujuk = str(refer).split("\n") if len(rujuk) >= 6: batas = 6 else: batas = len(rujuk) teks = "" for x in range(batas): if x == 0: if getlang == "id": teks += rujuk[x].replace('may refer to', 'dapat merujuk ke') + "\n" else: teks += rujuk[x] + "\n" else: teks += "- `" + rujuk[x] + "`\n" send_message(update.effective_message, teks, parse_mode="markdown") return except IndexError: send_message( update.effective_message, tl(update.effective_message, "Tulis pesan untuk mencari dari sumber wikipedia")) return judul = pagewiki.title summary = pagewiki.summary if update.effective_message.chat.type == "private": send_message(update.effective_message, tl(update.effective_message, "Hasil dari {} adalah:\n\n<b>{}</b>\n{}").format( teks, judul, summary), parse_mode=ParseMode.HTML) else: if len(summary) >= 200: judul = pagewiki.title summary = summary[:200] + "..." button = InlineKeyboardMarkup([[ InlineKeyboardButton(text=tl(update.effective_message, "Baca Lebih Lengkap"), url="t.me/{}?start=wiki-{}".format( context.bot.username, teks.replace(' ', '_'))) ]]) else: button = None send_message(update.effective_message, tl(update.effective_message, "Hasil dari {} adalah:\n\n<b>{}</b>\n{}").format( teks, judul, summary), parse_mode=ParseMode.HTML, reply_markup=button)
def del_lockables(update, context): chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] for lockable, filter in LOCK_TYPES.items(): if lockable == "rtl": if sql.is_locked(chat.id, lockable) and can_delete( chat, context.bot.id): if message.caption: check = ad.detect_alphabet(u"{}".format(message.caption)) if "ARABIC" in check: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in lockables") getconf = sql.get_lockconf(chat.id) if getconf: warn( update.effective_user, chat, tl( update.effective_message, "Mengirim 'Teks RTL' yang sedang di kunci saat ini", ), message, update.effective_user, conn=False, ) break if message.text: check = ad.detect_alphabet(u"{}".format(message.text)) if "ARABIC" in check: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in lockables") getconf = sql.get_lockconf(chat.id) if getconf: warn( update.effective_user, chat, tl( update.effective_message, "Mengirim 'Teks RTL' yang sedang di kunci saat ini", ), message, update.effective_user, conn=False, ) break continue if lockable == "button": if sql.is_locked(chat.id, lockable) and can_delete( chat, context.bot.id): if message.reply_markup and message.reply_markup.inline_keyboard: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in lockables") getconf = sql.get_lockconf(chat.id) if getconf: warn( update.effective_user, chat, tl( update.effective_message, "Mengirim 'Pesan Tombol' yang sedang di kunci saat ini", ), message, update.effective_user, conn=False, ) break continue if lockable == "inline": if sql.is_locked(chat.id, lockable) and can_delete( chat, context.bot.id): if message and message.via_bot: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in lockables") getconf = sql.get_lockconf(chat.id) if getconf: warn( update.effective_user, chat, tl( update.effective_message, "Mengirim '{}' yang sedang di kunci saat ini", ).format(lockable), message, update.effective_user, conn=False, ) break continue if (filter(update) and sql.is_locked(chat.id, lockable) and can_delete(chat, context.bot.id)): if lockable == "bots": new_members = update.effective_message.new_chat_members for new_mem in new_members: if new_mem.is_bot: if not is_bot_admin(chat, context.bot.id): send_message( update.effective_message, tl( update.effective_message, "Saya melihat bot, dan saya diberitahu untuk menghentikan mereka bergabung... " "tapi saya bukan admin!", ), ) return chat.kick_member(new_mem.id) send_message( update.effective_message, tl( update.effective_message, "Hanya admin yang diizinkan menambahkan bot ke obrolan ini! Keluar dari sini!", ), ) getconf = sql.get_lockconf(chat.id) if getconf: warn( update.effective_user, chat, tl( update.effective_message, "Memasukan 'Bot' yang sedang di kunci saat ini", ), message, update.effective_user, conn=False, ) break else: try: message.delete() except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("ERROR in lockables") getconf = sql.get_lockconf(chat.id) if getconf: warn( update.effective_user, chat, tl( update.effective_message, "Mengirim '{}' yang sedang di kunci saat ini", ).format(lockable), message, update.effective_user, conn=False, ) break
def settings_button(update, context): query = update.callback_query user = update.effective_user mod_match = re.match(r"stngs_module\((.+?),(.+?)\)", query.data) prev_match = re.match(r"stngs_prev\((.+?),(.+?)\)", query.data) next_match = re.match(r"stngs_next\((.+?),(.+?)\)", query.data) back_match = re.match(r"stngs_back\((.+?)\)", query.data) try: if mod_match: chat_id = mod_match.group(1) module = mod_match.group(2) chat = context.bot.get_chat(chat_id) getstatusadmin = context.bot.get_chat_member(chat_id, user.id) isadmin = getstatusadmin.status in ('administrator', 'creator') if isadmin == False or user.id != OWNER_ID: query.message.edit_text("Status admin anda telah berubah") return text = tl(update.effective_message, "*{}* memiliki pengaturan berikut untuk modul *{}*:\n\n").format(escape_markdown(chat.title), CHAT_SETTINGS[ module].__mod_name__) + \ CHAT_SETTINGS[module].__chat_settings__(chat_id, user.id) try: set_button = CHAT_SETTINGS[module].__chat_settings_btn__( chat_id, user.id) except AttributeError: set_button = [] set_button.append([ InlineKeyboardButton( text=tl(query.message, "Kembali"), callback_data="stngs_back({})".format(chat_id)) ]) query.message.edit_text( text=text, parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup(set_button)) elif prev_match: chat_id = prev_match.group(1) curr_page = int(prev_match.group(2)) chat = context.bot.get_chat(chat_id) query.message.edit_text(text=tl( update.effective_message, "Hai! Ada beberapa pengaturan untuk {} - lanjutkan dan pilih " "apa yang Anda minati.").format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules(curr_page - 1, CHAT_SETTINGS, "stngs", chat=chat_id))) elif next_match: chat_id = next_match.group(1) next_page = int(next_match.group(2)) chat = context.bot.get_chat(chat_id) query.message.edit_text(text=tl( update.effective_message, "Hai! Ada beberapa pengaturan untuk {} - lanjutkan dan pilih " "apa yang Anda minati.").format(chat.title), reply_markup=InlineKeyboardMarkup( paginate_modules(next_page + 1, CHAT_SETTINGS, "stngs", chat=chat_id))) elif back_match: chat_id = back_match.group(1) chat = context.bot.get_chat(chat_id) query.message.edit_text(text=tl( update.effective_message, "Hai! Ada beberapa pengaturan untuk {} - lanjutkan dan pilih " "apa yang Anda minati.").format(escape_markdown(chat.title)), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup( paginate_modules(0, CHAT_SETTINGS, "stngs", chat=chat_id))) # ensure no spinny white circle context.bot.answer_callback_query(query.id) except Exception as excp: if excp.message == "Message is not modified": pass elif excp.message == "Query_id_invalid": pass elif excp.message == "Message can't be deleted": pass else: query.message.edit_text(excp.message) LOGGER.exception("Exception in settings buttons. %s", str(query.data))
def __stats__(): return languages.tl(OWNER_ID, "{} pengguna, pada {} obrolan").format( sql.num_users(), sql.num_chats())
def __chat_settings__(chat_id, user_id): num_warn_filters = sql.num_warn_chat_filters(chat_id) limit, soft_warn, warn_mode = sql.get_warn_setting(chat_id) return tl(user_id, "Obrolan ini mempunyai `{}` saringan peringatkan. Dibutuhkan `{}` peringatan " \ "sebelum pengguna akan mendapatkan *{}*.").format(num_warn_filters, limit, "tendangan" if soft_warn else "pemblokiran")
def start(update, context): if update.effective_chat.type == "private": args = context.args if len(args) >= 1: if args[0].lower() == "help": send_help(update.effective_chat.id, tl(update.effective_message, HELP_STRINGS)) elif args[0].lower() == "get_notes": update.effective_message.reply_text( tl(update.effective_message, "Anda sekarang dapat mengambil catatan di grup.")) elif args[0].lower().startswith("stngs_"): match = re.match("stngs_(.*)", args[0].lower()) chat = dispatcher.bot.getChat(match.group(1)) if is_user_admin(chat, update.effective_user.id): send_settings(match.group(1), update.effective_user.id, False) else: send_settings(match.group(1), update.effective_user.id, True) elif args[0][1:].isdigit() and "rules" in IMPORTED: IMPORTED["rules"].send_rules(update, args[0], from_pm=True) elif args[0][:4] == "wiki": wiki = args[0].split("-")[1].replace('_', ' ') message = update.effective_message getlang = langsql.get_lang(message) if getlang == "id": wikipedia.set_lang("id") pagewiki = wikipedia.page(wiki) judul = pagewiki.title summary = pagewiki.summary if len(summary) >= 4096: summary = summary[:4000] + "..." message.reply_text("<b>{}</b>\n{}".format(judul, summary), parse_mode=ParseMode.HTML, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton(text=tl( update.effective_message, "Baca di Wikipedia"), url=pagewiki.url) ]])) elif args[0][:6].lower() == "verify": chat_id = args[0].split("_")[1] verify_welcome(update, context, chat_id) else: first_name = update.effective_user.first_name buttons = InlineKeyboardMarkup( [[ InlineKeyboardButton(text="💭 Language", callback_data="main_setlang"), InlineKeyboardButton(text="⚙️ Connect Group", callback_data="main_connect") ], [ InlineKeyboardButton(text="👥 Support Group", url="https://t.me/slpcgame"), InlineKeyboardButton(text="🔔 Update Channel", url="https://t.me/slpcgames") ], [ InlineKeyboardButton( text="❓ Help", url="https://t.me/{}?start=help".format( context.bot.username)), InlineKeyboardButton( text="💖 About Developer", url="https://slcreedtest.000webhostapp.com/") ], [ InlineKeyboardButton( text="🎉 Add me to your group", url="https://t.me/{}?startgroup=new".format( context.bot.username)) ]]) update.effective_message.reply_photo( DAISY_IMG, tl(update.effective_message, PM_START_TEXT).format( escape_markdown(first_name), escape_markdown(context.bot.first_name), OWNER_ID), disable_web_page_preview=True, parse_mode=ParseMode.MARKDOWN, reply_markup=buttons) else: update.effective_message.reply_text( tl(update.effective_message, "Ada yang bisa saya bantu? 😊"))
def __stats__(): return tl(OWNER_ID, "{} seluruh peringatan, pada {} obrolan.\n" \ "{} menyaring peringatkan, pada {} obrolan.").format(sql.num_warns(), sql.num_warn_chats(), sql.num_warn_filters(), sql.num_warn_filter_chats())
def set_warn_mode(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] msg = update.effective_message # type: Optional[Message] 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 args: if args[0].lower() in ("kick", "soft"): sql.set_warn_mode(chat.id, 1) if conn: text = tl(update.effective_message, "Terlalu banyak peringatan sekarang akan menghasilkan tendangan pada *{}*! Pengguna akan dapat bergabung lagi.").format(chat_name) else: text = tl(update.effective_message, "Terlalu banyak peringatan sekarang akan menghasilkan tendangan! Pengguna akan dapat bergabung lagi.") send_message(update.effective_message, text, parse_mode="markdown") return "<b>{}:</b>\n" \ "<b>Admin:</b> {}\n" \ "Has changed the final warning to kick.".format(html.escape(chat.title), mention_html(user.id, user.first_name)) elif args[0].lower() in ("ban", "banned", "hard"): sql.set_warn_mode(chat.id, 2) if conn: text = tl(update.effective_message, "Terlalu banyak peringatan akan menghasilkan blokir pada *{}*!").format(chat_name) else: text = tl(update.effective_message, "Terlalu banyak peringatan akan menghasilkan blokir!") send_message(update.effective_message, text, parse_mode="markdown") return "<b>{}:</b>\n" \ "<b>Admin:</b> {}\n" \ "Has changed the final warning to banned.".format(html.escape(chat.title), mention_html(user.id, user.first_name)) elif args[0].lower() in ("mute"): sql.set_warn_mode(chat.id, 3) if conn: text = tl(update.effective_message, "Terlalu banyak peringatan akan menghasilkan bisukan pada *{}*!").format(chat_name) else: text = tl(update.effective_message, "Terlalu banyak peringatan akan menghasilkan bisukan!") send_message(update.effective_message, text, parse_mode="markdown") return "<b>{}:</b>\n" \ "<b>Admin:</b> {}\n" \ "Has changed the final warning to mute.".format(html.escape(chat.title), mention_html(user.id, user.first_name)) else: send_message(update.effective_message, tl(update.effective_message, "Saya hanya mengerti kick/ban/mute!")) else: limit, soft_warn, warn_mode = sql.get_warn_setting(chat.id) if not soft_warn: if not warn_mode: if conn: text = tl(update.effective_message, "Peringatan saat ini disetel ke *tendangan* pengguna saat melampaui batas pada *{}*.").format(chat_name) else: text = tl(update.effective_message, "Peringatan saat ini disetel ke *tendangan* pengguna saat melampaui batas.") elif warn_mode == 1: if conn: text = tl(update.effective_message, "Peringatan saat ini disetel ke *tendangan* pengguna saat melampaui batas pada *{}*.").format(chat_name) else: text = tl(update.effective_message, "Peringatan saat ini disetel ke *tendangan* pengguna saat melampaui batas.") elif warn_mode == 2: if conn: text = tl(update.effective_message, "Peringatan saat ini disetel ke *blokir* pengguna saat melampaui batas pada *{}*.").format(chat_name) else: text = tl(update.effective_message, "Peringatan saat ini disetel ke *blokir* pengguna saat melampaui batas.") elif warn_mode == 3: if conn: text = tl(update.effective_message, "Peringatan saat ini disetel ke *bisukan* pengguna saat melampaui batas pada *{}*.").format(chat_name) else: text = tl(update.effective_message, "Peringatan saat ini disetel ke *bisukan* pengguna saat melampaui batas.") send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN) else: if conn: text = tl(update.effective_message, "Peringatan saat ini disetel untuk *blokir* pengguna saat melampaui batas pada *{}*.").format(chat_name) else: text = tl(update.effective_message, "Peringatan saat ini disetel untuk *blokir* pengguna saat melampaui batas.") send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN) return ""
def set_warn_strength(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] msg = update.effective_message # type: Optional[Message] 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 args: if args[0].lower() in ("on", "yes"): sql.set_warn_strength(chat.id, False) if conn: text = "Terlalu banyak peringatan sekarang akan menghasilkan blokir pada *{}*!".format(chat_name) else: text = "Terlalu banyak peringatan sekarang akan menghasilkan blokir!" send_message(update.effective_message, text, parse_mode="markdown") return "<b>{}:</b>\n" \ "<b>Admin:</b> {}\n" \ "Telah mengaktifkan peringatan yang kuat. Pengguna akan diblokir.".format(html.escape(chat.title), mention_html(user.id, user.first_name)) elif args[0].lower() in ("off", "no"): sql.set_warn_strength(chat.id, True) if conn: text = "Terlalu banyak peringatan akan menghasilkan tendangan pada *{}*! Pengguna akan dapat bergabung lagi.".format(chat_name) else: text = "Terlalu banyak peringatan akan menghasilkan tendangan! Pengguna akan dapat bergabung lagi." send_message(update.effective_message, text, parse_mode="markdown") return "<b>{}:</b>\n" \ "<b>Admin:</b> {}\n" \ "Telah menonaktifkan peringatan kuat. Pengguna hanya akan ditendang.".format(html.escape(chat.title), mention_html(user.id, user.first_name)) else: send_message(update.effective_message, "Saya hanya mengerti on/yes/no/off!") else: limit, soft_warn, warn_mode = sql.get_warn_setting(chat.id) if soft_warn: if conn: text = "Peringatan saat ini disetel ke *tendangan* pengguna saat melampaui batas pada *{}*.".format(chat_name) else: text = "Peringatan saat ini disetel ke *tendangan* pengguna saat melampaui batas." send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN) else: if conn: text = "Peringatan saat ini disetel untuk *diblokir* pengguna saat melampaui batas pada *{}*.".format(chat_name) else: text = "Peringatan saat ini disetel untuk *diblokir* pengguna saat melampaui batas." send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN) return ""
def ramalan(update, context): text = "" if random.randint(1, 10) >= 7: text += random.choice(tl(update.effective_message, "RAMALAN_FIRST")) text += random.choice(tl(update.effective_message, "RAMALAN_STRINGS")) send_message(update.effective_message, text)
def ungban(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id = extract_user(message, args) if not user_id: message.reply_text( tl(update.effective_message, "Anda sepertinya tidak mengacu pada pengguna.")) return user_chat = bot.get_chat(user_id) if user_chat.type != 'private': message.reply_text(tl(update.effective_message, "Itu bukan pengguna!")) return if not sql.is_user_gbanned(user_id): message.reply_text( tl(update.effective_message, "Pengguna ini tidak dilarang secara global!")) return banner = update.effective_user # type: Optional[User] message.reply_text( tl(update.effective_message, "Saya akan berikan {} kesempatan kedua, secara global.").format( user_chat.first_name)) send_to_list( bot, SUDO_USERS + SUPPORT_USERS, tl(update.effective_message, "{} telah menghapus larangan global untuk pengguna {}").format( mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name)), html=True) chats = get_all_chats() for chat in chats: chat_id = chat.chat_id # Check if this group has disabled gbans if not sql.does_chat_gban(chat_id): continue try: member = bot.get_chat_member(chat_id, user_id) if member.status == 'kicked': bot.unban_chat_member(chat_id, user_id) except BadRequest as excp: if excp.message in UNGBAN_ERRORS: pass else: message.reply_text( tl( update.effective_message, "Tidak dapat menghapus larangan secara global karena: {}" ).format(excp.message)) bot.send_message( OWNER_ID, tl( update.effective_message, "Tidak dapat menghapus larangan secara global karena: {}" ).format(excp.message)) return except TelegramError: pass sql.ungban_user(user_id) send_to_list( bot, SUDO_USERS + SUPPORT_USERS, tl(update.effective_message, "Menghapus larangan global selesai!")) message.reply_text( tl(update.effective_message, "Orang ini telah dihapus larangannya."))
def terjemah(update, context): msg = update.effective_message chat_id = update.effective_chat.id getlang = langsql.get_lang(update.effective_message.from_user.id) try: if msg.reply_to_message and msg.reply_to_message.text: args = update.effective_message.text.split() if len(args) >= 2: target = args[1] if "-" in target: target2 = target.split("-")[1] target = target.split("-")[0] else: target2 = None else: if getlang: target = getlang target2 = None else: raise IndexError teks = msg.reply_to_message.text #teks = deEmojify(teks) exclude_list = UNICODE_EMOJI.keys() for emoji in exclude_list: if emoji in teks: teks = teks.replace(emoji, '') message = update.effective_message trl = Translator() if target2 == None: deteksibahasa = trl.detect(teks) tekstr = trl.translate(teks, dest=target) send_message( update.effective_message, tl(update.effective_message, "Diterjemahkan dari `{}` ke `{}`:\n`{}`").format( deteksibahasa.lang, target, tekstr.text), parse_mode=ParseMode.MARKDOWN) else: tekstr = trl.translate(teks, dest=target2, src=target) send_message( update.effective_message, tl(update.effective_message, "Diterjemahkan dari `{}` ke `{}`:\n`{}`").format( target, target2, tekstr.text), parse_mode=ParseMode.MARKDOWN) else: args = update.effective_message.text.split(None, 2) if len(args) != 1: target = args[1] teks = args[2] target2 = None if "-" in target: target2 = target.split("-")[1] target = target.split("-")[0] else: target = getlang teks = args[1] #teks = deEmojify(teks) exclude_list = UNICODE_EMOJI.keys() for emoji in exclude_list: if emoji in teks: teks = teks.replace(emoji, '') message = update.effective_message trl = Translator() if target2 == None: deteksibahasa = trl.detect(teks) tekstr = trl.translate(teks, dest=target) return send_message( update.effective_message, tl(update.effective_message, "Diterjemahkan dari `{}` ke `{}`:\n`{}`").format( deteksibahasa.lang, target, tekstr.text), parse_mode=ParseMode.MARKDOWN) else: tekstr = trl.translate(teks, dest=target2, src=target) send_message( update.effective_message, tl(update.effective_message, "Diterjemahkan dari `{}` ke `{}`:\n`{}`").format( target, target2, tekstr.text), parse_mode=ParseMode.MARKDOWN) except IndexError: send_message( update.effective_message, tl( update.effective_message, "Balas pesan atau tulis pesan dari bahasa lain untuk " "diterjemahkan kedalam bahasa yang di dituju\n\n" "Contoh: `/tr en-id` untuk menerjemahkan dari Bahasa inggris ke Bahasa Indonesia\n" "Atau gunakan: `/tr id` untuk deteksi otomatis dan menerjemahkannya kedalam bahasa indonesia" ), parse_mode="markdown") except ValueError: send_message( update.effective_message, tl(update.effective_message, "Bahasa yang di tuju tidak ditemukan!")) else: return
def __stats__(): return tl(OWNER_ID, "{} pengguna global banned.").format(sql.num_gbanned_users())
def unlock(update, context) -> str: args = context.args chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] if is_user_admin(chat, message.from_user.id): if len(args) >= 1: ltype = args[0].lower() if ltype in LOCK_TYPES: # Connection check conn = connected(context.bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = chat.title text = tl( update.effective_message, "Tidak terkunci *{}* untuk semua orang pada *{}*!", ).format(ltype, chat_name) else: if update.effective_message.chat.type == "private": send_message( update.effective_message, tl( update.effective_message, "Anda bisa lakukan command ini pada grup, bukan pada PM", ), ) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title text = tl( update.effective_message, "Tidak terkunci *{}* untuk semua orang!", ).format(ltype) sql.update_lock(chat.id, ltype, locked=False) send_message(update.effective_message, text, parse_mode="markdown") return ("<b>{}:</b>" "\n#UNLOCK" "\n<b>Admin:</b> {}" "\nUnlocked <code>{}</code>.".format( html.escape(chat.title), mention_html(user.id, user.first_name), ltype, )) elif ltype in UNLOCK_CHAT_RESTRICTION: # Connection check conn = connected(context.bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = chat.title text = tl( update.effective_message, "Izin tidak terkunci *{}* untuk semua orang pada *{}*!", ).format(ltype, chat_name) else: if update.effective_message.chat.type == "private": send_message( update.effective_message, tl( update.effective_message, "Anda bisa lakukan command ini pada grup, bukan pada PM", ), ) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title text = tl( update.effective_message, "Izin tidak terkunci *{}* untuk semua orang!", ).format(ltype) current_permission = context.bot.getChat(chat_id).permissions context.bot.set_chat_permissions( chat_id=chat_id, permissions=get_permission_list( eval(str(current_permission)), UNLOCK_CHAT_RESTRICTION[ltype.lower()], ), ) send_message(update.effective_message, text, parse_mode="markdown") return ("<b>{}:</b>" "\n#UNLOCK" "\n<b>Admin:</b> {}" "\nUnlocked <code>{}</code>.".format( html.escape(chat.title), mention_html(user.id, user.first_name), ltype, )) else: send_message( update.effective_message, tl( update.effective_message, "Apa yang Anda coba untuk membuka kunci...? Coba /locktypes untuk daftar kunci yang dapat dikunci", ), ) else: send_message( update.effective_message, tl(update.effective_message, "Apa yang Anda coba untuk buka kunci...?"), ) return ""
def __chat_settings__(chat_id, user_id): return tl(user_id, "Obrolan ini memberlakukan *larangan global*: `{}`.").format( sql.does_chat_gban(chat_id))
def lock_warns(update, context): args = context.args 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_id = conn chat_name = chat.title else: if update.effective_message.chat.type == "private": send_message( update.effective_message, tl( update.effective_message, "Anda bisa lakukan command ini pada grup, bukan pada PM", ), ) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title if args: if args[0] == "on" or args[0] == "yes": sql.set_lockconf(chat_id, True) try: send_message( update.effective_message, tl( update.effective_message, "Saya *akan* memperingati pengguna jika dia mengirim pesan yang dikunci", ), parse_mode="markdown", ) except BadRequest: send_message( update.effective_message, tl( update.effective_message, "Saya *akan* memperingati pengguna jika dia mengirim pesan yang dikunci", parse_mode="markdown", quote=False, ), ) elif args[0] == "off" or args[0] == "no": sql.set_lockconf(chat_id, False) try: send_message( update.effective_message, tl( update.effective_message, "Saya *tidak akan* memperingati pengguna jika dia mengirim pesan yang dikunci", ), parse_mode="markdown", ) except BadRequest: send_message( update.effective_message, tl( update.effective_message, "Saya *tidak akan* memperingati pengguna jika dia mengirim pesan yang dikunci", parse_mode="markdown", quote=False, ), ) else: try: send_message( update.effective_message, tl( update.effective_message, "Saya hanya mengerti 'on/yes' atau 'off/no' saja!", ), parse_mode="markdown", ) except BadRequest: send_message( update.effective_message, tl( update.effective_message, "Saya hanya mengerti 'on/yes' atau 'off/no' saja!", ), parse_mode="markdown", quote=False, ) else: getconf = sql.get_lockconf(chat_id) if getconf: try: send_message( update.effective_message, tl( update.effective_message, "Saat ini saya *akan* memperingati pengguna jika dia mengirim pesan yang dikunci", ), parse_mode="markdown", ) except BadRequest: send_message( update.effective_message, tl( update.effective_message, "Saat ini saya *akan* memperingati pengguna jika dia mengirim pesan yang dikunci", ), parse_mode="markdown", quote=False, ) else: try: send_message( update.effective_message, tl( update.effective_message, "Saat ini saya *tidak akan* memperingati pengguna jika dia mengirim pesan yang dikunci", ), parse_mode="markdown", ) except BadRequest: send_message( update.effective_message, tl( update.effective_message, "Saat ini saya *tidak akan* memperingati pengguna jika dia mengirim pesan yang dikunci", ), parse_mode="markdown", quote=False, )
def gban(bot: Bot, update: Update, args: List[str]): message = update.effective_message # type: Optional[Message] user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text( tl(update.effective_message, "Anda sepertinya tidak mengacu pada pengguna.")) return if int(user_id) in SUDO_USERS: message.reply_text( tl( update.effective_message, "Saya memata-matai, dengan mata kecil saya... perang pengguna sudo! Mengapa kalian saling berpaling? 😱" )) return if int(user_id) in SUPPORT_USERS: message.reply_text( tl( update.effective_message, "OOOH seseorang mencoba untuk memblokir secara global pengguna dukungan! 😄 *mengambil popcorn*" )) return if user_id == bot.id: message.reply_text( tl( update.effective_message, "😑 Sangat lucu, mari kita blokir secara global diri saya sendiri? Usaha yang bagus 😒" )) return try: user_chat = bot.get_chat(user_id) except BadRequest as excp: message.reply_text(excp.message) return if user_chat.type != 'private': message.reply_text(tl(update.effective_message, "Itu bukan pengguna!")) return if sql.is_user_gbanned(user_id): if not reason: message.reply_text( tl( update.effective_message, "Pengguna ini sudah dilarang secara global; Saya akan mengubah alasannya, tetapi Anda belum memberi saya satu..." )) return old_reason = sql.update_gban_reason( user_id, user_chat.username or user_chat.first_name, reason) if old_reason: message.reply_text(tl( update.effective_message, "Pengguna ini sudah gbanned, karena alasan berikut:\n" "<code>{}</code>\n" "Saya telah melakukan dan memperbaruinya dengan alasan baru Anda!" ).format(html.escape(old_reason)), parse_mode=ParseMode.HTML) else: message.reply_text( tl( update.effective_message, "Pengguna ini sudah gbanned, tetapi tidak ada alasan yang ditetapkan; Saya telah melakukan dan memperbaruinya!" )) return message.reply_text( tl(update.effective_message, "*It's global banned time* 😉")) banner = update.effective_user # type: Optional[User] send_to_list(bot, SUDO_USERS + SUPPORT_USERS, tl(update.effective_message, "{} melarang secara global pengguna {} " "karena:\n{}").format( mention_html(banner.id, banner.first_name), mention_html(user_chat.id, user_chat.first_name), reason or tl(update.effective_message, "Tidak ada alasan yang diberikan")), html=True) sql.gban_user(user_id, user_chat.username or user_chat.first_name, reason) chats = get_all_chats() for chat in chats: chat_id = chat.chat_id # Check if this group has disabled gbans if not sql.does_chat_gban(chat_id): continue try: bot.kick_chat_member(chat_id, user_id) except BadRequest as excp: if excp.message in GBAN_ERRORS: pass else: message.reply_text( tl(update.effective_message, "Tidak dapat melarang secara global karena: {}").format( excp.message)) send_to_list( bot, SUDO_USERS + SUPPORT_USERS, tl(update.effective_message, "Tidak dapat melarang secara global karena: {}").format( excp.message)) sql.ungban_user(user_id) return except TelegramError: pass send_to_list( bot, SUDO_USERS + SUPPORT_USERS, tl(update.effective_message, "Melarang secara global selesai!")) message.reply_text( tl(update.effective_message, "Orang ini telah dilarang secara global."))
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 verify_button_pressed(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] query = update.callback_query # type: Optional[CallbackQuery] match = re.match(r"verify_me\((.+?)\)", query.data) match = match.group(1).split("|") is_ok = match[0] user_id = match[1] chat_id = match[2] message = update.effective_message # type: Optional[Message] print("-> {} was clicked welcome verify button".format(user.id)) if is_ok == "y": if context.bot.getChatMember(chat_id, user_id).status in ('left'): query.answer( text=tl(update.effective_message, "Failed: user left chat")) return try: context.bot.restrict_chat_member( chat_id, user_id, permissions=ChatPermissions(can_send_messages=True, can_send_media_messages=True, can_send_other_messages=True, can_add_web_page_previews=True)) sql.add_to_userlist(chat_id, user_id, True) sql.rm_from_timeout(chat_id, user_id) except BadRequest as err: if not update.effective_chat.get_member( context.bot.id).can_restrict_members: query.answer(text=tl( update.effective_message, "Saya tidak dapat membatasi orang disini, tanya admin untuk unmute!" )) else: query.answer(text="Error: " + str(err)) return chat_name = context.bot.get_chat(chat_id).title context.bot.edit_message_media( chat.id, message_id=query.message.message_id, media=InputMediaPhoto( media="https://telegra.ph/file/06d2c5ec80af3858c2d4b.jpg", caption=tl( update.effective_message, "*Berhasil!*\n\nKerja bagus manusia, kini Anda dapat chatting di: *{}*" ).format(chat_name), parse_mode="markdown")) query.answer(text=tl( update.effective_message, "Berhasil! Anda dapat chatting di {} sekarang").format(chat_name), show_alert=True) else: context.bot.edit_message_media( chat.id, message_id=query.message.message_id, media=InputMediaPhoto( media="https://telegra.ph/file/d81cdcbafb240071add84.jpg", caption=tl( update.effective_message, "Maaf robot, kamu telah salah klik tombol verifikasi.\n\nCoba lagi dengan klik tombol verifikasi pada pesan selamat datang." ), parse_mode="markdown")) query.answer(text=tl( update.effective_message, "Gagal! Kamu telah salah mengklik tombol verifikasi"), show_alert=True)
def __chat_settings__(chat_id, user_id): return tl(user_id, "Obrolan ini memiliki aturan yang ditetapkan: `{}`").format( bool(sql.get_rules(chat_id)))
def verify_welcome(update, context, chat_id): user_id = update.effective_user.id is_clicked = sql.get_chat_userlist(chat_id) if user_id not in list(is_clicked): send_message( update.effective_message, tl( update.effective_message, "Anda sedang tidak dalam mode verifikasi, jika anda sedang di bisukan, anda dapat meminta tolong pada admin di grup yang bersangkutan" )) return elif user_id in list(is_clicked) and is_clicked[user_id] == True: send_message( update.effective_message, tl( update.effective_message, "Anda sedang tidak dalam mode verifikasi, jika anda sedang di bisukan, anda dapat meminta tolong pada admin di grup yang bersangkutan" )) return verify_code = [ "🙏", "👈", "👉", "👇", "👆", "❤️", "🅰️", "🅱️", "0️⃣", "1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", "🔟" ] print(len(verify_code)) real_btn = random.choice(verify_code) verify_code.remove(real_btn) verbox = (random.randint(1, 3), random.randint(1, 3)) buttons = [] linebox = [] for x in range(3): x += 1 if verbox[1] == x: ver1 = True else: ver1 = False for y in range(3): y += 1 if verbox[0] == y and ver1: verify_emoji = real_btn linebox.append( InlineKeyboardButton( text=verify_emoji, callback_data="verify_me(y|{}|{})".format( user_id, chat_id))) else: verify_emoji = random.choice(verify_code) linebox.append( InlineKeyboardButton( text=verify_emoji, callback_data="verify_me(n|{}|{})".format( user_id, chat_id))) verify_code.remove(verify_emoji) buttons.append(linebox) linebox = [] context.bot.send_photo(user_id, photo=verify_code_images[real_btn], caption=tl( update.effective_message, "Tolong pilih emoji yang sama dibawah ini:"), parse_mode=ParseMode.MARKDOWN, reply_markup=InlineKeyboardMarkup(buttons))
def clear(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 = "local notes" else: chat_name = chat.title if len(args) >= 1: catatan = [] catatangagal = [] for x in range(len(args)): notename = args[x] if sql.rm_note(chat_id, notename): catatan.append(notename) else: catatangagal.append(notename) if len(catatan) >= 1 and len(catatangagal) == 0: if conn: rtext = tl( update.effective_message, "Catatan di *{chat_name}* untuk `{note_name}` dihapus 😁" ).format(chat_name=chat_name, note_name=", ".join(catatan)) else: rtext = tl(update.effective_message, "Catatan `{note_name}` dihapus 😁").format( note_name=", ".join(catatan)) try: send_message(update.effective_message, rtext, parse_mode=ParseMode.MARKDOWN) except BadRequest: if conn: rtext = tl( update.effective_message, "Catatan di <b>{chat_name}</b> untuk <code>{note_name}</code> dihapus 😁" ).format(chat_name=chat_name, note_name=", ".join(catatan)) else: rtext = tl( update.effective_message, "Catatan <code>{note_name}</code> dihapus 😁").format( note_name=", ".join(catatan)) send_message(update.effective_message, rtext, parse_mode=ParseMode.HTML) elif len(catatangagal) >= 0 and len(catatan) == 0: if conn: rtext = tl( update.effective_message, "Catatan di *{chat_name}* untuk `{fnote_name}` gagal dihapus!" ).format(chat_name=chat_name, fnote_name=", ".join(catatangagal)) else: rtext = tl(update.effective_message, "Catatan `{fnote_name}` gagal dihapus!").format( fnote_name=", ".join(catatangagal)) try: send_message(update.effective_message, rtext, parse_mode=ParseMode.MARKDOWN) except BadRequest: if conn: rtext = tl( update.effective_message, "Catatan di <b>{chat_name}</b> untuk <code>{fnote_name}</code> gagal dihapus!" ).format(chat_name=chat_name, fnote_name=", ".join(catatangagal)) else: rtext = tl( update.effective_message, "Catatan <code>{fnote_name}</code> gagal dihapus!" ).format(fnote_name=", ".join(catatangagal)) send_message(update.effective_message, tl(update.effective_message, rtext), parse_mode=ParseMode.HTML) else: if conn: rtext = tl( update.effective_message, "Catatan di *{chat_name}* untuk `{note_name}` dihapus 😁\nCatatan `{fnote_name}` gagal dihapus!" ).format(chat_name=chat_name, note_name=", ".join(catatan), fnote_name=", ".join(catatangagal)) else: rtext = tl( update.effective_message, "Catatan `{note_name}` dihapus 😁\nCatatan `{fnote_name}` gagal dihapus!" ).format(note_name=", ".join(catatan), fnote_name=", ".join(catatangagal)) try: send_message(update.effective_message, rtext, parse_mode=ParseMode.MARKDOWN) except BadRequest: if conn: rtext = tl( update.effective_message, "Catatan di <b>{chat_name}</b> untuk <code>{note_name}</code> dihapus 😁\nCatatan <code>{fnote_name}</code> gagal dihapus!" ).format(chat_name=chat_name, note_name=", ".join(catatan), fnote_name=", ".join(catatangagal)) else: rtext = tl( update.effective_message, "Catatan <code>{note_name}</code> dihapus 😁\nCatatan <code>{fnote_name}</code> gagal dihapus!" ).format(note_name=", ".join(catatan), fnote_name=", ".join(catatangagal)) send_message(update.effective_message, tl(update.effective_message, rtext), parse_mode=ParseMode.HTML) else: send_message(update.effective_message, tl(update.effective_message, "Apa yang ingin dihapus?"))
def rss_update(bot, job): user_data = sql.get_all() # this loop checks for every row in the DB for row in user_data: row_id = row.id tg_chat_id = row.chat_id tg_feed_link = row.feed_link feed_processed = parse(tg_feed_link) tg_old_entry_link = row.old_entry_link new_entry_links = [] new_entry_titles = [] # this loop checks for every entry from the RSS Feed link from the DB row for entry in feed_processed.entries: # check if there are any new updates to the RSS Feed from the old entry if entry.link != tg_old_entry_link: new_entry_links.append(entry.link) new_entry_titles.append(entry.title) else: break # check if there's any new entries queued from the last check if new_entry_links: sql.update_url(row_id, new_entry_links) else: pass if len(new_entry_links) < 5: # this loop sends every new update to each user from each group based on the DB entries for link, title in zip(reversed(new_entry_links), reversed(new_entry_titles)): final_message = "<b>{}</b>\n\n{}".format( html.escape(title), html.escape(link)) if len(final_message) <= constants.MAX_MESSAGE_LENGTH: try: bot.send_message(chat_id=tg_chat_id, text=final_message, parse_mode=ParseMode.HTML) except error.Unauthorized: print("Cannot send msg bcz bot is kicked") sql.remove_url(tg_chat_id, tg_feed_link) else: try: bot.send_message( chat_id=tg_chat_id, text=tl( tg_chat_id, "<b>Peringatan:</b> Pesan terlalu panjang untuk dikirim" ), parse_mode=ParseMode.HTML) except error.Unauthorized: print("Cannot send msg bcz bot is kicked") sql.remove_url(tg_chat_id, tg_feed_link) else: for link, title in zip(reversed(new_entry_links[-5:]), reversed(new_entry_titles[-5:])): final_message = "<b>{}</b>\n\n{}".format( html.escape(title), html.escape(link)) if len(final_message) <= constants.MAX_MESSAGE_LENGTH: try: bot.send_message(chat_id=tg_chat_id, text=final_message, parse_mode=ParseMode.HTML) except error.Unauthorized: sql.remove_url(tg_chat_id, tg_feed_link) else: try: bot.send_message( chat_id=tg_chat_id, text=tl( tg_chat_id, "<b>Peringatan:</b> Pesan terlalu panjang untuk dikirim" ), parse_mode=ParseMode.HTML) except error.Unauthorized: sql.remove_url(tg_chat_id, tg_feed_link) try: bot.send_message( chat_id=tg_chat_id, parse_mode=ParseMode.HTML, text=tl( tg_chat_id, "<b>Peringatan: </b>{} kejadian telah ditinggalkan untuk mencegah spam" ).format(len(new_entry_links) - 5)) except error.Unauthorized: sql.remove_url(tg_chat_id, tg_feed_link)
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 warn(user: User, chat: Chat, reason: str, message: Message, warner: User = None, conn=False) -> str: if is_user_admin(chat, user.id): return "" if warner: warner_tag = mention_html(warner.id, warner.first_name) else: warner_tag = tl(chat.id, "Filter peringatan otomatis.") limit, soft_warn, warn_mode = sql.get_warn_setting(chat.id) num_warns, reasons = sql.warn_user(user.id, chat.id, reason) if num_warns >= limit: sql.reset_warns(user.id, chat.id) if not soft_warn: if not warn_mode: chat.unban_member(user.id) reply = tl(chat.id, "{} peringatan, {} telah ditendang!").format(limit, mention_html(user.id, user.first_name)) elif warn_mode == 1: chat.unban_member(user.id) reply = tl(chat.id, "{} peringatan, {} telah ditendang!").format(limit, mention_html(user.id, user.first_name)) elif warn_mode == 2: chat.kick_member(user.id) reply = tl(chat.id, "{} peringatan, {} telah diblokir!").format(limit, mention_html(user.id, user.first_name)) elif warn_mode == 3: message.bot.restrict_chat_member(chat.id, user.id, can_send_messages=False) reply = tl(chat.id, "{} peringatan, {} telah dibisukan!").format(limit, mention_html(user.id, user.first_name)) else: chat.kick_member(user.id) reply = tl(chat.id, "{} peringatan, {} telah diblokir!").format(limit, mention_html(user.id, user.first_name)) for warn_reason in reasons: reply += "\n - {}".format(html.escape(warn_reason)) message.bot.send_sticker(chat.id, BAN_STICKER) # banhammer marie sticker keyboard = None log_reason = "<b>{}:</b>" \ "\n#WARN_BAN" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {} (<code>{}</code>)" \ "\n<b>Reason:</b> {}"\ "\n<b>Counts:</b> <code>{}/{}</code>".format(html.escape(chat.title), warner_tag, mention_html(user.id, user.first_name), user.id, reason, num_warns, limit) else: keyboard = InlineKeyboardMarkup( [[InlineKeyboardButton(tl(chat.id, "Hapus peringatan"), callback_data="rm_warn({})".format(user.id)), InlineKeyboardButton(tl(chat.id, "Peraturan"), url="t.me/{}?start={}".format(dispatcher.bot.username, chat.id))]]) if num_warns+1 == limit: if not warn_mode: action_mode = tl(chat.id, "tendang") elif warn_mode == 1: action_mode = tl(chat.id, "tendang") elif warn_mode == 2: action_mode = tl(chat.id, "blokir") elif warn_mode == 3: action_mode = tl(chat.id, "bisukan") reply = tl(chat.id, "{} punya {}/{} peringatan... Jika anda di peringati lagi maka kamu akan di {}!").format(mention_html(user.id, user.first_name), num_warns, limit, action_mode) else: reply = tl(chat.id, "{} punya {}/{} peringatan... Hati-hati!").format(mention_html(user.id, user.first_name), num_warns, limit) if reason: reply += tl(chat.id, "\nAlasan pada peringatan terakhir:\n{}").format(html.escape(reason)) log_reason = "<b>{}:</b>" \ "\n#WARN" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {} (<code>{}</code>)" \ "\n<b>Reason:</b> {}"\ "\n<b>Counts:</b> <code>{}/{}</code>".format(html.escape(chat.title), warner_tag, mention_html(user.id, user.first_name), user.id, reason, num_warns, limit) try: if conn: send_message_raw(chat.id, reply, reply_markup=keyboard, parse_mode=ParseMode.HTML) else: send_message_raw(chat.id, reply, reply_to_message_id=message.message_id, reply_markup=keyboard, parse_mode=ParseMode.HTML) #send_message(update.effective_message, reply, reply_markup=keyboard, parse_mode=ParseMode.HTML) except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply if conn: message.bot.sendMessage(chat.id, reply, reply_markup=keyboard, parse_mode=ParseMode.HTML) else: try: message.bot.sendMessage(chat.id, reply, reply_to_message_id=message.message_id, reply_markup=keyboard, parse_mode=ParseMode.HTML, quote=False) except BadRequest: message.bot.sendMessage(chat.id, reply, reply_markup=keyboard, parse_mode=ParseMode.HTML, quote=False) #send_message(update.effective_message, reply, reply_markup=keyboard, parse_mode=ParseMode.HTML, quote=False) else: raise return log_reason