Added 2 Anilist Commands

pull/51/head
Trivernis 6 years ago
parent 0223180053
commit 08dcf2f084

@ -1,4 +1,5 @@
const cmdLib = require('../../../CommandLib'), const cmdLib = require('../../CommandLib'),
anilistApi = require('../../api/AnilistApi'),
yaml = require('js-yaml'), yaml = require('js-yaml'),
fsx = require('fs-extra'), fsx = require('fs-extra'),
templateFile = 'AniListCommandsTemplate.yaml'; templateFile = 'AniListCommandsTemplate.yaml';
@ -44,13 +45,53 @@ class RichMediaInfo extends cmdLib.ExtendedRichEmbed {
let template = null; let template = null;
/**
* Initializes the module.
* @returns {Promise<void>}
*/
async function init() { async function init() {
let templateString = fsx.readFile(templateFile, {encoding: 'utf-8'}); let templateString = await fsx.readFile(templateFile, {encoding: 'utf-8'});
template = yaml.safeLoad(templateString); template = yaml.safeLoad(templateString);
} }
/**
* Registers the commands to the CommandHandler.
* @param commandHandler {cmdLib.CommandHandler}
* @returns {Promise<void>}
*/
async function register(commandHandler) {
// creating commands
let animeSearch = new cmdLib.Command(
template.anime_search,
new cmdLib.Answer(async (m, k, s) => {
try {
let animeData = await anilistApi.searchAnimeByName(s);
return new RichMediaInfo(animeData);
} catch (err) {
return template.anime_search.not_found;
}
}));
let mangaSearch = new cmdLib.Command(
template.manga_search,
new cmdLib.Answer(async (m, k, s) => {
try {
let mangaData = await anilistApi.searchMangaByName(s);
return new RichMediaInfo(mangaData);
} catch (err) {
return template.manga_search.not_found;
}
})
);
// registering commands
commandHandler.registerCommand(template.anime_search.name, animeSearch);
commandHandler.registerCommand(template.manga_search.name, mangaSearch);
}
// -- exports -- // // -- exports -- //
Object.assign(exports, { Object.assign(exports, {
init: init init: init,
register: register
}); });

@ -0,0 +1,23 @@
anime_search:
name: anime
permission: all
usage: anime [search query]
description: >
Searches AniList.co for the anime Title and returns information about
it if there is an result.
category: AniList
response:
not_found: >
I couldn't find the anime you were searching for :(
manga_search:
name: manga
permission: all
usage: manga [search query]
description: >
Searches AniList.co for the manga Title and returns information about
it if there is an result.
category: AniList
response:
not_found: >
I couldn't find the manga you were searching for :(
Loading…
Cancel
Save