endstone-qqsync-plugin 0.0.7__py3-none-any.whl

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 (73) hide show
  1. endstone_qqsync_plugin/__init__.py +3 -0
  2. endstone_qqsync_plugin/core/__init__.py +18 -0
  3. endstone_qqsync_plugin/core/config_manager.py +224 -0
  4. endstone_qqsync_plugin/core/data_manager.py +511 -0
  5. endstone_qqsync_plugin/core/event_handlers.py +552 -0
  6. endstone_qqsync_plugin/core/permission_manager.py +331 -0
  7. endstone_qqsync_plugin/core/verification_manager.py +718 -0
  8. endstone_qqsync_plugin/lib/websockets/__init__.py +236 -0
  9. endstone_qqsync_plugin/lib/websockets/__main__.py +5 -0
  10. endstone_qqsync_plugin/lib/websockets/asyncio/__init__.py +0 -0
  11. endstone_qqsync_plugin/lib/websockets/asyncio/async_timeout.py +282 -0
  12. endstone_qqsync_plugin/lib/websockets/asyncio/client.py +820 -0
  13. endstone_qqsync_plugin/lib/websockets/asyncio/compatibility.py +30 -0
  14. endstone_qqsync_plugin/lib/websockets/asyncio/connection.py +1237 -0
  15. endstone_qqsync_plugin/lib/websockets/asyncio/messages.py +314 -0
  16. endstone_qqsync_plugin/lib/websockets/asyncio/router.py +198 -0
  17. endstone_qqsync_plugin/lib/websockets/asyncio/server.py +981 -0
  18. endstone_qqsync_plugin/lib/websockets/auth.py +18 -0
  19. endstone_qqsync_plugin/lib/websockets/cli.py +178 -0
  20. endstone_qqsync_plugin/lib/websockets/client.py +389 -0
  21. endstone_qqsync_plugin/lib/websockets/connection.py +12 -0
  22. endstone_qqsync_plugin/lib/websockets/datastructures.py +187 -0
  23. endstone_qqsync_plugin/lib/websockets/exceptions.py +473 -0
  24. endstone_qqsync_plugin/lib/websockets/extensions/__init__.py +4 -0
  25. endstone_qqsync_plugin/lib/websockets/extensions/base.py +123 -0
  26. endstone_qqsync_plugin/lib/websockets/extensions/permessage_deflate.py +697 -0
  27. endstone_qqsync_plugin/lib/websockets/frames.py +430 -0
  28. endstone_qqsync_plugin/lib/websockets/headers.py +586 -0
  29. endstone_qqsync_plugin/lib/websockets/http.py +20 -0
  30. endstone_qqsync_plugin/lib/websockets/http11.py +427 -0
  31. endstone_qqsync_plugin/lib/websockets/imports.py +100 -0
  32. endstone_qqsync_plugin/lib/websockets/legacy/__init__.py +11 -0
  33. endstone_qqsync_plugin/lib/websockets/legacy/auth.py +190 -0
  34. endstone_qqsync_plugin/lib/websockets/legacy/client.py +705 -0
  35. endstone_qqsync_plugin/lib/websockets/legacy/exceptions.py +71 -0
  36. endstone_qqsync_plugin/lib/websockets/legacy/framing.py +225 -0
  37. endstone_qqsync_plugin/lib/websockets/legacy/handshake.py +158 -0
  38. endstone_qqsync_plugin/lib/websockets/legacy/http.py +201 -0
  39. endstone_qqsync_plugin/lib/websockets/legacy/protocol.py +1641 -0
  40. endstone_qqsync_plugin/lib/websockets/legacy/server.py +1191 -0
  41. endstone_qqsync_plugin/lib/websockets/protocol.py +758 -0
  42. endstone_qqsync_plugin/lib/websockets/py.typed +0 -0
  43. endstone_qqsync_plugin/lib/websockets/server.py +587 -0
  44. endstone_qqsync_plugin/lib/websockets/speedups.c +222 -0
  45. endstone_qqsync_plugin/lib/websockets/speedups.pyi +1 -0
  46. endstone_qqsync_plugin/lib/websockets/streams.py +151 -0
  47. endstone_qqsync_plugin/lib/websockets/sync/__init__.py +0 -0
  48. endstone_qqsync_plugin/lib/websockets/sync/client.py +648 -0
  49. endstone_qqsync_plugin/lib/websockets/sync/connection.py +1072 -0
  50. endstone_qqsync_plugin/lib/websockets/sync/messages.py +345 -0
  51. endstone_qqsync_plugin/lib/websockets/sync/router.py +192 -0
  52. endstone_qqsync_plugin/lib/websockets/sync/server.py +763 -0
  53. endstone_qqsync_plugin/lib/websockets/sync/utils.py +45 -0
  54. endstone_qqsync_plugin/lib/websockets/typing.py +74 -0
  55. endstone_qqsync_plugin/lib/websockets/uri.py +225 -0
  56. endstone_qqsync_plugin/lib/websockets/utils.py +51 -0
  57. endstone_qqsync_plugin/lib/websockets/version.py +92 -0
  58. endstone_qqsync_plugin/qqsync_plugin.py +356 -0
  59. endstone_qqsync_plugin/ui/__init__.py +7 -0
  60. endstone_qqsync_plugin/ui/forms.py +403 -0
  61. endstone_qqsync_plugin/utils/__init__.py +27 -0
  62. endstone_qqsync_plugin/utils/helpers.py +45 -0
  63. endstone_qqsync_plugin/utils/imports.py +31 -0
  64. endstone_qqsync_plugin/utils/info.py +262 -0
  65. endstone_qqsync_plugin/utils/message_utils.py +273 -0
  66. endstone_qqsync_plugin/utils/time_utils.py +347 -0
  67. endstone_qqsync_plugin/websocket/__init__.py +18 -0
  68. endstone_qqsync_plugin/websocket/client.py +244 -0
  69. endstone_qqsync_plugin/websocket/handlers.py +1117 -0
  70. endstone_qqsync_plugin-0.0.7.dist-info/METADATA +6 -0
  71. endstone_qqsync_plugin-0.0.7.dist-info/RECORD +73 -0
  72. endstone_qqsync_plugin-0.0.7.dist-info/WHEEL +5 -0
  73. endstone_qqsync_plugin-0.0.7.dist-info/entry_points.txt +2 -0
