You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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