@alemonjs/bubble 2.1.0-alpha.15 → 2.1.0-alpha.17

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/hook.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { EventKeys, Events } from 'alemonjs';
2
- import { BubbleAPI as API } from './sdk/api';
3
2
  type MAP = {
4
3
  'message.create': object;
5
4
  'private.message.create': object;
@@ -21,5 +20,30 @@ type MAP = {
21
20
  'private.guild.add': undefined;
22
21
  };
23
22
  export declare const useValue: <T extends EventKeys>(event: Events[T]) => readonly [MAP[T]];
24
- export declare const useClient: <T extends EventKeys>(event: Events[T]) => readonly [API, MAP[T]];
23
+ export declare const useClient: <T extends EventKeys>(event: Events[T]) => readonly [{
24
+ request: (options: import("axios").AxiosRequestConfig<any>) => Promise<import("alemonjs").Result<any>>;
25
+ getMe: () => Promise<import("alemonjs").Result<import(".").BotInfo>>;
26
+ sendMessage: (channelId: string | number, data: import(".").SendMessagePayload) => Promise<import("alemonjs").Result<import(".").BaseMessage>>;
27
+ getChannelMessages: (channelId: string | number) => Promise<import("alemonjs").Result<import(".").BaseMessage[]>>;
28
+ editMessage: (channelId: string | number, messageId: string | number, data: Partial<import(".").SendMessagePayload>) => Promise<import("alemonjs").Result<import(".").BaseMessage>>;
29
+ deleteMessage: (channelId: string | number, messageId: string | number) => Promise<import("alemonjs").Result<void>>;
30
+ listGuildChannels: (guildId: string | number) => Promise<import("alemonjs").Result<import(".").Channel[]>>;
31
+ getChannel: (channelId: string | number) => Promise<import("alemonjs").Result<import(".").Channel>>;
32
+ listGuildMembers: (guildId: string | number) => Promise<import("alemonjs").Result<import(".").User[]>>;
33
+ getGuildMember: (guildId: string | number, userId: string | number) => Promise<import("alemonjs").Result<import(".").User>>;
34
+ getOrCreateDm: (userId: string | number) => Promise<import("alemonjs").Result<{
35
+ id: number;
36
+ type: string;
37
+ }>>;
38
+ sendDm: (threadId: string | number, data: import(".").SendMessagePayload) => Promise<import("alemonjs").Result<import(".").BaseMessage>>;
39
+ getDmMessages: (threadId: string | number) => Promise<import("alemonjs").Result<import(".").BaseMessage[]>>;
40
+ uploadFile: (file: any, filename?: string, extra?: {
41
+ channelId?: string | number;
42
+ threadId?: string | number;
43
+ messageId?: string | number;
44
+ }) => Promise<import("alemonjs").Result<{
45
+ data: import(".").FileUploadResponse;
46
+ }>>;
47
+ filesQuota: () => Promise<import("alemonjs").Result<import(".").FileQuota>>;
48
+ }, MAP[T]];
25
49
  export {};
package/lib/index.js CHANGED
@@ -14,13 +14,13 @@ const main = () => {
14
14
  const client = new BubbleClient();
15
15
  void client.connect();
16
16
  const createUserAvatar = (_UserId, avatar) => {
17
- if (avatar) {
17
+ if (!avatar) {
18
18
  return '';
19
19
  }
20
20
  return `${CDN_URL}/${avatar}`;
21
21
  };
22
22
  client.on('MESSAGE_CREATE', event => {
23
- if (event.author?.is_bot) {
23
+ if (event.author?.is_bot || event.author?.isBot) {
24
24
  return;
25
25
  }
26
26
  const atUsers = [];
@@ -94,7 +94,7 @@ const main = () => {
94
94
  },
95
95
  use: {
96
96
  send: async (event, val) => {
97
- if (val.length < 0) {
97
+ if (!val || val.length <= 0) {
98
98
  return [];
99
99
  }
100
100
  const tag = event.tag;
@@ -117,9 +117,9 @@ const main = () => {
117
117
  },
118
118
  mention: e => {
119
119
  const event = e.value;
120
- const MessageMention = event.mentions.map(item => {
120
+ const MessageMention = (event.mentions || []).map(item => {
121
121
  const UserId = item.id;
122
- const avatar = event.author?.avatar;
122
+ const avatar = item.avatar;
123
123
  const UserAvatar = createUserAvatar(UserId, avatar);
124
124
  const [isMaster, UserKey] = getMaster(UserId);
125
125
  return {
@@ -79,15 +79,15 @@ const loggerError = err => {
79
79
  message: err?.message
80
80
  });
81
81
  };
82
- const createAxiosInstance = (service, options) => {
83
- return new Promise((resolve, reject) => {
84
- service(options)
85
- .then(res => resolve(res?.data ?? {}))
86
- .catch(err => {
87
- loggerError(err);
88
- reject(err?.response?.data);
89
- });
90
- });
82
+ const createAxiosInstance = async (service, options) => {
83
+ try {
84
+ const res = await service(options);
85
+ return res?.data ?? {};
86
+ }
87
+ catch (err) {
88
+ loggerError(err);
89
+ throw err?.response?.data ?? err;
90
+ }
91
91
  };
92
92
 
93
93
  export { createAxiosInstance };
@@ -35,6 +35,7 @@ export interface BaseMessage {
35
35
  authorId?: string | number;
36
36
  author: {
37
37
  id: number;
38
+ isBot?: boolean;
38
39
  is_bot?: boolean;
39
40
  avatar?: string | null;
40
41
  username: string;
package/lib/send.js CHANGED
@@ -71,7 +71,7 @@ const sendToRoom = async (client, param, val) => {
71
71
  bufferData = Buffer.from(base64Str, 'base64');
72
72
  }
73
73
  else if (item.value.startsWith('file://')) {
74
- bufferData = readFileSync(item.value);
74
+ bufferData = readFileSync(item.value.slice(7));
75
75
  }
76
76
  }
77
77
  else if (item.type === 'ImageURL') {
@@ -158,7 +158,7 @@ const sendToRoom = async (client, param, val) => {
158
158
  }
159
159
  return `\n- ${listItem.value}`;
160
160
  });
161
- contentMd += `${listStr}\n`;
161
+ contentMd += `${listStr.join('')}\n`;
162
162
  }
163
163
  else if (line.type === 'MD.code') {
164
164
  const language = line?.options?.language || '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alemonjs/bubble",
3
- "version": "2.1.0-alpha.15",
3
+ "version": "2.1.0-alpha.17",
4
4
  "description": "bubble platform",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",
@@ -65,4 +65,4 @@
65
65
  "type": "git",
66
66
  "url": "https://github.com/lemonade-lab/alemonjs.git"
67
67
  }
68
- }
68
+ }