ref: create separated verifyUserInput function (#34)
Co-authored-by: Aidan <aidan@p0ntus.com> Co-authored-by: Lucas Gabriel <lucmsilva651@gmail.com>
This commit is contained in:
parent
e252a97696
commit
12ca87f4fe
4 changed files with 30 additions and 41 deletions
|
@ -3,6 +3,7 @@ const { getStrings } = require('../plugins/checklang.js');
|
|||
const { isOnSpamWatch } = require('../spamwatch/spamwatch.js');
|
||||
const spamwatchMiddleware = require('../spamwatch/Middleware.js')(isOnSpamWatch);
|
||||
const axios = require("axios");
|
||||
const { verifyInput } = require('../plugins/verifyInput.js');
|
||||
|
||||
function capitalizeFirstLetter(string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
|
@ -22,14 +23,11 @@ module.exports = (bot) => {
|
|||
bot.command("mlpchar", spamwatchMiddleware, async (ctx) => {
|
||||
const Strings = getStrings(ctx.from.language_code);
|
||||
const userInput = ctx.message.text.split(' ').slice(1).join(' ').replace(" ", "+");
|
||||
const { noCharName } = Strings.ponyApi
|
||||
|
||||
if (!userInput) {
|
||||
ctx.reply(Strings.ponyApi.noCharName, {
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
});
|
||||
if (verifyInput(ctx, userInput, noCharName)) {
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
const capitalizedInput = capitalizeFirstLetter(userInput);
|
||||
const apiUrl = `${Resources.ponyApi}/character/${capitalizedInput}`;
|
||||
|
@ -98,13 +96,11 @@ module.exports = (bot) => {
|
|||
const Strings = getStrings(ctx.from.language_code);
|
||||
const userInput = ctx.message.text.split(' ').slice(1).join(' ').replace(" ", "+");
|
||||
|
||||
if (!userInput) {
|
||||
ctx.reply(Strings.ponyApi.noEpisodeNum, {
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
});
|
||||
const { noEpisodeNum } = Strings.ponyApi
|
||||
|
||||
if (verifyInput(ctx, userInput, noEpisodeNum, true)) {
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
const apiUrl = `${Resources.ponyApi}/episode/by-overall/${userInput}`;
|
||||
|
||||
|
@ -167,11 +163,9 @@ module.exports = (bot) => {
|
|||
const Strings = getStrings(ctx.from.language_code);
|
||||
const userInput = ctx.message.text.split(' ').slice(1).join(' ').replace(" ", "+");
|
||||
|
||||
if (!userInput) {
|
||||
ctx.reply(Strings.ponyApi.noComicName, {
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
});
|
||||
const { noComicName } = Strings.ponyApi
|
||||
|
||||
if (verifyInput(ctx, userInput, noComicName)) {
|
||||
return;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue