@alemonjs/discord 2.1.0-alpha.0 → 2.1.0-alpha.12
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/README.md +16 -2
- package/dist/assets/index.js +6 -1
- package/lib/config.d.ts +35 -0
- package/lib/config.js +22 -0
- package/lib/hook.d.ts +39 -0
- package/lib/hook.js +24 -0
- package/lib/index.d.ts +5 -2
- package/lib/index.js +47 -85
- package/lib/sdk/api.d.ts +879 -965
- package/lib/sdk/api.js +30 -43
- package/lib/sdk/message/INTERACTION_CREATE.d.ts +113 -113
- package/lib/sdk/message/MESSAGE_CREATE.d.ts +53 -53
- package/lib/sdk/types.d.ts +4 -4
- package/lib/sdk/typings.d.ts +221 -0
- package/lib/sdk/wss.js +15 -38
- package/lib/send.js +167 -83
- package/package.json +9 -2
- package/lib/sdk/config.js +0 -10
- package/lib/sdk/core/config.js +0 -46
- package/lib/sdk/message/CHANNEL_TOPIC_UPDATE.d.ts +0 -11
- package/lib/sdk/message/CHANNEL_UPDATE.d.ts +0 -48
- package/lib/sdk/message/GUILD_MEMBER_ADD.d.ts +0 -28
- package/lib/sdk/message/GUILD_MEMBER_REMOVE.d.ts +0 -18
- package/lib/sdk/message/GUILD_MEMBER_UPDATE.d.ts +0 -33
- package/lib/sdk/message/MESSAGE_DELETE.d.ts +0 -11
- package/lib/sdk/message/MESSAGE_REACTION_ADD.d.ts +0 -42
- package/lib/sdk/message/MESSAGE_UPDATE.d.ts +0 -56
- package/lib/sdk/message/PRESENCE_UPDATE.d.ts +0 -69
- package/lib/sdk/message/READY.d.ts +0 -9
- package/lib/sdk/message/TYPING_START.d.ts +0 -35
- package/lib/sdk/message/VOICE_CHANNEL_STATUS_UPDATE.d.ts +0 -10
- package/lib/sdk/message/VOICE_STATE_UPDATE.d.ts +0 -41
- package/lib/sdk/message.d.ts +0 -101
- package/lib/sdk/types.js +0 -25
- package/lib/sdk/wss.d.ts +0 -27
- package/lib/sdk/wss.types.d.ts +0 -30
- /package/lib/sdk/{core/from.js → createPicFrom.js} +0 -0
package/README.md
CHANGED
|
@@ -18,12 +18,26 @@ yarn add @alemonjs/discord
|
|
|
18
18
|
discord:
|
|
19
19
|
# 令牌
|
|
20
20
|
token: ''
|
|
21
|
-
# 主人
|
|
22
|
-
master_key: null
|
|
23
21
|
# 前缀(非必填)
|
|
24
22
|
intent: null
|
|
25
23
|
# 活动 非必填)
|
|
26
24
|
shard: null
|
|
25
|
+
# 使用 user_key
|
|
26
|
+
master_key:
|
|
27
|
+
- 'xxx'
|
|
28
|
+
# 使用 user_id
|
|
29
|
+
master_id:
|
|
30
|
+
- 'yyy'
|
|
31
|
+
# 请求代理(推荐使用)配置参考 axios
|
|
32
|
+
request_config:
|
|
33
|
+
proxy:
|
|
34
|
+
protocol: 'http'
|
|
35
|
+
host: 'localhost'
|
|
36
|
+
port: 7890
|
|
37
|
+
# ws 代理
|
|
38
|
+
websocket_proxy: 'http://localhost:7890'
|
|
39
|
+
# request_proxy: 'http://localhost:7890'
|
|
40
|
+
|
|
27
41
|
```
|
|
28
42
|
|
|
29
43
|
```sh
|
package/dist/assets/index.js
CHANGED
|
@@ -26,4 +26,9 @@ function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"de
|
|
|
26
26
|
*
|
|
27
27
|
* This source code is licensed under the MIT license found in the
|
|
28
28
|
* LICENSE file in the root directory of this source tree.
|
|
29
|
-
*/Mp.exports=function(){if(Fp)return Ip;Fp=1;var e=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function n(t,n,r){var l=null;if(void 0!==r&&(l=""+r),void 0!==n.key&&(l=""+n.key),"key"in n)for(var a in r={},n)"key"!==a&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:e,type:t,key:l,ref:void 0!==n?n:null,props:r}}return Ip.Fragment=t,Ip.jsx=n,Ip.jsxs=n,Ip}();var Up,Hp=Mp.exports,$p={exports:{}};
|
|
29
|
+
*/Mp.exports=function(){if(Fp)return Ip;Fp=1;var e=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function n(t,n,r){var l=null;if(void 0!==r&&(l=""+r),void 0!==n.key&&(l=""+n.key),"key"in n)for(var a in r={},n)"key"!==a&&(r[a]=n[a]);else r=n;return n=r.ref,{$$typeof:e,type:t,key:l,ref:void 0!==n?n:null,props:r}}return Ip.Fragment=t,Ip.jsx=n,Ip.jsxs=n,Ip}();var Up,Hp=Mp.exports,$p={exports:{}};
|
|
30
|
+
/*!
|
|
31
|
+
Copyright (c) 2018 Jed Watson.
|
|
32
|
+
Licensed under the MIT License (MIT), see
|
|
33
|
+
http://jedwatson.github.io/classnames
|
|
34
|
+
*/Up=$p,function(){var e={}.hasOwnProperty;function t(){for(var e="",t=0;t<arguments.length;t++){var l=arguments[t];l&&(e=r(e,n(l)))}return e}function n(n){if("string"==typeof n||"number"==typeof n)return n;if("object"!=typeof n)return"";if(Array.isArray(n))return t.apply(null,n);if(n.toString!==Object.prototype.toString&&!n.toString.toString().includes("[native code]"))return n.toString();var l="";for(var a in n)e.call(n,a)&&n[a]&&(l=r(l,a));return l}function r(e,t){return t?e?e+" "+t:e+t:e}Up.exports?(t.default=t,Up.exports=t):window.classNames=t}();const Vp=Dp($p.exports);function Bp(e){const{className:t,...n}=e;return Hp.jsx("button",{type:"button",className:Vp(t,"bg-[var(--alemonjs-button-bg)] border-[var(--alemonjs-button-border)] text-[var(--alemonjs-button-text)]","hover:bg-[var(--alemonjs-button-bg-hover)] hover:border-[var(--alemonjs-button-border-hover)] hover:text-[var(--alemonjs-button-text-hover)]","focus:outline-none focus:ring-2 focus:ring-[var(--alemonjs-button-bg)]","dark:bg-[var(--alemonjs-dark-button-bg)] dark:border-[var(--alemonjs-dark-button-border)] dark:text-[var(--alemonjs-dark-button-text)]","dark:hover:bg-[var(--alemonjs-dark-button-bg-hover)] dark:hover:border-[var(--alemonjs-dark-button-border-hover)] dark:hover:text-[var(--alemonjs-dark-button-text-hover)]"),...n})}function Qp(e){const{className:t,hover:n,...r}=e;return Hp.jsx("div",{className:Vp(t,"bg-[var(--alemonjs-secondary-bg)] border-[var(--alemonjs-secondary-border)] text-[var(--alemonjs-secondary-text)]","dark:bg-[var(--alemonjs-dark-secondary-bg)] dark:border-[var(--alemonjs-dark-secondary-border)] dark:text-[var(--alemonjs-dark-secondary-text)]",{"hover:bg-[var(--alemonjs-secondary-bg-hover)] hover:border-[var(--alemonjs-secondary-border-hover)] hover:text-[var(--alemonjs-secondary-text-hover)]":n},{"dark:hover:bg-[var(--alemonjs-dark-secondary-bg-hover)] dark:hover:border-[var(--alemonjs-dark-secondary-border-hover)] dark:hover:text-[var(--alemonjs-dark-secondary-text-hover)]":n}),...r})}function Wp(e){const{className:t,...n}=e;return Hp.jsx("input",{type:"text",className:Vp(t,"bg-[var(--alemonjs-input-bg)] border-[var(--alemonjs-input-border)] text-[var(--alemonjs-input-text)] placeholder:[var(--alemonjs-input-placeholder)]","focus:bg-[var(--alemonjs-input-bg-focus)] focus:border-[var(--alemonjs-input-border-focus)] focus:text-[var(--alemonjs-input-text-focus)]","disabled:bg-[var(--alemonjs-input-bg-disabled)] disabled:border-[var(--alemonjs-input-border-disabled)] disabled:text-[var(--alemonjs-input-text-disabled)]","hover:bg-[var(--alemonjs-input-bg-hover)] hover:border-[var(--alemonjs-input-border-hover)]","dark:bg-[var(--alemonjs-dark-input-bg)] dark:border-[var(--alemonjs-dark-input-border)] dark:text-[var(--alemonjs-dark-input-text)] dark:placeholder-[var(--alemonjs-dark-input-placeholder)]","dark:focus:bg-[var(--alemonjs-dark-input-bg-focus)] dark:focus:border-[var(--alemonjs-dark-input-border-focus)] dark:focus:text-[var(--alemonjs-dark-input-text-focus)]","dark:disabled:bg-[var(--alemonjs-dark-input-bg-disabled)] dark:disabled:border-[var(--alemonjs-dark-input-border-disabled)] dark:disabled:text-[var(--alemonjs-dark-input-text-disabled)]","dark:hover:bg-[var(--alemonjs-dark-input-bg-hover)] dark:hover:border-[var(--alemonjs-dark-input-border-hover)]"),...n})}function qp(e){const{className:t,hover:n,...r}=e;return Hp.jsx("div",{className:Vp(t,"bg-[var(--alemonjs-primary-bg)] border-[var(--alemonjs-primary-border)] text-[var(--alemonjs-primary-text)]",{"hover:bg-[var(--alemonjs-primary-bg-hover)] hover:border-[var(--alemonjs-primary-border-hover)] hover:text-[var(--alemonjs-primary-text-hover)]":n},"dark:bg-[var(--alemonjs-dark-primary-bg)] dark:border-[var(--alemonjs-dark-primary-border)] dark:text-[var(--alemonjs-dark-primary-text)]",{"dark:hover:bg-[var(--alemonjs-dark-primary-bg-hover)] dark:hover:border-[var(--alemonjs-dark-primary-border-hover)] dark:hover:text-[var(--alemonjs-dark-primary-text-hover)]":n}),...r})}function Kp(){const[e,t]=W.useState({token:"",master_key:""});W.useEffect((()=>{if(!window.createDesktopAPI)return;const e=window.createDesktopAPI();window.API=e,e.postMessage({type:"discord.init"}),e.onMessage((e=>{if("discord.init"===e.type){const n=e.data;t({token:(null==n?void 0:n.token)??"",master_key:Array.isArray(null==n?void 0:n.master_key)?n.master_key.join(","):""})}}))}),[]);const n=n=>{const{name:r,value:l,type:a}=n.target;t({...e,[r]:"checkbox"===a?n.target.checked:l})};return o.jsxs("form",{onSubmit:t=>{t.preventDefault(),window.API.postMessage({type:"discord.form.save",data:e})},className:"py-4 space-y-4",children:[o.jsxs("div",{children:[o.jsx("label",{htmlFor:"app_id",className:"block text-sm font-medium text-gray-700",children:"token"}),o.jsx(Wp,{type:"text",id:"token",name:"token",value:e.token,onChange:n,className:"mt-1 block w-full p-2 border rounded-md focus:outline-none focus:ring "})]}),o.jsxs("div",{children:[o.jsx("label",{htmlFor:"master_key",className:" block text-sm font-medium text-gray-700",children:"Master Key"}),o.jsx(Wp,{type:"text",id:"master_key",name:"master_key",value:e.master_key,placeholder:"sad12345678,kfp12345678,sgs12345678",onChange:n,className:"mt-1 block w-full p-2 border rounded-md focus:outline-none focus:ring "})]}),o.jsx(Bp,{type:"submit",className:"w-full p-2 rounded-md transition duration-200",children:"保存"})]})}function Yp(){return o.jsx(Qp,{className:"flex items-center justify-center p-8",children:o.jsxs(qp,{className:"rounded-lg shadow-inner w-full p-8",children:[o.jsx("div",{className:"flex justify-center text-3xl",children:"Discord"}),o.jsx(Kp,{})]})})}W.memo((({children:e,buttons:t,placement:n="bottom"})=>{const[r,l]=W.useState(!1),a=W.useRef(null),o=e=>{a.current&&!a.current.contains(e.target)&&l(!1)};q.useEffect((()=>(document.addEventListener("mousedown",o),()=>{document.removeEventListener("mousedown",o)})),[]);return Hp.jsxs("div",{className:"relative",ref:a,children:[r&&Hp.jsx(Qp,{className:Vp("absolute z-20 bg-opacity-90 border rounded-md shadow-md ",(()=>{switch(n){case"bottomRight":return"left-0 mt-2";case"bottom":default:return"left-1/2 transform -translate-x-1/2 mt-2";case"bottomLeft":return"right-0 mt-2";case"topRight":return"left-0 bottom-full mb-2";case"top":return"left-1/2 transform -translate-x-1/2 bottom-full mb-2";case"topLeft":return"right-0 bottom-full mb-2"}})()),children:Hp.jsx("div",{className:"flex flex-col gap-2 p-2",children:t.map(((e,t)=>Hp.jsx(Bp,{className:"px-3 py-1 min-w-16 rounded-md whitespace-nowrap",onClick:e=>{e.stopPropagation(),l(!1)},...e},t)))})}),Hp.jsx("div",{onClick:e=>{e.stopPropagation(),l((e=>!e))},className:"z-10",children:e})]})}));var Gp={};if(Gp){const e=Gp;Object.keys(e).forEach((t=>{document.documentElement.style.setProperty(`--${t}`,e[t])}))}jp.createRoot(document.getElementById("root")).render(o.jsx(Yp,{}));
|
package/lib/config.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { DCIntentsEnum } from './sdk/types.js';
|
|
2
|
+
|
|
3
|
+
interface Options {
|
|
4
|
+
/**
|
|
5
|
+
* 网关地址
|
|
6
|
+
*/
|
|
7
|
+
gatewayURL?: string;
|
|
8
|
+
/**
|
|
9
|
+
* 钥匙
|
|
10
|
+
*/
|
|
11
|
+
token: string;
|
|
12
|
+
/**
|
|
13
|
+
* 订阅(有默认值)
|
|
14
|
+
* ******
|
|
15
|
+
*/
|
|
16
|
+
intent?: DCIntentsEnum[];
|
|
17
|
+
/**
|
|
18
|
+
* 分片(有默认值)
|
|
19
|
+
* ******
|
|
20
|
+
* [0, 1]
|
|
21
|
+
*/
|
|
22
|
+
shard?: number[];
|
|
23
|
+
/**
|
|
24
|
+
* 主人钥匙
|
|
25
|
+
*/
|
|
26
|
+
master_key?: string[];
|
|
27
|
+
/**
|
|
28
|
+
* 主人ID
|
|
29
|
+
*/
|
|
30
|
+
master_id?: string[];
|
|
31
|
+
}
|
|
32
|
+
declare const platform = "discord";
|
|
33
|
+
|
|
34
|
+
export { platform };
|
|
35
|
+
export type { Options };
|
package/lib/config.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useUserHashKey, getConfigValue } from 'alemonjs';
|
|
2
|
+
|
|
3
|
+
// 平台
|
|
4
|
+
const platform = 'discord';
|
|
5
|
+
const getDiscordConfig = () => {
|
|
6
|
+
const value = getConfigValue() || {};
|
|
7
|
+
const config = value[platform] || {};
|
|
8
|
+
return config;
|
|
9
|
+
};
|
|
10
|
+
const getMaster = (UserId) => {
|
|
11
|
+
const config = getDiscordConfig();
|
|
12
|
+
const master_key = config.master_key || [];
|
|
13
|
+
const master_id = config.master_id || [];
|
|
14
|
+
const UserKey = useUserHashKey({
|
|
15
|
+
Platform: platform,
|
|
16
|
+
UserId: UserId
|
|
17
|
+
});
|
|
18
|
+
const is = master_key.includes(UserKey) || master_id.includes(UserId);
|
|
19
|
+
return [is, UserKey];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { getDiscordConfig, getMaster, platform };
|
package/lib/hook.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { EventKeys, Events } from 'alemonjs';
|
|
2
|
+
import { DCAPI } from './sdk/api.js';
|
|
3
|
+
import { MESSAGE_CREATE_TYPE } from './sdk/message/MESSAGE_CREATE.js';
|
|
4
|
+
import { INTERACTION_CREATE_TYPE } from './sdk/message/INTERACTION_CREATE.js';
|
|
5
|
+
|
|
6
|
+
type MAP = {
|
|
7
|
+
'message.create': MESSAGE_CREATE_TYPE;
|
|
8
|
+
'private.message.create': MESSAGE_CREATE_TYPE;
|
|
9
|
+
'interaction.create': INTERACTION_CREATE_TYPE;
|
|
10
|
+
'private.interaction.create': INTERACTION_CREATE_TYPE;
|
|
11
|
+
'message.update': undefined;
|
|
12
|
+
'message.delete': undefined;
|
|
13
|
+
'message.reaction.add': undefined;
|
|
14
|
+
'message.reaction.remove': undefined;
|
|
15
|
+
'channal.create': undefined;
|
|
16
|
+
'channal.delete': undefined;
|
|
17
|
+
'guild.join': undefined;
|
|
18
|
+
'guild.exit': undefined;
|
|
19
|
+
'member.add': undefined;
|
|
20
|
+
'member.remove': undefined;
|
|
21
|
+
'private.message.update': undefined;
|
|
22
|
+
'private.message.delete': undefined;
|
|
23
|
+
'private.friend.add': undefined;
|
|
24
|
+
'private.guild.add': undefined;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @param event
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
declare const useValue: <T extends EventKeys>(event: Events[T]) => readonly [MAP[T]];
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @param event
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
declare const useClient: <T extends EventKeys>(event: Events[T]) => readonly [DCAPI, MAP[T]];
|
|
38
|
+
|
|
39
|
+
export { useClient, useValue };
|
package/lib/hook.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createEventValue, useClient as useClient$1 } from 'alemonjs';
|
|
2
|
+
import { DCAPI } from './sdk/api.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param event
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
const useValue = (event) => {
|
|
10
|
+
const value = createEventValue(event);
|
|
11
|
+
return [value];
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @param event
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
const useClient = (event) => {
|
|
19
|
+
const [client] = useClient$1(event, DCAPI);
|
|
20
|
+
const value = createEventValue(event);
|
|
21
|
+
return [client, value];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { useClient, useValue };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
export { Options, platform } from './config.js';
|
|
2
|
+
export { DCAPI as API } from './sdk/api.js';
|
|
3
|
+
export { useClient, useValue } from './hook.js';
|
|
4
|
+
|
|
2
5
|
declare const _default: () => void;
|
|
3
6
|
|
|
4
|
-
export { _default as default
|
|
7
|
+
export { _default as default };
|
package/lib/index.js
CHANGED
|
@@ -1,34 +1,23 @@
|
|
|
1
|
-
import '
|
|
2
|
-
import { getConfigValue, cbpPlatform, useUserHashKey } from 'alemonjs';
|
|
1
|
+
import { cbpPlatform, createResult, ResultCode } from 'alemonjs';
|
|
3
2
|
import { sendchannel, senduser } from './send.js';
|
|
4
3
|
import { DCClient } from './sdk/wss.js';
|
|
5
|
-
import {
|
|
4
|
+
import { getMaster, platform } from './config.js';
|
|
5
|
+
export { DCAPI as API } from './sdk/api.js';
|
|
6
|
+
export { useClient, useValue } from './hook.js';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
// main
|
|
8
9
|
var index = () => {
|
|
9
|
-
|
|
10
|
-
if (!value)
|
|
11
|
-
value = {};
|
|
12
|
-
const config = value[platform];
|
|
13
|
-
// 创建客户端
|
|
14
|
-
const client = new DCClient({
|
|
15
|
-
gatewayURL: config?.gatewayURL,
|
|
16
|
-
token: config.token,
|
|
17
|
-
shard: config?.shard ?? [0, 1],
|
|
18
|
-
intent: config?.intent ?? AvailableIntentsEventsEnum
|
|
19
|
-
});
|
|
10
|
+
const port = process.env?.port || 17117;
|
|
20
11
|
/**
|
|
21
12
|
* 连接 alemonjs 服务器。
|
|
22
13
|
* 向 alemonjs 推送标准信息
|
|
23
14
|
*/
|
|
24
|
-
const url = `ws://127.0.0.1:${
|
|
15
|
+
const url = `ws://127.0.0.1:${port}`;
|
|
25
16
|
const cbp = cbpPlatform(url);
|
|
17
|
+
// 创建客户端
|
|
18
|
+
const client = new DCClient();
|
|
26
19
|
// 连接
|
|
27
|
-
client.connect(
|
|
28
|
-
const ImageURLToBuffer = async (url) => {
|
|
29
|
-
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
30
|
-
return Buffer.from(arrayBuffer);
|
|
31
|
-
};
|
|
20
|
+
client.connect();
|
|
32
21
|
/**
|
|
33
22
|
* 创建用户头像
|
|
34
23
|
* @param UserId
|
|
@@ -36,28 +25,7 @@ var index = () => {
|
|
|
36
25
|
* @returns
|
|
37
26
|
*/
|
|
38
27
|
const createUserAvatar = (UserId, avatar) => {
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
toBuffer: async () => {
|
|
42
|
-
if (!url) {
|
|
43
|
-
url = client.userAvatar(UserId, avatar);
|
|
44
|
-
}
|
|
45
|
-
return ImageURLToBuffer(url);
|
|
46
|
-
},
|
|
47
|
-
toBase64: async () => {
|
|
48
|
-
if (!url) {
|
|
49
|
-
url = client.userAvatar(UserId, avatar);
|
|
50
|
-
}
|
|
51
|
-
const buffer = await ImageURLToBuffer(url);
|
|
52
|
-
return buffer?.toString('base64');
|
|
53
|
-
},
|
|
54
|
-
toURL: async () => {
|
|
55
|
-
if (!url) {
|
|
56
|
-
url = client.userAvatar(UserId, avatar);
|
|
57
|
-
}
|
|
58
|
-
return url;
|
|
59
|
-
}
|
|
60
|
-
};
|
|
28
|
+
return client.userAvatar(UserId, avatar);
|
|
61
29
|
};
|
|
62
30
|
// 监听消息
|
|
63
31
|
client.on('MESSAGE_CREATE', async (event) => {
|
|
@@ -78,12 +46,7 @@ var index = () => {
|
|
|
78
46
|
msg = msg.replace(`<@${item.id}>`, '').trim();
|
|
79
47
|
}
|
|
80
48
|
const UserId = event.author.id;
|
|
81
|
-
const UserKey =
|
|
82
|
-
Platform: platform,
|
|
83
|
-
UserId: UserId
|
|
84
|
-
});
|
|
85
|
-
const master_key = config?.master_key ?? [];
|
|
86
|
-
const isMaster = master_key.includes(UserKey);
|
|
49
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
87
50
|
const UserAvatar = createUserAvatar(UserId, event.author.avatar);
|
|
88
51
|
if (event.type == 0 && event.member) {
|
|
89
52
|
const e = {
|
|
@@ -93,6 +56,7 @@ var index = () => {
|
|
|
93
56
|
// guild
|
|
94
57
|
GuildId: event.guild_id,
|
|
95
58
|
ChannelId: event.channel_id,
|
|
59
|
+
SpaceId: event.channel_id,
|
|
96
60
|
// user
|
|
97
61
|
UserId: UserId,
|
|
98
62
|
UserKey,
|
|
@@ -100,10 +64,10 @@ var index = () => {
|
|
|
100
64
|
UserAvatar: UserAvatar,
|
|
101
65
|
IsMaster: isMaster,
|
|
102
66
|
IsBot: false,
|
|
67
|
+
OpenId: UserId,
|
|
103
68
|
// message
|
|
104
69
|
MessageId: event.id,
|
|
105
70
|
MessageText: msg,
|
|
106
|
-
OpenId: '',
|
|
107
71
|
CreateAt: Date.now(),
|
|
108
72
|
// other
|
|
109
73
|
tag: 'message.create',
|
|
@@ -117,9 +81,6 @@ var index = () => {
|
|
|
117
81
|
name: 'private.message.create',
|
|
118
82
|
// 事件类型
|
|
119
83
|
Platform: platform,
|
|
120
|
-
// guild
|
|
121
|
-
// GuildId: event.guild_id,
|
|
122
|
-
// ChannelId: event.channel_id,
|
|
123
84
|
// user
|
|
124
85
|
UserId: UserId,
|
|
125
86
|
UserKey,
|
|
@@ -127,10 +88,10 @@ var index = () => {
|
|
|
127
88
|
UserAvatar: UserAvatar,
|
|
128
89
|
IsMaster: isMaster,
|
|
129
90
|
IsBot: false,
|
|
91
|
+
OpenId: UserId,
|
|
130
92
|
// message
|
|
131
93
|
MessageId: event.id,
|
|
132
94
|
MessageText: msg,
|
|
133
|
-
OpenId: '',
|
|
134
95
|
CreateAt: Date.now(),
|
|
135
96
|
// other
|
|
136
97
|
tag: 'private.message.create',
|
|
@@ -141,18 +102,12 @@ var index = () => {
|
|
|
141
102
|
else ;
|
|
142
103
|
});
|
|
143
104
|
client.on('INTERACTION_CREATE', event => {
|
|
144
|
-
console.log('event', event);
|
|
145
105
|
const isPrivate = typeof event['user'] === 'object' ? true : false;
|
|
146
106
|
const user = isPrivate ? event['user'] : event['member'].user;
|
|
147
107
|
const UserId = user.id;
|
|
148
|
-
const UserKey = useUserHashKey({
|
|
149
|
-
Platform: platform,
|
|
150
|
-
UserId: UserId
|
|
151
|
-
});
|
|
152
108
|
const UserAvatar = createUserAvatar(UserId, user.avatar);
|
|
153
109
|
const UserName = user.username;
|
|
154
|
-
const
|
|
155
|
-
const isMaster = master_key.includes(UserKey);
|
|
110
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
156
111
|
const MessageText = event.data.custom_id;
|
|
157
112
|
if (isPrivate) {
|
|
158
113
|
// 处理消息
|
|
@@ -160,9 +115,6 @@ var index = () => {
|
|
|
160
115
|
name: 'private.interaction.create',
|
|
161
116
|
// 事件类型
|
|
162
117
|
Platform: platform,
|
|
163
|
-
// guild
|
|
164
|
-
// GuildId: event['guild_id'],
|
|
165
|
-
// ChannelId: event.channel_id,
|
|
166
118
|
// user
|
|
167
119
|
UserId: UserId,
|
|
168
120
|
UserKey,
|
|
@@ -170,10 +122,10 @@ var index = () => {
|
|
|
170
122
|
UserAvatar: UserAvatar,
|
|
171
123
|
IsMaster: isMaster,
|
|
172
124
|
IsBot: false,
|
|
125
|
+
OpenId: UserId,
|
|
173
126
|
// message
|
|
174
127
|
MessageId: event.id,
|
|
175
128
|
MessageText: MessageText,
|
|
176
|
-
OpenId: '',
|
|
177
129
|
CreateAt: Date.now(),
|
|
178
130
|
// other
|
|
179
131
|
tag: 'private.interaction.create',
|
|
@@ -189,6 +141,7 @@ var index = () => {
|
|
|
189
141
|
// guild
|
|
190
142
|
GuildId: event['guild_id'],
|
|
191
143
|
ChannelId: event.channel_id,
|
|
144
|
+
SpaceId: event.channel_id,
|
|
192
145
|
// user
|
|
193
146
|
UserId: UserId,
|
|
194
147
|
UserKey,
|
|
@@ -199,7 +152,7 @@ var index = () => {
|
|
|
199
152
|
// message
|
|
200
153
|
MessageId: event.id,
|
|
201
154
|
MessageText: MessageText,
|
|
202
|
-
OpenId:
|
|
155
|
+
OpenId: UserId,
|
|
203
156
|
CreateAt: Date.now(),
|
|
204
157
|
// other
|
|
205
158
|
tag: 'interaction.create',
|
|
@@ -214,62 +167,62 @@ var index = () => {
|
|
|
214
167
|
const api = {
|
|
215
168
|
active: {
|
|
216
169
|
send: {
|
|
217
|
-
channel: (
|
|
218
|
-
|
|
170
|
+
channel: async (UserId, val) => {
|
|
171
|
+
const res = await sendchannel(client, { channel_id: UserId }, val);
|
|
172
|
+
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
219
173
|
},
|
|
220
|
-
user: async (
|
|
221
|
-
|
|
174
|
+
user: async (OpenId, val) => {
|
|
175
|
+
const res = await senduser(client, { author_id: OpenId }, val);
|
|
176
|
+
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
222
177
|
}
|
|
223
178
|
}
|
|
224
179
|
},
|
|
225
180
|
use: {
|
|
226
181
|
send: async (event, val) => {
|
|
227
182
|
if (val.length < 0) {
|
|
228
|
-
return
|
|
183
|
+
return [];
|
|
229
184
|
}
|
|
230
185
|
const tag = event.tag;
|
|
231
186
|
if (tag == 'message.create') {
|
|
232
187
|
const ChannelId = event.value.channel_id;
|
|
233
|
-
|
|
188
|
+
const res = await sendchannel(client, { channel_id: ChannelId }, val);
|
|
189
|
+
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
234
190
|
}
|
|
235
191
|
else if (tag == 'private.message.create') {
|
|
236
192
|
const UserId = event.value.author.id;
|
|
237
193
|
const ChannelId = event.value.channel_id;
|
|
238
|
-
|
|
194
|
+
const res = await senduser(client, {
|
|
239
195
|
channel_id: ChannelId,
|
|
240
196
|
author_id: UserId
|
|
241
197
|
}, val);
|
|
198
|
+
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
242
199
|
}
|
|
243
200
|
else if (tag == 'interaction.create') {
|
|
244
201
|
const ChannelId = event.value.channel_id;
|
|
245
|
-
|
|
202
|
+
const res = await sendchannel(client, { channel_id: ChannelId }, val);
|
|
203
|
+
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
246
204
|
}
|
|
247
205
|
else if (tag == 'private.interaction.create') {
|
|
248
206
|
const UserId = event.value.user.id;
|
|
249
207
|
const ChannelId = event.value.channel_id;
|
|
250
|
-
|
|
208
|
+
const res = await senduser(client, {
|
|
251
209
|
channel_id: ChannelId,
|
|
252
210
|
author_id: UserId
|
|
253
211
|
}, val);
|
|
212
|
+
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
254
213
|
}
|
|
255
|
-
return
|
|
214
|
+
return [];
|
|
256
215
|
},
|
|
257
216
|
mention: async (e) => {
|
|
258
217
|
const event = e.value;
|
|
259
218
|
const MessageMention = event.mentions.map(item => {
|
|
260
219
|
const UserId = item.id;
|
|
261
220
|
const avatar = event.author.avatar;
|
|
262
|
-
const value = getConfigValue();
|
|
263
|
-
const config = value?.discord;
|
|
264
|
-
const master_key = config?.master_key ?? [];
|
|
265
221
|
const UserAvatar = createUserAvatar(UserId, avatar);
|
|
266
|
-
const UserKey =
|
|
267
|
-
Platform: platform,
|
|
268
|
-
UserId: UserId
|
|
269
|
-
});
|
|
222
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
270
223
|
return {
|
|
271
224
|
UserId: item.id,
|
|
272
|
-
IsMaster:
|
|
225
|
+
IsMaster: isMaster,
|
|
273
226
|
IsBot: item.bot,
|
|
274
227
|
UserAvatar,
|
|
275
228
|
UserKey
|
|
@@ -301,7 +254,16 @@ var index = () => {
|
|
|
301
254
|
else if (data.action === 'mention.get') {
|
|
302
255
|
const event = data.payload.event;
|
|
303
256
|
const res = await api.use.mention(event);
|
|
304
|
-
consume(res);
|
|
257
|
+
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
cbp.onapis(async (data, consume) => {
|
|
261
|
+
const key = data.payload?.key;
|
|
262
|
+
if (client[key]) {
|
|
263
|
+
// 如果 client 上有对应的 key,直接调用。
|
|
264
|
+
const params = data.payload.params;
|
|
265
|
+
const res = await client[key](...params);
|
|
266
|
+
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
305
267
|
}
|
|
306
268
|
});
|
|
307
269
|
};
|