您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

69 行
2.7KB

  1. # encoding:utf-8
  2. import plugins
  3. from bridge.context import ContextType
  4. from bridge.reply import Reply, ReplyType
  5. from channel.chat_message import ChatMessage
  6. from common.log import logger
  7. from plugins import *
  8. @plugins.register(
  9. name="Hello",
  10. desire_priority=-1,
  11. hidden=True,
  12. desc="A simple plugin that says hello",
  13. version="0.1",
  14. author="lanvent",
  15. )
  16. class Hello(Plugin):
  17. def __init__(self):
  18. super().__init__()
  19. self.handlers[Event.ON_HANDLE_CONTEXT] = self.on_handle_context
  20. logger.info("[Hello] inited")
  21. def on_handle_context(self, e_context: EventContext):
  22. if e_context["context"].type not in [ContextType.TEXT, ContextType.JOIN_GROUP]:
  23. return
  24. if e_context["context"].type == ContextType.JOIN_GROUP:
  25. e_context["context"].type = ContextType.TEXT
  26. msg: ChatMessage = e_context["context"]["msg"]
  27. e_context[
  28. "context"
  29. ].content = f'请你随机使用一种风格说一句问候语来欢迎新用户"{msg.actual_user_nickname}"加入群聊。'
  30. e_context.action = EventAction.CONTINUE # 事件继续,交付给下个插件或默认逻辑
  31. return
  32. content = e_context["context"].content
  33. logger.debug("[Hello] on_handle_context. content: %s" % content)
  34. if content == "Hello":
  35. reply = Reply()
  36. reply.type = ReplyType.TEXT
  37. msg: ChatMessage = e_context["context"]["msg"]
  38. if e_context["context"]["isgroup"]:
  39. reply.content = (
  40. f"Hello, {msg.actual_user_nickname} from {msg.from_user_nickname}"
  41. )
  42. else:
  43. reply.content = f"Hello, {msg.from_user_nickname}"
  44. e_context["reply"] = reply
  45. e_context.action = EventAction.BREAK_PASS # 事件结束,并跳过处理context的默认逻辑
  46. if content == "Hi":
  47. reply = Reply()
  48. reply.type = ReplyType.TEXT
  49. reply.content = "Hi"
  50. e_context["reply"] = reply
  51. e_context.action = EventAction.BREAK # 事件结束,进入默认处理逻辑,一般会覆写reply
  52. if content == "End":
  53. # 如果是文本消息"End",将请求转换成"IMAGE_CREATE",并将content设置为"The World"
  54. e_context["context"].type = ContextType.IMAGE_CREATE
  55. content = "The World"
  56. e_context.action = EventAction.CONTINUE # 事件继续,交付给下个插件或默认逻辑
  57. def get_help_text(self, **kwargs):
  58. help_text = "输入Hello,我会回复你的名字\n输入End,我会回复你世界的图片\n"
  59. return help_text