@alemonjs/kook 0.0.1 → 0.0.2

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/lib/index.d.ts CHANGED
@@ -1,9 +1,5 @@
1
- import { ConfigType } from 'alemonjs';
1
+ import * as alemonjs from 'alemonjs';
2
2
 
3
- /**
4
- *
5
- * @param val
6
- */
7
- declare const login: (config: ConfigType) => void;
3
+ declare const _default: (_: alemonjs.ConfigType) => typeof global.alemonjs;
8
4
 
9
- export { login };
5
+ export { _default as default };
package/lib/index.js CHANGED
@@ -1,11 +1,7 @@
1
- import { Text, At, OnProcessor, useParse } from 'alemonjs';
1
+ import { defineBot, Text, At, OnProcessor, useParse } from 'alemonjs';
2
2
  import { KOOKClient } from 'chat-space';
3
3
 
4
- /**
5
- *
6
- * @param val
7
- */
8
- const login = (config) => {
4
+ var index = defineBot(config => {
9
5
  // 创建客户端
10
6
  const client = new KOOKClient({
11
7
  token: config.token
@@ -98,45 +94,40 @@ const login = (config) => {
98
94
  client.on('ERROR', msg => {
99
95
  console.error(msg);
100
96
  });
101
- /**
102
- * 开始实现全局接口
103
- */
104
- if (!global?.alemonjs) {
105
- global.alemonjs = {
106
- api: {
107
- use: {
108
- send: (event, val) => {
109
- if (val.length < 0)
110
- return;
111
- const content = useParse(val, 'Text');
112
- if (content) {
113
- return client.createMessage({
114
- type: 9,
97
+ return {
98
+ api: {
99
+ use: {
100
+ send: (event, val) => {
101
+ if (val.length < 0)
102
+ return Promise.all([]);
103
+ const content = useParse(val, 'Text');
104
+ if (content) {
105
+ return Promise.all([content].map(item => client.createMessage({
106
+ type: 9,
107
+ target_id: event.ChannelId,
108
+ content: item
109
+ })));
110
+ }
111
+ const images = useParse(val, 'Image');
112
+ if (images) {
113
+ return Promise.all(images.map(async (item) => {
114
+ // 上传图片
115
+ const res = await client.postImage(item);
116
+ if (!res)
117
+ return Promise.resolve();
118
+ // 发送消息
119
+ return await client.createMessage({
120
+ type: 2,
115
121
  target_id: event.ChannelId,
116
- content: content
122
+ content: res.data.url
117
123
  });
118
- }
119
- const images = useParse(val, 'Image');
120
- if (images) {
121
- return Promise.all(images.map(async (item) => {
122
- // 上传图片
123
- const res = await client.postImage(item);
124
- if (!res)
125
- return Promise.resolve();
126
- // 发送消息
127
- return await client.createMessage({
128
- type: 2,
129
- target_id: event.ChannelId,
130
- content: res.data.url
131
- });
132
- }));
133
- }
134
- return Promise.resolve();
124
+ }));
135
125
  }
126
+ return Promise.all([]);
136
127
  }
137
128
  }
138
- };
139
- }
140
- };
129
+ }
130
+ };
131
+ });
141
132
 
142
- export { login };
133
+ export { index as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alemonjs/kook",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "啊柠檬脚本",
5
5
  "author": "ningmengchongshui",
6
6
  "license": "MIT",