@alemonjs/bubble 2.1.0-alpha.13 → 2.1.0-alpha.14
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/send.js +42 -8
- package/package.json +1 -1
package/lib/send.js
CHANGED
|
@@ -59,7 +59,20 @@ const sendToRoom = async (client, param, val) => {
|
|
|
59
59
|
}
|
|
60
60
|
const item = images[i];
|
|
61
61
|
if (item.type === 'Image') {
|
|
62
|
-
|
|
62
|
+
if (item.value.startsWith('http://') || item.value.startsWith('https://')) {
|
|
63
|
+
const res = await ImageURLToBuffer(item.value);
|
|
64
|
+
bufferData = res;
|
|
65
|
+
}
|
|
66
|
+
else if (item.value.startsWith('buffer://')) {
|
|
67
|
+
const base64Str = item.value.replace('buffer://', '');
|
|
68
|
+
bufferData = Buffer.from(base64Str, 'base64');
|
|
69
|
+
}
|
|
70
|
+
else if (item.value.startsWith('file://')) {
|
|
71
|
+
bufferData = readFileSync(item.value);
|
|
72
|
+
}
|
|
73
|
+
else if (Buffer.isBuffer(item.value)) {
|
|
74
|
+
bufferData = item.value;
|
|
75
|
+
}
|
|
63
76
|
}
|
|
64
77
|
else if (item.type === 'ImageURL') {
|
|
65
78
|
const res = await ImageURLToBuffer(item.value);
|
|
@@ -95,7 +108,7 @@ const sendToRoom = async (client, param, val) => {
|
|
|
95
108
|
let contentMd = '';
|
|
96
109
|
if (mdAndButtons && mdAndButtons.length > 0) {
|
|
97
110
|
mdAndButtons.forEach(item => {
|
|
98
|
-
if (item.type === 'Markdown') {
|
|
111
|
+
if (item.type === 'Markdown' && typeof item.value !== 'string') {
|
|
99
112
|
const md = item.value;
|
|
100
113
|
const map = {
|
|
101
114
|
'MD.title': value => `# ${value}`,
|
|
@@ -109,12 +122,33 @@ const sendToRoom = async (client, param, val) => {
|
|
|
109
122
|
'MD.blockquote': value => `\n> ${value}`,
|
|
110
123
|
'MD.newline': () => '\n',
|
|
111
124
|
'MD.link': value => `[🔗${value.text}](${value.url}) `,
|
|
112
|
-
'MD.image': value => `\n\n
|
|
125
|
+
'MD.image': value => `\n\n`,
|
|
126
|
+
'MD.mention': (value, options) => {
|
|
127
|
+
const { belong } = options || {};
|
|
128
|
+
if (value === 'everyone' || value === 'all' || value === '' || typeof value !== 'string') {
|
|
129
|
+
return '<@everyone> ';
|
|
130
|
+
}
|
|
131
|
+
if (belong === 'user') {
|
|
132
|
+
return `<@${value}> `;
|
|
133
|
+
}
|
|
134
|
+
else if (belong === 'channel') {
|
|
135
|
+
return `<#${value}> `;
|
|
136
|
+
}
|
|
137
|
+
return '';
|
|
138
|
+
},
|
|
139
|
+
'MD.button': (value, options) => {
|
|
140
|
+
const autoEnter = options?.autoEnter ?? false;
|
|
141
|
+
const label = typeof value === 'object' ? value.title : value;
|
|
142
|
+
const command = options?.data || label;
|
|
143
|
+
return `<btn variant="borderless" command="${command}" enter="${String(autoEnter)}" >${label}</btn> `;
|
|
144
|
+
},
|
|
145
|
+
'MD.content': value => `${value}`
|
|
113
146
|
};
|
|
114
147
|
md.forEach(line => {
|
|
115
148
|
if (map[line.type]) {
|
|
116
|
-
const value = line?.value;
|
|
117
|
-
|
|
149
|
+
const value = (line)?.value;
|
|
150
|
+
const options = (line)?.options;
|
|
151
|
+
contentMd += map[line.type](value, options);
|
|
118
152
|
return;
|
|
119
153
|
}
|
|
120
154
|
if (line.type === 'MD.list') {
|
|
@@ -136,7 +170,7 @@ const sendToRoom = async (client, param, val) => {
|
|
|
136
170
|
}
|
|
137
171
|
});
|
|
138
172
|
}
|
|
139
|
-
else if (item.type === 'BT.group' && item.value.length > 0) {
|
|
173
|
+
else if (item.type === 'BT.group' && item.value.length > 0 && typeof item.value !== 'string') {
|
|
140
174
|
contentMd += `<box classWind="mt-2" variant="borderless" >${item.value
|
|
141
175
|
?.map(row => {
|
|
142
176
|
const val = row.value;
|
|
@@ -145,10 +179,10 @@ const sendToRoom = async (client, param, val) => {
|
|
|
145
179
|
}
|
|
146
180
|
return `<flex>${val
|
|
147
181
|
.map(button => {
|
|
148
|
-
const value = button
|
|
182
|
+
const value = button?.value || {};
|
|
149
183
|
const options = button.options;
|
|
150
184
|
const autoEnter = options?.autoEnter ?? false;
|
|
151
|
-
const label =
|
|
185
|
+
const label = value;
|
|
152
186
|
const command = options?.data || label;
|
|
153
187
|
return `<btn command="${command}" enter="${String(autoEnter)}" >${label}</btn>`;
|
|
154
188
|
})
|