@@ -0,0 +1,3 @@
1
+ from endstone_qqsync_plugin.qqsync_plugin import qqsync
2
+
3
+ __all__ = ["qqsync"]
@@ -0,0 +1,18 @@
1
+ """
2
+ QQsync插件核心模块
3
+ """
4
+
5
+ # 核心模块导出
6
+ from .config_manager import ConfigManager
7
+ from .data_manager import DataManager
8
+ from .verification_manager import VerificationManager
9
+ from .permission_manager import PermissionManager
10
+ from .event_handlers import EventHandlers
11
+
12
+ __all__ = [
13
+ "ConfigManager",
14
+ "DataManager",
15
+ "VerificationManager",
16
+ "PermissionManager",
17
+ "EventHandlers"
18
+ ]
@@ -0,0 +1,224 @@
1
+ """
2
+ 配置管理模块
3
+ 负责插件配置的加载、保存和管理
4
+ """
5
+
6
+ import json
7
+ from pathlib import Path
8
+ from typing import Any, Dict
9
+
10
+
11
+ class ConfigManager:
12
+ """配置管理器"""
13
+
14
+ def __init__(self, data_folder: Path, logger):
15
+ self.data_folder = data_folder
16
+ self.logger = logger
17
+ self.config_file = data_folder / "config.json"
18
+ self._config: Dict[str, Any] = {}
19
+ self._color_format = None # 延迟加载ColorFormat
20
+ self.default_config = {
21
+ "napcat_ws": "ws://127.0.0.1:3001",
22
+ "access_token": "",
23
+ "target_group": 712523104,
24
+ "admins": ["2899659758"],
25
+ "enable_qq_to_game": True,
26
+ "enable_game_to_qq": True,
27
+ "force_bind_qq": True,
28
+ "sync_group_card": True,
29
+ "check_group_member": True,
30
+ "chat_count_limit": 20,
31
+ "chat_ban_time": 300
32
+ }
33
+ self._init_config()
34
+
35
+ @property
36
+ def color_format(self):
37
+ """延迟加载ColorFormat以避免循环依赖"""
38
+ if self._color_format is None:
39
+ from endstone import ColorFormat
40
+ self._color_format = ColorFormat
41
+ return self._color_format
42
+
43
+ def _init_config(self):
44
+ """初始化配置文件"""
45
+ # 如果配置文件不存在,创建默认配置
46
+ if not self.config_file.exists():
47
+ self.config_file.parent.mkdir(parents=True, exist_ok=True)
48
+ with open(self.config_file, 'w', encoding='utf-8') as f:
49
+ json.dump(self.default_config, f, indent=2, ensure_ascii=False)
50
+ self.logger.info(f"已创建默认配置文件: {self.config_file}")
51
+
52
+ # 读取配置
53
+ try:
54
+ with open(self.config_file, 'r', encoding='utf-8') as f:
55
+ self._config = json.load(f)
56
+ except Exception as e:
57
+ self.logger.error(f"读取配置文件失败: {e}")
58
+ self._config = self.default_config.copy()
59
+
60
+ # 检查并合并新的配置项
61
+ config_updated = False
62
+ for key, value in self.default_config.items():
63
+ if key not in self._config:
64
+ self._config[key] = value
65
+ config_updated = True
66
+ self.logger.info(f"添加新配置项: {key}")
67
+
68
+ # 生成动态帮助信息
69
+ self._config["help_msg"] = self._generate_help_message()
70
+
71
+ # 如果有新配置项,保存到文件
72
+ if config_updated:
73
+ self.save_config()
74
+
75
+ self._log_config_info()
76
+
77
+ def _get_help_commands(self, include_bind: bool = True, include_admin: bool = False, mark_sections: bool = False) -> str:
78
+ """获取帮助命令文本的通用方法"""
79
+ basic_commands = [
80
+ "/help — 显示本帮助信息",
81
+ "/list — 查看在线玩家列表",
82
+ "/tps — 查看服务器性能指标",
83
+ "/info — 查看服务器综合信息"
84
+ ]
85
+
86
+ bind_commands = [
87
+ "/bindqq — 查看QQ绑定状态",
88
+ "/verify <验证码> — 验证QQ绑定"
89
+ ]
90
+
91
+ admin_commands = [
92
+ "/cmd <命令> — 执行服务器命令",
93
+ "/who <玩家名|QQ号> — 查询玩家详细信息",
94
+ "/unbindqq <玩家名|QQ号> — 解绑玩家的QQ绑定",
95
+ "/ban <玩家名> [原因] — 封禁玩家",
96
+ "/unban <玩家名> — 解除玩家封禁",
97
+ "/banlist — 查看封禁列表",
98
+ "/tog_qq — 切换QQ消息转发开关",
99
+ "/tog_game — 切换游戏转发开关",
100
+ "/reload — 重新加载配置文件"
101
+ ]
102
+
103
+ # 构建命令列表
104
+ result = ["QQsync群服互通 - 命令:"]
105
+
106
+ # 查询命令分节
107
+ if mark_sections and include_admin:
108
+ result.append("\n[查询命令](所有用户可用):")
109
+ else:
110
+ result.append("\n[查询命令]:")
111
+
112
+ result.extend(basic_commands)
113
+
114
+ if include_bind:
115
+ result.extend(bind_commands)
116
+
117
+ if include_admin:
118
+ # 管理命令分节
119
+ if mark_sections:
120
+ result.append("\n[管理命令](仅管理员可用):")
121
+ else:
122
+ result.append("\n[管理命令]:")
123
+
124
+ # 过滤管理员命令(如果没有绑定功能,则移除绑定相关命令)
125
+ filtered_admin = admin_commands if include_bind else [cmd for cmd in admin_commands if "QQ" not in cmd]
126
+ result.extend(filtered_admin)
127
+
128
+ return "\n".join(result)
129
+
130
+ def _generate_help_message(self) -> str:
131
+ """根据当前配置动态生成帮助信息"""
132
+ force_bind_enabled = self.get_config("force_bind_qq", True)
133
+ return self._get_help_commands(include_bind=force_bind_enabled, include_admin=True)
134
+
135
+ def get_help_text(self) -> str:
136
+ """获取普通用户帮助文本"""
137
+ force_bind_enabled = self.get_config("force_bind_qq", True)
138
+ return self._get_help_commands(include_bind=force_bind_enabled, include_admin=False)
139
+
140
+ def get_help_text_with_admin(self) -> str:
141
+ """获取包含管理员命令的帮助文本"""
142
+ force_bind_enabled = self.get_config("force_bind_qq", True)
143
+ return self._get_help_commands(include_bind=force_bind_enabled, include_admin=True, mark_sections=True)
144
+
145
+ def _log_config_info(self):
146
+ """记录配置信息"""
147
+ ColorFormat = self.color_format
148
+
149
+ self.logger.info(f"{ColorFormat.AQUA}配置文件已加载{ColorFormat.RESET}")
150
+ self.logger.info(f"{ColorFormat.GOLD}NapCat WebSocket: {ColorFormat.WHITE}{self._config.get('napcat_ws')}{ColorFormat.RESET}")
151
+ self.logger.info(f"{ColorFormat.GOLD}目标QQ群: {ColorFormat.WHITE}{self._config.get('target_group')}{ColorFormat.RESET}")
152
+ self.logger.info(f"{ColorFormat.GOLD}管理员列表: {ColorFormat.WHITE}{self._config.get('admins')}{ColorFormat.RESET}")
153
+
154
+ force_bind_enabled = self._config.get('force_bind_qq', True)
155
+ sync_card_enabled = self._config.get('sync_group_card', True)
156
+ check_group_enabled = self._config.get('check_group_member', True)
157
+
158
+ if force_bind_enabled:
159
+ self.logger.info(f"{ColorFormat.GOLD}强制QQ绑定: {ColorFormat.WHITE}启用 {ColorFormat.YELLOW}(未绑定玩家将限制为访客权限){ColorFormat.RESET}")
160
+
161
+ if sync_card_enabled:
162
+ self.logger.info(f"{ColorFormat.GOLD}同步群昵称: {ColorFormat.WHITE}启用 {ColorFormat.YELLOW}(绑定成功后自动设置群昵称){ColorFormat.RESET}")
163
+ else:
164
+ self.logger.info(f"{ColorFormat.GOLD}同步群昵称: {ColorFormat.WHITE}禁用{ColorFormat.RESET}")
165
+
166
+ if check_group_enabled:
167
+ self.logger.info(f"{ColorFormat.GOLD}退群检测: {ColorFormat.WHITE}启用 {ColorFormat.YELLOW}(退群玩家将自动设为访客权限){ColorFormat.RESET}")
168
+ else:
169
+ self.logger.info(f"{ColorFormat.GOLD}退群检测: {ColorFormat.WHITE}禁用{ColorFormat.RESET}")
170
+ else:
171
+ self.logger.info(f"{ColorFormat.GOLD}强制QQ绑定: {ColorFormat.WHITE}禁用 {ColorFormat.YELLOW}(所有玩家享有完整权限){ColorFormat.RESET}")
172
+ self.logger.info(f"{ColorFormat.GOLD}同步群昵称: {ColorFormat.WHITE}禁用 {ColorFormat.GRAY}(依赖强制QQ绑定){ColorFormat.RESET}")
173
+ self.logger.info(f"{ColorFormat.GOLD}退群检测: {ColorFormat.WHITE}禁用 {ColorFormat.GRAY}(依赖强制QQ绑定){ColorFormat.RESET}")
174
+
175
+ def get_config(self, key: str, default=None) -> Any:
176
+ """获取配置项"""
177
+ return self._config.get(key, default)
178
+
179
+ def set_config(self, key: str, value: Any):
180
+ """设置配置项"""
181
+ self._config[key] = value
182
+
183
+ def save_config(self):
184
+ """保存配置到文件"""
185
+ try:
186
+ with open(self.config_file, 'w', encoding='utf-8') as f:
187
+ json.dump(self._config, f, indent=2, ensure_ascii=False)
188
+ self.logger.info("配置已保存")
189
+ except Exception as e:
190
+ self.logger.error(f"保存配置失败: {e}")
191
+
192
+ def reload_config(self) -> bool:
193
+ """重新加载配置文件"""
194
+ try:
195
+ with open(self.config_file, 'r', encoding='utf-8') as f:
196
+ self._config = json.load(f)
197
+
198
+ # 检查并合并新的配置项(与_init_config保持一致)
199
+ config_updated = False
200
+ for key, value in self.default_config.items():
201
+ if key not in self._config:
202
+ self._config[key] = value
203
+ config_updated = True
204
+ self.logger.info(f"添加新配置项: {key}")
205
+
206
+ # 重新生成动态帮助信息
207
+ self._config["help_msg"] = self._generate_help_message()
208
+
209
+ # 如果有新配置项,保存到文件
210
+ if config_updated:
211
+ self.save_config()
212
+
213
+ ColorFormat = self.color_format
214
+ reload_msg = f"{ColorFormat.GREEN}配置已重新加载{ColorFormat.RESET}"
215
+ self.logger.info(reload_msg)
216
+ return True
217
+ except Exception as e:
218
+ self.logger.error(f"重新加载配置失败: {e}")
219
+ return False
220
+
221
+ @property
222
+ def config(self) -> Dict[str, Any]:
223
+ """获取完整配置"""
224
+ return self._config.copy()