k44Eqha/lib/DiscordMessageSender.js

40 lines
904 B
JavaScript
Raw Normal View History

2022-01-06 03:12:13 +01:00
module.exports = class DiscordMessageSender {
constructor(channel) {
this.channel = channel;
this.interval = setInterval(this.flush.bind(this), 3000);
}
//async init() {
// var webhooks = await this.channel.fetchWebhooks();
// this.webhook = webhooks.filter(w => w.token).first() || await this.channel.createWebhook("sdfadffg");
// this.interval = setInterval(this.flush.bind(this), 3000);
//}
send(text) {
this.pp ||= {content: ""};
this.pp.content += text + '\n';
}
sendEmbed(embed) {
this.pp ||= {};
this.pp.embeds = [embed];
this.flush();
}
flush() {
if (!this.pp) return;
var pp = this.pp;
delete this.pp;
2023-10-11 00:54:34 +02:00
if (pp.content?.length > 2000) {
2022-01-06 03:15:28 +01:00
pp.files = [{name: "message.txt", attachment: Buffer.from(pp.content)}];
2022-01-06 03:12:13 +01:00
delete pp.content;
}
//this.webhook.send(pp).catch(error => {
//handleError(error, "webhook");
this.channel.send(pp);
//});
}
2023-10-11 00:54:34 +02:00
}