dimples 0.2.1__tar.gz → 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. {dimples-0.2.1 → dimples-0.2.2}/PKG-INFO +1 -1
  2. {dimples-0.2.1 → dimples-0.2.2}/dimples/client/cpu/grp_expel.py +24 -12
  3. {dimples-0.2.1 → dimples-0.2.2}/dimples/client/cpu/grp_invite.py +14 -9
  4. {dimples-0.2.1 → dimples-0.2.2}/dimples/client/cpu/grp_query.py +12 -6
  5. {dimples-0.2.1 → dimples-0.2.2}/dimples/client/cpu/grp_quit.py +22 -11
  6. {dimples-0.2.1 → dimples-0.2.2}/dimples/client/cpu/grp_reset.py +26 -13
  7. {dimples-0.2.1 → dimples-0.2.2}/dimples/client/cpu/history.py +12 -9
  8. {dimples-0.2.1 → dimples-0.2.2}/dimples/server/cpu/ans.py +1 -2
  9. {dimples-0.2.1 → dimples-0.2.2}/dimples/server/cpu/handshake.py +1 -1
  10. {dimples-0.2.1 → dimples-0.2.2}/dimples/server/cpu/login.py +1 -1
  11. {dimples-0.2.1 → dimples-0.2.2}/dimples/server/cpu/report.py +4 -8
  12. {dimples-0.2.1 → dimples-0.2.2}/dimples/server/processor.py +1 -1
  13. {dimples-0.2.1 → dimples-0.2.2}/dimples/server/session.py +2 -1
  14. {dimples-0.2.1 → dimples-0.2.2}/dimples.egg-info/PKG-INFO +1 -1
  15. {dimples-0.2.1 → dimples-0.2.2}/dimples.egg-info/requires.txt +1 -1
  16. {dimples-0.2.1 → dimples-0.2.2}/setup.py +2 -2
  17. {dimples-0.2.1 → dimples-0.2.2}/README.md +0 -0
  18. {dimples-0.2.1 → dimples-0.2.2}/dimples/__init__.py +0 -0
  19. {dimples-0.2.1 → dimples-0.2.2}/dimples/client/__init__.py +0 -0
  20. {dimples-0.2.1 → dimples-0.2.2}/dimples/client/cpu/__init__.py +0 -0
  21. {dimples-0.2.1 → dimples-0.2.2}/dimples/client/cpu/handshake.py +0 -0
  22. {dimples-0.2.1 → dimples-0.2.2}/dimples/client/cpu/login.py +0 -0
  23. {dimples-0.2.1 → dimples-0.2.2}/dimples/client/cpu/text.py +0 -0
  24. {dimples-0.2.1 → dimples-0.2.2}/dimples/client/group.py +0 -0
  25. {dimples-0.2.1 → dimples-0.2.2}/dimples/client/messenger.py +0 -0
  26. {dimples-0.2.1 → dimples-0.2.2}/dimples/client/network/__init__.py +0 -0
  27. {dimples-0.2.1 → dimples-0.2.2}/dimples/client/network/session.py +0 -0
  28. {dimples-0.2.1 → dimples-0.2.2}/dimples/client/network/state.py +0 -0
  29. {dimples-0.2.1 → dimples-0.2.2}/dimples/client/network/transition.py +0 -0
  30. {dimples-0.2.1 → dimples-0.2.2}/dimples/client/packer.py +0 -0
  31. {dimples-0.2.1 → dimples-0.2.2}/dimples/client/processor.py +0 -0
  32. {dimples-0.2.1 → dimples-0.2.2}/dimples/client/terminal.py +0 -0
  33. {dimples-0.2.1 → dimples-0.2.2}/dimples/common/__init__.py +0 -0
  34. {dimples-0.2.1 → dimples-0.2.2}/dimples/common/ans.py +0 -0
  35. {dimples-0.2.1 → dimples-0.2.2}/dimples/common/dbi/__init__.py +0 -0
  36. {dimples-0.2.1 → dimples-0.2.2}/dimples/common/dbi/account.py +0 -0
  37. {dimples-0.2.1 → dimples-0.2.2}/dimples/common/dbi/message.py +0 -0
  38. {dimples-0.2.1 → dimples-0.2.2}/dimples/common/dbi/session.py +0 -0
  39. {dimples-0.2.1 → dimples-0.2.2}/dimples/common/facebook.py +0 -0
  40. {dimples-0.2.1 → dimples-0.2.2}/dimples/common/messenger.py +0 -0
  41. {dimples-0.2.1 → dimples-0.2.2}/dimples/common/packer.py +0 -0
  42. {dimples-0.2.1 → dimples-0.2.2}/dimples/common/protocol/__init__.py +0 -0
  43. {dimples-0.2.1 → dimples-0.2.2}/dimples/common/protocol/ans.py +0 -0
  44. {dimples-0.2.1 → dimples-0.2.2}/dimples/common/protocol/handshake.py +0 -0
  45. {dimples-0.2.1 → dimples-0.2.2}/dimples/common/protocol/login.py +0 -0
  46. {dimples-0.2.1 → dimples-0.2.2}/dimples/common/protocol/report.py +0 -0
  47. {dimples-0.2.1 → dimples-0.2.2}/dimples/common/session.py +0 -0
  48. {dimples-0.2.1 → dimples-0.2.2}/dimples/config.py +0 -0
  49. {dimples-0.2.1 → dimples-0.2.2}/dimples/conn/__init__.py +0 -0
  50. {dimples-0.2.1 → dimples-0.2.2}/dimples/conn/gate.py +0 -0
  51. {dimples-0.2.1 → dimples-0.2.2}/dimples/conn/gatekeeper.py +0 -0
  52. {dimples-0.2.1 → dimples-0.2.2}/dimples/conn/mars.py +0 -0
  53. {dimples-0.2.1 → dimples-0.2.2}/dimples/conn/mtp.py +0 -0
  54. {dimples-0.2.1 → dimples-0.2.2}/dimples/conn/protocol/__init__.py +0 -0
  55. {dimples-0.2.1 → dimples-0.2.2}/dimples/conn/protocol/mars.py +0 -0
  56. {dimples-0.2.1 → dimples-0.2.2}/dimples/conn/protocol/ws.py +0 -0
  57. {dimples-0.2.1 → dimples-0.2.2}/dimples/conn/queue.py +0 -0
  58. {dimples-0.2.1 → dimples-0.2.2}/dimples/conn/seeker.py +0 -0
  59. {dimples-0.2.1 → dimples-0.2.2}/dimples/conn/session.py +0 -0
  60. {dimples-0.2.1 → dimples-0.2.2}/dimples/conn/ws.py +0 -0
  61. {dimples-0.2.1 → dimples-0.2.2}/dimples/database/__init__.py +0 -0
  62. {dimples-0.2.1 → dimples-0.2.2}/dimples/database/account.py +0 -0
  63. {dimples-0.2.1 → dimples-0.2.2}/dimples/database/dos/__init__.py +0 -0
  64. {dimples-0.2.1 → dimples-0.2.2}/dimples/database/dos/base.py +0 -0
  65. {dimples-0.2.1 → dimples-0.2.2}/dimples/database/dos/document.py +0 -0
  66. {dimples-0.2.1 → dimples-0.2.2}/dimples/database/dos/group.py +0 -0
  67. {dimples-0.2.1 → dimples-0.2.2}/dimples/database/dos/login.py +0 -0
  68. {dimples-0.2.1 → dimples-0.2.2}/dimples/database/dos/meta.py +0 -0
  69. {dimples-0.2.1 → dimples-0.2.2}/dimples/database/dos/private.py +0 -0
  70. {dimples-0.2.1 → dimples-0.2.2}/dimples/database/dos/station.py +0 -0
  71. {dimples-0.2.1 → dimples-0.2.2}/dimples/database/dos/user.py +0 -0
  72. {dimples-0.2.1 → dimples-0.2.2}/dimples/database/message.py +0 -0
  73. {dimples-0.2.1 → dimples-0.2.2}/dimples/database/session.py +0 -0
  74. {dimples-0.2.1 → dimples-0.2.2}/dimples/database/t_cipherkey.py +0 -0
  75. {dimples-0.2.1 → dimples-0.2.2}/dimples/database/t_document.py +0 -0
  76. {dimples-0.2.1 → dimples-0.2.2}/dimples/database/t_group.py +0 -0
  77. {dimples-0.2.1 → dimples-0.2.2}/dimples/database/t_login.py +0 -0
  78. {dimples-0.2.1 → dimples-0.2.2}/dimples/database/t_message.py +0 -0
  79. {dimples-0.2.1 → dimples-0.2.2}/dimples/database/t_meta.py +0 -0
  80. {dimples-0.2.1 → dimples-0.2.2}/dimples/database/t_private.py +0 -0
  81. {dimples-0.2.1 → dimples-0.2.2}/dimples/database/t_station.py +0 -0
  82. {dimples-0.2.1 → dimples-0.2.2}/dimples/database/t_user.py +0 -0
  83. {dimples-0.2.1 → dimples-0.2.2}/dimples/edge/__init__.py +0 -0
  84. {dimples-0.2.1 → dimples-0.2.2}/dimples/edge/octopus.py +0 -0
  85. {dimples-0.2.1 → dimples-0.2.2}/dimples/edge/shared.py +0 -0
  86. {dimples-0.2.1 → dimples-0.2.2}/dimples/edge/start.py +0 -0
  87. {dimples-0.2.1 → dimples-0.2.2}/dimples/register/__init__.py +0 -0
  88. {dimples-0.2.1 → dimples-0.2.2}/dimples/register/generate.py +0 -0
  89. {dimples-0.2.1 → dimples-0.2.2}/dimples/register/modify.py +0 -0
  90. {dimples-0.2.1 → dimples-0.2.2}/dimples/register/run.py +0 -0
  91. {dimples-0.2.1 → dimples-0.2.2}/dimples/register/shared.py +0 -0
  92. {dimples-0.2.1 → dimples-0.2.2}/dimples/server/__init__.py +0 -0
  93. {dimples-0.2.1 → dimples-0.2.2}/dimples/server/broadcast.py +0 -0
  94. {dimples-0.2.1 → dimples-0.2.2}/dimples/server/cpu/__init__.py +0 -0
  95. {dimples-0.2.1 → dimples-0.2.2}/dimples/server/cpu/document.py +0 -0
  96. {dimples-0.2.1 → dimples-0.2.2}/dimples/server/dispatcher.py +0 -0
  97. {dimples-0.2.1 → dimples-0.2.2}/dimples/server/messenger.py +0 -0
  98. {dimples-0.2.1 → dimples-0.2.2}/dimples/server/packer.py +0 -0
  99. {dimples-0.2.1 → dimples-0.2.2}/dimples/server/push.py +0 -0
  100. {dimples-0.2.1 → dimples-0.2.2}/dimples/server/session_center.py +0 -0
  101. {dimples-0.2.1 → dimples-0.2.2}/dimples/server/trace.py +0 -0
  102. {dimples-0.2.1 → dimples-0.2.2}/dimples/station/__init__.py +0 -0
  103. {dimples-0.2.1 → dimples-0.2.2}/dimples/station/handler.py +0 -0
  104. {dimples-0.2.1 → dimples-0.2.2}/dimples/station/shared.py +0 -0
  105. {dimples-0.2.1 → dimples-0.2.2}/dimples/station/start.py +0 -0
  106. {dimples-0.2.1 → dimples-0.2.2}/dimples/utils/__init__.py +0 -0
  107. {dimples-0.2.1 → dimples-0.2.2}/dimples/utils/cache.py +0 -0
  108. {dimples-0.2.1 → dimples-0.2.2}/dimples/utils/checker.py +0 -0
  109. {dimples-0.2.1 → dimples-0.2.2}/dimples/utils/dos.py +0 -0
  110. {dimples-0.2.1 → dimples-0.2.2}/dimples/utils/log.py +0 -0
  111. {dimples-0.2.1 → dimples-0.2.2}/dimples/utils/singleton.py +0 -0
  112. {dimples-0.2.1 → dimples-0.2.2}/dimples.egg-info/SOURCES.txt +0 -0
  113. {dimples-0.2.1 → dimples-0.2.2}/dimples.egg-info/dependency_links.txt +0 -0
  114. {dimples-0.2.1 → dimples-0.2.2}/dimples.egg-info/entry_points.txt +0 -0
  115. {dimples-0.2.1 → dimples-0.2.2}/dimples.egg-info/top_level.txt +0 -0
  116. {dimples-0.2.1 → dimples-0.2.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dimples
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: DIMP Library for Edges and Stations
5
5
  Home-page: https://github.com/dimchat/demo-py
6
6
  Author: Albert Moky
@@ -48,10 +48,6 @@ from .history import GroupCommandProcessor
48
48
 
49
49
  class ExpelCommandProcessor(GroupCommandProcessor):
50
50
 
51
- STR_EXPEL_CMD_ERROR = 'Expel command error.'
52
- STR_EXPEL_NOT_ALLOWED = 'Sorry, you are not allowed to expel member from this group.'
53
- STR_CANNOT_EXPEL_OWNER = 'Group owner cannot be expelled.'
54
-
55
51
  # Override
56
52
  def process(self, content: Content, msg: ReliableMessage) -> List[Content]:
57
53
  assert isinstance(content, ExpelCommand), 'expel command error: %s' % content
@@ -61,25 +57,41 @@ class ExpelCommandProcessor(GroupCommandProcessor):
61
57
  members = facebook.members(identifier=group)
62
58
  # 0. check group
63
59
  if owner is None or members is None or len(members) == 0:
64
- text = self.STR_GROUP_EMPTY
65
- return self._respond_text(text=text, group=group)
60
+ return self._respond_receipt(text='Group empty.', msg=msg, group=group, extra={
61
+ 'template': 'Group empty: ${ID}',
62
+ 'replacements': {
63
+ 'ID': str(group),
64
+ }
65
+ })
66
66
  # 1. check permission
67
67
  sender = msg.sender
68
68
  if sender != owner:
69
69
  # not the owner? check assistants
70
70
  assistants = facebook.assistants(identifier=group)
71
71
  if assistants is None or sender not in assistants:
72
- text = self.STR_EXPEL_NOT_ALLOWED
73
- return self._respond_text(text=text, group=group)
72
+ return self._respond_receipt(text='Permission denied.', msg=msg, group=group, extra={
73
+ 'template': 'Not allowed to expel member from group: ${ID}',
74
+ 'replacements': {
75
+ 'ID': str(group),
76
+ }
77
+ })
74
78
  # 2. expelling members
75
79
  expel_list = self.members(content=content)
76
80
  if expel_list is None or len(expel_list) == 0:
77
- text = self.STR_EXPEL_CMD_ERROR
78
- return self._respond_text(text=text, group=group)
81
+ return self._respond_receipt(text='Command error.', msg=msg, group=group, extra={
82
+ 'template': 'Expel list is empty: ${ID}',
83
+ 'replacements': {
84
+ 'ID': str(group),
85
+ }
86
+ })
79
87
  # 2.1. check owner
80
88
  if owner in expel_list:
81
- text = self.STR_CANNOT_EXPEL_OWNER
82
- return self._respond_text(text=text, group=group)
89
+ return self._respond_receipt(text='Permission denied.', msg=msg, group=group, extra={
90
+ 'template': 'Not allowed to expel owner of group: ${ID}',
91
+ 'replacements': {
92
+ 'ID': str(group),
93
+ }
94
+ })
83
95
  # 2.2. build removed-list
84
96
  remove_list = []
85
97
  for item in expel_list:
@@ -48,9 +48,6 @@ from .grp_reset import ResetCommandProcessor
48
48
 
49
49
  class InviteCommandProcessor(ResetCommandProcessor):
50
50
 
51
- STR_INVITE_CMD_ERROR = 'Invite command error.'
52
- STR_INVITE_NOT_ALLOWED = 'Sorry, you are not allowed to invite new members into this group.'
53
-
54
51
  # Override
55
52
  def process(self, content: Content, msg: ReliableMessage) -> List[Content]:
56
53
  assert isinstance(content, InviteCommand), 'invite command error: %s' % content
@@ -62,25 +59,33 @@ class InviteCommandProcessor(ResetCommandProcessor):
62
59
  if owner is None or members is None or len(members) == 0:
63
60
  # NOTICE: group membership lost?
64
61
  # reset group members
65
- return self._temporary_save(content=content, sender=msg.sender)
62
+ return self._temporary_save(content=content, sender=msg.sender, msg=msg)
66
63
  # 1. check permission
67
64
  sender = msg.sender
68
65
  if sender not in members:
69
66
  # not a member? check assistants
70
67
  assistants = facebook.assistants(identifier=group)
71
68
  if assistants is None or sender not in assistants:
72
- text = self.STR_INVITE_NOT_ALLOWED
73
- return self._respond_text(text=text, group=group)
69
+ return self._respond_receipt(text='Permission denied.', msg=msg, group=group, extra={
70
+ 'template': 'Not allowed to invite member into group: ${ID}',
71
+ 'replacements': {
72
+ 'ID': str(group),
73
+ }
74
+ })
74
75
  # 2. inviting members
75
76
  invite_list = self.members(content=content)
76
77
  if invite_list is None or len(invite_list) == 0:
77
- text = self.STR_INVITE_CMD_ERROR
78
- return self._respond_text(text=text, group=group)
78
+ return self._respond_receipt(text='Command error.', msg=msg, group=group, extra={
79
+ 'template': 'Invite list is empty: ${ID}',
80
+ 'replacements': {
81
+ 'ID': str(group),
82
+ }
83
+ })
79
84
  # 2.1. check for reset
80
85
  if sender == owner and owner in invite_list:
81
86
  # NOTICE: owner invites owner?
82
87
  # it means this should be a 'reset' command
83
- return self._temporary_save(content=content, sender=sender)
88
+ return self._temporary_save(content=content, sender=sender, msg=msg)
84
89
  # 2.2. build invited-list
85
90
  add_list = []
86
91
  for item in invite_list:
@@ -50,8 +50,6 @@ from .history import GroupCommandProcessor
50
50
 
51
51
  class QueryCommandProcessor(GroupCommandProcessor):
52
52
 
53
- STR_QUERY_NOT_ALLOWED = 'Sorry, you are not allowed to query this group.'
54
-
55
53
  def _respond_group_members(self, owner: ID, group: ID, members: List[ID]) -> Content:
56
54
  facebook = self.facebook
57
55
  assert isinstance(facebook, CommonFacebook), 'facebook error: %s' % facebook
@@ -71,16 +69,24 @@ class QueryCommandProcessor(GroupCommandProcessor):
71
69
  members = facebook.members(identifier=group)
72
70
  # 0. check group
73
71
  if owner is None or members is None or len(members) == 0:
74
- text = self.STR_GROUP_EMPTY
75
- return self._respond_text(text=text, group=group)
72
+ return self._respond_receipt(text='Group empty.', msg=msg, group=group, extra={
73
+ 'template': 'Group empty: ${ID}',
74
+ 'replacements': {
75
+ 'ID': str(group),
76
+ }
77
+ })
76
78
  # 1. check permission
77
79
  sender = msg.sender
78
80
  if sender not in members:
79
81
  # not a member? check assistants
80
82
  assistants = facebook.assistants(identifier=group)
81
83
  if assistants is None or sender not in assistants:
82
- text = self.STR_QUERY_NOT_ALLOWED
83
- return self._respond_text(text=text, group=group)
84
+ return self._respond_receipt(text='Permission denied.', msg=msg, group=group, extra={
85
+ 'template': 'Not allowed to query members of group: ${ID}',
86
+ 'replacements': {
87
+ 'ID': str(group),
88
+ }
89
+ })
84
90
  # 2. respond
85
91
  res = self._respond_group_members(owner=owner, group=group, members=members)
86
92
  return [] if res is None else [res]
@@ -39,6 +39,7 @@
39
39
 
40
40
  from typing import List
41
41
 
42
+ from dimp import ID
42
43
  from dimp import ReliableMessage
43
44
  from dimp import Content
44
45
  from dimp import QuitCommand
@@ -48,14 +49,16 @@ from .history import GroupCommandProcessor
48
49
 
49
50
  class QuitCommandProcessor(GroupCommandProcessor):
50
51
 
51
- STR_OWNER_CANNOT_QUIT = 'Sorry, owner cannot quit.'
52
- STR_ASSISTANT_CANNOT_QUIT = 'Sorry, assistant cannot quit.'
53
-
54
52
  # noinspection PyUnusedLocal
55
- def _remove_assistant(self, content: QuitCommand, msg: ReliableMessage) -> List[Content]:
53
+ def _remove_assistant(self, content: QuitCommand, sender: ID, msg: ReliableMessage) -> List[Content]:
56
54
  # NOTICE: group assistant should be retired by the owner
57
- text = self.STR_ASSISTANT_CANNOT_QUIT
58
- return self._respond_text(text=text, group=content.group)
55
+ group = content.group
56
+ return self._respond_receipt(text='Permission denied.', msg=msg, group=group, extra={
57
+ 'template': 'Assistant cannot quit from group: ${ID}',
58
+ 'replacements': {
59
+ 'ID': str(group),
60
+ }
61
+ })
59
62
 
60
63
  # Override
61
64
  def process(self, content: Content, msg: ReliableMessage) -> List[Content]:
@@ -66,16 +69,24 @@ class QuitCommandProcessor(GroupCommandProcessor):
66
69
  members = facebook.members(identifier=group)
67
70
  # 0. check group
68
71
  if owner is None or members is None or len(members) == 0:
69
- text = self.STR_GROUP_EMPTY
70
- return self._respond_text(text=text, group=group)
72
+ return self._respond_receipt(text='Group empty.', msg=msg, group=group, extra={
73
+ 'template': 'Group empty: ${ID}',
74
+ 'replacements': {
75
+ 'ID': str(group),
76
+ }
77
+ })
71
78
  # 1. check permission
72
79
  sender = msg.sender
73
80
  if sender == owner:
74
- text = self.STR_OWNER_CANNOT_QUIT
75
- return self._respond_text(text=text, group=group)
81
+ return self._respond_receipt(text='Permission denied.', msg=msg, group=group, extra={
82
+ 'template': 'Owner cannot quit from group: ${ID}',
83
+ 'replacements': {
84
+ 'ID': str(group),
85
+ }
86
+ })
76
87
  assistants = facebook.assistants(identifier=group)
77
88
  if assistants is not None and sender in assistants:
78
- return self._remove_assistant(content=content, msg=msg)
89
+ return self._remove_assistant(content=content, sender=sender, msg=msg)
79
90
  # 2. remove sender from group members
80
91
  if sender in members:
81
92
  members.remove(sender)
@@ -55,23 +55,24 @@ from .history import GroupCommandProcessor
55
55
 
56
56
  class ResetCommandProcessor(GroupCommandProcessor):
57
57
 
58
- STR_RESET_CMD_ERROR = 'Reset command error.'
59
- STR_RESET_NOT_ALLOWED = 'Sorry, you are not allowed to reset this group.'
60
-
61
58
  def _query_owner(self, owner: ID, group: ID):
62
59
  command = GroupCommand.query(group=group)
63
60
  messenger = self.messenger
64
61
  assert isinstance(messenger, CommonMessenger), 'messenger error: %s' % messenger
65
62
  messenger.send_content(sender=None, receiver=owner, content=command, priority=1)
66
63
 
67
- def _temporary_save(self, content: GroupCommand, sender: ID) -> List[Content]:
64
+ def _temporary_save(self, content: GroupCommand, sender: ID, msg: ReliableMessage) -> List[Content]:
68
65
  facebook = self.facebook
69
66
  group = content.group
70
67
  # check whether the owner contained in the new members
71
68
  new_members = self.members(content=content)
72
69
  if new_members is None or len(new_members) == 0:
73
- text = self.STR_RESET_CMD_ERROR
74
- return self._respond_text(text=text, group=group)
70
+ return self._respond_receipt(text='Command error.', msg=msg, group=group, extra={
71
+ 'template': 'New member list is empty: ${ID}',
72
+ 'replacements': {
73
+ 'ID': str(group),
74
+ }
75
+ })
75
76
  man = group_manager()
76
77
  for item in new_members:
77
78
  if facebook.meta(identifier=item) is None:
@@ -106,24 +107,36 @@ class ResetCommandProcessor(GroupCommandProcessor):
106
107
  if owner is None or members is None or len(members) == 0:
107
108
  # FIXME: group profile lost?
108
109
  # FIXME: how to avoid strangers impersonating group members?
109
- return self._temporary_save(content=content, sender=msg.sender)
110
+ return self._temporary_save(content=content, sender=msg.sender, msg=msg)
110
111
  # 1. check permission
111
112
  sender = msg.sender
112
113
  if sender != owner:
113
114
  # not the owner? check assistants
114
115
  assistants = facebook.assistants(identifier=group)
115
116
  if assistants is None or sender not in assistants:
116
- text = self.STR_RESET_NOT_ALLOWED
117
- return self._respond_text(text=text, group=group)
117
+ return self._respond_receipt(text='Permission denied.', msg=msg, group=group, extra={
118
+ 'template': 'Not allowed to reset members of group: ${ID}',
119
+ 'replacements': {
120
+ 'ID': str(group),
121
+ }
122
+ })
118
123
  # 2. resetting members
119
124
  new_members = self.members(content=content)
120
125
  if new_members is None or len(new_members) == 0:
121
- text = self.STR_RESET_CMD_ERROR
122
- return self._respond_text(text=text, group=group)
126
+ return self._respond_receipt(text='Command error.', msg=msg, group=group, extra={
127
+ 'template': 'New member list is empty: ${ID}',
128
+ 'replacements': {
129
+ 'ID': str(group),
130
+ }
131
+ })
123
132
  # 2.1. check owner
124
133
  if owner not in new_members:
125
- text = self.STR_RESET_CMD_ERROR
126
- return self._respond_text(text=text, group=group)
134
+ return self._respond_receipt(text='Permission denied.', msg=msg, group=group, extra={
135
+ 'template': 'Owner not in the new member list of group: ${ID}',
136
+ 'replacements': {
137
+ 'ID': str(group),
138
+ }
139
+ })
127
140
  # 2.2. build expelled-list
128
141
  remove_list = []
129
142
  for item in members:
@@ -45,20 +45,19 @@ from dimsdk.cpu import BaseCommandProcessor
45
45
 
46
46
  class HistoryCommandProcessor(BaseCommandProcessor):
47
47
 
48
- FMT_HIS_CMD_NOT_SUPPORT = 'History command (name: %s) not support yet!'
49
-
50
48
  # Override
51
49
  def process(self, content: Content, msg: ReliableMessage) -> List[Content]:
52
50
  assert isinstance(content, Command), 'history command error: %s' % content
53
- text = self.FMT_HIS_CMD_NOT_SUPPORT % content.cmd
54
- return self._respond_text(text=text, group=content.group)
51
+ return self._respond_receipt(text='Command not support.', msg=msg, group=content.group, extra={
52
+ 'template': 'History command (name: ${command}) not support yet!',
53
+ 'replacements': {
54
+ 'command': content.cmd,
55
+ }
56
+ })
55
57
 
56
58
 
57
59
  class GroupCommandProcessor(HistoryCommandProcessor):
58
60
 
59
- FMT_GRP_CMD_NOT_SUPPORT = 'Group command (name: %s) not support yet!'
60
- STR_GROUP_EMPTY = 'Group empty.'
61
-
62
61
  @staticmethod
63
62
  def members(content: GroupCommand) -> List[ID]:
64
63
  # get from 'members'
@@ -75,5 +74,9 @@ class GroupCommandProcessor(HistoryCommandProcessor):
75
74
  # Override
76
75
  def process(self, content: Content, msg: ReliableMessage) -> List[Content]:
77
76
  assert isinstance(content, GroupCommand), 'group command error: %s' % content
78
- text = self.FMT_GRP_CMD_NOT_SUPPORT % content.cmd
79
- return self._respond_text(text=text, group=content.group)
77
+ return self._respond_receipt(text='Command not support.', msg=msg, group=content.group, extra={
78
+ 'template': 'Group command (name: ${command}) not support yet!',
79
+ 'replacements': {
80
+ 'command': content.cmd,
81
+ }
82
+ })
@@ -49,8 +49,7 @@ class AnsCommandProcessor(BaseCommandProcessor):
49
49
  assert isinstance(content, AnsCommand), 'report command error: %s' % content
50
50
  names = content.names
51
51
  if len(names) == 0:
52
- text = 'ANS command error.'
53
- return self._respond_text(text=text)
52
+ return self._respond_receipt(text='ANS command error.', msg=msg)
54
53
  records = {}
55
54
  missed = []
56
55
  for item in names:
@@ -54,7 +54,7 @@ class HandshakeCommandProcessor(BaseCommandProcessor):
54
54
  title = content.title
55
55
  if title in ['DIM?', 'DIM!']:
56
56
  # S -> C
57
- return self._respond_text(text='Command not support.', extra={
57
+ return self._respond_receipt(text='Command not support.', msg=msg, extra={
58
58
  'template': 'Handshake command error: title="${title}".',
59
59
  'replacements': {
60
60
  'title': title,
@@ -86,7 +86,7 @@ class LoginCommandProcessor(BaseCommandProcessor, Logging):
86
86
  session.set_active(active=True)
87
87
  # only respond the user login to this station
88
88
  self.info(msg='user login: %s -> %s' % (sender, roaming))
89
- return self._respond_text(text='Login received.', extra={
89
+ return self._respond_receipt(text='Login received.', msg=msg, extra={
90
90
  'template': 'Login command received: ${ID}.',
91
91
  'replacements': {
92
92
  'ID': str(sender),
@@ -65,7 +65,7 @@ class ReportCommandProcessor(BaseCommandProcessor, Logging):
65
65
  if title == ReportCommand.ONLINE:
66
66
  # online
67
67
  session.set_active(active=True, when=content.time)
68
- return self._respond_text(text='Online received.', extra={
68
+ return self._respond_receipt(text='Online received.', msg=msg, extra={
69
69
  'template': 'Online command received: ${ID}.',
70
70
  'replacements': {
71
71
  'ID': str(sender),
@@ -74,14 +74,10 @@ class ReportCommandProcessor(BaseCommandProcessor, Logging):
74
74
  elif title == ReportCommand.OFFLINE:
75
75
  # offline
76
76
  session.set_active(active=False, when=content.time)
77
- return self._respond_text(text='Offline received.', extra={
78
- 'template': 'Offline command received: ${ID}.',
79
- 'replacements': {
80
- 'ID': str(sender),
81
- }
82
- })
77
+ # respond nothing when user offline
78
+ return []
83
79
  else:
84
- return self._respond_text(text='Command not support.', extra={
80
+ return self._respond_receipt(text='Command not support.', msg=msg, extra={
85
81
  'template': 'Report command (title: ${title}) not support yet!',
86
82
  'replacements': {
87
83
  'title': title,
@@ -69,7 +69,7 @@ class ServerMessageProcessor(MessageProcessor, Logging):
69
69
  sender = r_msg.sender
70
70
  # 1. check login
71
71
  session = messenger.session
72
- if session.identifier is None or not session.active:
72
+ if session.identifier is None: # or not session.active:
73
73
  # not login yet, force to handshake again
74
74
  if not isinstance(content, HandshakeCommand):
75
75
  handshake = HandshakeCommand.ask(session=session.key)
@@ -99,7 +99,8 @@ class ServerSession(BaseSession):
99
99
  def set_active(self, active: bool, when: float = None):
100
100
  if super().set_active(active=active, when=when):
101
101
  session_change_active(session=self, active=active)
102
- load_cached_messages(session=self)
102
+ if active:
103
+ load_cached_messages(session=self)
103
104
  return True
104
105
 
105
106
  @property # Override
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dimples
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: DIMP Library for Edges and Stations
5
5
  Home-page: https://github.com/dimchat/demo-py
6
6
  Author: Albert Moky
@@ -1,5 +1,5 @@
1
1
  dimplugins>=0.1.4
2
- dimsdk>=0.8.6
2
+ dimsdk>=0.8.7
3
3
  dimp>=0.12.9
4
4
  dkd>=0.12.7
5
5
  mkm>=0.12.7
@@ -14,7 +14,7 @@ import io
14
14
 
15
15
  from setuptools import setup, find_packages
16
16
 
17
- __version__ = '0.2.1'
17
+ __version__ = '0.2.2'
18
18
  __author__ = 'Albert Moky'
19
19
  __contact__ = 'albert.moky@gmail.com'
20
20
 
@@ -53,7 +53,7 @@ setup(
53
53
  # 'ecdsa', # 0.16.1
54
54
  'dimplugins>=0.1.4',
55
55
 
56
- 'dimsdk>=0.8.6',
56
+ 'dimsdk>=0.8.7',
57
57
  'dimp>=0.12.9',
58
58
  'dkd>=0.12.7',
59
59
  'mkm>=0.12.7',
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes