Initial commit

This commit is contained in:
TheEssem 2019-09-13 15:02:41 -05:00
commit c33a86eb4c
132 changed files with 5860 additions and 0 deletions

View file

@ -0,0 +1,36 @@
// eris doesn't come with an awaitMessages method by default, so we make our own
const EventEmitter = require("events").EventEmitter;
class MessageCollector extends EventEmitter {
constructor(channel, filter, options = {}) {
super();
this.filter = filter;
this.channel = channel;
this.options = options;
this.ended = false;
this.collected = [];
this.bot = channel.guild ? channel.guild.shard.client : channel._client;
this.listener = message => this.verify(message);
this.bot.on("messageCreate", this.listener);
if (options.time) setTimeout(() => this.stop("time"), options.time);
}
verify(message) {
if (this.channel.id !== message.channel.id) return false;
if (this.filter(message)) {
this.collected.push(message);
this.emit("message", message);
if (this.collected.length >= this.options.maxMatches) this.stop("maxMatches");
return true;
}
return false;
}
stop(reason) {
if (this.ended) return;
this.ended = true;
this.bot.removeListener("messageCreate", this.listener);
this.emit("end", this.collected, reason);
}
}
module.exports = MessageCollector;

View file

@ -0,0 +1,36 @@
// eris doesn't come with an awaitReactions method by default, so we make our own
const EventEmitter = require("events").EventEmitter;
class ReactionCollector extends EventEmitter {
constructor(message, filter, options = {}) {
super();
this.filter = filter;
this.message = message;
this.options = options;
this.ended = false;
this.collected = [];
this.bot = message.channel.guild ? message.channel.guild.shard.client : message.channel._client;
this.listener = (message, emoji, userID) => this.verify(message, emoji, userID);
this.bot.on("messageReactionAdd", this.listener);
if (options.time) setTimeout(() => this.stop("time"), options.time);
}
verify(message, emoji, userID) {
if (this.message.id !== message.id) return false;
if (this.filter(message, emoji, userID)) {
this.collected.push({ message: message, emoji: emoji, userID: userID });
this.emit("reaction", message, emoji, userID);
if (this.collected.length >= this.options.maxMatches) this.stop("maxMatches");
return true;
}
return false;
}
stop(reason) {
if (this.ended) return;
this.ended = true;
this.bot.removeListener("messageReactionAdd", this.listener);
this.emit("end", this.collected, reason);
}
}
module.exports = ReactionCollector;

View file

@ -0,0 +1,49 @@
const ReactionCollector = require("./awaitreactions.js");
const MessageCollector = require("./awaitmessages.js");
const client = require("../client.js");
const paginationEmbed = async (message, pages, timeout = 120000) => {
let page = 0;
pages[page].embed.footer.text = `Page ${page + 1} of ${pages.length}`;
const currentPage = await message.channel.createMessage(pages[page]);
const emojiList = ["◀", "🔢", "▶", "🗑"];
for (const emoji of emojiList) {
await currentPage.addReaction(emoji);
}
const reactionCollector = new ReactionCollector(currentPage, (message, reaction, user) => emojiList.includes(reaction.name) && !client.users.get(user).bot, { time: timeout });
reactionCollector.on("reaction", (msg, reaction) => {
//reaction.users.remove(msg.author);
//const reactionAuthor = currentPage.getReactions();
switch (reaction.name) {
case "◀":
page = page > 0 ? --page : pages.length - 1;
pages[page].embed.footer.text = `Page ${page + 1} of ${pages.length}`;
currentPage.edit(pages[page]);
break;
case "🔢":
message.channel.createMessage(`${message.author.mention}, what page do you want to jump to?`).then(askMessage => {
const messageCollector = new MessageCollector(askMessage.channel, (response) => response.author.id === message.author.id && !isNaN(response.content) && Number(response.content) <= pages.length, { time: timeout, maxMatches: 1 });
return messageCollector.on("message", response => {
askMessage.delete();
page = Number(response.content) - 1;
pages[page].embed.footer.text = `Page ${page + 1} of ${pages.length}`;
currentPage.edit(pages[page]);
});
}).catch(error => { if (error) console.error; });
break;
case "▶":
page = page + 1 < pages.length ? ++page : 0;
pages[page].embed.footer.text = `Page ${page + 1} of ${pages.length}`;
currentPage.edit(pages[page]);
break;
case "🗑":
currentPage.delete();
return;
default:
break;
}
});
reactionCollector.on("end", () => currentPage.removeReactions());
return currentPage;
};
module.exports = paginationEmbed;