Finish initial test case for n?ani

master
Kit Kasune 4 years ago
parent 88aea7682e
commit 42a938717b
  1. 48
      commands/anime.js
  2. 1
      eee
  3. 5
      models/anime.js
  4. 33
      util/pagination.d.ts
  5. 86
      util/pagination.js

@ -1,5 +1,5 @@
import {TagFilter} from "../util/tagfilter"; const {TagFilter} = require("../util/tagfilter");
import {Tag} from "../util/tag"; const {Tag} = require ("../util/tag");
const Discord = require('discord.js'); const Discord = require('discord.js');
const UserData = require('../models/user'); const UserData = require('../models/user');
@ -17,16 +17,52 @@ module.exports = {
let queue = false; let queue = false;
if (['a', 'add', 'n', 'new'].includes(args[0])) { if (['a', 'add', 'n', 'new'].includes(args[0])) {
let tu = await UserData.findOne({uid: message.author.id}); 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!"); await message.channel.send("Since you aren't a Natsuki Staff member, this anime will be __submitted__ for reviewal!");
queue = true; queue = true;
} }
let options = new TagFilter([ let options = new TagFilter([
new Tag(['ask', 'question'], 'ask', 'toggle'), new Tag(['ask', 'question'], 'ask', 'toggle'),
new Tag(['title', 't', 'name', 'n'], 'name', 'append'), new Tag(['title', 't', 'name', 'n'], 'name', 'append'),
new Tag(['description', 'desc', 'd', 'plot', 'p'], 'plot', 'append') new Tag(['japname', 'japanesename', 'jn'], 'japname', 'listAppend'),
//new Tag(['']) 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()
);
} }
} }
}; };

1
eee

@ -1 +0,0 @@
testing

@ -6,7 +6,7 @@ const AniSchema = new mongoose.Schema({
japname: String, japname: String,
plot: String, plot: String,
publishers: [String], publishers: [String],
studio: [String], studios: [String],
airStartDate: Date, airStartDate: Date,
airEndDate: Date, airEndDate: Date,
isComplete: Boolean, isComplete: Boolean,
@ -19,7 +19,8 @@ const AniSchema = new mongoose.Schema({
watchers: Number, watchers: Number,
listed: Number, listed: Number,
liked: Number, liked: Number,
rating: Number rating: Number,
lastUpdate: Date
}); });
module.exports = mongoose.model('anime', AniSchema); module.exports = mongoose.model('anime', AniSchema);

@ -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 {};

@ -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;
Loading…
Cancel
Save