def permanent_pin(update, context): user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] message = update.effective_message get_permapin = sql.get_permapin(chat.id) if get_permapin and not user.id == context.bot.id: try: to_del = context.bot.pinChatMessage(chat.id, get_permapin, disable_notification=True) except BadRequest: sql.set_permapin(chat.id, 0) if chat.username: old_pin = "https://t.me/{}/{}".format(chat.username, get_permapin) else: old_pin = "https://t.me/c/{}/{}".format( str(chat.id)[4:], get_permapin) send_message( update.effective_message, tl( update.effective_message, "*Permanent pin error:*\nI can't pin messages here!\nMake sure I'm admin and can pin messages.\n\nPermanent pin disabled now, [here is your old pinned message]({})" ).format(old_pin), parse_mode="markdown") return if to_del: try: context.bot.deleteMessage(chat.id, message.message_id + 1) except BadRequest: print("Permanent pin error: cannot delete pin msg")
def set_warn_limit(update, context) -> str: chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] args = context.args conn = connected(context.bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_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_name = update.effective_message.chat.title if args: if args[0].isdigit(): if int(args[0]) < 3: send_message( update.effective_message, tl(update.effective_message, "Batas peringatan minimum adalah 3!")) else: sql.set_warn_limit(chat.id, int(args[0])) if conn: text = tl( update.effective_message, "Diperbarui batas untuk diperingatkan {} pada *{}*" ).format(args[0], chat_name) else: text = tl( update.effective_message, "Diperbarui batas untuk diperingatkan {}").format( args[0]) send_message(update.effective_message, text, parse_mode="markdown") return "<b>{}:</b>" \ "\n#SET_WARN_LIMIT" \ "\n<b>Admin:</b> {}" \ "\nSet the warn limit to <code>{}</code>".format(html.escape(chat.title), mention_html(user.id, user.first_name), args[0]) else: send_message(update.effective_message, tl(update.effective_message, "Beri aku angkanya!")) else: limit, soft_warn, warn_mode = sql.get_warn_setting(chat.id) if conn: text = tl(update.effective_message, "Batas peringatan saat ini adalah {} pada *{}*").format( limit, chat_name) else: text = tl(update.effective_message, "Batas peringatan saat ini adalah {}").format(limit) send_message(update.effective_message, text, parse_mode="markdown") return ""
def connected(bot, update, chat, user_id, need_admin=True): user = update.effective_user if chat.type == chat.PRIVATE and sql.get_connected_chat(user_id): conn_id = sql.get_connected_chat(user_id).chat_id getstatusadmin = bot.get_chat_member( conn_id, update.effective_message.from_user.id) isadmin = getstatusadmin.status in ('administrator', 'creator') ismember = getstatusadmin.status in ('member') isallow = sql.allow_connect_to_chat(conn_id) if (isadmin) or (isallow and ismember) or (user.id in SUDO_USERS): if need_admin is True: if getstatusadmin.status in ( 'administrator', 'creator') or user_id in SUDO_USERS: return conn_id else: send_message( update.effective_message, languages.tl( update.effective_message, "Anda harus menjadi admin dalam grup yang terhubung!" )) else: return conn_id else: send_message( update.effective_message, languages.tl( update.effective_message, "Grup mengubah koneksi hak atau Anda bukan admin lagi.\nSaya putuskan koneksi Anda." )) disconnect_chat(update, bot) else: return False
def set_verify_welcome(update, context): args = context.args chat = update.effective_chat getcur, extra_verify, cur_value, timeout, timeout_mode, cust_text = sql.welcome_security(chat.id) if len(args) >= 1: var = args[0].lower() if (var == "yes" or var == "on"): check = context.bot.getChatMember(chat.id, context.bot.id) if check.status == 'member' or check['can_restrict_members'] is False: text = tl(update.effective_message, "Saya tidak bisa membatasi orang di sini! Pastikan saya admin agar bisa membisukan seseorang!") send_message(update.effective_message, text, parse_mode="markdown") return "" sql.set_welcome_security(chat.id, getcur, True, str(cur_value), str(timeout), int(timeout_mode), cust_text) send_message(update.effective_message, tl(update.effective_message, "Keamanan untuk member baru di aktifkan! Pengguna baru di wajibkan harus menyelesaikan verifikasi untuk chat")) elif (var == "no" or var == "off"): sql.set_welcome_security(chat.id, getcur, False, str(cur_value), str(timeout), int(timeout_mode), cust_text) send_message(update.effective_message, tl(update.effective_message, "Di nonaktifkan, pengguna dapat mengklik tombol untuk langsung chat")) else: send_message(update.effective_message, tl(update.effective_message, "Silakan tulis `on`/`ya`/`off`/`ga`!"), parse_mode=ParseMode.MARKDOWN) else: getcur, extra_verify, cur_value, timeout, timeout_mode, cust_text = sql.welcome_security(chat.id) if cur_value[:1] == "0": cur_value = tl(update.effective_message, "Selamanya") text = tl(update.effective_message, "Pengaturan saat ini adalah:\nWelcome security: `{}`\nVerify security: `{}`\nMember akan di mute selama: `{}`\nWaktu verifikasi timeout: `{}`\nTombol unmute custom: `{}`").format( getcur, extra_verify, cur_value, make_time(int(timeout)), cust_text) send_message(update.effective_message, text, parse_mode="markdown")
def list_locks(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # Connection check conn = connected(context.bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_name = chat.title else: if update.effective_message.chat.type == "private": send_message( update.effective_message, 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 permapin(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] args = context.args conn = connected(context.bot, update, chat, user.id, need_admin=False) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: if update.effective_message.chat.type == "private": send_message( update.effective_message, tl(update.effective_message, "You can do this command in groups, not PM")) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title text, data_type, content, buttons = get_message_type(message) tombol = build_keyboard_alternate(buttons) try: message.delete() except BadRequest: pass if str(data_type) in ('Types.BUTTON_TEXT', 'Types.TEXT'): try: sendingmsg = context.bot.send_message( chat_id, text, parse_mode="markdown", disable_web_page_preview=True, reply_markup=InlineKeyboardMarkup(tombol)) except BadRequest: context.bot.send_message( chat_id, tl( update.effective_message, "Wrong markdown text!\nIf you don't know what markdown is, please type `/markdownhelp` in PM." ), parse_mode="markdown") return else: sendingmsg = ENUM_FUNC_MAP[str(data_type)]( chat_id, content, caption=text, parse_mode="markdown", disable_web_page_preview=True, reply_markup=InlineKeyboardMarkup(tombol)) try: context.bot.pinChatMessage(chat_id, sendingmsg.message_id) except BadRequest: send_message( update.effective_message, tl(update.effective_message, "I don't have access to pin message!"))
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 Exception: print("Fban: cannot ban 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 runs(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 send_message(update.effective_message, random.choice(tl(update.effective_message, "RUN_STRINGS")))
def cmd_get(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat # type: Optional[Chat] if len(args) >= 2 and args[1].lower() == "noformat": get(bot, update, args[0], show_none=True, no_format=True) elif len(args) >= 1: get(bot, update, args[0], show_none=True) else: send_message(update.effective_message, (tld(chat.id, "Get what?")))
def cmd_get(update, context): args = context.args if len(args) >= 2 and args[1].lower() == "noformat": get(context.bot, update, args[0], show_none=True, no_format=True) elif len(args) >= 1: get(context.bot, update, args[0], show_none=True) else: send_message(update.effective_message, tl(update.effective_message, "Get what?"))
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 set_blue_text_must_click(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] args = context.args conn = connected(context.bot, update, chat, user.id, need_admin=True) if conn: chat_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, "You can do this command in groups, not PM")) return "" chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title if len(args) >= 1: val = args[0].lower() if val == "off" or val == "no": sql.set_cleanbt(chat_id, False) if conn: text = tl(update.effective_message, "Blue text cleaner was *disabled* in *{}*.").format( chat_name) else: text = tl(update.effective_message, "Blue text cleaner was *disabled*.") send_message(update.effective_message, text, parse_mode="markdown") elif val == "yes" or val == "on": sql.set_cleanbt(chat_id, True) if conn: text = tl(update.effective_message, "Blue text cleaner was *enabled* in *{}*.").format( chat_name) else: text = tl(update.effective_message, "Blue text cleaner was *enabled*.") send_message(update.effective_message, text, parse_mode="markdown") else: send_message( update.effective_message, tl(update.effective_message, "Unknown argument - please use 'yes', or 'no'.")) else: send_message( update.effective_message, tl(update.effective_message, "Curent settings for Blue text cleaner at {}: *{}*").format( chat_name, "Enabled" if sql.is_enable(chat_id) else "Disabled"), parse_mode="markdown")
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 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 help_connect_chat(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] args = context.args 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 save(update, context): chat = update.effective_chat user = update.effective_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 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 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 add_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_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_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) >= 2: # set trigger -> lower, so as to avoid adding duplicate filters with different cases keyword = extracted[0].lower() content = extracted[1] else: return # Note: perhaps handlers can be removed somehow using sql.get_chat_filters for handler in dispatcher.handlers.get(WARN_HANDLER_GROUP, []): if handler.filters == (keyword, chat.id): dispatcher.remove_handler(handler, WARN_HANDLER_GROUP) sql.add_warn_filter(chat.id, keyword, content) if conn: text = tl( update.effective_message, "Peringatkan handler yang ditambahkan untuk '{}' pada *{}*!" ).format(keyword, chat_name) else: text = tl( update.effective_message, "Peringatkan handler yang ditambahkan untuk '{}'!").format(keyword) send_message(update.effective_message, text, parse_mode="markdown") raise DispatcherHandlerStop
def afk(update, context): 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, "{} is now AFK!").format(update.effective_user.first_name))
def no_longer_afk(update, context): user = update.effective_user # type: Optional[User] if not user: # ignore channels return res = sql.rm_afk(user.id) if res: send_message( update.effective_message, tl(update.effective_message, "{} is no longer AFK!").format( update.effective_user.first_name))
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(): send_message( update.effective_message, tl(update.effective_message, "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") send_message( update.effective_message, "Sekarang pukul {} di {}".format(time_there, location))
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 wiki(update, context): chat_id = update.effective_chat.id args = update.effective_message.text.split(None, 1) teks = args[1] getlang = langsql.get_lang(chat_id) if str(getlang) == "pt": wikipedia.set_lang("pt") else: wikipedia.set_lang("en") try: pagewiki = wikipedia.page(teks) except wikipedia.exceptions.PageError: send_message(update.effective_message, tl(update.effective_message, "Results not found")) 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 == "pt": teks += rujuk[x].replace('may refer to', 'pode se referir a') + "\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, "Write a message to search from the wikipedia source")) return judul = pagewiki.title summary = pagewiki.summary if update.effective_message.chat.type == "private": send_message(update.effective_message, tl(update.effective_message, "Results of {} is:\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, "Read More..."), url="t.me/{}?start=wiki-{}".format( context.bot.username, teks.replace(' ', '_')))]]) else: button = None send_message(update.effective_message, tl(update.effective_message, "Results of {} is:\n\n<b>{}</b>\n{}").format(teks, judul, summary), parse_mode=ParseMode.HTML, reply_markup=button)
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 disable_del(update, context): msg = update.effective_message chat = update.effective_chat if len(msg.text.split()) >= 2: args = msg.text.split(None, 1)[1] if args in ("yes", "on"): sql.disabledel_set(chat.id, True) send_message(update.effective_message, languages.tl(update.effective_message, "Ketika command di nonaktifkan, maka saya *akan menghapus* pesan command tsb."), parse_mode="markdown") return elif args in ("no", "off"): sql.disabledel_set(chat.id, False) send_message(update.effective_message, languages.tl(update.effective_message, "Saya *tidak akan menghapus* pesan dari command yang di nonaktifkan."), parse_mode="markdown") return else: send_message(update.effective_message, languages.tl(update.effective_message, "Argumen tidak dikenal - harap gunakan 'yes', atau 'no'.")) else: send_message(update.effective_message, languages.tl(update.effective_message, "Opsi disable del saat ini: *{}*").format( "Enabled" if sql.is_disable_del(chat.id) else "Disabled"), parse_mode="markdown")
def stop_filter(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user args = update.effective_message.text.split(None, 1) conn = connected(context.bot, update, chat, user.id) if conn is not False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = tl(update.effective_message, "catatan lokal") else: chat_name = chat.title if len(args) < 2: send_message(update.effective_message, tl(update.effective_message, "Apa yang harus saya hentikan?")) return chat_filters = sql.get_chat_triggers(chat_id) if not chat_filters: send_message(update.effective_message, tl(update.effective_message, "Tidak ada filter aktif di sini!")) return for keyword in chat_filters: if keyword == args[1].lower(): sql.remove_filter(chat_id, args[1].lower()) send_message(update.effective_message, tl(update.effective_message, "Ya, saya akan berhenti menjawabnya di *{}*.").format(chat_name), parse_mode=telegram.ParseMode.MARKDOWN) raise DispatcherHandlerStop send_message(update.effective_message, "Itu bukan filter aktif - jalankan /filter untuk semua filter aktif.")
def private_rules(update, context): args = context.args chat = update.effective_chat user = update.effective_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 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 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 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) 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 text = build_curr_disabled(chat.id) send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN)