Implemented basic AniList api features

- changed anilist query files
- added autocropping to ExtendedRichEmbed
- updated Readme
pull/51/head
Trivernis 6 years ago
parent e74fa83ed3
commit ff9d78566b

@ -63,6 +63,7 @@ At the moment the bot can...
- [x] ...log stuff in a database - [x] ...log stuff in a database
- [x] ...execute multiple commands as a sequence - [x] ...execute multiple commands as a sequence
- [x] ...save command sequences with a given name - [x] ...save command sequences with a given name
- [x] ...query AniList
- [ ] ...transform into a cow - [ ] ...transform into a cow
Presences Presences
@ -76,15 +77,19 @@ Command Sequences
A command sequence is a single message with several commands seperated by a semicolon. A command sequence is a single message with several commands seperated by a semicolon.
In a sequence the command can be ommitted if it is the same as the previous one. In a sequence the command can be ommitted if it is the same as the previous one.
That means you can add several videos to the queue and shuffle it afterwards with the sequence That means you can add several videos to the queue and shuffle it afterwards with the sequence
`~play [video1]; [video2]; [video3]; ~shuffle`. `~play [video1] && ~play [video2]; ~play [video3] && ~shuffle`.
A command sequence can be saved with `~savecmd [sequence] [commandname]`. A command sequence can be saved with `~savecmd [commandname] [sequence]`.
In this case the semicolon must be escaped with a backslash so it won't get interpreted as a seperate command. In this case the semicolon must be escaped with a backslash so it won't get interpreted as a seperate command. You can also escape sequences with `~play "whatever &&; you want"` (doublequotes). Command sequences with `&&` are executed in serial while command sequences with `;` are executed in parallel.
A saved command can be executed with `~execute [commandname]`. A saved command can be executed with `~execute [commandname]`.
References
---
You can test a running version of the bot. [Invite bot server](https://discordapp.com/oauth2/authorize?client_id=374703138575351809&scope=bot&permissions=1983380544)
Ideas Ideas
--- ---
- command replies saved in file (server specific file and global file) - command replies saved in file (server specific file and global file)
- reddit api - reddit api
- anilist api
- othercoolstuff api - othercoolstuff api

@ -226,7 +226,7 @@ class ExtendedRichEmbed extends Discord.RichEmbed {
* @returns {ExtendedRichEmbed} * @returns {ExtendedRichEmbed}
*/ */
addNonemptyField(name, content) { addNonemptyField(name, content) {
if (name && name.length > 0 && content) if (name && name.length > 0 && content && content.length > 0)
this.addField(name, content); this.addField(name, content);
return this; return this;
} }
@ -241,6 +241,29 @@ class ExtendedRichEmbed extends Discord.RichEmbed {
this.addNonemptyField(name, value); this.addNonemptyField(name, value);
return this; return this;
} }
/**
* Sets the description by shortening the value string to a fitting length for discord.
* @param value
*/
setDescription(value) {
let croppedValue = value.substring(0, 1024);
if (croppedValue.length < value.length)
croppedValue = croppedValue.replace(/\n.*$/g, '');
super.setDescription(croppedValue);
}
/**
* Sets the field by shortening the value stirn to a fitting length for discord.
* @param name
* @param value
*/
addField(name, value) {
let croppedValue = value.substring(0, 1024);
if (croppedValue.length < value.length)
croppedValue = croppedValue.replace(/\n.*$/g, '');
super.addField(name, croppedValue);
}
} }
// -- exports -- // // -- exports -- //

@ -277,7 +277,7 @@ class MusicPlayer {
} }
queue(args) { queue(args) {
let queue = this.dj.queue.map((x) => { let queue = this.musicPlayer.queue.map((x) => {
return { return {
id: generateID(['Media', x.url]), id: generateID(['Media', x.url]),
name: x.title, name: x.title,
@ -301,7 +301,7 @@ class MusicPlayer {
} }
get paused() { get paused() {
return this.musicPlayer.disp? this.dj.disp.paused : false; return this.musicPlayer.disp? this.musicPlayer.disp.paused : false;
} }
get queueCount() { get queueCount() {

@ -1,15 +1,26 @@
const fetch = require('node-fetch'), const fetch = require('node-fetch'),
fsx = require('fs-extra'), fsx = require('fs-extra'),
yaml = require('js-yaml'),
queryPath = './lib/api/graphql/AnilistApi', queryPath = './lib/api/graphql/AnilistApi',
alApiEndpoint = 'https://graphql.anilist.co'; alApiEndpoint = 'https://graphql.anilist.co';
async function getFragments() {
let fragments = await fsx.readFile(`${queryPath}/Fragments.yaml`, {encoding: 'utf-8'});
return yaml.safeLoad(fragments);
}
/** /**
* Return a graphql query read from a file from a configured path. * Return a graphql query read from a file from a configured path.
* @param name * @param name
* @returns {Promise<String>} * @returns {Promise<String>}
*/ */
async function getGraphqlQuery(name) { async function getGraphqlQuery(name) {
return await fsx.readFile(`${queryPath}/${name}.gql`, {encoding: 'utf-8'}); let query = await fsx.readFile(`${queryPath}/${name}.gql`, {encoding: 'utf-8'});
let fragments = await getFragments();
for (let [key, value] of Object.entries(fragments))
if (query.includes(`...${key}`))
query += '\n' + value;
return query;
} }
/** /**
@ -27,7 +38,7 @@ function postGraphqlQuery(queryName, queryVariables) {
'Accept': 'application/json' 'Accept': 'application/json'
}, },
body: JSON.stringify({ body: JSON.stringify({
query: await getGraphqlQuery(queryName), query: (await getGraphqlQuery(queryName)),
variables: queryVariables variables: queryVariables
}) })
}).then(async (response) => { }).then(async (response) => {
@ -39,65 +50,128 @@ function postGraphqlQuery(queryName, queryVariables) {
/** /**
* Get an anime by id. * Get an anime by id.
* @param id * @param id {Number}
* @param withStaff {Boolean} Include Staff information?
* @param withMetadata {Boolean} Include Metadata?
* @returns {Promise<JSON>} * @returns {Promise<JSON>}
*/ */
exports.getAnimeById = async function(id) { async function getAnimeById(id, withStaff, withMoreData) {
let data = await postGraphqlQuery('AnimeById', {id: id}); let data = await postGraphqlQuery('AnimeQuery',
if (data.Media) {id: id, withStaff: withStaff, withMoreData: withMoreData});
if (data && data.Media)
return data.Media; return data.Media;
else else
return null; return null;
}; }
/** /**
* Get a manga by id. * Get a manga by id.
* @param id * @param id {Number}
* @param withStaff {Boolean} Include Staff information?
* @param withMoreData {Boolean} Include Metadata?
* @returns {Promise<JSON>} * @returns {Promise<JSON>}
*/ */
exports.getMangaById = async function(id) { async function getMangaById(id, withStaff, withMoreData) {
let data = await postGraphqlQuery('MangaById', {id: id}); let data = await postGraphqlQuery('MangaQuery',
if (data.Media) {id: id, withStaff: withStaff, withMoreData: withMoreData});
if (data && data.Media)
return data.Media; return data.Media;
else else
return null; return null;
}; }
/** /**
* Search for a media entry by name and return it. * Returns a staff member by id.
* @param name * @param id {Number}
* @returns {Promise<JSON>} * @returns {Promise<*>}
*/ */
exports.searchMediaByName = async function(name) { async function getStaffById(id) {
let data = await postGraphqlQuery('MediaSearchByName', {name: name}); let data = await postGraphqlQuery('StaffQuery', {id: id});
if (data.Media) if (data && data.Staff)
return data.Media; return data.Staff;
else else
return null; return null;
}; }
/**
* Returns a character by id.
* @param id {Number}
* @returns {Promise<*>}
*/
async function getCharacterById(id) {
let data = await postGraphqlQuery('CharacterQuery', {id: id});
if (data && data.Character)
return data.Character;
else
return null;
}
/** /**
* Search for an anime by name and get it by id. * Search for an anime by name and get it by id.
* @param name * @param name {String}
* @param withStaff {Boolean} Include Staff information?
* @param withMoreData {Boolean} Include Metadata?
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
exports.searchAnimeByName = async function(name) { async function searchAnimeByName(name, withStaff, withMoreData) {
let data = await postGraphqlQuery('MediaSearchByName', {name: name, type: 'ANIME'}); let data = await postGraphqlQuery('AnimeQuery',
if (data && data.Media && data.Media.id) {name: name, withStaff: withStaff, withMoreData: withMoreData});
return await exports.getAnimeById(data.Media.id); if (data && data.Media)
return data.Media;
else else
return null; return null;
}; }
/** /**
* Search for a manga by name and get it by id. * Search for a manga by name and get it by id.
* @param name * @param name {String}
* @param withStaff {Boolean} Include Staff information?
* @param withMoreData {Boolean} Include Metadata?
* @returns {Promise<*>}
*/
async function searchMangaByName(name, withStaff, withMoreData) {
let data = await postGraphqlQuery('MangaQuery',
{name: name, withStaff: withStaff, withMoreData: withMoreData});
if (data && data.Media)
return data.Media;
else
return null;
}
/**
* Search for a staff member by name and get information.
* @param name {String} The name of the staff member
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
exports.searchMangaByName = async function(name) { async function searchStaffByName(name) {
let data = await postGraphqlQuery('MediaSearchByName', {name: name, type: 'MANGA'}); let data = await postGraphqlQuery('StaffQuery', {name: name});
if (data && data.Media && data.Media.id) if (data && data.Staff)
return await exports.getMangaById(data.Media.id); return data.Staff;
else else
return null; return null;
}; }
/**
* Seach for a character by name and get information.
* @param name {String} Character Name
* @returns {Promise<*>}
*/
async function searchCharacterByName(name) {
let data = await postGraphqlQuery('CharacterQuery', {name: name});
if (data && data.Character)
return data.Character;
else
return null;
}
// exports
Object.assign(exports, {
getAnimeById: getAnimeById,
getMangaById: getMangaById,
getStaffById: getStaffById,
getCharacterById: getCharacterById,
searchAnimeByName: searchAnimeByName,
searchMangaByName: searchMangaByName,
searchStaffByName: searchStaffByName,
searchCharacterByName: searchCharacterByName
});

@ -1,47 +0,0 @@
query ($id: Int) {
Media (id: $id, type: ANIME) {
id
title {
romaji
english
native
}
status
startDate {
year
month
day
}
endDate {
year
month
day
}
format
season
episodes
duration
genres
siteUrl
coverImage {
large
medium
color
}
description(asHtml: false)
averageScore
favourites
studios(isMain: true) {
studioList: nodes {
id
name
siteUrl
}
}
nextAiringEpisode {
id
airingAt
episode
}
}
}

@ -0,0 +1,22 @@
query AnimeData($name: String, $id: Int, $withStaff: Boolean = false, $withMoreData: Boolean = true) {
Media (id: $id, search: $name, type: ANIME) {
...mediaMetadata
...mediaAdditionalMetadata @include(if: $withMoreData)
...staffFields @include(if: $withStaff)
season @include(if: $withMoreData)
episodes @include(if: $withMoreData)
duration @include(if: $withMoreData)
studios(isMain: true) @include(if: $withMoreData) {
studioList: nodes {
id
name
siteUrl
}
}
nextAiringEpisode @include(if: $withMoreData) {
id
airingAt
episode
}
}
}

@ -0,0 +1,27 @@
query ($name: String, $id: Int) {
Character(search: $name, id: $id) {
id
name {
first
last
native
}
description
image {
large
medium
}
siteUrl
media {
edges {
characterRole
voiceActors(language: JAPANESE) {
...staffMetadata
}
node {
...mediaMetadata
}
}
}
}
}

@ -1,12 +1,27 @@
query ($id: Int) { mediaMetadata: |
Media (id: $id, type: MANGA) { fragment mediaMetadata on Media {
id id
siteUrl
title { title {
romaji romaji
english english
native native
} }
coverImage {
large
medium
color
}
}
mediaAdditionalMetadata: |
fragment mediaAdditionalMetadata on Media {
status status
description(asHtml: false)
format
genres
averageScore
favourites
startDate { startDate {
year year
month month
@ -17,19 +32,10 @@ query ($id: Int) {
month month
day day
} }
format
chapters
volumes
genres
siteUrl
coverImage {
large
medium
color
} }
staff {
edges { staffMetadata: |
node { fragment staffMetadata on Staff {
id id
name { name {
first first
@ -43,11 +49,15 @@ query ($id: Int) {
language language
siteUrl siteUrl
} }
role
staffFields: |
fragment staffFields on Media {
staff {
edges {
node {
...staffMetadata
} }
role
} }
description(asHtml: false)
averageScore
favourites
} }
} }

@ -0,0 +1,9 @@
query MangaData($name: String, $id: Int, $withStaff: Boolean = false, $withMoreData: Boolean = true) {
Media (id: $id, search: $name, type: MANGA) {
...mediaMetadata
...mediaAdditionalMetadata @include(if: $withMoreData)
...staffFields @include(if: $withStaff)
chapters @include(if: $withMoreData)
volumes @include(if: $withMoreData)
}
}

@ -1,11 +0,0 @@
query ($name: String, $type: MediaType) {
Media (search: $name, type: $type) {
id
title {
romaji
english
native
}
type
}
}

@ -0,0 +1,57 @@
query StaffData($name: String, $id: Int) {
Staff(id: $id, search: $name) {
id
name {
first
last
native
}
language
image {
large
medium
}
staffMedia(page: 0, perPage: 10) {
edges {
node {
id
title {
romaji
english
native
}
siteUrl
}
characters {
id
name {
first
last
}
siteUrl
image {
large
medium
}
}
staffRole
}
}
characters(page: 0, perPage: 10) {
nodes {
id
name {
first
last
}
siteUrl
image {
large
medium
}
}
}
description(asHtml: false)
siteUrl
}
}

@ -1,23 +1,58 @@
anime_search: anime_search:
name: anime name: alAnime
permission: all permission: all
usage: anime [search query] usage: alAnime [search query]
description: > description: >
Searches AniList.co for the anime title and returns information about Searches [AniList.co](https://anilist.co) for the anime *title* or *id* and returns information about
it if there is a result. it if there is a result. The staff members are not included because the message would grow too big.
category: AniList
response:
not_found: >
I couldn't find the anime you were searching for :(
anime_staff_search:
name: alAnimeStaff
permission: all
usage: alAnimeStaff [search query]
description: >
Searches [AniList.co](https://anilist.co) for the anime *title* or *id* and returns all staff members.
category: AniList category: AniList
response: response:
not_found: > not_found: >
I couldn't find the anime you were searching for :( I couldn't find the anime you were searching for :(
manga_search: manga_search:
name: manga name: alManga
permission: all permission: all
usage: manga [search query] usage: alManga [search query]
description: > description: >
Searches AniList.co for the manga title and returns information about Searches [AniList.co](https://anilist.co) for the manga *title* or *id* and returns information about
it if there is a result. it if there is a result.
category: AniList category: AniList
response: response:
not_found: > not_found: >
I couldn't find the manga you were searching for :( I couldn't find the manga you were searching for :(
staff_search:
name: alStaff
permission: all
usage: alStaff [search query]
description: >
Searches [AniList.co](https://anilist.co) for the staff member *name* or *id* and returns information about
the member aswell as roles in media.
category: AniList
response:
not_found: >
I couldn't find the staff member you were searching for :(
character_search:
name: alCharacter
permission: all
usage: alCharacter [search query]
description: >
Searches [AniList.co](https://anilist.co) for the character *name* or *id* and returns information about
the character aswell as media roles.
category: AniList
response:
not_found: >
I couldn't find the character member you were searching for :(

@ -2,6 +2,21 @@ const cmdLib = require('../../CommandLib'),
anilistApi = require('../../api/AnilistApi'), anilistApi = require('../../api/AnilistApi'),
location = './lib/commands/AnilistApiCommands'; location = './lib/commands/AnilistApiCommands';
/**
* Returns a string for a name.
* @param nameNode {String} The AniList name node in format {first, last, native}
*/
function getNameString(nameNode) {
let name = '';
if (nameNode.first)
name = nameNode.first;
if (nameNode.last)
name += ' ' + nameNode.last;
if (name.length === 0)
name = nameNode.native;
return name;
}
class RichMediaInfo extends cmdLib.ExtendedRichEmbed { class RichMediaInfo extends cmdLib.ExtendedRichEmbed {
/** /**
@ -10,16 +25,22 @@ class RichMediaInfo extends cmdLib.ExtendedRichEmbed {
*/ */
constructor(mediaInfo) { constructor(mediaInfo) {
super(mediaInfo.title.romaji); super(mediaInfo.title.romaji);
this.setDescription(mediaInfo.description.replace(/<\/?.*?>/g, '')) this.setThumbnail(mediaInfo.coverImage.large || mediaInfo.coverImage.medium)
.setThumbnail(mediaInfo.coverImage.large)
.setURL(mediaInfo.siteUrl) .setURL(mediaInfo.siteUrl)
.setColor(mediaInfo.coverImage.color) .setColor(mediaInfo.coverImage.color)
.setFooter('Provided by AniList.co'); .setFooter('Powered by AniList.co');
if (mediaInfo.description)
this.setDescription(mediaInfo.description
.replace(/<\/?.*?>/g, '')
.replace(/~!.*?!~/g, '')
.replace(/\n\n\n/g, ''));
let fields = { let fields = {
'Genres': mediaInfo.genres.join(' '), 'Genres': mediaInfo.genres? mediaInfo.genres.join(' ') : null,
'Studios': mediaInfo.studios? mediaInfo.studios.studioList.map(x => `[${x.name}](${x.siteUrl})`) : null, 'Studios': mediaInfo.studios? mediaInfo.studios.studioList.map(x => `[${x.name}](${x.siteUrl})`) : null,
'Scoring': `**AverageScore**: ${mediaInfo.averageScore}\n**Favourites**${mediaInfo.favourites}`, 'Scoring': mediaInfo.averageScore? `**AverageScore**: ${mediaInfo.averageScore}\n**Favourites:** ${mediaInfo.favourites}`: null,
'Episodes': mediaInfo.episodes, 'Episodes': mediaInfo.episodes,
'Volumes': mediaInfo.volumes,
'Chapters': mediaInfo.chapters,
'Duration': null, 'Duration': null,
'Season': mediaInfo.season, 'Season': mediaInfo.season,
'Status': mediaInfo.status, 'Status': mediaInfo.status,
@ -27,18 +48,109 @@ class RichMediaInfo extends cmdLib.ExtendedRichEmbed {
}; };
if (mediaInfo.duration) if (mediaInfo.duration)
fields['Episode Duration'] = `${mediaInfo.duration} min`; fields['Episode Duration'] = `${mediaInfo.duration} min`;
if (mediaInfo.startDate.day) if (mediaInfo.startDate && mediaInfo.startDate.day)
fields['Start Date'] = `${mediaInfo.startDate.day}.${mediaInfo.startDate.month}.${mediaInfo.startDate.year}`; fields['Start Date'] = `${mediaInfo.startDate.day}.${mediaInfo.startDate.month}.${mediaInfo.startDate.year}`;
if (mediaInfo.nextAiringEpisode) { if (mediaInfo.nextAiringEpisode) {
let epInfo = mediaInfo.nextAiringEpisode; let epInfo = mediaInfo.nextAiringEpisode;
fields['Next Episode'] = `**Episode** ${epInfo.episode}\n**Airing at:** ${new Date(epInfo.airingAt * 1000).toUTCString()}`; fields['Next Episode'] = `**Episode** ${epInfo.episode}\n**Airing at:** ${new Date(epInfo.airingAt * 1000).toUTCString()}`;
} }
if (mediaInfo.endDate.day) if (mediaInfo.endDate && mediaInfo.endDate.day)
fields['End Date'] = `${mediaInfo.endDate.day}.${mediaInfo.endDate.month}.${mediaInfo.endDate.year}`; fields['End Date'] = `${mediaInfo.endDate.day}.${mediaInfo.endDate.month}.${mediaInfo.endDate.year}`;
if (mediaInfo.staff && mediaInfo.staff.edges) {
let staffContent = mediaInfo.staff.edges.map((x) => {
let url = x.node.siteUrl;
let name = getNameString(x.node.name);
return `**${x.role}:** [${name}](${url})`;
});
let staffFieldValue = staffContent.join('\n');
if (staffFieldValue.length > 1024) {
let staffValues = [];
let currentValue = '';
for (let staffLine of staffContent) {
let concatValue = currentValue + '\n' + staffLine;
if (concatValue.length > 1024) {
staffValues.push(currentValue);
currentValue = staffLine;
} else {
currentValue = concatValue;
}
}
staffValues.push(currentValue);
for (let i = 0; i < staffValues.length; i++)
fields[`Staff part ${i + 1}`] = staffValues[i];
} else {
fields['Staff'] = staffFieldValue;
}
}
this.addFields(fields);
}
}
class RichStaffInfo extends cmdLib.ExtendedRichEmbed {
/**
* A Rich Embed with informatin about an AniList staff member.
* @param staffInfo
*/
constructor(staffInfo) {
super(getNameString(staffInfo.name));
this.setThumbnail(staffInfo.image.large || staffInfo.image.medium)
.setURL(staffInfo.siteUrl);
let fields = {
'Language': staffInfo.language
};
if (staffInfo.staffMedia && staffInfo.staffMedia.edges)
fields['Staff Media Roles (first 10)'] = staffInfo.staffMedia.edges.map(x => {
let node = x.node;
let title = node.title.romaji;
let url = node.siteUrl;
return `[**${title}**](${url}): ${x.staffRole}`;
}).join('\n');
if (staffInfo.characters && staffInfo.characters.nodes)
fields['Staff Character Roles (first 10)'] = staffInfo.characters.nodes.map(x => {
let name = getNameString(x.name);
let url = x.siteUrl;
return `[${name}](${url})`;
}).join('\n');
this.addFields(fields); this.addFields(fields);
} }
} }
class RichCharacterInfo extends cmdLib.ExtendedRichEmbed {
/**
* A RichEmbed with information about an AniList character.
* @param characterInfo {Object}
*/
constructor(characterInfo) {
super(getNameString(characterInfo.name));
this.setURL(characterInfo.siteUrl)
.setThumbnail(characterInfo.image.large || characterInfo.image.medium);
if (characterInfo.description)
this.setDescription(characterInfo.description
.replace(/<\/?.*?>/g, '')
.replace(/~!.*?!~/g, '')
.replace(/\n\n\n/g, ''));
if (characterInfo.media && characterInfo.media.edges)
this.addNonemptyField(
'Media Appeareance',
characterInfo.media.edges.map(x => {
let media = x.node;
let informationString = `**[${media.title.romaji}](${media.siteUrl})**: ${x.characterRole}`;
if (x.voiceActors && x.voiceActors.length > 0)
informationString += ` voice by ${x.voiceActors.map(y => {
`[${getNameString(y.name)}](${y.siteUrl})`;
}).join(', ')}`;
return informationString;
}).join('\n')
);
}
}
// -- initialize -- // // -- initialize -- //
/** /**
@ -54,38 +166,129 @@ class AniListCommandModule extends cmdLib.CommandModule {
async register(commandHandler) { async register(commandHandler) {
await this._loadTemplate(); await this._loadTemplate();
let animeSearch = new cmdLib.Command( let animeSearch = new cmdLib.Command(
this.template.anime_search, this.template.anime_search,
new cmdLib.Answer(async (m, k, s) => { new cmdLib.Answer(async (m, k, s) => {
try { try {
let animeData = await anilistApi.searchAnimeByName(s); let animeData = {};
if (/^\d+$/.test(s))
animeData = await anilistApi.getAnimeById(s, false, true);
else
animeData = await anilistApi.searchAnimeByName(s, false, true);
this._logger.silly(`Anime Query returned ${JSON.stringify(animeData)}`); this._logger.silly(`Anime Query returned ${JSON.stringify(animeData)}`);
return new RichMediaInfo(animeData); return new RichMediaInfo(animeData);
} catch (err) { } catch (err) {
if (err.message) if (err.message) {
this._logger.verbose(err.message); this._logger.verbose(err.message);
return this.template.anime_search.not_found; this._logger.silly(err.stack);
} else if (err.errors) {
this._logger.silly(`Graphql Errors ${JSON.stringify(err.errors)}`);
} }
})); return this.template.anime_search.response.not_found;
}
})
);
let animeStaffSearch = new cmdLib.Command(
this.template.anime_staff_search,
new cmdLib.Answer(async (m, k, s) => {
try {
let animeData = {};
if (/^\d+$/.test(s))
animeData = await anilistApi.getAnimeById(s, true, false);
else
animeData = await anilistApi.searchAnimeByName(s, true, false);
this._logger.silly(`Anime Query returned ${JSON.stringify(animeData)}`);
return new RichMediaInfo(animeData);
} catch (err) {
if (err.message) {
this._logger.verbose(err.message);
this._logger.silly(err.stack);
} else if (err.errors) {
this._logger.silly(`Graphql Errors ${JSON.stringify(err.errors)}`);
}
return this.template.anime_staff_search.response.not_found;
}
})
);
let mangaSearch = new cmdLib.Command( let mangaSearch = new cmdLib.Command(
this.template.manga_search, this.template.manga_search,
new cmdLib.Answer(async (m, k, s) => { new cmdLib.Answer(async (m, k, s) => {
try { try {
let mangaData = await anilistApi.searchMangaByName(s); let mangaData = {};
if (/^\d+$/.test(s))
mangaData = await anilistApi.getMangaById(s, true, true);
else
mangaData= await anilistApi.searchMangaByName(s, true, true);
this._logger.silly(`Manga Query returned ${JSON.stringify(mangaData)}`); this._logger.silly(`Manga Query returned ${JSON.stringify(mangaData)}`);
return new RichMediaInfo(mangaData); return new RichMediaInfo(mangaData);
} catch (err) { } catch (err) {
if (err.message) if (err.message) {
this._logger.verbose(err.message); this._logger.verbose(err.message);
return this.template.manga_search.not_found; this._logger.silly(err.stack);
} else if (err.errors) {
this._logger.silly(`Graphql Errors ${JSON.stringify(err.errors)}`);
}
return this.template.manga_search.response.not_found;
}
})
);
let staffSearch = new cmdLib.Command(
this.template.staff_search,
new cmdLib.Answer(async (m, k, s) => {
try {
let staffData = {};
if (/^\d+$/.test(s))
staffData = await anilistApi.getStaffById(s);
else
staffData = await anilistApi.searchStaffByName(s);
this._logger.silly(`Staff Query returned ${JSON.stringify(staffData)}`);
return new RichStaffInfo(staffData);
} catch (err) {
if (err.message) {
this._logger.verbose(err.message);
this._logger.silly(err.stack);
} else if (err.errors) {
this._logger.silly(`Graphql Errors ${JSON.stringify(err.errors)}`);
}
return this.template.staff_search.response.not_found;
}
})
);
let characterSearch = new cmdLib.Command(
this.template.character_search,
new cmdLib.Answer(async (m, k, s) => {
try {
let characterData = {};
if (/^\d+$/.test(s))
characterData = await anilistApi.getCharacterById(s);
else
characterData = await anilistApi.searchCharacterByName(s);
this._logger.silly(`Character Query returned ${JSON.stringify(characterData)}`);
return new RichCharacterInfo(characterData)
} catch (err) {
if (err.message) {
this._logger.verbose(err.message);
this._logger.silly(err.stack);
} else if (err.errors) {
this._logger.silly(`Graphql Errors ${JSON.stringify(err.errors)}`);
}
return this.template.character_search.response.not_found;
} }
}) })
); );
// registering commands // registering commands
commandHandler.registerCommand(animeSearch) commandHandler
.registerCommand(mangaSearch); .registerCommand(animeSearch)
.registerCommand(mangaSearch)
.registerCommand(staffSearch)
.registerCommand(animeStaffSearch)
.registerCommand(characterSearch);
} }
} }

@ -140,7 +140,6 @@ function queryGuildStatus(guildId) {
} }
} }
} }
config
}`; }`;
postQuery(query).then((res) => { postQuery(query).then((res) => {
let guild = res.data.client.guilds[0]; let guild = res.data.client.guilds[0];

Loading…
Cancel
Save