diff --git a/commands/help.js b/commands/help.js index 2939d31..454d7c2 100644 --- a/commands/help.js +++ b/commands/help.js @@ -1,14 +1,16 @@ const Discord = require("discord.js"); +const {Pagination} = require('../util/pagination'); + module.exports = { name: "help", aliases: ["h", "commands", "cmds"], help: 'you silly! What did you expect me to respond with?', - execute(message, msg, args, cmd, prefix, mention, client) { + async execute(message, msg, args, cmd, prefix, mention, client) { if (!args.length) { - + return message.channel.send("Heya! My help command is currently under construction since my devs are hard at work on my commands and they haven't released me to the full public yet! Consider yourself lucky..."); } else { - var command; + let command; if (client.commands.has(args[0])) {command = client.commands.get(args[0]);} else if (client.aliases.has(args[0])) {command = client.commands.get(client.aliases.get(args[0]));} else {return message.reply("I don't have that command! Try using `" + prefix + "help` to get a list of my commands");} diff --git a/commands/logs.js b/commands/logs.js index ae33f3b..1d558ca 100644 --- a/commands/logs.js +++ b/commands/logs.js @@ -60,7 +60,7 @@ module.exports = { tl.save(); if (!client.guildconfig.logs.has(message.guild.id)) {client.guildconfig.logs.set(message.guild.id, new Map());} client.guildconfig.logs.get(message.guild.id).set(lt, ch.id); - return message.channel.send("Log settings updated!"); + return message.channel.send("Log settings updated!") } if (['l', 'list'].includes(args[0].toLowerCase())) { diff --git a/util/pagination.d.ts b/util/pagination.d.ts index 8517714..6b1c5a9 100644 --- a/util/pagination.d.ts +++ b/util/pagination.d.ts @@ -1,33 +1,15 @@ -import { MessageEmbed, Message, Client } from 'discord.js'; +import { TextChannel, Message, MessageEmbed, Client } from 'discord.js'; export declare class Pagination { - title: string; - pages: Page[]; - zeroPage: Page | MessageEmbed; - pageTemplate: MessageEmbed; + channel: TextChannel; message: Message; - timeout: Number; - description: string; - activationMessage: Message; + pages: MessageEmbed[]; + originalMessage: Message; + currentPage: number; client: Client; - currentpos: number; - constructor(title: string, pages: Page[], zeroPage: Page | MessageEmbed, client: Client, message: Message, activationMessage: Message, timeout: number, description?: string, pageTemplate?: MessageEmbed); - addPage(page: Page): Pagination; - render(pos: number): Pagination; - nextPage(): Pagination; - prevPage(): Pagination; - destroy(delmsg?: boolean, fmsg?: Message): Pagination; - resetTimeout(newTimeout?: number): Pagination; - init(): Pagination; + constructor(channel: TextChannel, pages: MessageEmbed[], originalMessage: Message, client: Client, message?: Message); + setPage(page: number): Promise; + nextPage(): Promise; + prevPage(): Promise; + addPage(page: MessageEmbed): Pagination; + replacePage(index: number, page: MessageEmbed): Pagination; } -export declare class Page { - items: PageItem[]; - title: string; - description: string; - constructor(title: string, items: PageItem[], description?: string); - addItem(item: PageItem): Page; -} -interface PageItem { - title: string; - text: string; -} -export {}; diff --git a/util/pagination.js b/util/pagination.js index bbb8044..08d5209 100644 --- a/util/pagination.js +++ b/util/pagination.js @@ -1,86 +1,60 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.Page = exports.Pagination = void 0; -const discord_js_1 = require("discord.js"); +exports.Pagination = void 0; class Pagination { - constructor(title, pages, zeroPage, client, message, activationMessage, timeout, description, pageTemplate) { - this.currentpos = 0; - this.title = title; + constructor(channel, pages, originalMessage, client, message) { + this.channel = channel; this.pages = pages; - this.zeroPage = zeroPage; - this.message = message; - this.timeout = timeout; - this.activationMessage = activationMessage; + this.originalMessage = message; this.client = client; - this.description = description ? description : `Requested by ${activationMessage.guild ? activationMessage.member.displayName : activationMessage.author.username}.`; - this.pageTemplate = pageTemplate - ? pageTemplate - : new discord_js_1.MessageEmbed() - .setDescription(this.description) - .addField('Navigation', `Click or tap the arrows below this message to navigate through the pages!\n\n*This menu will timeout in ${this.timeout}ms.`) - .setColor('c375f0') - .setFooter('Natsuki', this.client.user.avatarURL()) - .setTimestamp(); - } - ; - addPage(page) { - this.pages.push(page); - return this; + this.currentPage = 0; + if (message) { + this.message = message; + } } ; - render(pos) { - let page = this.pages[this.currentpos]; - let pageEmbed = new discord_js_1.MessageEmbed() - .setTitle(`${this.title} -> ${page.title}`) - .setDescription(`${this.pageTemplate.description ? this.pageTemplate.description : this.description}\n\n${page.description}`) - .setColor(this.pageTemplate.hexColor ? this.pageTemplate.hexColor : 'c375f0') - .setFooter(this.pageTemplate.footer ? `${this.pageTemplate.footer.text} | Page ${this.currentpos + 1} of ${this.pages.length}` : `Natsuki | Page ${this.currentpos + 1} of ${this.pages.length}`) - .setTimestamp(); - let item; - for (item of page.items) { - pageEmbed.addField(item.title, item.text); + async setPage(page) { + if (this.pages.length < page + 1) { } + if (!this.message) { + let tempm = await this.channel.send("One moment...") + .catch(() => { this.originalMessage.reply("There seemed to be a problem doing that..."); return this; }); + if (tempm instanceof Pagination) { + return this; + } + else { + this.message = tempm; + } } - if (this.pageTemplate.thumbnail) { - pageEmbed.setThumbnail(this.pageTemplate.thumbnail.url); - } - this.message.edit(pageEmbed); + await this.message.edit(this.pages[page] + .setFooter(`Natsuki | Page ${page + 1} of ${this.pages.length}`, this.client.user.avatarURL()) + .setTimestamp()); + this.currentPage = page; return this; } ; - nextPage() { - return this.render(this.currentpos < (this.pages.length - 1) ? this.currentpos + 1 : this.currentpos); - } - ; - prevPage() { - return this.render(this.currentpos > 0 ? this.currentpos - 1 : this.currentpos); - } - ; - destroy(delmsg, fmsg) { + async nextPage() { + await this.setPage(typeof this.currentPage === "number" ? this.currentPage + 1 == this.pages.length ? this.currentPage : this.currentPage + 1 : 0); return this; } ; - resetTimeout(newTimeout) { + async prevPage() { + await this.setPage(typeof this.currentPage === "number" ? this.currentPage === 0 ? 0 : this.currentPage - 1 : this.pages.length - 1); return this; } ; - init() { + addPage(page) { + this.pages.push(page); return this; } - ; -} -exports.Pagination = Pagination; -class Page { - constructor(title, items, description) { - this.items = []; - this.title = title; - this.items = items; - this.description = description; - } - ; - addItem(item) { - this.items.push(item); + replacePage(index, page) { + if (index < 0) { + throw new RangeError("replacePage() param 'index' must be a value greater than 0"); + } + if (index > this.pages.length - 1) { + throw new RangeError("replacePage() param 'index' must be a value corresponding to an index that already exists in this instance's pages."); + } + this.pages[index] = page; return this; } - ; } -exports.Page = Page; +exports.Pagination = Pagination; diff --git a/util/ts/pagination.ts b/util/ts/pagination.ts index 14b1ada..7062b1c 100644 --- a/util/ts/pagination.ts +++ b/util/ts/pagination.ts @@ -1,119 +1,66 @@ -import {MessageEmbed, Message, Client} from 'discord.js'; - -import wait = require('../../util/wait'); +import {TextChannel, Message, MessageEmbed, Client} from 'discord.js'; export class Pagination { - title: string; - pages: Page[]; - zeroPage: Page | MessageEmbed; - pageTemplate: MessageEmbed; + channel: TextChannel; message: Message; - timeout: Number; - description: string; - activationMessage: Message; + pages: MessageEmbed[]; + originalMessage: Message; + currentPage: number; client: Client; - currentpos: number = 0; - - constructor (title: string, pages: Page[], zeroPage: Page | MessageEmbed, client: Client, message: Message, activationMessage: Message, timeout: number, description?: string, pageTemplate?: MessageEmbed) { - this.title = title; - let tpages = []; - tpages.push(zeroPage); - let tpage: Page; for (tpage of pages) {tpages.push(tpage);} - this.pages = tpages; - - this.zeroPage = zeroPage; - this.message = message; - this.timeout = timeout; - this.activationMessage = activationMessage; + constructor (channel: TextChannel, pages: MessageEmbed[], originalMessage: Message, client: Client, message?: Message) { + this.channel = channel; + this.pages = pages; + this.originalMessage = message; this.client = client; + this.currentPage = 0; - this.description = description ? description : `Requested by ${activationMessage.guild ? activationMessage.member.displayName : activationMessage.author.username}.`; - - this.pageTemplate = pageTemplate - ? pageTemplate - : new MessageEmbed() - .setDescription(this.description) - .addField('Navigation', `Click or tap the arrows below this message to navigate through the pages!\n\n*This menu will timeout in ${this.timeout}ms.`) - .setColor('c375f0') - .setFooter('Natsuki', this.client.user.avatarURL()) - .setTimestamp(); + if (message) {this.message = message;} }; - - - public addPage(page: Page): Pagination { - this.pages.push(page); - return this; - }; - public render(pos: number): Pagination { - let page = this.pages[this.currentpos]; - let pageEmbed: MessageEmbed = new MessageEmbed() - .setTitle(`${this.title} -> ${page.title}`) - .setDescription(`${this.pageTemplate.description ? this.pageTemplate.description : this.description}\n\n${page.description}`) - .setColor(this.pageTemplate.hexColor ? this.pageTemplate.hexColor : 'c375f0') - .setFooter(this.pageTemplate.footer ? `${this.pageTemplate.footer.text} | Page ${this.currentpos + 1} of ${this.pages.length}` : `Natsuki | Page ${this.currentpos + 1} of ${this.pages.length}`) - .setTimestamp(); - let item: PageItem; for (item of page.items) {pageEmbed.addField(item.title, item.text);} - if (this.pageTemplate.thumbnail) {pageEmbed.setThumbnail(this.pageTemplate.thumbnail.url);} - - this.message.edit(pageEmbed); - return this; - }; + public async setPage(page: number): Promise { + if (this.pages.length < page + 1) {} - public nextPage(): Pagination { - return this.render(this.currentpos < (this.pages.length - 1) ? this.currentpos + 1 : this.currentpos); - }; + if (!this.message) { + let tempm = await this.channel.send("One moment...") + .catch(() => {this.originalMessage.reply("There seemed to be a problem doing that..."); return this;}); + if (tempm instanceof Pagination) {return this;} + else {this.message = tempm;} + } - public prevPage(): Pagination { - return this.render(this.currentpos > 0 ? this.currentpos - 1 : this.currentpos); - }; + await this.message.edit(this.pages[page] + .setFooter(`Natsuki | Page ${page + 1} of ${this.pages.length}`, this.client.user.avatarURL()) + .setTimestamp() + ); + this.currentPage = page; - public destroy(delmsg?: boolean, fmsg?: Message): Pagination { return this; }; - public resetTimeout(newTimeout?: number): Pagination { + public async nextPage(): Promise { + await this.setPage(typeof this.currentPage === "number" ? this.currentPage + 1 == this.pages.length ? this.currentPage : this.currentPage + 1 : 0); return this; }; - public init(): Pagination { - - + public async prevPage(): Promise { + await this.setPage(typeof this.currentPage === "number" ? this.currentPage === 0 ? 0 : this.currentPage - 1 : this.pages.length - 1); return this; }; -} - - - -export class Page { - items: PageItem[] = []; - title: string; - description: string; - - - - constructor(title: string, items: PageItem[], description?: string) { - this.title = title; - this.items = items; - this.description = description; - }; - - - - public addItem(item: PageItem): Page { - this.items.push(item); + public addPage(page: MessageEmbed): Pagination { + this.pages.push(page); return this; - }; + } -} + public replacePage(index: number, page: MessageEmbed): Pagination { + if (index < 0) {throw new RangeError("replacePage() param 'index' must be a value greater than 0");} + if (index > this.pages.length - 1) {throw new RangeError("replacePage() param 'index' must be a value corresponding to an index that already exists in this instance's pages.");} -interface PageItem { - title: string, - text: string + this.pages[index] = page; + return this; + } } \ No newline at end of file