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.

45 líneas
1.8KB

  1. # encoding:utf-8
  2. import plugins
  3. from plugins import *
  4. from common.log import logger
  5. @plugins.register(name="Hello", desc="A simple plugin that says hello", version="0.1", author="lanvent")
  6. class Hello(Plugin):
  7. def __init__(self):
  8. super().__init__()
  9. self.handlers[Event.ON_HANDLE_CONTEXT] = self.on_handle_context
  10. logger.info("[Hello] inited")
  11. def on_handle_context(self, e_context: EventContext):
  12. if e_context['context']['type'] != "TEXT":
  13. return
  14. content = e_context['context']['content']
  15. logger.debug("[Hello] on_handle_context. content: %s" % content)
  16. if content == "Hello":
  17. reply = {}
  18. reply['type'] = "TEXT"
  19. msg = e_context['context']['msg']
  20. if e_context['context']['isgroup']:
  21. reply['content'] = "Hello, " + msg['ActualNickName'] + " from " + msg['User'].get('NickName', "Group")
  22. else:
  23. reply['content'] = "Hello, " + msg['User'].get('NickName', "My friend")
  24. e_context['reply'] = reply
  25. e_context.action = EventAction.BREAK_PASS # 事件结束,并跳过处理context的默认逻辑
  26. if content == "Hi":
  27. reply={}
  28. reply['type'] = "TEXT"
  29. reply['content'] = "Hi"
  30. e_context['reply'] = reply
  31. e_context.action = EventAction.BREAK # 事件结束,进入默认处理逻辑,一般会覆写reply
  32. if content == "End":
  33. # 如果是文本消息"End",将请求转换成"IMAGE_CREATE",并将content设置为"The World"
  34. e_context['context']['type'] = "IMAGE_CREATE"
  35. content = "The World"
  36. e_context.action = EventAction.CONTINUE # 事件继续,交付给下个插件或默认逻辑