@alemonjs/discord 2.1.0-alpha.1 → 2.1.0-alpha.13
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 +46 -59
- 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 +16 -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/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,30 +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(
|
|
20
|
+
client.connect();
|
|
28
21
|
/**
|
|
29
22
|
* 创建用户头像
|
|
30
23
|
* @param UserId
|
|
@@ -53,12 +46,7 @@ var index = () => {
|
|
|
53
46
|
msg = msg.replace(`<@${item.id}>`, '').trim();
|
|
54
47
|
}
|
|
55
48
|
const UserId = event.author.id;
|
|
56
|
-
const UserKey =
|
|
57
|
-
Platform: platform,
|
|
58
|
-
UserId: UserId
|
|
59
|
-
});
|
|
60
|
-
const master_key = config?.master_key ?? [];
|
|
61
|
-
const isMaster = master_key.includes(UserKey);
|
|
49
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
62
50
|
const UserAvatar = createUserAvatar(UserId, event.author.avatar);
|
|
63
51
|
if (event.type == 0 && event.member) {
|
|
64
52
|
const e = {
|
|
@@ -68,6 +56,7 @@ var index = () => {
|
|
|
68
56
|
// guild
|
|
69
57
|
GuildId: event.guild_id,
|
|
70
58
|
ChannelId: event.channel_id,
|
|
59
|
+
SpaceId: event.channel_id,
|
|
71
60
|
// user
|
|
72
61
|
UserId: UserId,
|
|
73
62
|
UserKey,
|
|
@@ -75,10 +64,10 @@ var index = () => {
|
|
|
75
64
|
UserAvatar: UserAvatar,
|
|
76
65
|
IsMaster: isMaster,
|
|
77
66
|
IsBot: false,
|
|
67
|
+
OpenId: UserId,
|
|
78
68
|
// message
|
|
79
69
|
MessageId: event.id,
|
|
80
70
|
MessageText: msg,
|
|
81
|
-
OpenId: '',
|
|
82
71
|
CreateAt: Date.now(),
|
|
83
72
|
// other
|
|
84
73
|
tag: 'message.create',
|
|
@@ -92,9 +81,6 @@ var index = () => {
|
|
|
92
81
|
name: 'private.message.create',
|
|
93
82
|
// 事件类型
|
|
94
83
|
Platform: platform,
|
|
95
|
-
// guild
|
|
96
|
-
// GuildId: event.guild_id,
|
|
97
|
-
// ChannelId: event.channel_id,
|
|
98
84
|
// user
|
|
99
85
|
UserId: UserId,
|
|
100
86
|
UserKey,
|
|
@@ -102,10 +88,10 @@ var index = () => {
|
|
|
102
88
|
UserAvatar: UserAvatar,
|
|
103
89
|
IsMaster: isMaster,
|
|
104
90
|
IsBot: false,
|
|
91
|
+
OpenId: UserId,
|
|
105
92
|
// message
|
|
106
93
|
MessageId: event.id,
|
|
107
94
|
MessageText: msg,
|
|
108
|
-
OpenId: '',
|
|
109
95
|
CreateAt: Date.now(),
|
|
110
96
|
// other
|
|
111
97
|
tag: 'private.message.create',
|
|
@@ -116,18 +102,12 @@ var index = () => {
|
|
|
116
102
|
else ;
|
|
117
103
|
});
|
|
118
104
|
client.on('INTERACTION_CREATE', event => {
|
|
119
|
-
console.log('event', event);
|
|
120
105
|
const isPrivate = typeof event['user'] === 'object' ? true : false;
|
|
121
106
|
const user = isPrivate ? event['user'] : event['member'].user;
|
|
122
107
|
const UserId = user.id;
|
|
123
|
-
const UserKey = useUserHashKey({
|
|
124
|
-
Platform: platform,
|
|
125
|
-
UserId: UserId
|
|
126
|
-
});
|
|
127
108
|
const UserAvatar = createUserAvatar(UserId, user.avatar);
|
|
128
109
|
const UserName = user.username;
|
|
129
|
-
const
|
|
130
|
-
const isMaster = master_key.includes(UserKey);
|
|
110
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
131
111
|
const MessageText = event.data.custom_id;
|
|
132
112
|
if (isPrivate) {
|
|
133
113
|
// 处理消息
|
|
@@ -135,9 +115,6 @@ var index = () => {
|
|
|
135
115
|
name: 'private.interaction.create',
|
|
136
116
|
// 事件类型
|
|
137
117
|
Platform: platform,
|
|
138
|
-
// guild
|
|
139
|
-
// GuildId: event['guild_id'],
|
|
140
|
-
// ChannelId: event.channel_id,
|
|
141
118
|
// user
|
|
142
119
|
UserId: UserId,
|
|
143
120
|
UserKey,
|
|
@@ -145,10 +122,10 @@ var index = () => {
|
|
|
145
122
|
UserAvatar: UserAvatar,
|
|
146
123
|
IsMaster: isMaster,
|
|
147
124
|
IsBot: false,
|
|
125
|
+
OpenId: UserId,
|
|
148
126
|
// message
|
|
149
127
|
MessageId: event.id,
|
|
150
128
|
MessageText: MessageText,
|
|
151
|
-
OpenId: '',
|
|
152
129
|
CreateAt: Date.now(),
|
|
153
130
|
// other
|
|
154
131
|
tag: 'private.interaction.create',
|
|
@@ -164,6 +141,7 @@ var index = () => {
|
|
|
164
141
|
// guild
|
|
165
142
|
GuildId: event['guild_id'],
|
|
166
143
|
ChannelId: event.channel_id,
|
|
144
|
+
SpaceId: event.channel_id,
|
|
167
145
|
// user
|
|
168
146
|
UserId: UserId,
|
|
169
147
|
UserKey,
|
|
@@ -174,7 +152,7 @@ var index = () => {
|
|
|
174
152
|
// message
|
|
175
153
|
MessageId: event.id,
|
|
176
154
|
MessageText: MessageText,
|
|
177
|
-
OpenId:
|
|
155
|
+
OpenId: UserId,
|
|
178
156
|
CreateAt: Date.now(),
|
|
179
157
|
// other
|
|
180
158
|
tag: 'interaction.create',
|
|
@@ -189,62 +167,62 @@ var index = () => {
|
|
|
189
167
|
const api = {
|
|
190
168
|
active: {
|
|
191
169
|
send: {
|
|
192
|
-
channel: (
|
|
193
|
-
|
|
170
|
+
channel: async (UserId, val) => {
|
|
171
|
+
const res = await sendchannel(client, { channel_id: UserId }, val);
|
|
172
|
+
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
194
173
|
},
|
|
195
|
-
user: async (
|
|
196
|
-
|
|
174
|
+
user: async (OpenId, val) => {
|
|
175
|
+
const res = await senduser(client, { author_id: OpenId }, val);
|
|
176
|
+
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
197
177
|
}
|
|
198
178
|
}
|
|
199
179
|
},
|
|
200
180
|
use: {
|
|
201
181
|
send: async (event, val) => {
|
|
202
182
|
if (val.length < 0) {
|
|
203
|
-
return
|
|
183
|
+
return [];
|
|
204
184
|
}
|
|
205
185
|
const tag = event.tag;
|
|
206
186
|
if (tag == 'message.create') {
|
|
207
187
|
const ChannelId = event.value.channel_id;
|
|
208
|
-
|
|
188
|
+
const res = await sendchannel(client, { channel_id: ChannelId }, val);
|
|
189
|
+
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
209
190
|
}
|
|
210
191
|
else if (tag == 'private.message.create') {
|
|
211
192
|
const UserId = event.value.author.id;
|
|
212
193
|
const ChannelId = event.value.channel_id;
|
|
213
|
-
|
|
194
|
+
const res = await senduser(client, {
|
|
214
195
|
channel_id: ChannelId,
|
|
215
196
|
author_id: UserId
|
|
216
197
|
}, val);
|
|
198
|
+
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
217
199
|
}
|
|
218
200
|
else if (tag == 'interaction.create') {
|
|
219
201
|
const ChannelId = event.value.channel_id;
|
|
220
|
-
|
|
202
|
+
const res = await sendchannel(client, { channel_id: ChannelId }, val);
|
|
203
|
+
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
221
204
|
}
|
|
222
205
|
else if (tag == 'private.interaction.create') {
|
|
223
206
|
const UserId = event.value.user.id;
|
|
224
207
|
const ChannelId = event.value.channel_id;
|
|
225
|
-
|
|
208
|
+
const res = await senduser(client, {
|
|
226
209
|
channel_id: ChannelId,
|
|
227
210
|
author_id: UserId
|
|
228
211
|
}, val);
|
|
212
|
+
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
229
213
|
}
|
|
230
|
-
return
|
|
214
|
+
return [];
|
|
231
215
|
},
|
|
232
216
|
mention: async (e) => {
|
|
233
217
|
const event = e.value;
|
|
234
218
|
const MessageMention = event.mentions.map(item => {
|
|
235
219
|
const UserId = item.id;
|
|
236
220
|
const avatar = event.author.avatar;
|
|
237
|
-
const value = getConfigValue();
|
|
238
|
-
const config = value?.discord;
|
|
239
|
-
const master_key = config?.master_key ?? [];
|
|
240
221
|
const UserAvatar = createUserAvatar(UserId, avatar);
|
|
241
|
-
const UserKey =
|
|
242
|
-
Platform: platform,
|
|
243
|
-
UserId: UserId
|
|
244
|
-
});
|
|
222
|
+
const [isMaster, UserKey] = getMaster(UserId);
|
|
245
223
|
return {
|
|
246
224
|
UserId: item.id,
|
|
247
|
-
IsMaster:
|
|
225
|
+
IsMaster: isMaster,
|
|
248
226
|
IsBot: item.bot,
|
|
249
227
|
UserAvatar,
|
|
250
228
|
UserKey
|
|
@@ -276,7 +254,16 @@ var index = () => {
|
|
|
276
254
|
else if (data.action === 'mention.get') {
|
|
277
255
|
const event = data.payload.event;
|
|
278
256
|
const res = await api.use.mention(event);
|
|
279
|
-
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)]);
|
|
280
267
|
}
|
|
281
268
|
});
|
|
282
269
|
};
|