utils.py 1017B

12345678910111213141516171819202122232425262728
  1. from config import global_config
  2. from bridge.reply import Reply, ReplyType
  3. from plugins.event import EventContext, EventAction
  4. class Util:
  5. @staticmethod
  6. def is_admin(e_context: EventContext) -> bool:
  7. """
  8. 判断消息是否由管理员用户发送
  9. :param e_context: 消息上下文
  10. :return: True: 是, False: 否
  11. """
  12. context = e_context["context"]
  13. if context["isgroup"]:
  14. actual_user_id = context.kwargs.get("msg").actual_user_id
  15. for admin_user in global_config["admin_users"]:
  16. if actual_user_id and actual_user_id in admin_user:
  17. return True
  18. return False
  19. else:
  20. return context["receiver"] in global_config["admin_users"]
  21. @staticmethod
  22. def set_reply_text(content: str, e_context: EventContext, level: ReplyType = ReplyType.ERROR):
  23. reply = Reply(level, content)
  24. e_context["reply"] = reply
  25. e_context.action = EventAction.BREAK_PASS