def enforce_gban(update: Update, context: CallbackContext): # Not using @restrict handler to avoid spamming - just ignore if cant gban. bot = context.bot try: restrict_permission = update.effective_chat.get_member( bot.id).can_restrict_members except Unauthorized: return if sql.does_chat_gban(update.effective_chat.id) and restrict_permission: 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) return 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)
def slap(update: Update, context: CallbackContext): nek = nekos.img("slap") bot, args = context.bot, context.args message = update.effective_message chat = update.effective_chat reply_text = message.reply_to_message.reply_text if message.reply_to_message else message.reply_text curr_user = message.from_user user_id = extract_user(message, args) if user_id == bot.id: temp = random.choice(fun_strings.SLAP_SAITAMA_TEMPLATES) if isinstance(temp, list): if temp[2] == "tmute": if is_user_admin(chat, message.from_user.id): reply_text(temp[1]) return mutetime = int(time.time() + 60) bot.restrict_chat_member( chat.id, message.from_user.id, until_date=mutetime, permissions=ChatPermissions(can_send_messages=False)) reply_text(temp[0]) else: reply_text(temp) return if user_id: slapped_user = bot.get_chat(user_id) user1 = mention_html(curr_user.id, curr_user.first_name) user2 = mention_html(slapped_user.id, slapped_user.first_name) else: user1 = mention_html(bot.id, bot.first_name) user2 = mention_html(curr_user.id, curr_user.first_name) temp = random.choice(fun_strings.SLAP_TEMPLATES) item = random.choice(fun_strings.ITEMS) hit = random.choice(fun_strings.HIT) throw = random.choice(fun_strings.THROW) if update.effective_user.id == 1096215023: temp = "@NeoTheKitty scratches {user2}" reply = temp.format(user1=user1, user2=user2, item=item, hits=hit, throws=throw) bot.send_animation(chat_id=chat.id, animation=nek, caption=reply, reply_to_message_id=message.message_id, parse_mode=ParseMode.HTML)
def punchme(update: Update, context: CallbackContext): user_id = update.effective_message.from_user.id if is_user_admin(update.effective_chat, user_id): update.effective_message.reply_text("I wish I could... but you're an admin.") return res = update.effective_chat.unban_member(user_id) # unban on current user = kick if res: update.effective_message.reply_text("*removes you out of the group*") else: update.effective_message.reply_text("Huh? I can't :/")
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 chat = update.effective_chat user = update.effective_user if user.id == 1087968824: user_id = chat.id else: user_id = user.id if SpamChecker.check_user(user_id): return None filter_result = self.filters(update) if filter_result: # disabled, admincmd, user admin if sql.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 check_user(user_id: int, bot: Bot, chat: Chat) -> Optional[str]: if not user_id: reply = "Meoww.... You don't seem to be referring to a kitty or the ID specified is incorrect.." return reply try: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": reply = "I can't seem to find this kitty" return reply else: raise if user_id == bot.id: reply = "Why the.....meow!! How high are you?! meow!! " return reply if is_user_admin(chat, user_id, member) or user_id in TIGERS: reply = "Can't. Find someone else to mute but not this one." return reply return None
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 = "Unlocked {} for everyone in {}!".format( ltype, chat_name) else: if update.effective_message.chat.type == "private": send_message( update.effective_message, "This command is meant to use in group not in PM", ) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title text = "Unlocked {} for everyone!".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 = "Unlocked {} for everyone in {}!".format( ltype, chat_name) else: if update.effective_message.chat.type == "private": send_message( update.effective_message, "This command is meant to use in group not in PM", ) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title text = "Unlocked {} for everyone!".format(ltype) can_change_info = chat.get_member( context.bot.id).can_change_info if not can_change_info: send_message( update.effective_message, "I don't have permission to change group info.", parse_mode="markdown") return 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, "What are you trying to unlock...? Try /locktypes for the list of lockables.", ) else: send_message(update.effective_message, "What are you trying to unlock...?") return ""
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 "" #chek = sql2.is_approved(chat.id, user.id) # ignore admins and whitelists if (is_user_admin(chat, user.id) or user.id in WOLVES or user.id in TIGERS): sql.update_flood(chat.id, None) return "" elif sql2.is_approved(chat.id, 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 = ("Banned for {}".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 = ("Now stay taped {}".format(getvalue)) tag = "TMUTE" send_message( update.effective_message, "Meow.. You won't lose your virginity by fukking this group... \n{}!" .format(execstrings)) return "<b>{}:</b>" \ "\n#{}" \ "\n<b>User:</b> {}" \ "\nFlooded the group.".format(tag, html.escape(chat.title), mention_html(user.id, html.escape(user.first_name))) except BadRequest: msg.reply_text( "I can't restrict people here, give me permissions first! Until then, I'll disable anti-flood." ) sql.set_flood(chat.id, 0) return "<b>{}:</b>" \ "\n#INFO" \ "\nDon't have enough permission to restrict users so automatically disabled 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("Nyah!! admins, They are too far to be eliminated!") return if user.id in TIGERS: if warner: message.reply_text("Blades cant be warned.") else: message.reply_text( "Nyah a blade triggered an auto warn filter!\n I can't warn balde but trysweet sama is watching!! " ) return if user.id in WOLVES: if warner: message.reply_text( "This kitty has a shield given by trysweet sama?!") else: message.reply_text( " A shield user triggered an auto warn filter!\nI can't warn them but they should avoid abusing this." ) 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: # punch chat.unban_member(user.id) reply = ( f"<code>�</code><b>Punch Event</b>\n" f"<code> </code><b>• User:</b> {mention_html(user.id, user.first_name)}\n" f"<code> </code><b>• Count:</b> {limit}") else: # ban chat.kick_member(user.id) reply = ( f"<code>�</code><b>Ban Carnival</b>\n" f"<code> </code><b>• The Prey:</b> {mention_html(user.id, user.first_name)}\n" f"<code> </code><b>• Count:</b> {limit}") for warn_reason in reasons: reply += f"\n - {html.escape(warn_reason)}" # message.bot.send_sticker(chat.id, BAN_STICKER) # Saitama's sticker keyboard = None log_reason = ( f"<b>{html.escape(chat.title)}:</b>\n" f"#WARN_BAN\n" f"<b>Admin:</b> {warner_tag}\n" f"<b>User:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Reason:</b> {reason}\n" f"<b>Counts:</b> <code>{num_warns}/{limit}</code>") else: keyboard = InlineKeyboardMarkup([[ InlineKeyboardButton("🔘 Release warn", callback_data="rm_warn({})".format(user.id)) ]]) reply = ( f"<code>�</code><b>Warn Event</b>\n" f"<code> </code><b>• User:</b> {mention_html(user.id, user.first_name)}\n" f"<code> </code><b>• Count:</b> {num_warns}/{limit}") if reason: reply += f"\n<code> </code><b>• Reason:</b> {html.escape(reason)}" log_reason = ( f"<b>{html.escape(chat.title)}:</b>\n" f"#WARN\n" f"<b>Admin:</b> {warner_tag}\n" f"<b>User:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Reason:</b> {reason}\n" f"<b>Counts:</b> <code>{num_warns}/{limit}</code>") 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