1
+
'use strict';
2
+
3
+
const { readFile } = require('node:fs/promises');
4
+
const { createReadStream } = require('node:fs');
5
+
const path = require('node:path');
6
+
const { setTimeout: sleep } = require('node:timers/promises');
7
+
const util = require('node:util');
8
+
const { fetch } = require('undici');
9
+
const { Client, GatewayIntentBits, AttachmentBuilder, EmbedBuilder, MessageFlags, ComponentType } = require('../src');
10
+
11
+
const client = new Client({
12
+
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent],
13
+
});
14
+
15
+
const buffer = l =>
16
+
fetch(l)
17
+
.then(res => res.arrayBuffer())
18
+
.then(Buffer.from);
19
+
20
+
const linkA = 'https://discord.js.org/static/logo.svg';
21
+
const fileA = path.join(__dirname, 'blobReach.png');
22
+
23
+
const embed = () => new EmbedBuilder();
24
+
const attach = (attachment, name) => new AttachmentBuilder(attachment, { name });
25
+
26
+
const tests = [
27
+
m => m.channel.send('x'),
28
+
29
+
m => m.channel.send({ content: 'x', embeds: [{ description: 'a' }] }),
30
+
m => m.channel.send({ embeds: [{ description: 'a' }] }),
31
+
m => m.channel.send({ files: [{ attachment: fileA }] }),
32
+
m =>
33
+
m.channel.send({
34
+
embeds: [{ description: 'a' }],
35
+
files: [{ attachment: fileA, name: 'xyz.png' }],
36
+
}),
37
+
38
+
m => m.channel.send({ content: 'x', embeds: [embed().setDescription('a')] }),
39
+
m => m.channel.send({ embeds: [embed().setDescription('a')] }),
40
+
m => m.channel.send({ embeds: [embed().setDescription('a'), embed().setDescription('b')] }),
41
+
42
+
m => m.channel.send({ content: 'x', files: [attach(fileA)] }),
43
+
m => m.channel.send({ files: [fileA] }),
44
+
m => m.channel.send({ files: [attach(fileA)] }),
45
+
async m => m.channel.send({ files: [await buffer(linkA)] }),
46
+
async m => m.channel.send({ files: [{ attachment: await buffer(linkA) }] }),
47
+
m => m.channel.send({ files: [attach(fileA), attach(fileA)] }),
48
+
49
+
m => m.channel.send({ embeds: [{ description: 'a' }] }).then(m2 => m2.edit('x')),
50
+
m => m.channel.send({ embeds: [embed().setDescription('a')] }).then(m2 => m2.edit('x')),
51
+
52
+
m => m.channel.send('x').then(m2 => m2.edit({ embeds: [{ description: 'a' }] })),
53
+
m => m.channel.send('x').then(m2 => m2.edit({ embeds: [embed().setDescription('a')] })),
54
+
55
+
m => m.channel.send({ embeds: [{ description: 'a' }] }).then(m2 => m2.edit({ content: 'x', embeds: [] })),
56
+
m => m.channel.send({ embeds: [embed().setDescription('a')] }).then(m2 => m2.edit({ content: 'x', embeds: [] })),
57
+
58
+
m => m.channel.send({ content: 'x', embeds: [embed().setDescription('a')], files: [attach(fileA)] }),
59
+
m => m.channel.send({ content: 'x', files: [attach(fileA), attach(fileA)] }),
60
+
61
+
m => m.channel.send({ embeds: [embed().setDescription('a')], files: [attach(fileA)] }),
62
+
m =>
63
+
m.channel.send({
64
+
embeds: [embed().setImage('attachment://two.png')],
65
+
files: [attach(fileA, 'two.png')],
66
+
}),
67
+
m => m.channel.send({ content: 'x', files: [attach(fileA)] }),
68
+
m => m.channel.send({ files: [fileA] }),
69
+
m => m.channel.send({ files: [attach(fileA)] }),
70
+
async m => m.channel.send({ files: [await readFile(fileA)] }),
71
+
72
+
m => m.channel.send({ content: 'x', files: [attach(createReadStream(fileA))] }),
73
+
m => m.channel.send({ files: [createReadStream(fileA)] }),
74
+
m => m.channel.send({ files: [{ attachment: createReadStream(fileA) }] }),
75
+
76
+
m => m.reply({ content: 'x', allowedMentions: { repliedUser: false } }),
77
+
m => m.reply({ content: 'x', allowedMentions: { repliedUser: true } }),
78
+
m => m.reply({ content: 'x' }),
79
+
m => m.reply({ content: `${m.author}`, allowedMentions: { repliedUser: false } }),
80
+
m => m.reply({ content: `${m.author}`, allowedMentions: { parse: ['users'], repliedUser: false } }),
81
+
m => m.reply({ content: `${m.author}`, allowedMentions: { parse: ['users'], repliedUser: true } }),
82
+
m => m.reply({ content: `${m.author}` }),
83
+
84
+
m => m.edit({ flags: MessageFlags.SuppressEmbeds }),
85
+
m => m.edit({ flags: MessageFlags.SuppressEmbeds, allowedMentions: { repliedUser: false } }),
86
+
87
+
m =>
88
+
m
89
+
.reply({ content: 'x', allowedMentions: { repliedUser: false } })
90
+
.then(msg => msg.edit({ content: 'a', allowedMentions: { repliedUser: true } })),
91
+
92
+
m =>
93
+
m.channel.send({
94
+
components: [{ type: ComponentType.TextDisplay, content: `${m.author}` }],
95
+
flags: MessageFlags.IsComponentsV2,
96
+
}),
97
+
m =>
98
+
m.channel.send({
99
+
components: [{ type: ComponentType.TextDisplay, content: `${m.author}` }],
100
+
flags: MessageFlags.IsComponentsV2,
101
+
allowedMentions: { parse: ['users'] },
102
+
}),
103
+
m =>
104
+
m.channel.send({
105
+
components: [{ type: ComponentType.TextDisplay, content: `${m.author}` }],
106
+
flags: MessageFlags.IsComponentsV2,
107
+
allowedMentions: { parse: [] },
108
+
}),
109
+
m =>
110
+
m.reply({
111
+
components: [{ type: ComponentType.TextDisplay, content: `${m.author}` }],
112
+
flags: MessageFlags.IsComponentsV2,
113
+
allowedMentions: { parse: [], repliedUser: true },
114
+
}),
115
+
m =>
116
+
m.reply({
117
+
components: [{ type: ComponentType.TextDisplay, content: `${m.author}` }],
118
+
flags: MessageFlags.IsComponentsV2,
119
+
allowedMentions: { parse: [], repliedUser: false },
120
+
}),
121
+
122
+
m => m.channel.send('Done!'),
123
+
];
124
+
125
+
client.on('messageCreate', async message => {
126
+
if (message.author.id !== process.env.OWNER) return;
127
+
const match = message.content.match(/^do (.+)$/);
128
+
if (match?.[1] === 'it') {
129
+
/* eslint-disable no-await-in-loop */
130
+
for (const [i, test] of tests.entries()) {
131
+
await message.channel.send(`**#${i}**\n\`\`\`js\n${test.toString()}\`\`\``);
132
+
await test(message).catch(e => message.channel.send(`Error!\n\`\`\`\n${e}\`\`\``));
133
+
await sleep(1_000);
134
+
}
135
+
/* eslint-enable no-await-in-loop */
136
+
} else if (match) {
137
+
const n = parseInt(match[1]) || 0;
138
+
const test = tests.slice(n)[0];
139
+
const i = tests.indexOf(test);
140
+
await message.channel.send(`**#${i}**\n\`\`\`js\n${test.toString()}\`\`\``);
141
+
await test(message).catch(e => message.channel.send(`Error!\n\`\`\`\n${e}\`\`\``));
142
+
}
143
+
});
144
+
145
+
client.login();
146
+
147
+
// eslint-disable-next-line no-console
148
+
process.on('unhandledRejection', console.error);
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4