@zhin.js/adapter-qq 2.0.12 → 3.0.1
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.
- package/CHANGELOG.md +20 -4
- package/README.md +9 -9
- package/client/Dashboard.tsx +32 -32
- package/dist/index.js +1 -1
- package/lib/adapter.d.ts +10 -9
- package/lib/adapter.d.ts.map +1 -1
- package/lib/adapter.js +33 -32
- package/lib/adapter.js.map +1 -1
- package/lib/{bot.d.ts → endpoint.d.ts} +13 -8
- package/lib/endpoint.d.ts.map +1 -0
- package/lib/{bot.js → endpoint.js} +101 -35
- package/lib/endpoint.js.map +1 -0
- package/lib/gateway-config.d.ts +3 -3
- package/lib/gateway-config.d.ts.map +1 -1
- package/lib/gateway-config.js +2 -2
- package/lib/gateway-config.js.map +1 -1
- package/lib/group-at-normalize.d.ts +1 -1
- package/lib/group-at-normalize.d.ts.map +1 -1
- package/lib/group-at-normalize.js +8 -8
- package/lib/group-at-normalize.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +124 -96
- package/lib/index.js.map +1 -1
- package/lib/platform-permit.d.ts +17 -0
- package/lib/platform-permit.d.ts.map +1 -0
- package/lib/platform-permit.js +47 -0
- package/lib/platform-permit.js.map +1 -0
- package/lib/sdk-version.d.ts +1 -1
- package/lib/sdk-version.js +1 -1
- package/lib/types.d.ts +4 -4
- package/lib/types.d.ts.map +1 -1
- package/package.json +13 -10
- package/skills/qq/PERMITS.md +25 -0
- package/skills/qq/SKILL.md +1 -1
- package/src/adapter.ts +27 -25
- package/src/{bot.ts → endpoint.ts} +116 -42
- package/src/gateway-config.ts +5 -5
- package/src/group-at-normalize.ts +8 -8
- package/src/index.ts +118 -85
- package/src/platform-permit.ts +62 -0
- package/src/sdk-version.ts +1 -1
- package/src/types.ts +5 -5
- package/lib/bot.d.ts.map +0 -1
- package/lib/bot.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
# @zhin.js/adapter-qq
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 3.0.1
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
- d8def69: fix: 性能优化
|
|
8
|
+
- 2ef4896: fix: 更新概念 Bot=>Endpoint,已适配后续更多的业务场景;统一角色权限
|
|
9
|
+
- Updated dependencies [d8def69]
|
|
10
|
+
- Updated dependencies [2ef4896]
|
|
11
|
+
- @zhin.js/host-router@1.0.1
|
|
12
|
+
- @zhin.js/host-api@1.0.1
|
|
13
|
+
- zhin.js@2.0.1
|
|
14
|
+
- @zhin.js/logger@0.1.71
|
|
15
|
+
- @zhin.js/client@2.0.3
|
|
16
|
+
|
|
17
|
+
## 3.0.0
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- e62c23a: fix: update pnpm-lock.yaml and vitest configurations- Added new dependencies for the full-bot example, including multiple Zhin.js adapters and TypeScript.- Updated the test-bot example to include '@puniyu/system-info' and other necessary packages.- Modified vitest configuration to include additional module directories for better dependency resolution.- Enhanced documentation for the KOOK adapter, including new features like typing indicators and system notifications.- Removed unused test assets and scripts from the test-bot example to streamline the project.
|
|
22
|
+
- Updated dependencies [65f4b0a]
|
|
23
|
+
- @zhin.js/host-api@1.0.0
|
|
24
|
+
- zhin.js@2.0.0
|
|
25
|
+
- @zhin.js/host-router@1.0.0
|
|
10
26
|
|
|
11
27
|
## 2.0.11
|
|
12
28
|
|
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ pnpm add @zhin.js/adapter-qq
|
|
|
16
16
|
import { defineConfig } from 'zhin.js';
|
|
17
17
|
|
|
18
18
|
export default defineConfig({
|
|
19
|
-
|
|
19
|
+
endpoints: [
|
|
20
20
|
{
|
|
21
21
|
context: 'qq',
|
|
22
22
|
name: 'my-qq-bot',
|
|
@@ -38,7 +38,7 @@ export default defineConfig({
|
|
|
38
38
|
### 完整配置选项
|
|
39
39
|
|
|
40
40
|
```typescript
|
|
41
|
-
const config:
|
|
41
|
+
const config: QQEndpointConfig = {
|
|
42
42
|
context: 'qq',
|
|
43
43
|
name: 'my-qq-bot',
|
|
44
44
|
appid: 'YOUR_APPID', // 机器人 AppID(必需,小写 appid)
|
|
@@ -272,7 +272,7 @@ addCommand(new MessageCommand('embed')
|
|
|
272
272
|
| `false` | 始终发纯文本(与旧行为一致) |
|
|
273
273
|
|
|
274
274
|
```yaml
|
|
275
|
-
|
|
275
|
+
endpoints:
|
|
276
276
|
- context: qq
|
|
277
277
|
name: my-bot
|
|
278
278
|
outboundMarkdown: auto # 或 true / false
|
|
@@ -285,19 +285,19 @@ bots:
|
|
|
285
285
|
### 基础方法
|
|
286
286
|
|
|
287
287
|
```typescript
|
|
288
|
-
const
|
|
288
|
+
const endpoint = app.adapters.get('qq')?.endpoints.get('你的机器人ID')
|
|
289
289
|
|
|
290
290
|
// 发送私信
|
|
291
|
-
await
|
|
291
|
+
await endpoint.sendPrivateMessage(userId, '消息内容')
|
|
292
292
|
|
|
293
293
|
// 发送群消息
|
|
294
|
-
await
|
|
294
|
+
await endpoint.sendGroupMessage(groupId, '消息内容')
|
|
295
295
|
|
|
296
296
|
// 发送频道消息
|
|
297
|
-
await
|
|
297
|
+
await endpoint.sendGuildMessage(channelId, '消息内容')
|
|
298
298
|
|
|
299
299
|
// 撤回消息
|
|
300
|
-
await
|
|
300
|
+
await endpoint.$recallMessage(messageId)
|
|
301
301
|
```
|
|
302
302
|
|
|
303
303
|
## 消息 ID 格式
|
|
@@ -349,7 +349,7 @@ A: 检查以下几点:
|
|
|
349
349
|
|
|
350
350
|
### Q: Typing Indicator 群聊报 `40034105 主动消息失败, 无权限`?
|
|
351
351
|
|
|
352
|
-
A: QQ **群聊**不允许无引用的主动消息。框架已对 QQ 群场景的「正在处理中…」自动附带 `reply` 引用触发消息;若仍失败,可在
|
|
352
|
+
A: QQ **群聊**不允许无引用的主动消息。框架已对 QQ 群场景的「正在处理中…」自动附带 `reply` 引用触发消息;若仍失败,可在 Endpoint 配置中关闭群聊 typing:
|
|
353
353
|
|
|
354
354
|
```yaml
|
|
355
355
|
typingIndicator:
|
package/client/Dashboard.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import { useEffect, useState, useCallback } from 'react'
|
|
|
2
2
|
import { apiFetch } from './utils/api'
|
|
3
3
|
import { RefreshCw, Server, Wifi, WifiOff, Power, PowerOff, ChevronRight, ChevronDown, Hash, Loader2 } from 'lucide-react'
|
|
4
4
|
|
|
5
|
-
interface
|
|
5
|
+
interface EndpointRow {
|
|
6
6
|
name: string
|
|
7
7
|
connected: boolean
|
|
8
8
|
guildCount: number
|
|
@@ -25,14 +25,14 @@ interface Channel {
|
|
|
25
25
|
type Tab = 'overview' | 'guilds'
|
|
26
26
|
|
|
27
27
|
export default function QQDashboard() {
|
|
28
|
-
const [
|
|
28
|
+
const [endpoints, setEndpoints] = useState<EndpointRow[]>([])
|
|
29
29
|
const [loading, setLoading] = useState(true)
|
|
30
30
|
const [error, setError] = useState('')
|
|
31
31
|
const [tab, setTab] = useState<Tab>('overview')
|
|
32
32
|
const [actionLoading, setActionLoading] = useState<Record<string, boolean>>({})
|
|
33
33
|
|
|
34
34
|
// Guild browser state
|
|
35
|
-
const [
|
|
35
|
+
const [selectedEndpoint, setSelectedEndpoint] = useState('')
|
|
36
36
|
const [guilds, setGuilds] = useState<Guild[]>([])
|
|
37
37
|
const [guildsLoading, setGuildsLoading] = useState(false)
|
|
38
38
|
const [expandedGuild, setExpandedGuild] = useState<string | null>(null)
|
|
@@ -43,9 +43,9 @@ export default function QQDashboard() {
|
|
|
43
43
|
setLoading(true)
|
|
44
44
|
setError('')
|
|
45
45
|
try {
|
|
46
|
-
const res = await apiFetch('/api/qq/
|
|
46
|
+
const res = await apiFetch('/api/qq/endpoints')
|
|
47
47
|
const json = await res.json()
|
|
48
|
-
if (json.success)
|
|
48
|
+
if (json.success) setEndpoints(json.data)
|
|
49
49
|
else setError(json.error || '获取数据失败')
|
|
50
50
|
} catch {
|
|
51
51
|
setError('无法连接服务器')
|
|
@@ -60,7 +60,7 @@ export default function QQDashboard() {
|
|
|
60
60
|
setActionLoading(prev => ({ ...prev, [name]: true }))
|
|
61
61
|
try {
|
|
62
62
|
const endpoint = connected ? 'disconnect' : 'connect'
|
|
63
|
-
const res = await apiFetch(`/api/qq/
|
|
63
|
+
const res = await apiFetch(`/api/qq/endpoints/${encodeURIComponent(name)}/${endpoint}`, { method: 'POST' })
|
|
64
64
|
const json = await res.json()
|
|
65
65
|
if (!json.success) setError(json.error || '操作失败')
|
|
66
66
|
await fetchData()
|
|
@@ -71,14 +71,14 @@ export default function QQDashboard() {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
const loadGuilds = async (
|
|
75
|
-
|
|
74
|
+
const loadGuilds = async (endpointName: string) => {
|
|
75
|
+
setSelectedEndpoint(endpointName)
|
|
76
76
|
setGuildsLoading(true)
|
|
77
77
|
setGuilds([])
|
|
78
78
|
setExpandedGuild(null)
|
|
79
79
|
setChannels({})
|
|
80
80
|
try {
|
|
81
|
-
const res = await apiFetch(`/api/qq/
|
|
81
|
+
const res = await apiFetch(`/api/qq/endpoints/${encodeURIComponent(endpointName)}/guilds`)
|
|
82
82
|
const json = await res.json()
|
|
83
83
|
if (json.success) setGuilds(json.data)
|
|
84
84
|
else setError(json.error || '获取频道失败')
|
|
@@ -95,7 +95,7 @@ export default function QQDashboard() {
|
|
|
95
95
|
if (channels[guildId]) return
|
|
96
96
|
setChannelsLoading(guildId)
|
|
97
97
|
try {
|
|
98
|
-
const res = await apiFetch(`/api/qq/
|
|
98
|
+
const res = await apiFetch(`/api/qq/endpoints/${encodeURIComponent(selectedEndpoint)}/guilds/${encodeURIComponent(guildId)}/channels`)
|
|
99
99
|
const json = await res.json()
|
|
100
100
|
if (json.success) setChannels(prev => ({ ...prev, [guildId]: json.data }))
|
|
101
101
|
} catch { /* ignore */ } finally {
|
|
@@ -103,7 +103,7 @@ export default function QQDashboard() {
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
const
|
|
106
|
+
const onlineEndpoints = endpoints.filter((e) => e.connected)
|
|
107
107
|
|
|
108
108
|
return (
|
|
109
109
|
<div className="p-6 max-w-5xl mx-auto">
|
|
@@ -135,33 +135,33 @@ export default function QQDashboard() {
|
|
|
135
135
|
{/* Overview Tab */}
|
|
136
136
|
{tab === 'overview' && (
|
|
137
137
|
<>
|
|
138
|
-
{!loading && !
|
|
139
|
-
<div className="text-center text-gray-500 py-12">暂无 QQ
|
|
138
|
+
{!loading && !endpoints.length && !error && (
|
|
139
|
+
<div className="text-center text-gray-500 py-12">暂无 QQ Endpoint 实例</div>
|
|
140
140
|
)}
|
|
141
141
|
<div className="grid gap-4 md:grid-cols-2">
|
|
142
|
-
{
|
|
143
|
-
<div key={
|
|
142
|
+
{endpoints.map((endpoint) => (
|
|
143
|
+
<div key={endpoint.name} className="border rounded-lg p-4 bg-card shadow-sm">
|
|
144
144
|
<div className="flex items-center justify-between mb-3">
|
|
145
|
-
<span className="font-medium text-lg">{
|
|
146
|
-
{
|
|
145
|
+
<span className="font-medium text-lg">{endpoint.name}</span>
|
|
146
|
+
{endpoint.connected
|
|
147
147
|
? <span className="flex items-center gap-1 text-green-600 text-sm"><Wifi className="w-4 h-4" /> 在线</span>
|
|
148
148
|
: <span className="flex items-center gap-1 text-gray-400 text-sm"><WifiOff className="w-4 h-4" /> 离线</span>}
|
|
149
149
|
</div>
|
|
150
150
|
<div className="grid grid-cols-1 gap-2 text-sm text-gray-600 mb-3">
|
|
151
|
-
<div className="flex justify-between"><span>频道数</span><span className="font-mono">{
|
|
151
|
+
<div className="flex justify-between"><span>频道数</span><span className="font-mono">{endpoint.guildCount}</span></div>
|
|
152
152
|
</div>
|
|
153
153
|
<div className="flex gap-2">
|
|
154
154
|
<button
|
|
155
|
-
onClick={() => toggleConnect(
|
|
156
|
-
disabled={actionLoading[
|
|
157
|
-
className={`flex items-center gap-1 px-3 py-1.5 rounded text-sm text-white ${
|
|
158
|
-
{actionLoading[
|
|
155
|
+
onClick={() => toggleConnect(endpoint.name, endpoint.connected)}
|
|
156
|
+
disabled={actionLoading[endpoint.name]}
|
|
157
|
+
className={`flex items-center gap-1 px-3 py-1.5 rounded text-sm text-white ${endpoint.connected ? 'bg-red-500 hover:bg-red-600' : 'bg-green-500 hover:bg-green-600'} disabled:opacity-50`}>
|
|
158
|
+
{actionLoading[endpoint.name]
|
|
159
159
|
? <Loader2 className="w-3.5 h-3.5 animate-spin" />
|
|
160
|
-
:
|
|
161
|
-
{
|
|
160
|
+
: endpoint.connected ? <PowerOff className="w-3.5 h-3.5" /> : <Power className="w-3.5 h-3.5" />}
|
|
161
|
+
{endpoint.connected ? '断开' : '连接'}
|
|
162
162
|
</button>
|
|
163
|
-
{
|
|
164
|
-
<button onClick={() => { setTab('guilds'); loadGuilds(
|
|
163
|
+
{endpoint.connected && (
|
|
164
|
+
<button onClick={() => { setTab('guilds'); loadGuilds(endpoint.name) }}
|
|
165
165
|
className="flex items-center gap-1 px-3 py-1.5 rounded text-sm bg-gray-100 hover:bg-gray-200 text-gray-700">
|
|
166
166
|
<Hash className="w-3.5 h-3.5" /> 浏览频道
|
|
167
167
|
</button>
|
|
@@ -176,18 +176,18 @@ export default function QQDashboard() {
|
|
|
176
176
|
{/* Guilds Tab */}
|
|
177
177
|
{tab === 'guilds' && (
|
|
178
178
|
<div>
|
|
179
|
-
{/*
|
|
180
|
-
{
|
|
179
|
+
{/* Endpoint selector */}
|
|
180
|
+
{onlineEndpoints.length > 0 && (
|
|
181
181
|
<div className="mb-4 flex items-center gap-2">
|
|
182
182
|
<label className="text-sm text-gray-500">选择机器人:</label>
|
|
183
|
-
<select value={
|
|
183
|
+
<select value={selectedEndpoint} onChange={(e) => loadGuilds(e.target.value)}
|
|
184
184
|
className="border rounded px-2 py-1 text-sm">
|
|
185
185
|
<option value="">--</option>
|
|
186
|
-
{
|
|
186
|
+
{onlineEndpoints.map((e) => <option key={e.name} value={e.name}>{e.name}</option>)}
|
|
187
187
|
</select>
|
|
188
188
|
</div>
|
|
189
189
|
)}
|
|
190
|
-
{!
|
|
190
|
+
{!onlineEndpoints.length && <div className="text-center text-gray-500 py-8">暂无在线 Endpoint</div>}
|
|
191
191
|
{guildsLoading && <div className="flex justify-center py-8"><Loader2 className="w-6 h-6 animate-spin text-blue-500" /></div>}
|
|
192
192
|
|
|
193
193
|
{/* Guild → Channel tree */}
|
|
@@ -222,7 +222,7 @@ export default function QQDashboard() {
|
|
|
222
222
|
))}
|
|
223
223
|
</div>
|
|
224
224
|
)}
|
|
225
|
-
{!guildsLoading &&
|
|
225
|
+
{!guildsLoading && selectedEndpoint && !guilds.length && <div className="text-center text-gray-400 py-8">该机器人未加入任何频道</div>}
|
|
226
226
|
</div>
|
|
227
227
|
)}
|
|
228
228
|
</div>
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{useEffect as we,useState as c,useCallback as Pe}from"react";var Q="zhin_api_token",ue="zhin_api_base";function de(){let t=localStorage.getItem(ue)?.trim();return t?t.replace(/\/$/,""):typeof window<"u"?window.location.origin:""}function le(){return localStorage.getItem(Q)}async function k(t,o){let l=le(),s=new Headers(o?.headers);l&&s.set("Authorization",`Bearer ${l}`);let p=de(),f=typeof t=="string"&&t.startsWith("/")?`${p}${t}`:t,m=await fetch(f,{...o,headers:s});return m.status===401&&(localStorage.removeItem(Q),window.dispatchEvent(new CustomEvent("zhin:auth-required"))),m}import{forwardRef as ce,createElement as ne}from"react";var v=(...t)=>t.filter((o,l,s)=>!!o&&o.trim()!==""&&s.indexOf(o)===l).join(" ").trim();var J=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();var _=t=>t.replace(/^([A-Z])|[\s-_]+(\w)/g,(o,l,s)=>s?s.toUpperCase():l.toLowerCase());var V=t=>{let o=_(t);return o.charAt(0).toUpperCase()+o.slice(1)};import{forwardRef as ie,createElement as Y}from"react";var U={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};var j=t=>{for(let o in t)if(o.startsWith("aria-")||o==="role"||o==="title")return!0;return!1};import{createContext as fe,useContext as se,useMemo as ve,createElement as Ue}from"react";var re=fe({});var $=()=>se(re);var ee=ie(({color:t,size:o,strokeWidth:l,absoluteStrokeWidth:s,className:p="",children:f,iconNode:m,...L},R)=>{let{size:I=24,strokeWidth:x=2,absoluteStrokeWidth:O=!1,color:h="currentColor",className:q=""}=$()??{},g=s??O?Number(l??x)*24/Number(o??I):l??x;return Y("svg",{ref:R,...U,width:o??I??U.width,height:o??I??U.height,stroke:t??h,strokeWidth:g,className:v("lucide",q,p),...!f&&!j(L)&&{"aria-hidden":"true"},...L},[...m.map(([T,S])=>Y(T,S)),...Array.isArray(f)?f:[f]])});var d=(t,o)=>{let l=ce(({className:s,...p},f)=>ne(ee,{ref:f,iconNode:o,className:v(`lucide-${J(V(t))}`,`lucide-${t}`,s),...p}));return l.displayName=V(t),l};var pe=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],w=d("chevron-down",pe);var me=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],P=d("chevron-right",me);var Le=[["line",{x1:"4",x2:"20",y1:"9",y2:"9",key:"4lhtct"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15",key:"vyu0kd"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21",key:"1ggp8o"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21",key:"weycgp"}]],C=d("hash",Le);var Ie=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],n=d("loader-circle",Ie);var xe=[["path",{d:"M18.36 6.64A9 9 0 0 1 20.77 15",key:"dxknvb"}],["path",{d:"M6.16 6.16a9 9 0 1 0 12.68 12.68",key:"1x7qb5"}],["path",{d:"M12 2v4",key:"3427ic"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],A=d("power-off",xe);var Ce=[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]],B=d("power",Ce);var he=[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]],M=d("refresh-cw",he);var ge=[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]],F=d("server",ge);var Se=[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}],["path",{d:"M5 12.859a10 10 0 0 1 5.17-2.69",key:"1dl1wf"}],["path",{d:"M19 12.859a10 10 0 0 0-2.007-1.523",key:"4k23kn"}],["path",{d:"M2 8.82a15 15 0 0 1 4.177-2.643",key:"1grhjp"}],["path",{d:"M22 8.82a15 15 0 0 0-11.288-3.764",key:"z3jwby"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],D=d("wifi-off",Se);var ke=[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M2 8.82a15 15 0 0 1 20 0",key:"dnpr2z"}],["path",{d:"M5 12.859a10 10 0 0 1 14 0",key:"1x1e6c"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}]],y=d("wifi",ke);import{Fragment as Ae,jsx as a,jsxs as u}from"react/jsx-runtime";function E(){let[t,o]=c([]),[l,s]=c(!0),[p,f]=c(""),[m,L]=c("overview"),[R,I]=c({}),[x,O]=c(""),[h,q]=c([]),[g,T]=c(!1),[S,H]=c(null),[G,z]=c({}),[ae,N]=c(null),b=Pe(async()=>{s(!0),f("");try{let i=await(await k("/api/qq/bots")).json();i.success?o(i.data):f(i.error||"\u83B7\u53D6\u6570\u636E\u5931\u8D25")}catch{f("\u65E0\u6CD5\u8FDE\u63A5\u670D\u52A1\u5668")}finally{s(!1)}},[]);we(()=>{b()},[b]);let te=async(e,i)=>{I(r=>({...r,[e]:!0}));try{let r=i?"disconnect":"connect",Z=await(await k(`/api/qq/bots/${encodeURIComponent(e)}/${r}`,{method:"POST"})).json();Z.success||f(Z.error||"\u64CD\u4F5C\u5931\u8D25"),await b()}catch{f("\u64CD\u4F5C\u5931\u8D25")}finally{I(r=>({...r,[e]:!1}))}},X=async e=>{O(e),T(!0),q([]),H(null),z({});try{let r=await(await k(`/api/qq/bots/${encodeURIComponent(e)}/guilds`)).json();r.success?q(r.data):f(r.error||"\u83B7\u53D6\u9891\u9053\u5931\u8D25")}catch{f("\u83B7\u53D6\u9891\u9053\u5931\u8D25")}finally{T(!1)}},oe=async e=>{if(S===e){H(null);return}if(H(e),!G[e]){N(e);try{let r=await(await k(`/api/qq/bots/${encodeURIComponent(x)}/guilds/${encodeURIComponent(e)}/channels`)).json();r.success&&z(K=>({...K,[e]:r.data}))}catch{}finally{N(null)}}},W=t.filter(e=>e.connected);return u("div",{className:"p-6 max-w-5xl mx-auto",children:[u("div",{className:"flex items-center justify-between mb-6",children:[u("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[a(F,{className:"w-6 h-6"})," QQ \u5B98\u65B9\u673A\u5668\u4EBA"]}),u("button",{onClick:b,disabled:l,className:"flex items-center gap-1 px-3 py-1.5 rounded bg-blue-500 text-white hover:bg-blue-600 disabled:opacity-50 text-sm",children:[a(M,{className:`w-4 h-4 ${l?"animate-spin":""}`})," \u5237\u65B0"]})]}),p&&a("div",{className:"mb-4 p-3 bg-red-50 text-red-600 rounded border border-red-200",children:p}),u("div",{className:"flex gap-1 mb-6 border-b",children:[a("button",{onClick:()=>L("overview"),className:`px-4 py-2 text-sm font-medium border-b-2 transition-colors ${m==="overview"?"border-blue-500 text-blue-600":"border-transparent text-gray-500 hover:text-gray-700"}`,children:"\u6982\u89C8"}),a("button",{onClick:()=>L("guilds"),className:`px-4 py-2 text-sm font-medium border-b-2 transition-colors ${m==="guilds"?"border-blue-500 text-blue-600":"border-transparent text-gray-500 hover:text-gray-700"}`,children:"\u9891\u9053\u6D4F\u89C8"})]}),m==="overview"&&u(Ae,{children:[!l&&!t.length&&!p&&a("div",{className:"text-center text-gray-500 py-12",children:"\u6682\u65E0 QQ \u673A\u5668\u4EBA\u5B9E\u4F8B"}),a("div",{className:"grid gap-4 md:grid-cols-2",children:t.map(e=>u("div",{className:"border rounded-lg p-4 bg-card shadow-sm",children:[u("div",{className:"flex items-center justify-between mb-3",children:[a("span",{className:"font-medium text-lg",children:e.name}),e.connected?u("span",{className:"flex items-center gap-1 text-green-600 text-sm",children:[a(y,{className:"w-4 h-4"})," \u5728\u7EBF"]}):u("span",{className:"flex items-center gap-1 text-gray-400 text-sm",children:[a(D,{className:"w-4 h-4"})," \u79BB\u7EBF"]})]}),a("div",{className:"grid grid-cols-1 gap-2 text-sm text-gray-600 mb-3",children:u("div",{className:"flex justify-between",children:[a("span",{children:"\u9891\u9053\u6570"}),a("span",{className:"font-mono",children:e.guildCount})]})}),u("div",{className:"flex gap-2",children:[u("button",{onClick:()=>te(e.name,e.connected),disabled:R[e.name],className:`flex items-center gap-1 px-3 py-1.5 rounded text-sm text-white ${e.connected?"bg-red-500 hover:bg-red-600":"bg-green-500 hover:bg-green-600"} disabled:opacity-50`,children:[R[e.name]?a(n,{className:"w-3.5 h-3.5 animate-spin"}):e.connected?a(A,{className:"w-3.5 h-3.5"}):a(B,{className:"w-3.5 h-3.5"}),e.connected?"\u65AD\u5F00":"\u8FDE\u63A5"]}),e.connected&&u("button",{onClick:()=>{L("guilds"),X(e.name)},className:"flex items-center gap-1 px-3 py-1.5 rounded text-sm bg-gray-100 hover:bg-gray-200 text-gray-700",children:[a(C,{className:"w-3.5 h-3.5"})," \u6D4F\u89C8\u9891\u9053"]})]})]},e.name))})]}),m==="guilds"&&u("div",{children:[W.length>0&&u("div",{className:"mb-4 flex items-center gap-2",children:[a("label",{className:"text-sm text-gray-500",children:"\u9009\u62E9\u673A\u5668\u4EBA\uFF1A"}),u("select",{value:x,onChange:e=>X(e.target.value),className:"border rounded px-2 py-1 text-sm",children:[a("option",{value:"",children:"--"}),W.map(e=>a("option",{value:e.name,children:e.name},e.name))]})]}),!W.length&&a("div",{className:"text-center text-gray-500 py-8",children:"\u6682\u65E0\u5728\u7EBF\u673A\u5668\u4EBA"}),g&&a("div",{className:"flex justify-center py-8",children:a(n,{className:"w-6 h-6 animate-spin text-blue-500"})}),!g&&h.length>0&&a("div",{className:"border rounded-lg bg-card shadow-sm divide-y",children:h.map(e=>u("div",{children:[u("button",{onClick:()=>oe(e.id),className:"w-full flex items-center gap-2 px-4 py-3 hover:bg-gray-50 text-left",children:[S===e.id?a(w,{className:"w-4 h-4 text-gray-400"}):a(P,{className:"w-4 h-4 text-gray-400"}),a("span",{className:"font-medium",children:e.name}),a("span",{className:"text-xs text-gray-400 ml-auto",children:e.id})]}),S===e.id&&a("div",{className:"px-4 pb-3",children:ae===e.id?u("div",{className:"flex items-center gap-2 text-gray-400 text-sm py-2 pl-6",children:[a(n,{className:"w-4 h-4 animate-spin"})," \u52A0\u8F7D\u4E2D\u2026"]}):G[e.id]?.length?a("div",{className:"pl-6 space-y-1",children:G[e.id].map(i=>u("div",{className:"flex items-center gap-2 text-sm text-gray-600 py-1",children:[a(C,{className:"w-3.5 h-3.5 text-gray-400"}),a("span",{children:i.name}),a("span",{className:"text-xs text-gray-400 ml-auto",children:i.id})]},i.id))}):a("div",{className:"pl-6 text-sm text-gray-400 py-1",children:"\u65E0\u5B50\u9891\u9053"})})]},e.id))}),!g&&x&&!h.length&&a("div",{className:"text-center text-gray-400 py-8",children:"\u8BE5\u673A\u5668\u4EBA\u672A\u52A0\u5165\u4EFB\u4F55\u9891\u9053"})]})]})}function Ta(t){t.addRoute({path:"/console/qq",name:"QQ\u5B98\u65B9",element:t.React.createElement(E,{hostReact:t.React})}),t.addTool({id:"qq",name:"QQ\u5B98\u65B9",path:"/console/qq"})}export{Ta as register};
|
|
1
|
+
import{useEffect as we,useState as c,useCallback as Pe}from"react";var Q="zhin_api_token",ue="zhin_api_base";function de(){let t=localStorage.getItem(ue)?.trim();return t?t.replace(/\/$/,""):typeof window<"u"?window.location.origin:""}function le(){return localStorage.getItem(Q)}async function k(t,o){let l=le(),s=new Headers(o?.headers);l&&s.set("Authorization",`Bearer ${l}`);let p=de(),f=typeof t=="string"&&t.startsWith("/")?`${p}${t}`:t,m=await fetch(f,{...o,headers:s});return m.status===401&&(localStorage.removeItem(Q),window.dispatchEvent(new CustomEvent("zhin:auth-required"))),m}import{forwardRef as ce,createElement as ne}from"react";var v=(...t)=>t.filter((o,l,s)=>!!o&&o.trim()!==""&&s.indexOf(o)===l).join(" ").trim();var J=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();var _=t=>t.replace(/^([A-Z])|[\s-_]+(\w)/g,(o,l,s)=>s?s.toUpperCase():l.toLowerCase());var E=t=>{let o=_(t);return o.charAt(0).toUpperCase()+o.slice(1)};import{forwardRef as ie,createElement as Y}from"react";var U={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};var j=t=>{for(let o in t)if(o.startsWith("aria-")||o==="role"||o==="title")return!0;return!1};import{createContext as fe,useContext as se,useMemo as ve,createElement as Ue}from"react";var re=fe({});var $=()=>se(re);var ee=ie(({color:t,size:o,strokeWidth:l,absoluteStrokeWidth:s,className:p="",children:f,iconNode:m,...L},R)=>{let{size:I=24,strokeWidth:x=2,absoluteStrokeWidth:O=!1,color:h="currentColor",className:q=""}=$()??{},g=s??O?Number(l??x)*24/Number(o??I):l??x;return Y("svg",{ref:R,...U,width:o??I??U.width,height:o??I??U.height,stroke:t??h,strokeWidth:g,className:v("lucide",q,p),...!f&&!j(L)&&{"aria-hidden":"true"},...L},[...m.map(([T,S])=>Y(T,S)),...Array.isArray(f)?f:[f]])});var d=(t,o)=>{let l=ce(({className:s,...p},f)=>ne(ee,{ref:f,iconNode:o,className:v(`lucide-${J(E(t))}`,`lucide-${t}`,s),...p}));return l.displayName=E(t),l};var pe=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],w=d("chevron-down",pe);var me=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],P=d("chevron-right",me);var Le=[["line",{x1:"4",x2:"20",y1:"9",y2:"9",key:"4lhtct"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15",key:"vyu0kd"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21",key:"1ggp8o"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21",key:"weycgp"}]],C=d("hash",Le);var Ie=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],n=d("loader-circle",Ie);var xe=[["path",{d:"M18.36 6.64A9 9 0 0 1 20.77 15",key:"dxknvb"}],["path",{d:"M6.16 6.16a9 9 0 1 0 12.68 12.68",key:"1x7qb5"}],["path",{d:"M12 2v4",key:"3427ic"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],A=d("power-off",xe);var Ce=[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]],B=d("power",Ce);var he=[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]],M=d("refresh-cw",he);var ge=[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]],F=d("server",ge);var Se=[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}],["path",{d:"M5 12.859a10 10 0 0 1 5.17-2.69",key:"1dl1wf"}],["path",{d:"M19 12.859a10 10 0 0 0-2.007-1.523",key:"4k23kn"}],["path",{d:"M2 8.82a15 15 0 0 1 4.177-2.643",key:"1grhjp"}],["path",{d:"M22 8.82a15 15 0 0 0-11.288-3.764",key:"z3jwby"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],D=d("wifi-off",Se);var ke=[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M2 8.82a15 15 0 0 1 20 0",key:"dnpr2z"}],["path",{d:"M5 12.859a10 10 0 0 1 14 0",key:"1x1e6c"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}]],y=d("wifi",ke);import{Fragment as Ae,jsx as a,jsxs as u}from"react/jsx-runtime";function V(){let[t,o]=c([]),[l,s]=c(!0),[p,f]=c(""),[m,L]=c("overview"),[R,I]=c({}),[x,O]=c(""),[h,q]=c([]),[g,T]=c(!1),[S,H]=c(null),[G,z]=c({}),[ae,N]=c(null),b=Pe(async()=>{s(!0),f("");try{let i=await(await k("/api/qq/endpoints")).json();i.success?o(i.data):f(i.error||"\u83B7\u53D6\u6570\u636E\u5931\u8D25")}catch{f("\u65E0\u6CD5\u8FDE\u63A5\u670D\u52A1\u5668")}finally{s(!1)}},[]);we(()=>{b()},[b]);let te=async(e,i)=>{I(r=>({...r,[e]:!0}));try{let r=i?"disconnect":"connect",Z=await(await k(`/api/qq/endpoints/${encodeURIComponent(e)}/${r}`,{method:"POST"})).json();Z.success||f(Z.error||"\u64CD\u4F5C\u5931\u8D25"),await b()}catch{f("\u64CD\u4F5C\u5931\u8D25")}finally{I(r=>({...r,[e]:!1}))}},X=async e=>{O(e),T(!0),q([]),H(null),z({});try{let r=await(await k(`/api/qq/endpoints/${encodeURIComponent(e)}/guilds`)).json();r.success?q(r.data):f(r.error||"\u83B7\u53D6\u9891\u9053\u5931\u8D25")}catch{f("\u83B7\u53D6\u9891\u9053\u5931\u8D25")}finally{T(!1)}},oe=async e=>{if(S===e){H(null);return}if(H(e),!G[e]){N(e);try{let r=await(await k(`/api/qq/endpoints/${encodeURIComponent(x)}/guilds/${encodeURIComponent(e)}/channels`)).json();r.success&&z(K=>({...K,[e]:r.data}))}catch{}finally{N(null)}}},W=t.filter(e=>e.connected);return u("div",{className:"p-6 max-w-5xl mx-auto",children:[u("div",{className:"flex items-center justify-between mb-6",children:[u("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[a(F,{className:"w-6 h-6"})," QQ \u5B98\u65B9\u673A\u5668\u4EBA"]}),u("button",{onClick:b,disabled:l,className:"flex items-center gap-1 px-3 py-1.5 rounded bg-blue-500 text-white hover:bg-blue-600 disabled:opacity-50 text-sm",children:[a(M,{className:`w-4 h-4 ${l?"animate-spin":""}`})," \u5237\u65B0"]})]}),p&&a("div",{className:"mb-4 p-3 bg-red-50 text-red-600 rounded border border-red-200",children:p}),u("div",{className:"flex gap-1 mb-6 border-b",children:[a("button",{onClick:()=>L("overview"),className:`px-4 py-2 text-sm font-medium border-b-2 transition-colors ${m==="overview"?"border-blue-500 text-blue-600":"border-transparent text-gray-500 hover:text-gray-700"}`,children:"\u6982\u89C8"}),a("button",{onClick:()=>L("guilds"),className:`px-4 py-2 text-sm font-medium border-b-2 transition-colors ${m==="guilds"?"border-blue-500 text-blue-600":"border-transparent text-gray-500 hover:text-gray-700"}`,children:"\u9891\u9053\u6D4F\u89C8"})]}),m==="overview"&&u(Ae,{children:[!l&&!t.length&&!p&&a("div",{className:"text-center text-gray-500 py-12",children:"\u6682\u65E0 QQ Endpoint \u5B9E\u4F8B"}),a("div",{className:"grid gap-4 md:grid-cols-2",children:t.map(e=>u("div",{className:"border rounded-lg p-4 bg-card shadow-sm",children:[u("div",{className:"flex items-center justify-between mb-3",children:[a("span",{className:"font-medium text-lg",children:e.name}),e.connected?u("span",{className:"flex items-center gap-1 text-green-600 text-sm",children:[a(y,{className:"w-4 h-4"})," \u5728\u7EBF"]}):u("span",{className:"flex items-center gap-1 text-gray-400 text-sm",children:[a(D,{className:"w-4 h-4"})," \u79BB\u7EBF"]})]}),a("div",{className:"grid grid-cols-1 gap-2 text-sm text-gray-600 mb-3",children:u("div",{className:"flex justify-between",children:[a("span",{children:"\u9891\u9053\u6570"}),a("span",{className:"font-mono",children:e.guildCount})]})}),u("div",{className:"flex gap-2",children:[u("button",{onClick:()=>te(e.name,e.connected),disabled:R[e.name],className:`flex items-center gap-1 px-3 py-1.5 rounded text-sm text-white ${e.connected?"bg-red-500 hover:bg-red-600":"bg-green-500 hover:bg-green-600"} disabled:opacity-50`,children:[R[e.name]?a(n,{className:"w-3.5 h-3.5 animate-spin"}):e.connected?a(A,{className:"w-3.5 h-3.5"}):a(B,{className:"w-3.5 h-3.5"}),e.connected?"\u65AD\u5F00":"\u8FDE\u63A5"]}),e.connected&&u("button",{onClick:()=>{L("guilds"),X(e.name)},className:"flex items-center gap-1 px-3 py-1.5 rounded text-sm bg-gray-100 hover:bg-gray-200 text-gray-700",children:[a(C,{className:"w-3.5 h-3.5"})," \u6D4F\u89C8\u9891\u9053"]})]})]},e.name))})]}),m==="guilds"&&u("div",{children:[W.length>0&&u("div",{className:"mb-4 flex items-center gap-2",children:[a("label",{className:"text-sm text-gray-500",children:"\u9009\u62E9\u673A\u5668\u4EBA\uFF1A"}),u("select",{value:x,onChange:e=>X(e.target.value),className:"border rounded px-2 py-1 text-sm",children:[a("option",{value:"",children:"--"}),W.map(e=>a("option",{value:e.name,children:e.name},e.name))]})]}),!W.length&&a("div",{className:"text-center text-gray-500 py-8",children:"\u6682\u65E0\u5728\u7EBF Endpoint"}),g&&a("div",{className:"flex justify-center py-8",children:a(n,{className:"w-6 h-6 animate-spin text-blue-500"})}),!g&&h.length>0&&a("div",{className:"border rounded-lg bg-card shadow-sm divide-y",children:h.map(e=>u("div",{children:[u("button",{onClick:()=>oe(e.id),className:"w-full flex items-center gap-2 px-4 py-3 hover:bg-gray-50 text-left",children:[S===e.id?a(w,{className:"w-4 h-4 text-gray-400"}):a(P,{className:"w-4 h-4 text-gray-400"}),a("span",{className:"font-medium",children:e.name}),a("span",{className:"text-xs text-gray-400 ml-auto",children:e.id})]}),S===e.id&&a("div",{className:"px-4 pb-3",children:ae===e.id?u("div",{className:"flex items-center gap-2 text-gray-400 text-sm py-2 pl-6",children:[a(n,{className:"w-4 h-4 animate-spin"})," \u52A0\u8F7D\u4E2D\u2026"]}):G[e.id]?.length?a("div",{className:"pl-6 space-y-1",children:G[e.id].map(i=>u("div",{className:"flex items-center gap-2 text-sm text-gray-600 py-1",children:[a(C,{className:"w-3.5 h-3.5 text-gray-400"}),a("span",{children:i.name}),a("span",{className:"text-xs text-gray-400 ml-auto",children:i.id})]},i.id))}):a("div",{className:"pl-6 text-sm text-gray-400 py-1",children:"\u65E0\u5B50\u9891\u9053"})})]},e.id))}),!g&&x&&!h.length&&a("div",{className:"text-center text-gray-400 py-8",children:"\u8BE5\u673A\u5668\u4EBA\u672A\u52A0\u5165\u4EFB\u4F55\u9891\u9053"})]})]})}function Ta(t){t.addRoute({path:"/console/qq",name:"QQ\u5B98\u65B9",element:t.React.createElement(V,{hostReact:t.React})}),t.addTool({id:"qq",name:"QQ\u5B98\u65B9",path:"/console/qq"})}export{Ta as register};
|
|
2
2
|
/*! Bundled license information:
|
|
3
3
|
|
|
4
4
|
lucide-react/dist/esm/shared/src/utils/mergeClasses.mjs:
|
package/lib/adapter.d.ts
CHANGED
|
@@ -3,18 +3,19 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { Adapter, Plugin } from "zhin.js";
|
|
5
5
|
import type { Router } from "@zhin.js/host-router";
|
|
6
|
-
import {
|
|
7
|
-
import type {
|
|
8
|
-
export declare class QQAdapter extends Adapter<
|
|
6
|
+
import { QQEndpoint } from "./endpoint.js";
|
|
7
|
+
import type { QQEndpointConfig, ReceiverMode } from "./types.js";
|
|
8
|
+
export declare class QQAdapter extends Adapter<QQEndpoint<ReceiverMode>> {
|
|
9
9
|
#private;
|
|
10
|
+
static readonly capabilities: readonly ["inbound", "outbound"];
|
|
10
11
|
constructor(plugin: Plugin, router?: Router);
|
|
11
12
|
getRouter(): Router | undefined;
|
|
12
|
-
|
|
13
|
-
kickMember(
|
|
14
|
-
muteMember(
|
|
15
|
-
muteAll(
|
|
16
|
-
listMembers(
|
|
17
|
-
getGroupInfo(
|
|
13
|
+
createEndpoint(config: QQEndpointConfig<ReceiverMode>): QQEndpoint<ReceiverMode>;
|
|
14
|
+
kickMember(endpointId: string, sceneId: string, userId: string): Promise<boolean>;
|
|
15
|
+
muteMember(endpointId: string, sceneId: string, userId: string, duration?: number): Promise<boolean>;
|
|
16
|
+
muteAll(endpointId: string, sceneId: string, enable?: boolean): Promise<boolean>;
|
|
17
|
+
listMembers(endpointId: string, sceneId: string): Promise<any[]>;
|
|
18
|
+
getGroupInfo(endpointId: string, sceneId: string): Promise<any>;
|
|
18
19
|
start(): Promise<void>;
|
|
19
20
|
}
|
|
20
21
|
//# sourceMappingURL=adapter.d.ts.map
|
package/lib/adapter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,OAAO,EACP,MAAM,EACP,MAAM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4
|
import { Adapter, } from "zhin.js";
|
|
5
|
-
import {
|
|
5
|
+
import { QQEndpoint } from "./endpoint.js";
|
|
6
6
|
export class QQAdapter extends Adapter {
|
|
7
|
+
static capabilities = ['inbound', 'outbound'];
|
|
7
8
|
#router;
|
|
8
9
|
constructor(plugin, router) {
|
|
9
10
|
super(plugin, "qq", []);
|
|
@@ -12,39 +13,39 @@ export class QQAdapter extends Adapter {
|
|
|
12
13
|
getRouter() {
|
|
13
14
|
return this.#router;
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
-
return new
|
|
16
|
+
createEndpoint(config) {
|
|
17
|
+
return new QQEndpoint(this, config);
|
|
17
18
|
}
|
|
18
19
|
// ── IGroupManagement 标准群管方法 ──────────────────────────────────
|
|
19
|
-
async kickMember(
|
|
20
|
-
const
|
|
21
|
-
if (!
|
|
22
|
-
throw new Error(`
|
|
23
|
-
return
|
|
24
|
-
}
|
|
25
|
-
async muteMember(
|
|
26
|
-
const
|
|
27
|
-
if (!
|
|
28
|
-
throw new Error(`
|
|
29
|
-
return
|
|
30
|
-
}
|
|
31
|
-
async muteAll(
|
|
32
|
-
const
|
|
33
|
-
if (!
|
|
34
|
-
throw new Error(`
|
|
35
|
-
return
|
|
36
|
-
}
|
|
37
|
-
async listMembers(
|
|
38
|
-
const
|
|
39
|
-
if (!
|
|
40
|
-
throw new Error(`
|
|
41
|
-
return
|
|
42
|
-
}
|
|
43
|
-
async getGroupInfo(
|
|
44
|
-
const
|
|
45
|
-
if (!
|
|
46
|
-
throw new Error(`
|
|
47
|
-
return
|
|
20
|
+
async kickMember(endpointId, sceneId, userId) {
|
|
21
|
+
const endpoint = this.endpoints.get(endpointId);
|
|
22
|
+
if (!endpoint)
|
|
23
|
+
throw new Error(`Endpoint ${endpointId} 不存在`);
|
|
24
|
+
return endpoint.removeGuildMember(sceneId, userId, false);
|
|
25
|
+
}
|
|
26
|
+
async muteMember(endpointId, sceneId, userId, duration = 600) {
|
|
27
|
+
const endpoint = this.endpoints.get(endpointId);
|
|
28
|
+
if (!endpoint)
|
|
29
|
+
throw new Error(`Endpoint ${endpointId} 不存在`);
|
|
30
|
+
return endpoint.muteMembers(sceneId, [userId], duration);
|
|
31
|
+
}
|
|
32
|
+
async muteAll(endpointId, sceneId, enable = true) {
|
|
33
|
+
const endpoint = this.endpoints.get(endpointId);
|
|
34
|
+
if (!endpoint)
|
|
35
|
+
throw new Error(`Endpoint ${endpointId} 不存在`);
|
|
36
|
+
return endpoint.muteAll(sceneId, enable ? 600 : 0);
|
|
37
|
+
}
|
|
38
|
+
async listMembers(endpointId, sceneId) {
|
|
39
|
+
const endpoint = this.endpoints.get(endpointId);
|
|
40
|
+
if (!endpoint)
|
|
41
|
+
throw new Error(`Endpoint ${endpointId} 不存在`);
|
|
42
|
+
return endpoint.getGuildMembers(sceneId);
|
|
43
|
+
}
|
|
44
|
+
async getGroupInfo(endpointId, sceneId) {
|
|
45
|
+
const endpoint = this.endpoints.get(endpointId);
|
|
46
|
+
if (!endpoint)
|
|
47
|
+
throw new Error(`Endpoint ${endpointId} 不存在`);
|
|
48
|
+
return endpoint.getGuildInfo(sceneId);
|
|
48
49
|
}
|
|
49
50
|
// ── 生命周期 ───────────────────────────────────────────────────────
|
|
50
51
|
async start() {
|
package/lib/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,OAAO,GAER,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,OAAO,GAER,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,MAAM,OAAO,SAAU,SAAQ,OAAiC;IAC9D,MAAM,CAAmB,YAAY,GAAG,CAAC,SA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
|
|
4
|
-
import { Bot, PrivateMessageEvent, GroupMessageEvent } from "qq-official-bot";
|
|
5
|
-
import {
|
|
6
|
-
import { ReceiverMode, type
|
|
4
|
+
import { Bot as QQOfficialClient, PrivateMessageEvent, GroupMessageEvent } from "qq-official-bot";
|
|
5
|
+
import { Endpoint, Message, SendOptions } from "zhin.js";
|
|
6
|
+
import { ReceiverMode, type QQEndpointConfig, type ApplicationPlatform } from "./types.js";
|
|
7
7
|
import type { QQAdapter } from "./adapter.js";
|
|
8
8
|
import { type QqWsPacket } from "./inbound-normalize.js";
|
|
9
|
-
|
|
9
|
+
/** 从 qq-official-bot SendResult / 审核回包中解析出站消息 ID */
|
|
10
|
+
export declare function resolveOutboundMessageId(result: unknown): string;
|
|
11
|
+
export declare class QQEndpoint<T extends ReceiverMode, M extends ApplicationPlatform = ApplicationPlatform> extends QQOfficialClient implements Endpoint<QQEndpointConfig<T, M>, PrivateMessageEvent | GroupMessageEvent> {
|
|
10
12
|
adapter: QQAdapter;
|
|
11
13
|
$connected: boolean;
|
|
12
|
-
$config:
|
|
14
|
+
$config: QQEndpointConfig<T, M>;
|
|
13
15
|
/** 平台侧机器人 user_id,用于 @ 触发匹配 */
|
|
14
16
|
$platformUserId?: string;
|
|
15
17
|
get pluginLogger(): import("zhin.js").Logger;
|
|
16
18
|
get $id(): string;
|
|
17
|
-
constructor(adapter: QQAdapter, config:
|
|
19
|
+
constructor(adapter: QQAdapter, config: QQEndpointConfig<T, M>);
|
|
18
20
|
/** 出站 QQ API 请求附带 SDK 版本,便于平台侧日志排查 */
|
|
19
21
|
private attachSdkVersionHeader;
|
|
20
22
|
/** 归一化 QQ API v2 群聊字段后再交给 qq-official-bot 解析 */
|
|
21
23
|
dispatchEvent(event: string, wsRes: QqWsPacket): void;
|
|
24
|
+
private guildMemberCache;
|
|
25
|
+
private guildOwnerCache;
|
|
26
|
+
private enrichGuildSender;
|
|
22
27
|
private handleQQMessage;
|
|
23
28
|
private handleGroupNotice;
|
|
24
29
|
$connect(): Promise<void>;
|
|
@@ -112,4 +117,4 @@ export declare class QQBot<T extends ReceiverMode, M extends ApplicationPlatform
|
|
|
112
117
|
*/
|
|
113
118
|
muteAll(guildId: string, muteSeconds: number): Promise<boolean>;
|
|
114
119
|
}
|
|
115
|
-
//# sourceMappingURL=
|
|
120
|
+
//# sourceMappingURL=endpoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoint.d.ts","sourceRoot":"","sources":["../src/endpoint.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,GAAG,IAAI,gBAAgB,EACvB,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,EACL,QAAQ,EACR,OAAO,EACP,WAAW,EAGZ,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,KAAK,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAC3F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAA+B,KAAK,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAQtF,oDAAoD;AACpD,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAoBhE;AAED,qBAAa,UAAU,CAAC,CAAC,SAAS,YAAY,EAAE,CAAC,SAAS,mBAAmB,GAAG,mBAAmB,CACjG,SAAQ,gBACR,YAAW,QAAQ,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,mBAAmB,GAAG,iBAAiB,CAAC;IAejE,OAAO,EAAE,SAAS;IAbrC,UAAU,EAAE,OAAO,CAAS;IACpB,OAAO,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACxC,+BAA+B;IAC/B,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,IAAI,YAAY,6BAEf;IAED,IAAI,GAAG,WAEN;gBAEkB,OAAO,EAAE,S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