Add response to no arg n?help and finish base pagination class

master
Kit Kasune 4 years ago
parent bfd2a168ff
commit ab34712dec
  1. 8
      commands/help.js
  2. 2
      commands/logs.js
  3. 40
      util/pagination.d.ts
  4. 94
      util/pagination.js
  5. 125
      util/ts/pagination.ts

@ -1,14 +1,16 @@
const Discord = require("discord.js"); const Discord = require("discord.js");
const {Pagination} = require('../util/pagination');
module.exports = { module.exports = {
name: "help", name: "help",
aliases: ["h", "commands", "cmds"], aliases: ["h", "commands", "cmds"],
help: 'you silly! What did you expect me to respond with?', 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) { 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 { } else {
var command; let command;
if (client.commands.has(args[0])) {command = client.commands.get(args[0]);} 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 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");} else {return message.reply("I don't have that command! Try using `" + prefix + "help` to get a list of my commands");}

@ -60,7 +60,7 @@ module.exports = {
tl.save(); tl.save();
if (!client.guildconfig.logs.has(message.guild.id)) {client.guildconfig.logs.set(message.guild.id, new Map());} 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); 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())) { if (['l', 'list'].includes(args[0].toLowerCase())) {

@ -1,33 +1,15 @@
import { MessageEmbed, Message, Client } from 'discord.js'; import { TextChannel, Message, MessageEmbed, Client } from 'discord.js';
export declare class Pagination { export declare class Pagination {
title: string; channel: TextChannel;
pages: Page[];
zeroPage: Page | MessageEmbed;
pageTemplate: MessageEmbed;
message: Message; message: Message;
timeout: Number; pages: MessageEmbed[];
description: string; originalMessage: Message;
activationMessage: Message; currentPage: number;
client: Client; client: Client;
currentpos: number; constructor(channel: TextChannel, pages: MessageEmbed[], originalMessage: Message, client: Client, message?: Message);
constructor(title: string, pages: Page[], zeroPage: Page | MessageEmbed, client: Client, message: Message, activationMessage: Message, timeout: number, description?: string, pageTemplate?: MessageEmbed); setPage(page: number): Promise<Pagination>;
addPage(page: Page): Pagination; nextPage(): Promise<Pagination>;
render(pos: number): Pagination; prevPage(): Promise<Pagination>;
nextPage(): Pagination; addPage(page: MessageEmbed): Pagination;
prevPage(): Pagination; replacePage(index: number, page: MessageEmbed): Pagination;
destroy(delmsg?: boolean, fmsg?: Message): Pagination;
resetTimeout(newTimeout?: number): Pagination;
init(): 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 {};

@ -1,86 +1,60 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.Page = exports.Pagination = void 0; exports.Pagination = void 0;
const discord_js_1 = require("discord.js");
class Pagination { class Pagination {
constructor(title, pages, zeroPage, client, message, activationMessage, timeout, description, pageTemplate) { constructor(channel, pages, originalMessage, client, message) {
this.currentpos = 0; this.channel = channel;
this.title = title;
this.pages = pages; this.pages = pages;
this.zeroPage = zeroPage; this.originalMessage = message;
this.message = message;
this.timeout = timeout;
this.activationMessage = activationMessage;
this.client = client; this.client = client;
this.description = description ? description : `Requested by ${activationMessage.guild ? activationMessage.member.displayName : activationMessage.author.username}.`; this.currentPage = 0;
this.pageTemplate = pageTemplate if (message) {
? pageTemplate this.message = message;
: 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) { async setPage(page) {
this.pages.push(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; return this;
} }
; else {
render(pos) { this.message = tempm;
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);
} }
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; return this;
} }
; ;
nextPage() { async nextPage() {
return this.render(this.currentpos < (this.pages.length - 1) ? this.currentpos + 1 : this.currentpos); await this.setPage(typeof this.currentPage === "number" ? this.currentPage + 1 == this.pages.length ? this.currentPage : this.currentPage + 1 : 0);
}
;
prevPage() {
return this.render(this.currentpos > 0 ? this.currentpos - 1 : this.currentpos);
}
;
destroy(delmsg, fmsg) {
return this; 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; return this;
} }
; ;
init() { addPage(page) {
this.pages.push(page);
return this; return this;
} }
; replacePage(index, page) {
} if (index < 0) {
exports.Pagination = Pagination; throw new RangeError("replacePage() param 'index' must be a value greater than 0");
class Page {
constructor(title, items, description) {
this.items = [];
this.title = title;
this.items = items;
this.description = description;
} }
; if (index > this.pages.length - 1) {
addItem(item) { throw new RangeError("replacePage() param 'index' must be a value corresponding to an index that already exists in this instance's pages.");
this.items.push(item); }
this.pages[index] = page;
return this; return this;
} }
;
} }
exports.Page = Page; exports.Pagination = Pagination;

@ -1,119 +1,66 @@
import {MessageEmbed, Message, Client} from 'discord.js'; import {TextChannel, Message, MessageEmbed, Client} from 'discord.js';
import wait = require('../../util/wait');
export class Pagination { export class Pagination {
title: string; channel: TextChannel;
pages: Page[];
zeroPage: Page | MessageEmbed;
pageTemplate: MessageEmbed;
message: Message; message: Message;
timeout: Number; pages: MessageEmbed[];
description: string; originalMessage: Message;
activationMessage: Message; currentPage: number;
client: Client; 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 = []; constructor (channel: TextChannel, pages: MessageEmbed[], originalMessage: Message, client: Client, message?: Message) {
tpages.push(zeroPage); this.channel = channel;
let tpage: Page; for (tpage of pages) {tpages.push(tpage);} this.pages = pages;
this.pages = tpages; this.originalMessage = message;
this.zeroPage = zeroPage;
this.message = message;
this.timeout = timeout;
this.activationMessage = activationMessage;
this.client = client; this.client = client;
this.currentPage = 0;
this.description = description ? description : `Requested by ${activationMessage.guild ? activationMessage.member.displayName : activationMessage.author.username}.`; if (message) {this.message = message;}
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();
}; };
public addPage(page: Page): Pagination { public async setPage(page: number): Promise<Pagination> {
this.pages.push(page); if (this.pages.length < page + 1) {}
return this;
};
public render(pos: number): Pagination { if (!this.message) {
let page = this.pages[this.currentpos]; let tempm = await this.channel.send("One moment...")
let pageEmbed: MessageEmbed = new MessageEmbed() .catch(() => {this.originalMessage.reply("There seemed to be a problem doing that..."); return this;});
.setTitle(`${this.title} -> ${page.title}`) if (tempm instanceof Pagination) {return this;}
.setDescription(`${this.pageTemplate.description ? this.pageTemplate.description : this.description}\n\n${page.description}`) else {this.message = tempm;}
.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); 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; return this;
}; };
public nextPage(): Pagination { public async nextPage(): Promise<Pagination> {
return this.render(this.currentpos < (this.pages.length - 1) ? this.currentpos + 1 : this.currentpos); await this.setPage(typeof this.currentPage === "number" ? this.currentPage + 1 == this.pages.length ? this.currentPage : this.currentPage + 1 : 0);
};
public prevPage(): Pagination {
return this.render(this.currentpos > 0 ? this.currentpos - 1 : this.currentpos);
};
public destroy(delmsg?: boolean, fmsg?: Message): Pagination {
return this; return this;
}; };
public resetTimeout(newTimeout?: number): Pagination { public async prevPage(): Promise<Pagination> {
await this.setPage(typeof this.currentPage === "number" ? this.currentPage === 0 ? 0 : this.currentPage - 1 : this.pages.length - 1);
return this; return this;
}; };
public init(): Pagination { public addPage(page: MessageEmbed): Pagination {
this.pages.push(page);
return this; 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 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.");}
this.pages[index] = page;
public addItem(item: PageItem): Page {
this.items.push(item);
return this; return this;
}; }
}
interface PageItem {
title: string,
text: string
} }
Loading…
Cancel
Save