Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

52 lignes
2.1KB

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