@zhin.js/adapter-kook 1.0.84 → 2.0.0
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/client/index.tsx +2 -2
- package/client/utils/api.ts +14 -1
- package/dist/index.js +1 -1
- package/lib/adapter.d.ts +1 -1
- package/lib/adapter.d.ts.map +1 -1
- package/lib/adapter.js +2 -3
- package/lib/adapter.js.map +1 -1
- package/package.json +4 -4
- package/src/adapter.ts +2 -6
package/CHANGELOG.md
CHANGED
package/client/index.tsx
CHANGED
|
@@ -3,9 +3,9 @@ import KookDashboard from './Dashboard'
|
|
|
3
3
|
|
|
4
4
|
export function register(api: PluginRegisterHostApi) {
|
|
5
5
|
api.addRoute({
|
|
6
|
-
path: '/
|
|
6
|
+
path: '/kook',
|
|
7
7
|
name: 'KOOK',
|
|
8
8
|
element: api.React.createElement(KookDashboard, { hostReact: api.React }),
|
|
9
9
|
})
|
|
10
|
-
api.addTool({ id: 'kook', name: 'KOOK', path: '/
|
|
10
|
+
api.addTool({ id: 'kook', name: 'KOOK', path: '/kook' })
|
|
11
11
|
}
|
package/client/utils/api.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
const TOKEN_KEY = "zhin_api_token";
|
|
2
|
+
const API_BASE_KEY = "zhin_api_base";
|
|
3
|
+
|
|
4
|
+
export function getApiBase(): string {
|
|
5
|
+
const stored = localStorage.getItem(API_BASE_KEY)?.trim();
|
|
6
|
+
if (stored) return stored.replace(/\/$/, "");
|
|
7
|
+
if (typeof window !== "undefined") return window.location.origin;
|
|
8
|
+
return "";
|
|
9
|
+
}
|
|
2
10
|
|
|
3
11
|
export function getToken(): string | null {
|
|
4
12
|
return localStorage.getItem(TOKEN_KEY);
|
|
@@ -8,7 +16,12 @@ export async function apiFetch(input: RequestInfo | URL, init?: RequestInit): Pr
|
|
|
8
16
|
const token = getToken();
|
|
9
17
|
const headers = new Headers(init?.headers);
|
|
10
18
|
if (token) headers.set("Authorization", `Bearer ${token}`);
|
|
11
|
-
|
|
19
|
+
|
|
20
|
+
const base = getApiBase();
|
|
21
|
+
const url =
|
|
22
|
+
typeof input === "string" && input.startsWith("/") ? `${base}${input}` : input;
|
|
23
|
+
|
|
24
|
+
const res = await fetch(url, { ...init, headers });
|
|
12
25
|
if (res.status === 401) {
|
|
13
26
|
localStorage.removeItem(TOKEN_KEY);
|
|
14
27
|
window.dispatchEvent(new CustomEvent("zhin:auth-required"));
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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 S(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,...g},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(g)&&{"aria-hidden":"true"},...g},[...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 Se=[["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",Se);var ge=[["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",ge);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"}]],y=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"}]],R=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,g]=p("overview"),[q,C]=p({}),[r,G]=p(""),[c,W]=p(""),[h,k]=p([]),[I,N]=p(!1),[b,z]=p(""),[X,K]=p(!1),[Z,Q]=p(null),v=Me(async()=>{s(!0),l("");try{let i=await(await S("/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 S(`/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)){N(!0),k([]);try{let i=await(await S(`/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{N(!1)}}},j=async()=>{if(!(!r||!c||!b.trim())){K(!0);try{let i=await(await S(`/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?(z(""),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 S(`/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:()=>g("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:()=>g("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(R,{className:"w-4 h-4"})," \u5728\u7EBF"]}):o("span",{className:"flex items-center gap-1 text-gray-400 text-sm",children:[a(y,{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=>z(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};
|
|
1
|
+
import{useEffect as Fe,useState as p,useCallback as De}from"react";var Y="zhin_api_token",se="zhin_api_base";function re(){let t=localStorage.getItem(se)?.trim();return t?t.replace(/\/$/,""):typeof window<"u"?window.location.origin:""}function ie(){return localStorage.getItem(Y)}async function S(t,u){let f=ie(),s=new Headers(u?.headers);f&&s.set("Authorization",`Bearer ${f}`);let m=re(),l=typeof t=="string"&&t.startsWith("/")?`${m}${t}`:t,L=await fetch(l,{...u,headers:s});return L.status===401&&(localStorage.removeItem(Y),window.dispatchEvent(new CustomEvent("zhin:auth-required"))),L}import{forwardRef as Le,createElement as Ie}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 me,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 ce,useContext as ne,useMemo as We,createElement as Ve}from"react";var pe=ce({});var oe=()=>ne(pe);var de=me(({color:t,size:u,strokeWidth:f,absoluteStrokeWidth:s,className:m="",children:l,iconNode:L,...g},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(g)&&{"aria-hidden":"true"},...g},[...L.map(([k,x])=>ue(k,x)),...Array.isArray(l)?l:[l]])});var d=(t,u)=>{let f=Le(({className:s,...m},l)=>Ie(de,{ref:l,iconNode:u,className:O(`lucide-${ee(V(t))}`,`lucide-${t}`,s),...m}));return f.displayName=V(t),f};var xe=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],n=d("loader-circle",xe);var Ce=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],w=d("plus",Ce);var he=[["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",he);var Se=[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]],A=d("power",Se);var ge=[["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",ge);var ke=[["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",ke);var we=[["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",we);var Pe=[["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",Pe);var Ae=[["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"}]],y=d("wifi-off",Ae);var Be=[["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"}]],R=d("wifi",Be);var Me=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],T=d("x",Me);import{Fragment as ye,jsx as a,jsxs as o}from"react/jsx-runtime";function E(){let[t,u]=p([]),[f,s]=p(!0),[m,l]=p(""),[L,g]=p("overview"),[q,C]=p({}),[r,G]=p(""),[c,W]=p(""),[h,k]=p([]),[x,N]=p(!1),[b,z]=p(""),[X,K]=p(!1),[Z,Q]=p(null),v=De(async()=>{s(!0),l("");try{let i=await(await S("/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)}},[]);Fe(()=>{v()},[v]);let le=async(e,i)=>{C(I=>({...I,[e]:!0}));try{let I=i?"disconnect":"connect",U=await(await S(`/api/kook/bots/${encodeURIComponent(e)}/${I}`,{method:"POST"})).json();U.success||l(U.error||"\u64CD\u4F5C\u5931\u8D25"),await v()}catch{l("\u64CD\u4F5C\u5931\u8D25")}finally{C(I=>({...I,[e]:!1}))}},J=async()=>{if(!(!r||!c)){N(!0),k([]);try{let i=await(await S(`/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{N(!1)}}},_=async()=>{if(!(!r||!c||!b.trim())){K(!0);try{let i=await(await S(`/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?(z(""),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 I=await(await S(`/api/kook/bots/${encodeURIComponent(r)}/guilds/${encodeURIComponent(c)}/roles/${encodeURIComponent(e)}`,{method:"DELETE"})).json();I.success?k($=>$.filter(U=>U.id!==e)):l(I.error||"\u5220\u9664\u89D2\u8272\u5931\u8D25")}catch{l("\u5220\u9664\u89D2\u8272\u5931\u8D25")}finally{Q(null)}}},j=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:()=>g("overview"),className:`px-4 py-2 text-sm font-medium border-b-2 transition-colors ${L==="overview"?"border-sky-500 text-sky-600":"border-transparent text-gray-500 hover:text-gray-700"}`,children:"\u6982\u89C8"}),a("button",{onClick:()=>g("roles"),className:`px-4 py-2 text-sm font-medium border-b-2 transition-colors ${L==="roles"?"border-sky-500 text-sky-600":"border-transparent text-gray-500 hover:text-gray-700"}`,children:"\u89D2\u8272\u7BA1\u7406"})]}),L==="overview"&&o(ye,{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(R,{className:"w-4 h-4"})," \u5728\u7EBF"]}):o("span",{className:"flex items-center gap-1 text-gray-400 text-sm",children:[a(y,{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))})]}),L==="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:"--"}),j.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||x,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:[x?a(n,{className:"w-3.5 h-3.5 animate-spin"}):a(F,{className:"w-3.5 h-3.5"})," \u67E5\u8BE2\u89D2\u8272"]})]}),!j.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=>z(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"&&_()}),o("button",{onClick:_,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"]})]}),x&&a("div",{className:"flex justify-center py-8",children:a(n,{className:"w-6 h-6 animate-spin text-sky-500"})}),!x&&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))}),!x&&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 Va(t){t.addRoute({path:"/kook",name:"KOOK",element:t.React.createElement(E,{hostReact:t.React})}),t.addTool({id:"kook",name:"KOOK",path:"/kook"})}export{Va 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
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,
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAiB,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,qBAAa,WAAY,SAAQ,OAAO,CAAC,OAAO,CAAC;gBACnC,MAAM,EAAE,MAAM;IAI1B,SAAS,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO;IAMnC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAMzD,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAMzE,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAM1D,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAMlF,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;;;;;;;;;IAe1C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAI5B"}
|
package/lib/adapter.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* KOOK 适配器
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { formatCompact, Adapter } from 'zhin.js';
|
|
5
5
|
import { KookBot } from "./bot.js";
|
|
6
6
|
export class KookAdapter extends Adapter {
|
|
7
7
|
constructor(plugin) {
|
|
@@ -51,11 +51,10 @@ export class KookAdapter extends Adapter {
|
|
|
51
51
|
// ── 生命周期 ───────────────────────────────────────────────────────
|
|
52
52
|
async start() {
|
|
53
53
|
await super.start();
|
|
54
|
-
this.plugin.logger.info("KOOK 适配器已启动");
|
|
55
54
|
}
|
|
56
55
|
async stop() {
|
|
57
56
|
await super.stop();
|
|
58
|
-
this.plugin.logger.info("
|
|
57
|
+
this.plugin.logger.info(formatCompact({ op: "stop" }));
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
60
|
//# sourceMappingURL=adapter.js.map
|
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,
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,aAAa,EAAE,OAAO,EAA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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/adapter-kook",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Zhin.js adapter for KOOK (开黑啦)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -41,12 +41,12 @@
|
|
|
41
41
|
"lucide-react": "^1.16.0",
|
|
42
42
|
"typescript": "^6.0.3",
|
|
43
43
|
"@zhin.js/cli": "1.0.77",
|
|
44
|
-
"@zhin.js/console": "
|
|
44
|
+
"@zhin.js/console": "3.0.0",
|
|
45
45
|
"zhin.js": "1.0.81"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@zhin.js/client": "1.0
|
|
49
|
-
"@zhin.js/console": "
|
|
48
|
+
"@zhin.js/client": "1.1.0",
|
|
49
|
+
"@zhin.js/console": "3.0.0",
|
|
50
50
|
"@zhin.js/http": "1.0.74",
|
|
51
51
|
"@zhin.js/logger": "0.1.63",
|
|
52
52
|
"zhin.js": "1.0.81"
|
package/src/adapter.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* KOOK 适配器
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
Adapter,
|
|
6
|
-
Plugin,
|
|
7
|
-
} from "zhin.js";
|
|
4
|
+
import { formatCompact, Adapter, Plugin } from 'zhin.js';
|
|
8
5
|
import { KookBot } from "./bot.js";
|
|
9
6
|
import type { KookBotConfig } from "./types.js";
|
|
10
7
|
|
|
@@ -60,12 +57,11 @@ export class KookAdapter extends Adapter<KookBot> {
|
|
|
60
57
|
|
|
61
58
|
async start(): Promise<void> {
|
|
62
59
|
await super.start();
|
|
63
|
-
this.plugin.logger.info("KOOK 适配器已启动");
|
|
64
60
|
}
|
|
65
61
|
|
|
66
62
|
async stop(): Promise<void> {
|
|
67
63
|
await super.stop();
|
|
68
|
-
this.plugin.logger.info("
|
|
64
|
+
this.plugin.logger.info(formatCompact( { op: "stop" }));
|
|
69
65
|
}
|
|
70
66
|
}
|
|
71
67
|
|