def get_settings(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] msg = update.effective_message # type: Optional[Message] msg.text.split(None, 1) # ONLY send settings in PM if chat.type != chat.PRIVATE: if is_user_admin(chat, user.id): text = "Klik di sini untuk mendapatkan pengaturan obrolan ini, serta milik Anda." msg.reply_text( text, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton( text="Pengaturan", url="t.me/{}?start=stngs_{}".format( context.bot.username, chat.id), ) ]]), ) else: text = "Klik di sini untuk memeriksa pengaturan Anda." else: send_settings(chat.id, user.id, True)
def start(update, context): if update.effective_chat.type == "private": args = context.args if len(args) >= 1: if args[0].lower() == "help": user = update.effective_user keyb = paginate_modules(0, HELPABLE, "help") if ( user.id in DEV_USERS or user.id in SUDO_USERS or user.id in SUPPORT_USERS ): keyb += [ [ InlineKeyboardButton( text="Staff", callback_data="help_staff" ) ] ] send_help( update.effective_chat.id, HELP_STRINGS, InlineKeyboardMarkup(keyb), ) 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) else: update.effective_message.reply_photo( "https://telegra.ph/file/c5d6f195010431a937190.jpg", PM_START_TEXT, reply_markup=InlineKeyboardMarkup(buttons), parse_mode=ParseMode.MARKDOWN, timeout=60, ) else: update.effective_message.reply_text( "Mengirimi Anda salam hangat & berharap hari Anda menyenangkan!" )
def mute(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 if user_can_ban(chat, user, context.bot.id) == False: message.reply_text( "Anda tidak memiliki cukup hak untuk membatasi seseorang agar tidak berbicara!" ) return "" user_id = extract_user(message, args) if not user_id: message.reply_text( "Anda harus memberi saya nama pengguna untuk membungkam, atau membalas seseorang untuk dibungkam." ) return "" if user_id == context.bot.id: message.reply_text("Yah... Aku tidak membungkam diriku sendiri!") return "" member = chat.get_member(int(user_id)) if member: if is_user_admin(chat, user_id, member=member): message.reply_text( "Yah, saya tidak akan menghentikan admin untuk berbicara!") elif member.can_send_messages is None or member.can_send_messages: context.bot.restrict_chat_member( chat.id, user_id, permissions=ChatPermissions(can_send_messages=False), ) message.reply_text("👍🏻 dibisukan! 🤐") return ("<b>{}:</b>" "\n#MUTE" "\n<b>Admin:</b> {}" "\n<b>User:</b> {}".format( html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), )) else: message.reply_text("Pengguna ini sudah dibisukan 🤐") else: message.reply_text("Pengguna ini tidak sedang mengobrol!") return ""
def kickme(update, context): user_id = update.effective_message.from_user.id if is_user_admin(update.effective_chat, user_id): update.effective_message.reply_text( "Yeahhh .. tidak akan menendang admin.") return res = update.effective_chat.unban_member( user_id) # unban on current user = kick if res: update.effective_message.reply_text("Ya, Anda benar. Keluar!..") else: update.effective_message.reply_text("Hah? Aku tidak bisa :/")
def enforce_gban(update, context): # Not using @restrict handler to avoid spamming - just ignore if cant gban. try: if (gban_db.does_chat_gban(update.effective_chat.id) and update.effective_chat.get_member( context.bot.id).can_restrict_members): user = update.effective_user chat = update.effective_chat msg = update.effective_message if user and not is_user_admin(chat, user.id): check_and_ban(update, user.id) if msg.new_chat_members: new_members = update.effective_message.new_chat_members for mem in new_members: check_and_ban(update, mem.id) if msg.reply_to_message: user = msg.reply_to_message.from_user if user and not is_user_admin(chat, user.id): check_and_ban(update, user.id, should_message=False) except (Unauthorized, BadRequest): pass
def check_update(self, update): if isinstance(update, Update) and update.effective_message: message = update.effective_message if message.text and len(message.text) > 1: fst_word = message.text.split(None, 1)[0] if len(fst_word) > 1 and any( fst_word.startswith(start) for start in CMD_STARTERS ): args = message.text.split()[1:] command = fst_word[1:].split("@") command.append(message.bot.username) if not ( command[0].lower() in self.command and command[1].lower() == message.bot.username.lower() ): return None filter_result = self.filters(update) if filter_result: chat = update.effective_chat user = update.effective_user # disabled, admincmd, user admin if disable_db.is_command_disabled( chat.id, command[0].lower() ): # check if command was disabled is_disabled = command[ 0 ] in ADMIN_CMDS and is_user_admin( chat, user.id ) if not is_disabled: return None else: return args, filter_result return args, filter_result else: return False
def banme(update, context): user_id = update.effective_message.from_user.id chat = update.effective_chat user = update.effective_user if is_user_admin(update.effective_chat, user_id): update.effective_message.reply_text( "Yeahhh .. tidak akan melarang admin.") return res = update.effective_chat.kick_member(user_id) if res: update.effective_message.reply_text("Ya kau benar! Kawan..") log = ("<b>{}:</b>" "\n#BANME" "\n<b>User:</b> {}" "\n<b>ID:</b> <code>{}</code>".format( html.escape(chat.title), mention_html(user.id, user.first_name), user_id, )) return log else: update.effective_message.reply_text("Hah? Aku tidak bisa :/")
def check_flood(update, context) -> str: user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] msg = update.effective_message # type: Optional[Message] if not user: # ignore channels return "" # ignore admins if is_user_admin(chat, user.id): sql.update_flood(chat.id, None) return "" should_ban = sql.update_flood(chat.id, user.id) if not should_ban: return "" try: getmode, getvalue = sql.get_flood_setting(chat.id) if getmode == 1: chat.kick_member(user.id) execstrings = "Banned" tag = "BANNED" elif getmode == 2: chat.kick_member(user.id) chat.unban_member(user.id) execstrings = "Kicked" tag = "KICKED" elif getmode == 3: context.bot.restrict_chat_member( chat.id, user.id, permissions=ChatPermissions(can_send_messages=False), ) execstrings = "Muted" tag = "MUTED" elif getmode == 4: bantime = extract_time(msg, getvalue) chat.kick_member(user.id, until_date=bantime) execstrings = "Dilarang ukepada {}".format(getvalue) tag = "TBAN" elif getmode == 5: mutetime = extract_time(msg, getvalue) context.bot.restrict_chat_member( chat.id, user.id, until_date=mutetime, permissions=ChatPermissions(can_send_messages=False), ) execstrings = "Dibisukan kepada {}".format(getvalue) tag = "TMUTE" send_message( update.effective_message, "Bagus, aku suka meninggalkan flood tapi, " "Anda hanya kecewa. {}!".format(execstrings), ) return ("<b>{}:</b>" "\n#{}" "\n<b>Pengguna:</b> {}" "\nFlooded the group.".format( tag, html.escape(chat.title), mention_html(user.id, user.first_name), )) except BadRequest: msg.reply_text( "Saya tidak bisa membatasi orang di sini, memberi saya izin terlebih dahulu! Sampai saat itu, aku akan menonaktifkan anti-flood." ) sql.set_flood(chat.id, 0) return ( "<b>{}:</b>" "\n#INFO" "\nTidak memiliki cukup izin untuk membatasi pengguna sehingga secara otomatis menonaktifkan anti-flood" .format(chat.title))
def warn(user: User, chat: Chat, reason: str, message: Message, warner: User = None) -> str: if is_user_admin(chat, user.id): message.reply_text("Admin sialan, bahkan tidak bisa diperingatkan!") return "" if warner: warner_tag = mention_html(warner.id, warner.first_name) else: warner_tag = "Filter peringatan otomatis." limit, soft_warn = 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 soft_warn: # kick chat.unban_member(user.id) reply = "Itu {} peringatan, {} telah ditendang!".format( limit, mention_html(user.id, user.first_name)) else: # ban chat.kick_member(user.id) reply = "tu {} peringatan, {} telah dilarang!".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>Pengguna:</b> {} (<code>{}</code>)" "\n<b>Alasan:</b> {}" "\n<b>Jumlah:</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( "Hapus peringatan ⚠️", callback_data="rm_warn({})".format(user.id), ) ]]) reply = "Pengguna {} memiliki {}/{} peringatan ... hati-hati!".format( mention_html(user.id, user.first_name), num_warns, limit) if reason: reply += "\nAlasan 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: message.reply_text(reply, reply_markup=keyboard, parse_mode=ParseMode.HTML) except BadRequest as excp: if excp.message == "Pesan balasan tidak ditemukan": # Do not reply message.reply_text( reply, reply_markup=keyboard, parse_mode=ParseMode.HTML, quote=False, ) else: raise return log_reason
def warn(user: User, chat: Chat, reason: str, message: Message, warner: User = None) -> str: if is_user_admin(chat, user.id): message.reply_text("Damn admins, can't even be warned!") return "" if warner: warner_tag = mention_html(warner.id, warner.first_name) else: warner_tag = "Automated warn filter." limit, soft_warn = 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 soft_warn: # kick chat.unban_member(user.id) reply = "That's {} warnings, {} has been kicked!".format( limit, mention_html(user.id, user.first_name)) else: # ban chat.kick_member(user.id) reply = "That's{} warnings, {} has been banned!".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( "Remove warn ⚠️", callback_data="rm_warn({})".format(user.id), ) ]]) reply = "User {} has {}/{} warnings... watch out!".format( mention_html(user.id, user.first_name), num_warns, limit) if reason: reply += "\nReason for last warn:\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: message.reply_text(reply, reply_markup=keyboard, parse_mode=ParseMode.HTML) except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text( reply, reply_markup=keyboard, parse_mode=ParseMode.HTML, quote=False, ) else: raise return log_reason
def unlock(update, context) -> str: args = context.args chat = update.effective_chat user = update.effective_user message = update.effective_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 = "Pesan {} tidak terkunci untuk semua orang di {}!".format( ltype, chat_name ) else: if update.effective_message.chat.type == "private": send_message( update.effective_message, "Perintah ini dimaksudkan untuk digunakan dalam grup bukan di PM", ) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title text = "Pesan {} 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 = "Terbuka {} untuk semua orang di {}!".format( ltype, chat_name ) else: if update.effective_message.chat.type == "private": send_message( update.effective_message, "Perintah ini dimaksudkan untuk digunakan dalam grup bukan di PM", ) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title text = "Terbuka {} 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, "Apa yang Anda coba buka kuncinya ...? Coba /locktypes untuk daftar yang dapat dikunci.", ) else: send_message( update.effective_message, "Apa yang Anda coba buka kuncinya...?" ) return ""
def temp_mute(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 if user_can_ban(chat, user, context.bot.id) == False: message.reply_text( "Anda tidak memiliki cukup hak untuk membatasi seseorang agar tidak berbicara!" ) return "" user_id, reason = extract_user_and_text(message, args) if not user_id: message.reply_text("Anda sepertinya tidak mengacu pada pengguna.") return "" try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": message.reply_text( "Sepertinya saya tidak dapat menemukan pengguna ini") return "" else: raise if is_user_admin(chat, user_id, member): message.reply_text( "Saya benar-benar berharap dapat menonaktifkan admin...") return "" if user_id == context.bot.id: message.reply_text( "Saya tidak akan BISUKAN diri saya sendiri, apakah Anda sudah gila?" ) return "" if not reason: message.reply_text( "Anda belum menentukan waktu untuk menonaktifkan pengguna ini!") return "" split_reason = reason.split(None, 1) time_val = split_reason[0].lower() if len(split_reason) > 1: reason = split_reason[1] else: reason = "" mutetime = extract_time(message, time_val) if not mutetime: return "" log = ("<b>{}:</b>" "\n#TEMP MUTED" "\n<b>Admin:</b> {}" "\n<b>User:</b> {}" "\n<b>Time:</b> {}".format( html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), time_val, )) if reason: log += "\n<b>Alasan:</b> {}".format(reason) try: if member.can_send_messages is None or member.can_send_messages: context.bot.restrict_chat_member( chat.id, user_id, until_date=mutetime, permissions=ChatPermissions(can_send_messages=False), ) message.reply_text("diam! 🤐 Dibisukan untuk {}!".format(time_val)) return log else: message.reply_text("Pengguna ini telah dibungkam.") except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text("diam! 🤐 Dibisukan untuk {}!".format(time_val), quote=False) return log else: LOGGER.warning(update) LOGGER.exception( "ERROR muting user %s in chat %s (%s) due to %s", user_id, chat.title, chat.id, excp.message, ) message.reply_text( "Sial, saya tidak bisa menonaktifkan pengguna itu.") return ""