12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # encoding:utf-8
  2. from enum import Enum
  3. class Event(Enum):
  4. # ON_RECEIVE_MESSAGE = 1 # 收到消息
  5. ON_HANDLE_CONTEXT = 2 # 处理消息前
  6. """
  7. e_context = { "channel": 消息channel, "context" : 本次消息的context, "reply" : 目前的回复,初始为空 }
  8. """
  9. ON_DECORATE_REPLY = 3 # 得到回复后准备装饰
  10. """
  11. e_context = { "channel": 消息channel, "context" : 本次消息的context, "reply" : 目前的回复 }
  12. """
  13. ON_SEND_REPLY = 4 # 发送回复前
  14. """
  15. e_context = { "channel": 消息channel, "context" : 本次消息的context, "reply" : 目前的回复 }
  16. """
  17. # AFTER_SEND_REPLY = 5 # 发送回复后
  18. class EventAction(Enum):
  19. CONTINUE = 1 # 事件未结束,继续交给下个插件处理,如果没有下个插件,则交付给默认的事件处理逻辑
  20. BREAK = 2 # 事件结束,不再给下个插件处理,交付给默认的事件处理逻辑
  21. BREAK_PASS = 3 # 事件结束,不再给下个插件处理,不交付给默认的事件处理逻辑
  22. class EventContext:
  23. def __init__(self, event, econtext=dict()):
  24. self.event = event
  25. self.econtext = econtext
  26. self.action = EventAction.CONTINUE
  27. def __getitem__(self, key):
  28. return self.econtext[key]
  29. def __setitem__(self, key, value):
  30. self.econtext[key] = value
  31. def __delitem__(self, key):
  32. del self.econtext[key]
  33. def is_pass(self):
  34. return self.action == EventAction.BREAK_PASS