ErisPulse 2.1.15__tar.gz → 2.2.0__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 (109) hide show
  1. {erispulse-2.1.15 → erispulse-2.2.0}/.github/workflows/auto-tag-release.yml +2 -2
  2. erispulse-2.2.0/CONTRIBUTING.md +43 -0
  3. {erispulse-2.1.15 → erispulse-2.2.0}/PKG-INFO +1 -1
  4. erispulse-2.2.0/devs/test_cmd.py +242 -0
  5. erispulse-2.2.0/devs/test_event.py +100 -0
  6. {erispulse-2.1.15 → erispulse-2.2.0}/docs/AIDocs/ErisPulse-AdapterDev.md +758 -72
  7. {erispulse-2.1.15 → erispulse-2.2.0}/docs/AIDocs/ErisPulse-Core.md +818 -71
  8. {erispulse-2.1.15 → erispulse-2.2.0}/docs/AIDocs/ErisPulse-Full.md +831 -75
  9. {erispulse-2.1.15 → erispulse-2.2.0}/docs/AIDocs/ErisPulse-ModuleDev.md +829 -73
  10. {erispulse-2.1.15 → erispulse-2.2.0}/docs/CHANGELOG.md +66 -0
  11. {erispulse-2.1.15 → erispulse-2.2.0}/docs/Development/Adapter.md +2 -2
  12. {erispulse-2.1.15 → erispulse-2.2.0}/docs/Development/Module.md +11 -2
  13. {erispulse-2.1.15 → erispulse-2.2.0}/docs/PlatformFeatures.md +62 -1
  14. erispulse-2.2.0/docs/UseCore.md +425 -0
  15. erispulse-2.2.0/docs/api/ErisPulse/Core/Event/__init__.md +29 -0
  16. erispulse-2.2.0/docs/api/ErisPulse/Core/Event/base.md +78 -0
  17. erispulse-2.2.0/docs/api/ErisPulse/Core/Event/command.md +20 -0
  18. erispulse-2.2.0/docs/api/ErisPulse/Core/Event/exceptions.md +46 -0
  19. erispulse-2.2.0/docs/api/ErisPulse/Core/Event/message.md +20 -0
  20. erispulse-2.2.0/docs/api/ErisPulse/Core/Event/meta.md +19 -0
  21. erispulse-2.2.0/docs/api/ErisPulse/Core/Event/notice.md +19 -0
  22. erispulse-2.2.0/docs/api/ErisPulse/Core/Event/request.md +19 -0
  23. {erispulse-2.1.15 → erispulse-2.2.0}/docs/api/ErisPulse/Core/adapter.md +2 -2
  24. {erispulse-2.1.15 → erispulse-2.2.0}/docs/api/ErisPulse/Core/config.md +2 -2
  25. {erispulse-2.1.15 → erispulse-2.2.0}/docs/api/ErisPulse/Core/env.md +2 -2
  26. {erispulse-2.1.15 → erispulse-2.2.0}/docs/api/ErisPulse/Core/erispulse_config.md +2 -2
  27. {erispulse-2.1.15 → erispulse-2.2.0}/docs/api/ErisPulse/Core/exceptions.md +2 -2
  28. {erispulse-2.1.15 → erispulse-2.2.0}/docs/api/ErisPulse/Core/logger.md +2 -2
  29. erispulse-2.2.0/docs/api/ErisPulse/Core/module.md +108 -0
  30. erispulse-2.1.15/docs/api/ErisPulse/Core/mods.md → erispulse-2.2.0/docs/api/ErisPulse/Core/module_registry.md +42 -37
  31. {erispulse-2.1.15 → erispulse-2.2.0}/docs/api/ErisPulse/Core/router.md +2 -2
  32. {erispulse-2.1.15 → erispulse-2.2.0}/docs/api/ErisPulse/Core/storage.md +2 -2
  33. {erispulse-2.1.15 → erispulse-2.2.0}/docs/api/ErisPulse/__init__.md +2 -2
  34. {erispulse-2.1.15 → erispulse-2.2.0}/docs/api/ErisPulse/__main__.md +2 -2
  35. erispulse-2.2.0/examples/example-module/MyModule/Core.py +91 -0
  36. erispulse-2.2.0/examples/example-module/README.md +29 -0
  37. {erispulse-2.1.15 → erispulse-2.2.0}/packages.json +2 -2
  38. {erispulse-2.1.15 → erispulse-2.2.0}/pyproject.toml +1 -1
  39. erispulse-2.2.0/src/ErisPulse/Core/Event/__init__.py +51 -0
  40. erispulse-2.2.0/src/ErisPulse/Core/Event/base.py +100 -0
  41. erispulse-2.2.0/src/ErisPulse/Core/Event/command.py +310 -0
  42. erispulse-2.2.0/src/ErisPulse/Core/Event/exceptions.py +37 -0
  43. erispulse-2.2.0/src/ErisPulse/Core/Event/message.py +84 -0
  44. erispulse-2.2.0/src/ErisPulse/Core/Event/meta.py +77 -0
  45. erispulse-2.2.0/src/ErisPulse/Core/Event/notice.py +91 -0
  46. erispulse-2.2.0/src/ErisPulse/Core/Event/request.py +61 -0
  47. {erispulse-2.1.15 → erispulse-2.2.0}/src/ErisPulse/Core/__init__.py +7 -2
  48. {erispulse-2.1.15 → erispulse-2.2.0}/src/ErisPulse/Core/logger.py +2 -2
  49. erispulse-2.2.0/src/ErisPulse/Core/module.py +150 -0
  50. erispulse-2.1.15/src/ErisPulse/Core/mods.py → erispulse-2.2.0/src/ErisPulse/Core/module_registry.py +41 -37
  51. {erispulse-2.1.15 → erispulse-2.2.0}/src/ErisPulse/__init__.py +16 -9
  52. {erispulse-2.1.15 → erispulse-2.2.0}/src/ErisPulse/__main__.py +5 -5
  53. erispulse-2.1.15/docs/UseCore.md +0 -138
  54. erispulse-2.1.15/examples/example-module/MyModule/Core.py +0 -31
  55. erispulse-2.1.15/examples/example-module/README.md +0 -0
  56. {erispulse-2.1.15 → erispulse-2.2.0}/.github/ISSUE_TEMPLATE/config.yml +0 -0
  57. {erispulse-2.1.15 → erispulse-2.2.0}/.github/ISSUE_TEMPLATE/module_submission.md +0 -0
  58. {erispulse-2.1.15 → erispulse-2.2.0}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
  59. {erispulse-2.1.15 → erispulse-2.2.0}/.github/assets/docs/install_pip.gif +0 -0
  60. {erispulse-2.1.15 → erispulse-2.2.0}/.github/assets/erispulse_logo.png +0 -0
  61. {erispulse-2.1.15 → erispulse-2.2.0}/.github/scripts/update_packages.py +0 -0
  62. {erispulse-2.1.15 → erispulse-2.2.0}/.github/tools/merge_md.py +0 -0
  63. {erispulse-2.1.15 → erispulse-2.2.0}/.github/tools/update-api-docs.py +0 -0
  64. {erispulse-2.1.15 → erispulse-2.2.0}/.github/workflows/auto-update-packages.yml +0 -0
  65. {erispulse-2.1.15 → erispulse-2.2.0}/.github/workflows/pypi-publish.yml +0 -0
  66. {erispulse-2.1.15 → erispulse-2.2.0}/.gitignore +0 -0
  67. {erispulse-2.1.15 → erispulse-2.2.0}/.python-version +0 -0
  68. {erispulse-2.1.15 → erispulse-2.2.0}/.worker/worker.js +0 -0
  69. {erispulse-2.1.15 → erispulse-2.2.0}/CODE_OF_CONDUCT.md +0 -0
  70. {erispulse-2.1.15 → erispulse-2.2.0}/LICENSE +0 -0
  71. {erispulse-2.1.15 → erispulse-2.2.0}/README.md +0 -0
  72. {erispulse-2.1.15 → erispulse-2.2.0}/SECURITY.md +0 -0
  73. {erispulse-2.1.15 → erispulse-2.2.0}/devs/test.py +0 -0
  74. {erispulse-2.1.15 → erispulse-2.2.0}/devs/test_adapter.py +0 -0
  75. {erispulse-2.1.15 → erispulse-2.2.0}/devs/test_files/test.docx +0 -0
  76. {erispulse-2.1.15 → erispulse-2.2.0}/devs/test_files/test.jpg +0 -0
  77. {erispulse-2.1.15 → erispulse-2.2.0}/devs/test_files/test.mp4 +0 -0
  78. {erispulse-2.1.15 → erispulse-2.2.0}/docs/AIModuleGeneration.md +0 -0
  79. {erispulse-2.1.15 → erispulse-2.2.0}/docs/AdapterStandards/APIResponse.md +0 -0
  80. {erispulse-2.1.15 → erispulse-2.2.0}/docs/AdapterStandards/EventConversion.md +0 -0
  81. {erispulse-2.1.15 → erispulse-2.2.0}/docs/AdapterStandards/README.md +0 -0
  82. {erispulse-2.1.15 → erispulse-2.2.0}/docs/CLI.md +0 -0
  83. {erispulse-2.1.15 → erispulse-2.2.0}/docs/Development/CLI.md +0 -0
  84. {erispulse-2.1.15 → erispulse-2.2.0}/docs/Development/README.md +0 -0
  85. {erispulse-2.1.15 → erispulse-2.2.0}/docs/StyleGuide/DocstringSpec.md +0 -0
  86. {erispulse-2.1.15 → erispulse-2.2.0}/docs/StyleGuide/README.md +0 -0
  87. {erispulse-2.1.15 → erispulse-2.2.0}/docs/quick-start.md +0 -0
  88. {erispulse-2.1.15 → erispulse-2.2.0}/examples/example-adapter/LICENSE +0 -0
  89. {erispulse-2.1.15 → erispulse-2.2.0}/examples/example-adapter/MyAdapter/Core.py +0 -0
  90. {erispulse-2.1.15 → erispulse-2.2.0}/examples/example-adapter/MyAdapter/__init__.py +0 -0
  91. {erispulse-2.1.15 → erispulse-2.2.0}/examples/example-adapter/README.md +0 -0
  92. {erispulse-2.1.15 → erispulse-2.2.0}/examples/example-adapter/pyproject.toml +0 -0
  93. {erispulse-2.1.15 → erispulse-2.2.0}/examples/example-cli-module/LICENSE +0 -0
  94. {erispulse-2.1.15 → erispulse-2.2.0}/examples/example-cli-module/README.md +0 -0
  95. {erispulse-2.1.15 → erispulse-2.2.0}/examples/example-cli-module/my_cli_module/__init__.py +0 -0
  96. {erispulse-2.1.15 → erispulse-2.2.0}/examples/example-cli-module/my_cli_module/cli.py +0 -0
  97. {erispulse-2.1.15 → erispulse-2.2.0}/examples/example-cli-module/pyproject.toml +0 -0
  98. {erispulse-2.1.15 → erispulse-2.2.0}/examples/example-module/LICENSE +0 -0
  99. {erispulse-2.1.15 → erispulse-2.2.0}/examples/example-module/MyModule/__init__.py +0 -0
  100. {erispulse-2.1.15 → erispulse-2.2.0}/examples/example-module/pyproject.toml +0 -0
  101. {erispulse-2.1.15 → erispulse-2.2.0}/scripts/install/install.ps1 +0 -0
  102. {erispulse-2.1.15 → erispulse-2.2.0}/scripts/install/install.sh +0 -0
  103. {erispulse-2.1.15 → erispulse-2.2.0}/src/ErisPulse/Core/adapter.py +0 -0
  104. {erispulse-2.1.15 → erispulse-2.2.0}/src/ErisPulse/Core/config.py +0 -0
  105. {erispulse-2.1.15 → erispulse-2.2.0}/src/ErisPulse/Core/env.py +0 -0
  106. {erispulse-2.1.15 → erispulse-2.2.0}/src/ErisPulse/Core/erispulse_config.py +0 -0
  107. {erispulse-2.1.15 → erispulse-2.2.0}/src/ErisPulse/Core/exceptions.py +0 -0
  108. {erispulse-2.1.15 → erispulse-2.2.0}/src/ErisPulse/Core/router.py +0 -0
  109. {erispulse-2.1.15 → erispulse-2.2.0}/src/ErisPulse/Core/storage.py +0 -0
