No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

76 líneas
3.1KB

  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 [
  23. ContextType.TEXT,
  24. ContextType.JOIN_GROUP,
  25. ContextType.PATPAT,
  26. ]:
  27. return
  28. if e_context["context"].type == ContextType.JOIN_GROUP:
  29. e_context["context"].type = ContextType.TEXT
  30. msg: ChatMessage = e_context["context"]["msg"]
  31. e_context["context"].content = f'请你随机使用一种风格说一句问候语来欢迎新用户"{msg.actual_user_nickname}"加入群聊。'
  32. e_context.action = EventAction.CONTINUE # 事件继续,交付给下个插件或默认逻辑
  33. return
  34. if e_context["context"].type == ContextType.PATPAT:
  35. e_context["context"].type = ContextType.TEXT
  36. msg: ChatMessage = e_context["context"]["msg"]
  37. e_context["context"].content = f"请你随机使用一种风格介绍你自己,并告诉用户输入#help可以查看帮助信息。"
  38. e_context.action = EventAction.CONTINUE # 事件继续,交付给下个插件或默认逻辑
  39. return
  40. content = e_context["context"].content
  41. logger.debug("[Hello] on_handle_context. content: %s" % content)
  42. if content == "Hello":
  43. reply = Reply()
  44. reply.type = ReplyType.TEXT
  45. msg: ChatMessage = e_context["context"]["msg"]
  46. if e_context["context"]["isgroup"]:
  47. reply.content = f"Hello, {msg.actual_user_nickname} from {msg.from_user_nickname}"
  48. else:
  49. reply.content = f"Hello, {msg.from_user_nickname}"
  50. e_context["reply"] = reply
  51. e_context.action = EventAction.BREAK_PASS # 事件结束,并跳过处理context的默认逻辑
  52. if content == "Hi":
  53. reply = Reply()
  54. reply.type = ReplyType.TEXT
  55. reply.content = "Hi"
  56. e_context["reply"] = reply
  57. e_context.action = EventAction.BREAK # 事件结束,进入默认处理逻辑,一般会覆写reply
  58. if content == "End":
  59. # 如果是文本消息"End",将请求转换成"IMAGE_CREATE",并将content设置为"The World"
  60. e_context["context"].type = ContextType.IMAGE_CREATE
  61. content = "The World"
  62. e_context.action = EventAction.CONTINUE # 事件继续,交付给下个插件或默认逻辑
  63. def get_help_text(self, **kwargs):
  64. help_text = "输入Hello,我会回复你的名字\n输入End,我会回复你世界的图片\n"
  65. return help_text