Added error reporting functionality, fixed bugs in the various game's code and tidied up a bit

This commit is contained in:
ION606
2022-07-19 15:41:49 +03:00
parent 4e1214a312
commit 0b13f6db29
13 changed files with 259 additions and 79 deletions
+10 -2
View File
@@ -13,9 +13,10 @@ module.exports = {
}
} else { name = args[0]; }
if (args[args.length - 1] != args[args.length - 1] != '~fancy' && args[args.length - 1] != '~summary' && args[args.length - 1] != '~stats') { args.push('~stats'); }
if (args[args.length - 1] != '~fancy' && args[args.length - 1] != '~summary' && args[args.length - 1] != '~stats') { args.push('~stats'); }
scraper.getInfoFromName(name).then((data) => {
//When set to true, getInfoFromName.getBestMatch did not, in fact, return the best results
scraper.getInfoFromName(name, false).then((data) => {
try {
if (args[args.length - 1] == '~stats') {
const newEmbed = new Discord.MessageEmbed()
@@ -51,7 +52,14 @@ module.exports = {
} catch (err) {
if (err.message.indexOf('MessageEmbed field values must be non-empty strings') != -1) {
message.reply(`Insufficient information on website!\nThe page can be found here: ${data.url}`);
} else {
message.reply("Uh oh, an unknown error occured, click the ✅ to report this!");
const { addComplaintButton } = require('../dev only/submitcomplaint');
addComplaintButton(bot, message);
}
console.log(err);
}
});
+47 -30
View File
@@ -6,6 +6,8 @@ module.exports = {
description: 'Selmer bot gives you info on a manga',
async execute(message, args, Discord, Client, bot) {
if (args.length < 1) { return message.reply("Please specify a manga!"); }
if (args[args.length - 1] != '~fancy' && args[args.length - 1] != '~summary' && args[args.length - 1] != '~stats') { args.push('~stats'); }
let name = "";
if (args.length > 1) {
let i = 0;
@@ -16,37 +18,52 @@ module.exports = {
}
let cmd = args[args.length - 1];
search.search(type, {
maxResults: 1,
term: name
}).then((data1) => {
let data = data1[0];
if (cmd == "~stats") {
const newEmbed = new Discord.MessageEmbed()
.setColor('#ff9900')
.setTitle(data.title)
.setURL(data.url)
.setImage(data.thumbnail)
//.setDescription('My professional resume')
.addFields(
{name: 'Type:', value: data.type},
{name: 'Score:', value: data.score},
{name: 'Volumes:', value: data.vols}
);
message.channel.send({ embeds: [newEmbed] });
} else if (cmd == "~fancy") {
let temp = `The ${data.type} _${data.title}_ currently has ${data.vols} volumes with ${data.nbChapters} chapters, `;
temp += `running from _${data.startDate.replace(/-/g, "/")}_ to _${data.endDate.replace(/-/g, "/")}_, and has a score of ${data.score} on MyAnimeList!\n`;
temp += `You can read more about _${data.title}_ at ${data.url}`;
message.channel.send(temp);
} else if (cmd == "~summary") {
//Remove the "read more." at the end
let temp = data.shortDescription.slice(0, -10);
temp += ` _read more at_ ${data.url}`;
return message.channel.send(temp);
try {
search.search(type, {
maxResults: 1,
term: name
}).then((data1) => {
let data = data1[0];
if (cmd == "~stats") {
const newEmbed = new Discord.MessageEmbed()
.setColor('#ff9900')
.setTitle(data.title)
.setURL(data.url)
.setImage(data.thumbnail)
//.setDescription('My professional resume')
.addFields(
{name: 'Type:', value: data.type},
{name: 'Score:', value: data.score},
{name: 'Volumes:', value: data.vols}
);
message.channel.send({ embeds: [newEmbed] });
} else if (cmd == "~fancy") {
let temp = `The ${data.type} _${data.title}_ currently has ${data.vols} volumes with ${data.nbChapters} chapters, `;
temp += `running from _${data.startDate.replace(/-/g, "/")}_ to _${data.endDate.replace(/-/g, "/")}_, and has a score of ${data.score} on MyAnimeList!\n`;
temp += `You can read more about _${data.title}_ at ${data.url}`;
message.channel.send(temp);
} else if (cmd == "~summary") {
//Remove the "read more." at the end
let temp = data.shortDescription.slice(0, -10);
temp += ` _read more at_ ${data.url}`;
return message.channel.send(temp);
} else {
message.reply(`Unknown command, try using the format '${bot.prefix}msearch <manga name> [~stats or ~fancy or ~summary]`);
}
});
} catch (err) {
if (err.message.indexOf('MessageEmbed field values must be non-empty strings') != -1) {
message.reply(`Insufficient information on website!\nThe page can be found here: ${data.url}`);
} else {
message.reply("Uh oh, an unknown error occured, click the ✅ to report this!");
const { addComplaintButton } = require('../dev only/submitcomplaint');
addComplaintButton(bot, message);
}
});
console.log(err);
}
}
}