@zhin.js/adapter-discord 1.0.76 → 1.0.77
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 +29 -0
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import{useEffect as ce,useState as n,useCallback as ne}from"react";var V="zhin_api_token";function J(){return localStorage.getItem(V)}async function T(t,u){let l=J(),f=new Headers(u?.headers);l&&f.set("Authorization",`Bearer ${l}`);let r=await fetch(t,{...u,headers:f});return r.status===401&&(localStorage.removeItem(V),window.dispatchEvent(new CustomEvent("zhin:auth-required"))),r}import{forwardRef as ee,createElement as ae}from"react";var q=(...t)=>t.filter((u,l,f)=>!!u&&u.trim()!==""&&f.indexOf(u)===l).join(" ").trim();var E=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();var z=t=>t.replace(/^([A-Z])|[\s-_]+(\w)/g,(u,l,f)=>f?f.toUpperCase():l.toLowerCase());var O=t=>{let u=z(t);return u.charAt(0).toUpperCase()+u.slice(1)};import{forwardRef as Y,createElement as K}from"react";var b={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 N=t=>{for(let u in t)if(u.startsWith("aria-")||u==="role"||u==="title")return!0;return!1};import{createContext as j,useContext as _,useMemo as Pe,createElement as Ae}from"react";var $=j({});var X=()=>_($);var Z=Y(({color:t,size:u,strokeWidth:l,absoluteStrokeWidth:f,className:r="",children:s,iconNode:p,...m},D)=>{let{size:L=24,strokeWidth:C=2,absoluteStrokeWidth:v=!1,color:h="currentColor",className:R=""}=X()??{},g=f??v?Number(l??C)*24/Number(u??L):l??C;return K("svg",{ref:D,...b,width:u??L??b.width,height:u??L??b.height,stroke:t??h,strokeWidth:g,className:q("lucide",R,r),...!s&&!N(m)&&{"aria-hidden":"true"},...m},[...p.map(([y,I])=>K(y,I)),...Array.isArray(s)?s:[s]])});var d=(t,u)=>{let l=ee(({className:f,...r},s)=>ae(Z,{ref:s,iconNode:u,className:q(`lucide-${E(O(t))}`,`lucide-${t}`,f),...r}));return l.displayName=O(t),l};var te=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]],S=d("globe",te);var oe=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],c=d("loader-circle",oe);var ue=[["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"}]],k=d("power-off",ue);var de=[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]],w=d("power",de);var le=[["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"}]],P=d("refresh-cw",le);var fe=[["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"}]],A=d("server",fe);var se=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["path",{d:"M16 3.128a4 4 0 0 1 0 7.744",key:"16gr8j"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}]],B=d("users",se);var re=[["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"}]],M=d("wifi-off",re);var ie=[["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"}]],F=d("wifi",ie);import{Fragment as pe,jsx as a,jsxs as o}from"react/jsx-runtime";function H(){let[t,u]=n([]),[l,f]=n(!0),[r,s]=n(""),[p,m]=n("overview"),[D,L]=n({}),[C,v]=n(""),[h,R]=n([]),[g,y]=n(!1),I=ne(async()=>{f(!0),s("");try{let x=await(await T("/api/discord/bots")).json();x.success?u(x.data):s(x.error||"\u83B7\u53D6\u6570\u636E\u5931\u8D25")}catch{s("\u65E0\u6CD5\u8FDE\u63A5\u670D\u52A1\u5668")}finally{f(!1)}},[]);ce(()=>{I()},[I]);let Q=async(e,x)=>{L(i=>({...i,[e]:!0}));try{let i=x?"disconnect":"connect",W=await(await T(`/api/discord/bots/${encodeURIComponent(e)}/${i}`,{method:"POST"})).json();W.success||s(W.error||"\u64CD\u4F5C\u5931\u8D25"),await I()}catch{s("\u64CD\u4F5C\u5931\u8D25")}finally{L(i=>({...i,[e]:!1}))}},G=async e=>{v(e),y(!0),R([]);try{let i=await(await T(`/api/discord/bots/${encodeURIComponent(e)}/guilds`)).json();i.success?R(i.data):s(i.error||"\u83B7\u53D6\u670D\u52A1\u5668\u5217\u8868\u5931\u8D25")}catch{s("\u83B7\u53D6\u670D\u52A1\u5668\u5217\u8868\u5931\u8D25")}finally{y(!1)}},U=t.filter(e=>e.connected&&e.mode==="gateway");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(A,{className:"w-6 h-6"})," Discord \u673A\u5668\u4EBA"]}),o("button",{onClick:I,disabled:l,className:"flex items-center gap-1 px-3 py-1.5 rounded bg-indigo-500 text-white hover:bg-indigo-600 disabled:opacity-50 text-sm",children:[a(P,{className:`w-4 h-4 ${l?"animate-spin":""}`})," \u5237\u65B0"]})]}),r&&a("div",{className:"mb-4 p-3 bg-red-50 text-red-600 rounded border border-red-200",children:r}),o("div",{className:"flex gap-1 mb-6 border-b",children:[a("button",{onClick:()=>m("overview"),className:`px-4 py-2 text-sm font-medium border-b-2 transition-colors ${p==="overview"?"border-indigo-500 text-indigo-600":"border-transparent text-gray-500 hover:text-gray-700"}`,children:"\u6982\u89C8"}),a("button",{onClick:()=>m("guilds"),className:`px-4 py-2 text-sm font-medium border-b-2 transition-colors ${p==="guilds"?"border-indigo-500 text-indigo-600":"border-transparent text-gray-500 hover:text-gray-700"}`,children:"\u670D\u52A1\u5668\u5217\u8868"})]}),p==="overview"&&o(pe,{children:[!l&&!t.length&&!r&&a("div",{className:"text-center text-gray-500 py-12",children:"\u6682\u65E0 Discord \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(F,{className:"w-4 h-4"})," \u5728\u7EBF"]}):o("span",{className:"flex items-center gap-1 text-gray-400 text-sm",children:[a(M,{className:"w-4 h-4"})," \u79BB\u7EBF"]})]}),e.user&&o("div",{className:"text-sm text-gray-500 mb-2",children:["@",e.user.tag]}),o("div",{className:"grid grid-cols-2 gap-2 text-sm text-gray-600 mb-3",children:[o("div",{className:"flex justify-between",children:[a("span",{children:"\u6A21\u5F0F"}),a("span",{className:"font-mono",children:e.mode})]}),o("div",{className:"flex justify-between",children:[a("span",{children:"\u670D\u52A1\u5668"}),a("span",{className:"font-mono",children:e.guildCount})]}),o("div",{className:"flex justify-between",children:[a("span",{children:"\u9891\u9053"}),a("span",{className:"font-mono",children:e.channelCount})]})]}),o("div",{className:"flex gap-2",children:[o("button",{onClick:()=>Q(e.name,e.connected),disabled:D[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:[D[e.name]?a(c,{className:"w-3.5 h-3.5 animate-spin"}):e.connected?a(k,{className:"w-3.5 h-3.5"}):a(w,{className:"w-3.5 h-3.5"}),e.connected?"\u65AD\u5F00":"\u8FDE\u63A5"]}),e.connected&&e.mode==="gateway"&&o("button",{onClick:()=>{m("guilds"),G(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(S,{className:"w-3.5 h-3.5"})," \u67E5\u770B\u670D\u52A1\u5668"]})]})]},e.name))})]}),p==="guilds"&&o("div",{children:[U.length>0&&o("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"}),o("select",{value:C,onChange:e=>G(e.target.value),className:"border rounded px-2 py-1 text-sm",children:[a("option",{value:"",children:"--"}),U.map(e=>a("option",{value:e.name,children:e.name},e.name))]}),a("span",{className:"text-xs text-gray-400 ml-2",children:"\u4EC5 Gateway \u6A21\u5F0F\u652F\u6301"})]}),!U.length&&a("div",{className:"text-center text-gray-500 py-8",children:"\u6682\u65E0 Gateway \u6A21\u5F0F\u5728\u7EBF\u673A\u5668\u4EBA"}),g&&a("div",{className:"flex justify-center py-8",children:a(c,{className:"w-6 h-6 animate-spin text-indigo-500"})}),!g&&h.length>0&&a("div",{className:"grid gap-3 md:grid-cols-2 lg:grid-cols-3",children:h.map(e=>o("div",{className:"border rounded-lg p-3 bg-card shadow-sm flex items-center gap-3",children:[e.icon?a("img",{src:e.icon,alt:"",className:"w-10 h-10 rounded-full"}):a("div",{className:"w-10 h-10 rounded-full bg-indigo-100 flex items-center justify-center text-indigo-500 font-bold text-sm",children:e.name[0]}),o("div",{className:"flex-1 min-w-0",children:[a("div",{className:"font-medium text-sm truncate",children:e.name}),o("div",{className:"flex items-center gap-1 text-xs text-gray-400",children:[a(B,{className:"w-3 h-3"})," ",e.memberCount," \u6210\u5458"]})]})]},e.id))}),!g&&C&&!h.length&&a("div",{className:"text-center text-gray-400 py-8",children:"\u8BE5\u673A\u5668\u4EBA\u672A\u52A0\u5165\u4EFB\u4F55\u670D\u52A1\u5668"})]})]})}function ha(t){t.addRoute({path:"/console/discord",name:"Discord",element:t.React.createElement(H,{hostReact:t.React})}),t.addTool({id:"discord",name:"Discord",path:"/console/discord"})}export{ha 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/globe.mjs:
|
|
14
|
+
lucide-react/dist/esm/icons/loader-circle.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/users.mjs:
|
|
20
|
+
lucide-react/dist/esm/icons/wifi-off.mjs:
|
|
21
|
+
lucide-react/dist/esm/icons/wifi.mjs:
|
|
22
|
+
lucide-react/dist/esm/lucide-react.mjs:
|
|
23
|
+
(**
|
|
24
|
+
* @license lucide-react v1.11.0 - ISC
|
|
25
|
+
*
|
|
26
|
+
* This source code is licensed under the ISC license.
|
|
27
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
28
|
+
*)
|
|
29
|
+
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/adapter-discord",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.77",
|
|
4
4
|
"description": "Zhin.js adapter for Discord",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -42,12 +42,13 @@
|
|
|
42
42
|
"@types/react-dom": "^19.2.1",
|
|
43
43
|
"lucide-react": "^1.11.0",
|
|
44
44
|
"typescript": "^6.0.3",
|
|
45
|
-
"@zhin.js/
|
|
45
|
+
"@zhin.js/cli": "1.0.68",
|
|
46
|
+
"@zhin.js/console": "2.0.14",
|
|
46
47
|
"zhin.js": "1.0.72"
|
|
47
48
|
},
|
|
48
49
|
"peerDependencies": {
|
|
49
50
|
"@zhin.js/client": "1.0.18",
|
|
50
|
-
"@zhin.js/console": "2.0.
|
|
51
|
+
"@zhin.js/console": "2.0.14",
|
|
51
52
|
"@zhin.js/http": "1.0.65",
|
|
52
53
|
"zhin.js": "1.0.72"
|
|
53
54
|
},
|
|
@@ -75,7 +76,7 @@
|
|
|
75
76
|
"registry": "https://registry.npmjs.org"
|
|
76
77
|
},
|
|
77
78
|
"scripts": {
|
|
78
|
-
"build": "
|
|
79
|
+
"build": "zhin build",
|
|
79
80
|
"clean": "rimraf lib dist",
|
|
80
81
|
"build:node": "tsc"
|
|
81
82
|
}
|