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 list_handlers(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user conn = connected(context.bot, update, chat, user.id, need_admin=False) if conn is not False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title filter_list = "*Filter di {}:*\n" else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = tl(update.effective_message, "filter lokal") filter_list = tl(update.effective_message, "*filter lokal:*\n") else: chat_name = chat.title filter_list = tl(update.effective_message, "*Filter di {}*:\n") all_handlers = sql.get_chat_triggers(chat_id) if not all_handlers: send_message(update.effective_message, tl(update.effective_message, "Tidak ada filter di {}!").format(chat_name)) return for keyword in all_handlers: entry = " - {}\n".format(escape_markdown(keyword)) if len(entry) + len(filter_list) > telegram.MAX_MESSAGE_LENGTH: send_message(update.effective_message, filter_list.format(chat_name), parse_mode=telegram.ParseMode.MARKDOWN) filter_list = entry else: filter_list += entry send_message(update.effective_message, filter_list.format(chat_name), parse_mode=telegram.ParseMode.MARKDOWN)
def 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 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 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 leavechat(update, context): args = context.args if args: chat_id = int(args[0]) else: send_message( update.effective_message, tl(update.effective_message, "Anda sepertinya tidak mengacu pada obrolan")) try: titlechat = context.bot.get_chat(chat_id).title context.bot.sendMessage( chat_id, tl(update.effective_message, "Selamat tinggal semua 😁")) context.bot.leaveChat(chat_id) send_message( update.effective_message, tl(update.effective_message, "Saya telah keluar dari grup {}").format(titlechat)) except BadRequest as excp: if excp.message == "Chat not found": send_message( update.effective_message, tl( update.effective_message, "Sepertinya saya sudah keluar atau di tendang di grup tersebut" )) else: return
def button(update, context): query = update.callback_query # type: Optional[CallbackQuery] user = update.effective_user # type: Optional[User] match = re.match(r"rm_warn\((.+?)\)", query.data) if match: user_id = match.group(1) chat = update.effective_chat # type: Optional[Chat] res = sql.remove_warn(user_id, chat.id) if res: update.effective_message.edit_text(tl( update.effective_message, "Peringatkan dihapus oleh {}.").format( mention_html(user.id, user.first_name)), parse_mode=ParseMode.HTML) user_member = chat.get_member(user_id) return "<b>{}:</b>" \ "\n#UNWARN" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(user_member.user.id, user_member.user.first_name), user_member.user.id) else: update.effective_message.edit_text(tl( update.effective_message, "Pengguna sudah tidak memiliki peringatan.").format( mention_html(user.id, user.first_name)), parse_mode=ParseMode.HTML) return ""
def send_settings(chat_id, user_id, user=False): if user: if USER_SETTINGS: settings = "\n\n".join( "*{}*:\n{}".format(mod.__mod_name__, mod.__user_settings__(user_id)) for mod in USER_SETTINGS.values()) dispatcher.bot.send_message(user_id, tl(chat_id, "These are your current settings:") + "\n\n" + settings, parse_mode=ParseMode.MARKDOWN) else: dispatcher.bot.send_message(user_id, tl(chat_id, "Seems like there aren't any user specific settings available 😢"), parse_mode=ParseMode.MARKDOWN) else: if CHAT_SETTINGS: chat_name = dispatcher.bot.getChat(chat_id).title dispatcher.bot.send_message(user_id, text=tl(chat_id, "Which module would you like to check {}'s settings for?").format( chat_name), reply_markup=InlineKeyboardMarkup( paginate_modules(0, CHAT_SETTINGS, "stngs", chat=chat_id))) else: dispatcher.bot.send_message(user_id, tl(chat_id, "Seems like there aren't any chat settings available :'(\n " "Send this in a group chat you're admin in to find its current settings!"), parse_mode=ParseMode.MARKDOWN)
def report_alt(update, context) -> str: message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] if chat and message.reply_to_message and sql.chat_should_report(chat.id): reported_user = message.reply_to_message.from_user admin_list = chat.get_administrators() msg = tl(update.effective_message, "<b>{}:</b>" "\n<b>Pengguna yang dilaporkan:</b> {} (<code>{}</code>)" "\n<b>Dilaporkan oleh:</b> {} (<code>{}</code>)").format(html.escape(chat.title), mention_html( reported_user.id, reported_user.first_name), reported_user.id, mention_html(user.id, user.first_name), user.id) all_admins = [] for admin in admin_list: if admin.user.is_bot: # don't tag bot continue if sql.user_should_report(admin.user.id): all_admins.append("<a href='tg://user?id={}'></a>".format(admin.user.id)) context.bot.send_message(chat.id, tl(update.effective_message, "⚠️ {} <b>telah di laporkan ke admin!</b>{}").format( mention_html(reported_user.id, reported_user.first_name), "".join(all_admins)), parse_mode=ParseMode.HTML, reply_to_message_id=message.reply_to_message.message_id) return msg return ""
def 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 set_welctimeout(update, context): args = context.args chat = update.effective_chat message = update.effective_message getcur, extra_verify, cur_value, timeout, timeout_mode, cust_text = sql.welcome_security(chat.id) if len(args) >= 1: var = args[0] if var[:1] == "0": mutetime = "0" sql.set_welcome_security(chat.id, getcur, extra_verify, cur_value, "0", timeout_mode, cust_text) text = tl(update.effective_message, "Batas waktu verifikasi telah di nonaktifkan!") else: mutetime = extract_time_int(message, var) if mutetime == "": return sql.set_welcome_security(chat.id, getcur, extra_verify, cur_value, str(mutetime), timeout_mode, cust_text) text = tl(update.effective_message, "Jika member baru tidak memverifikasi selama *{}* maka dia akan di *{}*").format(var, "Kick" if timeout_mode == 1 else "Banned") send_message(update.effective_message, text, parse_mode="markdown") else: if timeout == "0": send_message(update.effective_message, tl(update.effective_message, "Pengaturan batas waktu ketika join: *{}*").format("Disabled"), parse_mode="markdown") else: send_message(update.effective_message, tl(update.effective_message, "Pengaturan batas waktu ketika join: *{}*").format( make_time(int(timeout))), parse_mode="markdown")
def __chat_settings__(chat_id, user_id): administrators = dispatcher.bot.getChatAdministrators(chat_id) chat = dispatcher.bot.getChat(chat_id) text = "Admin in *{}*:".format(chat.title or "chat ini") for admin in administrators: user = admin.user status = admin.status if user.first_name == '': name = tl(user_id, "☠Deleted Account") else: name = "{}".format( mention_markdown( user.id, user.first_name + " " + (user.last_name or ""))) #if user.username: # name = escape_markdown("@" + user.username) if status == "creator": text += "\n 👑 Creator:" text += "\n` • `{} \n\n 🔱 Admin:".format(name) for admin in administrators: user = admin.user status = admin.status if user.first_name == '': name = tl(user_id, "☠Deleted Account") else: name = "{}".format( mention_markdown( user.id, user.first_name + " " + (user.last_name or ""))) #if user.username: # name = escape_markdown("@" + user.username) if status == "administrator": text += "\n` • `{}".format(name) text += tl(user_id, "\n\nYou are *{}*").format( dispatcher.bot.get_chat_member(chat_id, user_id).status) return text
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 remove_all_notes(update, context): chat = update.effective_chat user = update.effective_user message = update.effective_message if chat.type == "private": chat.title = tl(chat.id, "local notes") else: owner = chat.get_member(user.id) chat.title = chat.title if owner.status != 'creator': message.reply_text(tl(chat.id, "You must be this chat creator.")) return note_list = sql.get_all_chat_notes(chat.id) if not note_list: message.reply_text(tl(chat.id, "No notes in *{}*!").format(chat.title), parse_mode=ParseMode.MARKDOWN) return x = 0 a_note = [] for notename in note_list: x += 1 note = notename.name.lower() a_note.append(note) for note in a_note: sql.rm_note(chat.id, note) message.reply_text( tl(chat.id, "{} notes from this chat have been removed.").format(x))
def stop_all_filters(update, context): chat = update.effective_chat user = update.effective_user message = update.effective_message if chat.type == "private": chat.title = tl(chat.id, "local filters") else: owner = chat.get_member(user.id) chat.title = chat.title if owner.status != 'creator': message.reply_text(tl(chat.id, "You must be this chat creator.")) return x = 0 flist = sql.get_chat_triggers(chat.id) if not flist: message.reply_text( tl(chat.id, "There aren't any active filters in {}!").format(chat.title)) return f_flist = [] for f in flist: x += 1 f_flist.append(f) for fx in f_flist: sql.remove_filter(chat.id, fx) message.reply_text( tl(chat.id, "{} filters from this chat have been removed.").format(x))
def getlink(update, context): args = context.args if args: chat_id = int(args[0]) else: send_message( update.effective_message, tl(update.effective_message, "You don't seem to be referring to chat")) chat = context.bot.getChat(chat_id) bot_member = chat.get_member(context.bot.id) if bot_member.can_invite_users: titlechat = context.bot.get_chat(chat_id).title invitelink = context.bot.get_chat(chat_id).invite_link send_message( update.effective_message, tl( update.effective_message, "Successfully retrieve the invite link in the group {}. \nInvite link : {}" ).format(titlechat, invitelink)) else: send_message( update.effective_message, tl(update.effective_message, "I don't have access to the invitation link!"))
def adminlist(update, context): chat = update.effective_chat user = update.effective_user conn = connected(context.bot, update, chat, user.id, need_admin=False) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn 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 administrators = context.bot.getChatAdministrators(chat_id) text = tl(update.effective_message, "Admin in *{}*:").format( update.effective_chat.title or tl(update.effective_message, "chat ini")) for admin in administrators: user = admin.user status = admin.status if user.first_name == '': name = tl(update.effective_message, "☠Deleted Account") else: name = "{}".format( mention_markdown( user.id, user.first_name + " " + (user.last_name or ""))) # if user.username: # name = escape_markdown("@" + user.username) if status == "creator": text += "\n 👑 Creator:" text += "\n` • `{} \n\n 🔱 Admins:".format(name) for admin in administrators: user = admin.user status = admin.status if user.first_name == '': name = tl(update.effective_message, "☠Deleted Account") else: name = "{}".format( mention_markdown( user.id, user.first_name + " " + (user.last_name or ""))) # if user.username: # name = escape_markdown("@" + user.username) if status == "administrator": text += "\n` • `{}".format(name) try: send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN) except BadRequest: send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN, quote=False)
def buttonask(update, context): query = update.callback_query splitter = query.data.replace("ak_", "").split("+") isyes = splitter[1].split('|')[0] report_chat = splitter[1].split('|')[1].split('=')[0] report_target = splitter[1].split('|')[1].split('=')[1] chat = update.effective_chat msg = CURRENT_REPORT.get(str(report_chat)) userinfo = CURRENT_REPORT.get(str(report_chat)+"user") key = CURRENT_REPORT.get(str(report_chat)+"key") if isyes == "y": a, b = user_protection_checker(context.bot, report_target) if not a: context.bot.edit_message_text(text=msg + b, chat_id=query.message.chat_id, message_id=query.message.message_id, parse_mode=ParseMode.HTML) return if splitter[0] == "1": try: context.bot.unbanChatMember(report_chat, report_target) context.bot.sendMessage(report_chat, text=tl(update.effective_message, "{} telah di tendang!\nOleh: {}").format(\ mention_markdown(userinfo['id'], userinfo['name']), mention_markdown(chat.id, chat.first_name)), \ parse_mode=ParseMode.MARKDOWN) context.bot.edit_message_text(text=msg + tl(update.effective_message, "\n\n{} telah di tendang!").format(mention_html(userinfo['id'], userinfo['name'])), chat_id=query.message.chat_id, message_id=query.message.message_id, parse_mode=ParseMode.HTML) except Exception as err: context.bot.edit_message_text(text=msg + "\n\nError: {}".format(err), chat_id=query.message.chat_id, message_id=query.message.message_id, parse_mode=ParseMode.HTML) elif splitter[0] == "2": try: context.bot.kickChatMember(report_chat, report_target) context.bot.sendMessage(report_chat, text=tl(update.effective_message, "{} telah di banned!\nOleh: {}").format(\ mention_markdown(userinfo['id'], userinfo['name']), mention_markdown(chat.id, chat.first_name)), \ parse_mode=ParseMode.MARKDOWN) context.bot.edit_message_text(text=msg + tl(update.effective_message, "\n\n{} telah di banned!").format(mention_html(userinfo['id'], userinfo['name'])), chat_id=query.message.chat_id, message_id=query.message.message_id, parse_mode=ParseMode.HTML) except Exception as err: context.bot.edit_message_text(text=msg + "\n\nError: {}".format(err), chat_id=query.message.chat_id, message_id=query.message.message_id, parse_mode=ParseMode.HTML) elif splitter[0] == "3": try: context.bot.deleteMessage(report_chat, report_target) context.bot.edit_message_text(text=msg + tl(update.effective_message, "\n\nPesan dihapus!"), chat_id=query.message.chat_id, message_id=query.message.message_id, parse_mode=ParseMode.HTML) except Exception as err: context.bot.edit_message_text(text=msg + "\n\nError: {}".format(err), chat_id=query.message.chat_id, message_id=query.message.message_id, parse_mode=ParseMode.HTML) elif isyes == "n": context.bot.edit_message_text(text=msg, chat_id=query.message.chat_id, message_id=query.message.message_id, parse_mode=ParseMode.HTML, reply_markup=key)
def build_curr_disabled(chat_id: Union[str, int]) -> str: disabled = sql.get_all_disabled(chat_id) if not disabled: return languages.tl(chat_id, "Tidak ada perintah yang dinonaktifkan!") result = "" for cmd in disabled: result += " - `{}`\n".format(escape_markdown(cmd)) return languages.tl(chat_id, "Perintah-perintah berikut saat ini dibatasi:\n{}").format(result)
def 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 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 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 __chat_settings__(chat_id, user_id): log_channel = sql.get_chat_log_channel(chat_id) if log_channel: log_channel_info = dispatcher.bot.get_chat(log_channel) return tl( user_id, "Grup ini memiliki semua log yang dikirim ke: {} (`{}`)" ).format(escape_markdown(log_channel_info.title), log_channel) return tl(user_id, "Tidak ada saluran masuk yang ditetapkan untuk grup ini!")
def 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 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 list_notes(update, context): chat = update.effective_chat user = update.effective_user conn = connected(context.bot, update, chat, user.id, need_admin=False) if conn: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title msg = tl(update.effective_message, "*Notes on {}:*\n").format(chat_name) else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "" msg = tl(update.effective_message, "*Local notes:*\n") else: chat_name = chat.title msg = tl(update.effective_message, "*Notes on {}:*\n").format(chat_name) note_list = sql.get_all_chat_notes(chat_id) for note in note_list: note_name = " • `#{}`\n".format(note.name) if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: send_message(update.effective_message, msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name if msg == tl(update.effective_message, "*Notes on {}:*\n").format(chat_name) or msg == tl(update.effective_message, "*Local notes:*\n"): if conn: send_message(update.effective_message, tl(update.effective_message, "No notes in *{}*!").format(chat_name), parse_mode="markdown") else: send_message(update.effective_message, tl(update.effective_message, "No notes in this chat!")) elif len(msg) != 0: msg += tl(update.effective_message, "\nYou can retrieve these notes by using `/get notename`, or `#notename`") try: send_message(update.effective_message, msg, parse_mode=ParseMode.MARKDOWN) except BadRequest: if chat.type == "private": chat_name = "" msg = tl(update.effective_message, "<b>Local notes:</b>\n") else: chat_name = chat.title msg = tl(update.effective_message, "<b>Notes on {}:</b>\n").format(chat_name) for note in note_list: note_name = " - <code>{}</code>\n".format(note.name) if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: send_message(update.effective_message, msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name msg += tl(update.effective_message, "\nYou can retrieve these notes by using <code>/get notename</code>, or <code>#notename</code>") send_message(update.effective_message, msg, parse_mode=ParseMode.HTML)
def __user_info__(user_id, chat_id): if user_id == dispatcher.bot.id: return languages.tl( chat_id, """I have seen it... Wow. Are they following me? They're in all the same places with me... oh. This is me.""" ) num_chats = sql.get_user_num_chats(user_id) return languages.tl( chat_id, """I've seen them in <code>{}</code> chats in total.""").format( num_chats)
def kickme(update, context): user_id = update.effective_message.from_user.id if is_user_admin(update.effective_chat, user_id): send_message(update.effective_message, tl(update.effective_message, "Saya berharap saya bisa... tetapi Anda " "seorang admin 😒")) return res = update.effective_chat.unban_member(user_id) # unban on current user = kick if res: send_message(update.effective_message, tl(update.effective_message, "Tidak masalah 😊")) else: send_message(update.effective_message, tl(update.effective_message, "Hah? Aku tidak bisa 🙄"))