const Discord = require('discord.js'); const fs = require('fs').promises; const events = require('events'); const shutEmitter = new events.EventEmitter(); module.exports.meta = { name: 'copypasta', aliases: ['pasta'], staffOnly: false, epicOnly: true } /** * * @param {Discord.Message} message * @param {Array} args */ 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') .split('\n') .filter(line => line.trim() != ''); this.copypastaing[message.channel.id] = true; sendLine(); const interval = setInterval(sendLine, 1500); const listener = shutEmitter.once('shut', cid => { if (cid == message.channel.id) { clearInterval(interval); this.copypastaing[message.channel.id] = false; } }); 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 = {}