@@ -5,7 +5,7 @@ permissions:
5
5
 
6
6
  on:
7
7
  push:
8
- branches: [main]
8
+ branches: [main, Pre-Release/v2]
9
9
 
10
10
  jobs:
11
11
  auto-tag-and-release:
@@ -126,4 +126,4 @@ jobs:
126
126
  --prerelease=$is_dev
127
127
  echo "✨ 已发布新的魔法版本 $tag_name"
128
128
  fi
129
-
129
+
@@ -0,0 +1,43 @@
1
+ # 项目贡献指南
2
+
3
+ ## 分支管理规范
4
+
5
+ ### 分支结构
6
+ - **main**: 主分支,存放稳定可发布的代码
7
+ - **Develop/v2**: 开发主分支,所有功能分支最终合并至此
8
+ - **Pre-Release/v2**: 预发布分支,用于版本发布前的测试
9
+ - **feature/***: 功能开发分支,按功能命名
10
+ - **Archive/v1**: 归档分支,存放旧版本代码
11
+
12
+ ## 贡献流程
13
+
14
+ 1. **Fork仓库**
15
+ - 首先fork主仓库到您的个人账户
16
+
17
+ 2. **创建个人分支**
18
+ - 从`Develop/v2`创建您的功能分支,命名规范:
19
+ - `feature/描述性名称` (如`feature/wsu2059q`) -> 可为长期的功能开发/修复分支
20
+
21
+ 3. **开发工作**
22
+ - 在您的功能分支上进行开发
23
+ - 保持提交信息清晰明确
24
+ - 提交前确保已经在ChangeLog中添加描述
25
+ - 定期从`Develop/v2`拉取更新以避免冲突
26
+
27
+ 4. **提交Pull Request**
28
+ - 开发完成后,向`Develop/v2`分支提交PR
29
+ - 在PR的模板中勾选对应选项 或 添加一些详情信息
30
+
31
+ 5. **合并到Develop/v2**
32
+ - 审查通过后,代码将被合并到`Develop/v2`
33
+
34
+ 6. **发布流程**
35
+ - 版本更新, `Develop/v2` 会随更新合并到 `Pre-Release/v2` 发布并进行测试
36
+ - 测试通过后,代码将最终发布到`main`分支
37
+
38
+ ## 注意事项
39
+
40
+ - 请勿直接向`main`或`Pre-Release/v2`分支提交代码
41
+ - 如有疑问,请联系 `support@erisdev.com` 或者 添加我们的社交讨论群: 云湖群ID -> 635409929
42
+
43
+ 感谢您的贡献!
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ErisPulse
3
- Version: 2.1.15
3
+ Version: 2.2.0
4
4
  Summary: ErisPulse 是一个模块化、可扩展的异步 Python SDK 框架,主要用于构建高效、可维护的机器人应用程序。
5
5
  Author-email: "艾莉丝·格雷拉特(WSu2059)" <wsu2059@qq.com>
6
6
  License: MIT License
@@ -0,0 +1,242 @@
1
+ import asyncio
2
+ import json
3
+ from ErisPulse import sdk
4
+ from ErisPulse.Core.Event import command, message, notice, request, meta
5
+
6
+ # 全局状态变量
7
+ echo_status = False
8
+ admin_users = ["5197892", "admin2"] # 示例管理员用户ID
9
+
10
+ @command("test", help="测试命令", usage="/test [参数]")
11
+ async def test_command(event):
12
+ platform = event["platform"]
13
+
14
+ if event.get("detail_type") == "group":
15
+ type = "group"
16
+ id = event["group_id"]
17
+ else:
18
+ type = "user"
19
+ id = event["user_id"]
20
+
21
+ adapter = getattr(sdk.adapter, platform)
22
+ await adapter.Send.To(type, id).Text("收到测试命令")
23
+ sdk.logger.info(f"处理测试命令: {event}")
24
+
25
+ @command("help", help="帮助命令", usage="/help")
26
+ async def help_command(event):
27
+ platform = event["platform"]
28
+
29
+ if event.get("detail_type") == "group":
30
+ type = "group"
31
+ id = event["group_id"]
32
+ else:
33
+ type = "user"
34
+ id = event["user_id"]
35
+
36
+ adapter = getattr(sdk.adapter, platform)
37
+ await adapter.Send.To(type, id).Text(command.help())
38
+
39
+ @command("echo", help="控制事件回显", usage="/echo <on|off>")
40
+ async def echo_control_command(event):
41
+ platform = event["platform"]
42
+
43
+ if event.get("detail_type") == "group":
44
+ type = "group"
45
+ id = event["group_id"]
46
+ else:
47
+ type = "user"
48
+ id = event["user_id"]
49
+
50
+ adapter = getattr(sdk.adapter, platform)
51
+
52
+ alt_message = event["alt_message"].strip()
53
+ args = alt_message.split()[1:]
54
+
55
+ global echo_status
56
+
57
+ if not args:
58
+ status_text = "开启" if echo_status else "关闭"
59
+ await adapter.Send.To(type, id).Text(f"Echo当前状态: {status_text}")
60
+ return
61
+
62
+ subcommand = args[0].lower()
63
+
64
+ if subcommand == "on":
65
+ echo_status = True
66
+ await adapter.Send.To(type, id).Text("Echo已开启")
67
+ elif subcommand == "off":
68
+ echo_status = False
69
+ await adapter.Send.To(type, id).Text("Echo已关闭")
70
+ else:
71
+ await adapter.Send.To(type, id).Text("无效参数,请使用 'on' 或 'off'")
72
+
73
+ @command(["alias", "别名"], aliases=["a"], help="别名命令测试", usage="/alias 或 /a")
74
+ async def alias_command(event):
75
+ platform = event["platform"]
76
+
77
+ if event.get("detail_type") == "group":
78
+ type = "group"
79
+ id = event["group_id"]
80
+ else:
81
+ type = "user"
82
+ id = event["user_id"]
83
+
84
+ adapter = getattr(sdk.adapter, platform)
85
+ used_name = event["command"]["name"]
86
+ await adapter.Send.To(type, id).Text(f"通过别名 '{used_name}' 调用了命令")
87
+
88
+ @command("admin", group="admin", help="管理员命令组测试", usage="/admin")
89
+ async def admin_command(event):
90
+ platform = event["platform"]
91
+
92
+ if event.get("detail_type") == "group":
93
+ type = "group"
94
+ id = event["group_id"]
95
+ else:
96
+ type = "user"
97
+ id = event["user_id"]
98
+
99
+ adapter = getattr(sdk.adapter, platform)
100
+ await adapter.Send.To(type, id).Text("管理员命令执行成功")
101
+
102
+ @command("hidden", hidden=True, help="隐藏命令", usage="/hidden")
103
+ async def hidden_command(event):
104
+ platform = event["platform"]
105
+
106
+ if event.get("detail_type") == "group":
107
+ type = "group"
108
+ id = event["group_id"]
109
+ else:
110
+ type = "user"
111
+ id = event["user_id"]
112
+
113
+ adapter = getattr(sdk.adapter, platform)
114
+ await adapter.Send.To(type, id).Text("这是一个隐藏命令")
115
+
116
+ @command("permission", help="权限检查测试", usage="/permission")
117
+ def check_permission(event):
118
+ user_id = event.get("user_id")
119
+ return user_id in admin_users
120
+
121
+ @command("permission", permission=check_permission, help="需要权限的命令", usage="/permission")
122
+ async def permission_command(event):
123
+ platform = event["platform"]
124
+
125
+ if event.get("detail_type") == "group":
126
+ type = "group"
127
+ id = event["group_id"]
128
+ else:
129
+ type = "user"
130
+ id = event["user_id"]
131
+
132
+ adapter = getattr(sdk.adapter, platform)
133
+ await adapter.Send.To(type, id).Text("权限检查通过,命令执行成功")
134
+
135
+ @command("args", help="参数测试命令", usage="/args <参数1> [参数2] ...")
136
+ async def args_command(event):
137
+ platform = event["platform"]
138
+
139
+ if event.get("detail_type") == "group":
140
+ type = "group"
141
+ id = event["group_id"]
142
+ else:
143
+ type = "user"
144
+ id = event["user_id"]
145
+
146
+ adapter = getattr(sdk.adapter, platform)
147
+
148
+ args = event["command"]["args"]
149
+ if not args:
150
+ await adapter.Send.To(type, id).Text("未提供参数")
151
+ else:
152
+ args_str = ", ".join(args)
153
+ await adapter.Send.To(type, id).Text(f"接收到参数: {args_str}")
154
+
155
+ @sdk.adapter.on("message")
156
+ async def echo_message(event):
157
+ global echo_status
158
+ platform = event["platform"]
159
+
160
+ if echo_status:
161
+ try:
162
+ adapter = getattr(sdk.adapter, platform)
163
+
164
+ if event.get("detail_type") == "group":
165
+ target_type = "group"
166
+ target_id = event["group_id"]
167
+ else:
168
+ target_type = "user"
169
+ target_id = event["user_id"]
170
+
171
+ event_copy = event.copy()
172
+ platform_raw_key = f"{platform}_raw"
173
+ if platform_raw_key in event_copy:
174
+ del event_copy[platform_raw_key]
175
+
176
+ event_str = json.dumps(event_copy, ensure_ascii=False, indent=2)
177
+ if len(event_str) > 1000:
178
+ event_str = event_str[:1000] + "... (内容过长已截断)"
179
+
180
+ await adapter.Send.To(target_type, target_id).Text(f"Event内容:\n{event_str}")
181
+ except Exception as e:
182
+ sdk.logger.error(f"Echo回显失败: {e}")
183
+
184
+ return event
185
+
186
+ # 消息事件处理测试
187
+ @message.on_message(priority=10)
188
+ async def message_handler(event):
189
+ sdk.logger.info(f"消息处理器收到事件: {event.get('alt_message')}")
190
+
191
+ @message.on_private_message()
192
+ async def private_message_handler(event):
193
+ sdk.logger.info(f"收到私聊消息,来自用户: {event.get('user_id')}")
194
+
195
+ @message.on_group_message()
196
+ async def group_message_handler(event):
197
+ sdk.logger.info(f"收到群消息,群: {event.get('group_id')},用户: {event.get('user_id')}")
198
+
199
+ # 通知事件处理测试
200
+ @notice.on_friend_add()
201
+ async def friend_add_handler(event):
202
+ sdk.logger.info(f"新好友添加: {event.get('user_id')}")
203
+
204
+ @notice.on_group_increase()
205
+ async def group_increase_handler(event):
206
+ sdk.logger.info(f"新成员加入群: {event.get('group_id')},用户: {event.get('user_id')}")
207
+
208
+ # 请求事件处理测试
209
+ @request.on_friend_request()
210
+ async def friend_request_handler(event):
211
+ sdk.logger.info(f"收到好友请求,来自用户: {event.get('user_id')}")
212
+
213
+ # 元事件处理测试
214
+ @meta.on_connect()
215
+ async def connect_handler(event):
216
+ sdk.logger.info(f"平台 {event.get('platform')} 连接成功")
217
+
218
+ @meta.on_disconnect()
219
+ async def disconnect_handler(event):
220
+ sdk.logger.info(f"平台 {event.get('platform')} 断开连接")
221
+
222
+ async def main():
223
+ try:
224
+ isInit = await sdk.init_task()
225
+
226
+ if not isInit:
227
+ sdk.logger.error("ErisPulse 初始化失败,请检查日志")
228
+ return
229
+
230
+ await sdk.adapter.startup()
231
+
232
+ # 保持程序运行(不建议修改)
233
+ await asyncio.Event().wait()
234
+ except Exception as e:
235
+ sdk.logger.error(e)
236
+ except KeyboardInterrupt:
237
+ sdk.logger.info("正在停止程序")
238
+ finally:
239
+ await sdk.adapter.shutdown()
240
+
241
+ if __name__ == "__main__":
242
+ asyncio.run(main())
@@ -0,0 +1,100 @@
1
+ import asyncio
2
+ import time
3
+ from ErisPulse import sdk
4
+ from ErisPulse.Core.Event import command, message, notice, request, meta
5
+
6
+ # 测试命令处理
7
+ @command("test", help="测试命令", usage="/test [参数]")
8
+ async def test_command(event):
9
+ platform = event["platform"]
10
+ user_id = event["user_id"]
11
+
12
+ reply = "收到测试命令,无参数"
13
+
14
+ adapter = getattr(sdk.adapter, platform)
15
+ await adapter.Send.To("user", user_id).Text(reply)
16
+ sdk.logger.info(f"处理测试命令: {event}")
17
+
18
+ # 测试消息事件处理
19
+ @message.on_message()
20
+ async def handle_all_messages(event):
21
+ sdk.logger.info(f"收到消息事件: {event['alt_message']}")
22
+
23
+ @message.on_private_message()
24
+ async def handle_private_messages(event):
25
+ sdk.logger.info(f"收到私聊消息,来自用户: {event['user_id']}")
26
+
27
+ @message.on_group_message()
28
+ async def handle_group_messages(event):
29
+ sdk.logger.info(f"收到群消息,群: {event['group_id']},用户: {event['user_id']}")
30
+
31
+ # 测试通知事件处理
32
+ @notice.on_friend_add()
33
+ async def handle_friend_add(event):
34
+ sdk.logger.info(f"新好友添加: {event['user_id']}")
35
+
36
+ platform = event["platform"]
37
+ user_id = event["user_id"]
38
+ adapter = getattr(sdk.adapter, platform)
39
+ await adapter.Send.To("user", user_id).Text("感谢添加我为好友!")
40
+
41
+ @notice.on_group_increase()
42
+ async def handle_group_increase(event):
43
+ sdk.logger.info(f"新成员加入群: {event['group_id']},用户: {event['user_id']}")
44
+
45
+ # 测试元事件处理
46
+ @meta.on_connect()
47
+ async def handle_connect(event):
48
+ sdk.logger.info(f"平台 {event['platform']} 连接成功")
49
+
50
+ @meta.on_disconnect()
51
+ async def handle_disconnect(event):
52
+ sdk.logger.info(f"平台 {event['platform']} 断开连接")
53
+
54
+ # 测试中间件
55
+ @message.handler.middleware
56
+ async def message_middleware(event):
57
+ sdk.logger.info(f"消息中间件处理: {event['message_id']}")
58
+ return event
59
+
60
+ @command.handler.middleware
61
+ async def command_middleware(event):
62
+ sdk.logger.info(f"命令中间件处理: {event}")
63
+ return event
64
+
65
+ async def main():
66
+ try:
67
+ isInit = await sdk.init_task()
68
+
69
+ if not isInit:
70
+ sdk.logger.error("ErisPulse 初始化失败,请检查日志")
71
+ return
72
+
73
+ await sdk.adapter.startup()
74
+
75
+ # 模拟发送测试事件
76
+ test_event = {
77
+ "id": "test_event_123",
78
+ "time": int(time.time()),
79
+ "type": "message",
80
+ "detail_type": "private",
81
+ "platform": "yunhu",
82
+ "self": {"platform": "yunhu", "user_id": "bot_123"},
83
+ "message_id": "test_msg_456",
84
+ "message": [{"type": "text", "data": {"text": "/test 测试参数"}}],
85
+ "alt_message": "/test 测试参数",
86
+ "user_id": "user_789"
87
+ }
88
+ await sdk.adapter.emit(test_event)
89
+
90
+ # 保持程序运行
91
+ await asyncio.Event().wait()
92
+ except Exception as e:
93
+ sdk.logger.error(f"测试程序出错: {e}")
94
+ except KeyboardInterrupt:
95
+ sdk.logger.info("正在停止测试程序")
96
+ finally:
97
+ await sdk.adapter.shutdown()
98
+
99
+ if __name__ == "__main__":
100
+ asyncio.run(main())