您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

42 行
1.1KB

  1. # encoding:utf-8
  2. from enum import Enum
  3. class ContextType (Enum):
  4. TEXT = 1 # 文本消息
  5. VOICE = 2 # 音频消息
  6. IMAGE_CREATE = 3 # 创建图片命令
  7. def __str__(self):
  8. return self.name
  9. class Context:
  10. def __init__(self, type : ContextType = None , content = None, kwargs = dict()):
  11. self.type = type
  12. self.content = content
  13. self.kwargs = kwargs
  14. def __getitem__(self, key):
  15. if key == 'type':
  16. return self.type
  17. elif key == 'content':
  18. return self.content
  19. else:
  20. return self.kwargs[key]
  21. def __setitem__(self, key, value):
  22. if key == 'type':
  23. self.type = value
  24. elif key == 'content':
  25. self.content = value
  26. else:
  27. self.kwargs[key] = value
  28. def __delitem__(self, key):
  29. if key == 'type':
  30. self.type = None
  31. elif key == 'content':
  32. self.content = None
  33. else:
  34. del self.kwargs[key]
  35. def __str__(self):
  36. return "Context(type={}, content={}, kwargs={})".format(self.type, self.content, self.kwargs)