From 42a938717b1c4d19f5942dbd2c8066b76be58780 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Sat, 24 Oct 2020 04:35:05 -0600 Subject: [PATCH] Finish initial test case for n?ani --- commands/anime.js | 48 +++++++++++++++++++++---- eee | 1 - models/anime.js | 5 +-- util/pagination.d.ts | 33 +++++++++++++++++ util/pagination.js | 86 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 164 insertions(+), 9 deletions(-) delete mode 100644 eee create mode 100644 util/pagination.d.ts create mode 100644 util/pagination.js diff --git a/commands/anime.js b/commands/anime.js index c4ccd8e..ad9edf0 100644 --- a/commands/anime.js +++ b/commands/anime.js @@ -1,5 +1,5 @@ -import {TagFilter} from "../util/tagfilter"; -import {Tag} from "../util/tag"; +const {TagFilter} = require("../util/tagfilter"); +const {Tag} = require ("../util/tag"); const Discord = require('discord.js'); const UserData = require('../models/user'); @@ -17,16 +17,52 @@ module.exports = { let queue = false; if (['a', 'add', 'n', 'new'].includes(args[0])) { let tu = await UserData.findOne({uid: message.author.id}); - if (!tu || tu.staff) { + if (!tu || !tu.staff) { await message.channel.send("Since you aren't a Natsuki Staff member, this anime will be __submitted__ for reviewal!"); queue = true; } let options = new TagFilter([ new Tag(['ask', 'question'], 'ask', 'toggle'), new Tag(['title', 't', 'name', 'n'], 'name', 'append'), - new Tag(['description', 'desc', 'd', 'plot', 'p'], 'plot', 'append') - //new Tag(['']) - ]); + new Tag(['japname', 'japanesename', 'jn'], 'japname', 'listAppend'), + new Tag(['description', 'desc', 'd', 'plot', 'p'], 'plot', 'append'), + new Tag(['pub', 'pubs', 'publishers', 'publisher', 'pb'], 'publishers', 'listAppend'), + new Tag(['stud', 's', 'studio', 'studs', 'studios'], 'studios', 'listAppend'), + new Tag(['began', 'airstart', 'as'], 'airStartDate', 'append'), + new Tag(['ended', 'airend', 'ae'], 'airEndDate', 'append'), + new Tag(['iscomplete', 'completed', 'ic'], 'isComplete', 'toggle'), + new Tag(['seasons', 'sns'], 'seasons', 'append'), + new Tag(['episodes', 'es'], 'episodes', 'append'), + new Tag(['genres', 'g'], 'genres', 'listAppend'), + new Tag(['tags', 'ta', 'tgs', 'tg', 'tag'], 'tags', 'listAppend'), + new Tag(['cs', 'characters', 'chars', 'chs'], 'characters', 'listAppend'), + new Tag(['streams', 'streamat', 'sa'], 'streamAt', 'listAppend') + ]).test(args.join(' ')); + + var foptions = {}; + let option; for (option of Object.keys(options)) { + if (Array.isArray(options[option])) { + let s = ''; + let data; + for (data of options[option]) { + s += data; + s += options[option].indexOf(data) < (options[option].length - 1) ? ', ' : ''; + } + foptions[option] = s; + } + } + + message.channel.send(new Discord.MessageEmbed() + .setTitle(`New Anime -> ${options.name}`) + .setDescription(`${queue ? 'Requested' : 'Added'} by ${message.guild ? message.member.displayName : message.author.username}`) + .addField('Info', `**Name:** ${options.name}\n**Japanese Name:** ${options.japname}\n\n**Publishers:** ${foptions.publishers}\n**Studios:** ${foptions.studios}`) + .addField('Length', `**# of Seasons:** ${options.seasons}\n**# of Episodes:** ${options.episodes}`) + .addField('Airing', `**Began:** ${options.airStartDate}\n**Ended:** ${options.isComplete ? options.airEndDate : 'This anime is still airing!'}`) + .addField('Other', `**Genre(s):** ${foptions.genres}\n**Tags:** ${foptions.tags}\n**Characters:** ${foptions.characters}\n**Stream this at:** ${foptions.streamAt}`) + .setColor("c375f0") + .setFooter('Natsuki', client.user.avatarURL()) + .setTimestamp() + ); } } }; \ No newline at end of file diff --git a/eee b/eee deleted file mode 100644 index 038d718..0000000 --- a/eee +++ /dev/null @@ -1 +0,0 @@ -testing diff --git a/models/anime.js b/models/anime.js index bab2440..44226e9 100644 --- a/models/anime.js +++ b/models/anime.js @@ -6,7 +6,7 @@ const AniSchema = new mongoose.Schema({ japname: String, plot: String, publishers: [String], - studio: [String], + studios: [String], airStartDate: Date, airEndDate: Date, isComplete: Boolean, @@ -19,7 +19,8 @@ const AniSchema = new mongoose.Schema({ watchers: Number, listed: Number, liked: Number, - rating: Number + rating: Number, + lastUpdate: Date }); module.exports = mongoose.model('anime', AniSchema); \ No newline at end of file diff --git a/util/pagination.d.ts b/util/pagination.d.ts new file mode 100644 index 0000000..8517714 --- /dev/null +++ b/util/pagination.d.ts @@ -0,0 +1,33 @@ +import { MessageEmbed, Message, Client } from 'discord.js'; +export declare class Pagination { + title: string; + pages: Page[]; + zeroPage: Page | MessageEmbed; + pageTemplate: MessageEmbed; + message: Message; + timeout: Number; + description: string; + activationMessage: Message; + 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; +} +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 new file mode 100644 index 0000000..bbb8044 --- /dev/null +++ b/util/pagination.js @@ -0,0 +1,86 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Page = exports.Pagination = void 0; +const discord_js_1 = require("discord.js"); +class Pagination { + constructor(title, pages, zeroPage, client, message, activationMessage, timeout, description, pageTemplate) { + this.currentpos = 0; + this.title = title; + this.pages = pages; + this.zeroPage = zeroPage; + this.message = message; + this.timeout = timeout; + this.activationMessage = activationMessage; + 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; + } + ; + 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); + } + if (this.pageTemplate.thumbnail) { + pageEmbed.setThumbnail(this.pageTemplate.thumbnail.url); + } + this.message.edit(pageEmbed); + 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) { + return this; + } + ; + resetTimeout(newTimeout) { + return this; + } + ; + init() { + 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); + return this; + } + ; +} +exports.Page = Page;