def unban(self, bot: Bot, chat_id): # 只有当 kicked 的情况才做解封 if self.status(bot, chat_id) == ChatMember.KICKED: bot.unban_chat_member(chat_id, user_id=self.user_id) send_message( bot, chat_id, f'已将该用户 {self.mention()} 从全局黑名单中移除({self.status_cn(bot, chat_id)})。' )
def demote(bot: Bot, update: Update): logger.info("promote user...") chat_id, users = get_chat_id_and_users(bot, update) if not users: send_message(bot, chat_id, TIP_TEMPLATE + '进行管理员添加操作') for user in users: user.demote(bot, chat_id) logger.info("promote user done!!")
def unban(bot: Bot, update: Update): logger.info("unban user...") chat_id, users = get_chat_id_and_users(bot, update) if not users: send_message(bot, chat_id, TIP_TEMPLATE + '进行解冻') for user in users: AllChats.unban(bot, chat_id, user) logger.info("unban user done!!!")
def get_status(bot: Bot, update: Update): logger.info("get_status user...") chat_id, users = get_chat_id_and_users(bot, update) if not users: send_message(bot, chat_id, TIP_TEMPLATE + '进行用户状态查看') for user in users: memo = "不在黑名单中" if user.is_active else "已被全球拉黑" send_message(bot, chat_id, f'该用户 {user.mention()} {memo}({user.status_cn(bot, chat_id)})') logger.info("get_status done!!")
def is_admin(bot: Bot, update: Update): logger.info("checking user is manager...") chat_id, users = get_chat_id_and_users(bot, update) if not users: send_message(bot, chat_id, TIP_TEMPLATE + '进行管理员查询操作') for user in users: status = "管理员" if user.is_manager(bot, chat_id) else "普通用户" send_message(bot, chat_id, f'该用户的状态:{status}') logger.info("checking user is manager done!!")
def demote(self, bot: Bot, chat_id): if self.status(bot, chat_id) != ChatMember.ADMINISTRATOR: send_message(bot, chat_id, f'操作失败,该用户 {self.mention()} 目前不是管理员') return bot.promote_chat_member(chat_id, self.user_id, can_change_info=False, can_post_messages=False, can_edit_messages=False, can_delete_messages=False, can_invite_users=False, can_restrict_members=False, can_pin_messages=False, can_promote_members=False) send_message(bot, chat_id, f'已将该用户 {self.mention()} 设置为普通用户')
def ban(self, bot: Bot, chat_id): if self.status(bot, chat_id) == ChatMember.MEMBER: bot.kick_chat_member(chat_id, user_id=self.user_id) send_message( bot, chat_id, f'将该用户 {self.mention()} 全球封杀({self.status_cn(bot, chat_id)})')