@zhin.js/adapter-kook 1.0.73 → 1.0.74
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 +8 -0
- package/dist/index.js +31 -0
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
package/dist/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import{useEffect as Be,useState as p,useCallback as Me}from"react";var Y="zhin_api_token";function se(){return localStorage.getItem(Y)}async function g(t,u){let f=se(),s=new Headers(u?.headers);f&&s.set("Authorization",`Bearer ${f}`);let m=await fetch(t,{...u,headers:s});return m.status===401&&(localStorage.removeItem(Y),window.dispatchEvent(new CustomEvent("zhin:auth-required"))),m}import{forwardRef as pe,createElement as me}from"react";var O=(...t)=>t.filter((u,f,s)=>!!u&&u.trim()!==""&&s.indexOf(u)===f).join(" ").trim();var ee=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();var ae=t=>t.replace(/^([A-Z])|[\s-_]+(\w)/g,(u,f,s)=>s?s.toUpperCase():f.toLowerCase());var V=t=>{let u=ae(t);return u.charAt(0).toUpperCase()+u.slice(1)};import{forwardRef as ne,createElement as ue}from"react";var H={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 te=t=>{for(let u in t)if(u.startsWith("aria-")||u==="role"||u==="title")return!0;return!1};import{createContext as re,useContext as ie,useMemo as He,createElement as Ge}from"react";var ce=re({});var oe=()=>ie(ce);var de=ne(({color:t,size:u,strokeWidth:f,absoluteStrokeWidth:s,className:m="",children:l,iconNode:x,...S},q)=>{let{size:C=24,strokeWidth:r=2,absoluteStrokeWidth:G=!1,color:c="currentColor",className:W=""}=oe()??{},h=s??G?Number(f??r)*24/Number(u??C):f??r;return ue("svg",{ref:q,...H,width:u??C??H.width,height:u??C??H.height,stroke:t??c,strokeWidth:h,className:O("lucide",W,m),...!l&&!te(S)&&{"aria-hidden":"true"},...S},[...x.map(([k,I])=>ue(k,I)),...Array.isArray(l)?l:[l]])});var d=(t,u)=>{let f=pe(({className:s,...m},l)=>me(de,{ref:l,iconNode:u,className:O(`lucide-${ee(V(t))}`,`lucide-${t}`,s),...m}));return f.displayName=V(t),f};var Le=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],n=d("loader-circle",Le);var Ie=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],w=d("plus",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"}]],P=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"}]],A=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"}]],B=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"}]],M=d("server",ge);var Se=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]],F=d("shield",Se);var ke=[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],D=d("trash-2",ke);var we=[["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"}]],R=d("wifi-off",we);var Pe=[["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",Pe);var Ae=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],T=d("x",Ae);import{Fragment as Fe,jsx as a,jsxs as o}from"react/jsx-runtime";function E(){let[t,u]=p([]),[f,s]=p(!0),[m,l]=p(""),[x,S]=p("overview"),[q,C]=p({}),[r,G]=p(""),[c,W]=p(""),[h,k]=p([]),[I,z]=p(!1),[b,N]=p(""),[X,K]=p(!1),[Z,Q]=p(null),v=Me(async()=>{s(!0),l("");try{let i=await(await g("/api/kook/bots")).json();i.success?u(i.data):l(i.error||"\u83B7\u53D6\u6570\u636E\u5931\u8D25")}catch{l("\u65E0\u6CD5\u8FDE\u63A5\u670D\u52A1\u5668")}finally{s(!1)}},[]);Be(()=>{v()},[v]);let le=async(e,i)=>{C(L=>({...L,[e]:!0}));try{let L=i?"disconnect":"connect",U=await(await g(`/api/kook/bots/${encodeURIComponent(e)}/${L}`,{method:"POST"})).json();U.success||l(U.error||"\u64CD\u4F5C\u5931\u8D25"),await v()}catch{l("\u64CD\u4F5C\u5931\u8D25")}finally{C(L=>({...L,[e]:!1}))}},J=async()=>{if(!(!r||!c)){z(!0),k([]);try{let i=await(await g(`/api/kook/bots/${encodeURIComponent(r)}/guilds/${encodeURIComponent(c)}/roles`)).json();i.success?k(i.data):l(i.error||"\u83B7\u53D6\u89D2\u8272\u5931\u8D25")}catch{l("\u83B7\u53D6\u89D2\u8272\u5931\u8D25")}finally{z(!1)}}},j=async()=>{if(!(!r||!c||!b.trim())){K(!0);try{let i=await(await g(`/api/kook/bots/${encodeURIComponent(r)}/guilds/${encodeURIComponent(c)}/roles`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:b.trim()})})).json();i.success?(N(""),await J()):l(i.error||"\u521B\u5EFA\u89D2\u8272\u5931\u8D25")}catch{l("\u521B\u5EFA\u89D2\u8272\u5931\u8D25")}finally{K(!1)}}},fe=async e=>{if(!(!r||!c)){Q(e);try{let L=await(await g(`/api/kook/bots/${encodeURIComponent(r)}/guilds/${encodeURIComponent(c)}/roles/${encodeURIComponent(e)}`,{method:"DELETE"})).json();L.success?k($=>$.filter(U=>U.id!==e)):l(L.error||"\u5220\u9664\u89D2\u8272\u5931\u8D25")}catch{l("\u5220\u9664\u89D2\u8272\u5931\u8D25")}finally{Q(null)}}},_=t.filter(e=>e.connected);return o("div",{className:"p-6 max-w-5xl mx-auto",children:[o("div",{className:"flex items-center justify-between mb-6",children:[o("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[a(M,{className:"w-6 h-6"})," KOOK \u673A\u5668\u4EBA"]}),o("button",{onClick:v,disabled:f,className:"flex items-center gap-1 px-3 py-1.5 rounded bg-sky-500 text-white hover:bg-sky-600 disabled:opacity-50 text-sm",children:[a(B,{className:`w-4 h-4 ${f?"animate-spin":""}`})," \u5237\u65B0"]})]}),m&&o("div",{className:"mb-4 p-3 bg-red-50 text-red-600 rounded border border-red-200 flex items-center justify-between",children:[a("span",{children:m}),a("button",{onClick:()=>l(""),className:"text-red-400 hover:text-red-600",children:a(T,{className:"w-4 h-4"})})]}),o("div",{className:"flex gap-1 mb-6 border-b",children:[a("button",{onClick:()=>S("overview"),className:`px-4 py-2 text-sm font-medium border-b-2 transition-colors ${x==="overview"?"border-sky-500 text-sky-600":"border-transparent text-gray-500 hover:text-gray-700"}`,children:"\u6982\u89C8"}),a("button",{onClick:()=>S("roles"),className:`px-4 py-2 text-sm font-medium border-b-2 transition-colors ${x==="roles"?"border-sky-500 text-sky-600":"border-transparent text-gray-500 hover:text-gray-700"}`,children:"\u89D2\u8272\u7BA1\u7406"})]}),x==="overview"&&o(Fe,{children:[!f&&!t.length&&!m&&a("div",{className:"text-center text-gray-500 py-12",children:"\u6682\u65E0 KOOK \u673A\u5668\u4EBA\u5B9E\u4F8B"}),a("div",{className:"grid gap-4 md:grid-cols-2",children:t.map(e=>o("div",{className:"border rounded-lg p-4 bg-card shadow-sm",children:[o("div",{className:"flex items-center justify-between mb-3",children:[a("span",{className:"font-medium text-lg",children:e.name}),e.connected?o("span",{className:"flex items-center gap-1 text-green-600 text-sm",children:[a(y,{className:"w-4 h-4"})," \u5728\u7EBF"]}):o("span",{className:"flex items-center gap-1 text-gray-400 text-sm",children:[a(R,{className:"w-4 h-4"})," \u79BB\u7EBF"]})]}),a("div",{className:"text-sm text-gray-600 mb-3",children:o("div",{className:"flex justify-between",children:[a("span",{children:"\u670D\u52A1\u5668"}),a("span",{className:"font-mono",children:e.guildCount})]})}),o("button",{onClick:()=>le(e.name,e.connected),disabled:q[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:[q[e.name]?a(n,{className:"w-3.5 h-3.5 animate-spin"}):e.connected?a(P,{className:"w-3.5 h-3.5"}):a(A,{className:"w-3.5 h-3.5"}),e.connected?"\u65AD\u5F00":"\u8FDE\u63A5"]})]},e.name))})]}),x==="roles"&&o("div",{className:"space-y-4",children:[o("div",{className:"flex flex-wrap items-end gap-3",children:[o("div",{children:[a("label",{className:"block text-xs text-gray-500 mb-1",children:"\u673A\u5668\u4EBA"}),o("select",{value:r,onChange:e=>G(e.target.value),className:"border rounded px-2 py-1.5 text-sm min-w-[140px]",children:[a("option",{value:"",children:"--"}),_.map(e=>a("option",{value:e.name,children:e.name},e.name))]})]}),o("div",{children:[a("label",{className:"block text-xs text-gray-500 mb-1",children:"\u670D\u52A1\u5668 ID"}),a("input",{value:c,onChange:e=>W(e.target.value),placeholder:"\u8F93\u5165\u670D\u52A1\u5668 ID",className:"border rounded px-2 py-1.5 text-sm w-[180px]"})]}),o("button",{onClick:J,disabled:!r||!c||I,className:"px-3 py-1.5 rounded bg-sky-500 text-white text-sm hover:bg-sky-600 disabled:opacity-50 flex items-center gap-1",children:[I?a(n,{className:"w-3.5 h-3.5 animate-spin"}):a(F,{className:"w-3.5 h-3.5"})," \u67E5\u8BE2\u89D2\u8272"]})]}),!_.length&&a("div",{className:"text-center text-gray-500 py-4",children:"\u6682\u65E0\u5728\u7EBF\u673A\u5668\u4EBA"}),r&&c&&h.length>0&&o("div",{className:"flex items-center gap-2",children:[a("input",{value:b,onChange:e=>N(e.target.value),placeholder:"\u65B0\u89D2\u8272\u540D\u79F0",className:"border rounded px-2 py-1.5 text-sm flex-1 max-w-[240px]",onKeyDown:e=>e.key==="Enter"&&j()}),o("button",{onClick:j,disabled:X||!b.trim(),className:"px-3 py-1.5 rounded bg-green-500 text-white text-sm hover:bg-green-600 disabled:opacity-50 flex items-center gap-1",children:[X?a(n,{className:"w-3.5 h-3.5 animate-spin"}):a(w,{className:"w-3.5 h-3.5"})," \u521B\u5EFA"]})]}),I&&a("div",{className:"flex justify-center py-8",children:a(n,{className:"w-6 h-6 animate-spin text-sky-500"})}),!I&&h.length>0&&a("div",{className:"border rounded-lg bg-card shadow-sm divide-y",children:h.map(e=>o("div",{className:"flex items-center px-4 py-2.5 hover:bg-gray-50",children:[a("div",{className:"w-3 h-3 rounded-full mr-3",style:{backgroundColor:e.color?`#${e.color.toString(16).padStart(6,"0")}`:"#999"}}),a("span",{className:"font-medium text-sm flex-1",children:e.name}),o("span",{className:"text-xs text-gray-400 mr-4",children:["ID: ",e.id]}),a("button",{onClick:()=>fe(e.id),disabled:Z===e.id,className:"text-gray-400 hover:text-red-500 disabled:opacity-50",children:Z===e.id?a(n,{className:"w-4 h-4 animate-spin"}):a(D,{className:"w-4 h-4"})})]},e.id))}),!I&&r&&c&&!h.length&&a("div",{className:"text-center text-gray-400 py-6",children:"\u6682\u65E0\u89D2\u8272\u6570\u636E\uFF0C\u8BF7\u5148\u67E5\u8BE2"})]})]})}function Ga(t){t.addRoute({path:"/console/kook",name:"KOOK",element:t.React.createElement(E,{hostReact:t.React})}),t.addTool({id:"kook",name:"KOOK",path:"/console/kook"})}export{Ga as register};
|
|
2
|
+
/*! Bundled license information:
|
|
3
|
+
|
|
4
|
+
lucide-react/dist/esm/shared/src/utils/mergeClasses.mjs:
|
|
5
|
+
lucide-react/dist/esm/shared/src/utils/toKebabCase.mjs:
|
|
6
|
+
lucide-react/dist/esm/shared/src/utils/toCamelCase.mjs:
|
|
7
|
+
lucide-react/dist/esm/shared/src/utils/toPascalCase.mjs:
|
|
8
|
+
lucide-react/dist/esm/defaultAttributes.mjs:
|
|
9
|
+
lucide-react/dist/esm/shared/src/utils/hasA11yProp.mjs:
|
|
10
|
+
lucide-react/dist/esm/context.mjs:
|
|
11
|
+
lucide-react/dist/esm/Icon.mjs:
|
|
12
|
+
lucide-react/dist/esm/createLucideIcon.mjs:
|
|
13
|
+
lucide-react/dist/esm/icons/loader-circle.mjs:
|
|
14
|
+
lucide-react/dist/esm/icons/plus.mjs:
|
|
15
|
+
lucide-react/dist/esm/icons/power-off.mjs:
|
|
16
|
+
lucide-react/dist/esm/icons/power.mjs:
|
|
17
|
+
lucide-react/dist/esm/icons/refresh-cw.mjs:
|
|
18
|
+
lucide-react/dist/esm/icons/server.mjs:
|
|
19
|
+
lucide-react/dist/esm/icons/shield.mjs:
|
|
20
|
+
lucide-react/dist/esm/icons/trash-2.mjs:
|
|
21
|
+
lucide-react/dist/esm/icons/wifi-off.mjs:
|
|
22
|
+
lucide-react/dist/esm/icons/wifi.mjs:
|
|
23
|
+
lucide-react/dist/esm/icons/x.mjs:
|
|
24
|
+
lucide-react/dist/esm/lucide-react.mjs:
|
|
25
|
+
(**
|
|
26
|
+
* @license lucide-react v1.11.0 - ISC
|
|
27
|
+
*
|
|
28
|
+
* This source code is licensed under the ISC license.
|
|
29
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
30
|
+
*)
|
|
31
|
+
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/adapter-kook",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.74",
|
|
4
4
|
"description": "Zhin.js adapter for KOOK (开黑啦)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -40,12 +40,13 @@
|
|
|
40
40
|
"@types/react-dom": "^19.2.1",
|
|
41
41
|
"lucide-react": "^1.11.0",
|
|
42
42
|
"typescript": "^6.0.3",
|
|
43
|
-
"@zhin.js/
|
|
43
|
+
"@zhin.js/cli": "1.0.68",
|
|
44
|
+
"@zhin.js/console": "2.0.14",
|
|
44
45
|
"zhin.js": "1.0.72"
|
|
45
46
|
},
|
|
46
47
|
"peerDependencies": {
|
|
47
|
-
"@zhin.js/console": "2.0.13",
|
|
48
48
|
"@zhin.js/client": "1.0.18",
|
|
49
|
+
"@zhin.js/console": "2.0.14",
|
|
49
50
|
"@zhin.js/http": "1.0.65",
|
|
50
51
|
"@zhin.js/logger": "0.1.54",
|
|
51
52
|
"zhin.js": "1.0.72"
|
|
@@ -77,7 +78,7 @@
|
|
|
77
78
|
"registry": "https://registry.npmjs.org"
|
|
78
79
|
},
|
|
79
80
|
"scripts": {
|
|
80
|
-
"build": "
|
|
81
|
+
"build": "zhin build",
|
|
81
82
|
"clean": "rimraf lib dist",
|
|
82
83
|
"build:node": "tsc"
|
|
83
84
|
}
|