2020-12-27 12:57:35 +00:00
|
|
|
const Discord = require('discord.js');
|
|
|
|
const fs = require('fs').promises;
|
|
|
|
|
2021-02-13 14:35:24 +00:00
|
|
|
const events = require('events');
|
|
|
|
const shutEmitter = new events.EventEmitter();
|
|
|
|
|
2020-12-27 12:57:35 +00:00
|
|
|
module.exports.meta = {
|
|
|
|
name: 'copypasta',
|
|
|
|
aliases: ['pasta'],
|
|
|
|
staffOnly: false,
|
|
|
|
epicOnly: true
|
|
|
|
}
|
|
|
|
|
2020-12-27 12:59:54 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {Discord.Message} message
|
|
|
|
* @param {Array<string>} args
|
|
|
|
*/
|
2020-12-27 12:57:35 +00:00
|
|
|
module.exports.run = async (message, args) => {
|
|
|
|
let copypastas = await fs.readdir(__dirname + '/copypastas');
|
|
|
|
let pasta = copypastas.find((p) => p.toLowerCase() == args[0]?.toLowerCase());
|
|
|
|
|
|
|
|
if (!pasta) {
|
|
|
|
message.channel.send(`Please choose one of: \`${copypastas.join('`, `')}\``);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let lines = (await fs.readFile(__dirname + '/copypastas/' + pasta))
|
|
|
|
.toString('utf-8')
|
2021-02-13 14:35:24 +00:00
|
|
|
.split('\n')
|
|
|
|
.filter(line => line.trim() != '');
|
2020-12-27 12:57:35 +00:00
|
|
|
|
2021-02-13 14:35:24 +00:00
|
|
|
this.copypastaing[message.channel.id] = true;
|
|
|
|
|
|
|
|
sendLine();
|
2021-02-13 14:50:55 +00:00
|
|
|
const interval = setInterval(sendLine, 1500);
|
2021-02-13 14:35:24 +00:00
|
|
|
const listener = shutEmitter.once('shut', cid => {
|
|
|
|
if (cid == message.channel.id) {
|
|
|
|
clearInterval(interval);
|
|
|
|
this.copypastaing[message.channel.id] = false;
|
|
|
|
}
|
2020-12-27 12:57:35 +00:00
|
|
|
});
|
2021-02-13 14:35:24 +00:00
|
|
|
|
|
|
|
async function sendLine() {
|
|
|
|
if (lines.length == 0) {
|
|
|
|
this.copypastaing[message.channel.id] = false;
|
|
|
|
clearTimeout(interval);
|
|
|
|
shutEmitter.removeListener('shut', listener);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const line = lines.shift();
|
|
|
|
await message.channel.send(line, { tts: true });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.shut = (channelID) => {
|
|
|
|
shutEmitter.emit('shut', channelID);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.copypastaing = {}
|