ref: create separated verifyUserInput function
This commit is contained in:
parent
4c02ebc265
commit
9535c69dbc
4 changed files with 30 additions and 41 deletions
|
@ -3,6 +3,7 @@ const { getStrings } = require('../plugins/checklang.js');
|
||||||
const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js');
|
const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js');
|
||||||
const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch);
|
const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch);
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
|
const { verifyInput } = require('../plugins/verifyInput.js');
|
||||||
|
|
||||||
async function getDeviceList() {
|
async function getDeviceList() {
|
||||||
try {
|
try {
|
||||||
|
@ -23,12 +24,10 @@ module.exports = (bot) => {
|
||||||
bot.command(['codename', 'whatis'], spamwatchMiddleware, async (ctx) => {
|
bot.command(['codename', 'whatis'], spamwatchMiddleware, async (ctx) => {
|
||||||
const userInput = ctx.message.text.split(" ").slice(1).join(" ");
|
const userInput = ctx.message.text.split(" ").slice(1).join(" ");
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(ctx.from.language_code);
|
||||||
|
const { noCodename } = Strings.codenameCheck
|
||||||
|
|
||||||
if (!userInput) {
|
if(verifyInput(ctx, userInput, noCodename)){
|
||||||
ctx.reply(Strings.codenameCheck.noCodename, {
|
return;
|
||||||
parse_mode: "Markdown",
|
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const jsonRes = await getDeviceList()
|
const jsonRes = await getDeviceList()
|
||||||
|
|
|
@ -3,19 +3,18 @@ const { getStrings } = require('../plugins/checklang.js');
|
||||||
const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js');
|
const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js');
|
||||||
const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch);
|
const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch);
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
|
const { verifyInput } = require('../plugins/verifyInput.js');
|
||||||
|
|
||||||
module.exports = (bot) => {
|
module.exports = (bot) => {
|
||||||
bot.command("http", spamwatchMiddleware, async (ctx) => {
|
bot.command("http", spamwatchMiddleware, async (ctx) => {
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(ctx.from.language_code);
|
||||||
const userInput = ctx.message.text.split(' ')[1];
|
const userInput = ctx.message.text.split(' ')[1];
|
||||||
const apiUrl = Resources.httpApi;
|
const apiUrl = Resources.httpApi;
|
||||||
|
const { invalidCode } = Strings.httpCodes
|
||||||
|
|
||||||
if (!userInput || isNaN(userInput)) {
|
if (verifyInput(ctx, userInput, invalidCode, true)) {
|
||||||
return ctx.reply(Strings.httpCodes.invalidCode, {
|
return;
|
||||||
parse_mode: 'Markdown',
|
}
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(apiUrl);
|
const response = await axios.get(apiUrl);
|
||||||
|
@ -50,12 +49,10 @@ module.exports = (bot) => {
|
||||||
bot.command("httpcat", spamwatchMiddleware, async (ctx) => {
|
bot.command("httpcat", spamwatchMiddleware, async (ctx) => {
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(ctx.from.language_code);
|
||||||
const userInput = ctx.message.text.split(' ').slice(1).join(' ').replace(/\s+/g, '');
|
const userInput = ctx.message.text.split(' ').slice(1).join(' ').replace(/\s+/g, '');
|
||||||
|
const { invalidCode } = Strings.httpCodes
|
||||||
|
|
||||||
if (!userInput || isNaN(userInput)) {
|
if (verifyInput(ctx, userInput, invalidCode, true)) {
|
||||||
return ctx.reply(Strings.httpCodes.invalidCode, {
|
return;
|
||||||
parse_mode: 'Markdown',
|
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiUrl = `${Resources.httpCatApi}${userInput}`;
|
const apiUrl = `${Resources.httpCatApi}${userInput}`;
|
||||||
|
|
|
@ -3,6 +3,7 @@ const { getStrings } = require('../plugins/checklang.js');
|
||||||
const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js');
|
const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js');
|
||||||
const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch);
|
const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch);
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
|
const { verifyInput } = require('../plugins/verifyInput.js');
|
||||||
|
|
||||||
function capitalizeFirstLetter(string) {
|
function capitalizeFirstLetter(string) {
|
||||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||||
|
@ -22,14 +23,11 @@ module.exports = (bot) => {
|
||||||
bot.command("mlpchar", spamwatchMiddleware, async (ctx) => {
|
bot.command("mlpchar", spamwatchMiddleware, async (ctx) => {
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(ctx.from.language_code);
|
||||||
const userInput = ctx.message.text.split(' ').slice(1).join(' ').replace(" ", "+");
|
const userInput = ctx.message.text.split(' ').slice(1).join(' ').replace(" ", "+");
|
||||||
|
const { noCharName } = Strings.ponyApi
|
||||||
|
|
||||||
if (!userInput) {
|
if (verifyInput(ctx, userInput, noCharName)) {
|
||||||
ctx.reply(Strings.ponyApi.noCharName, {
|
|
||||||
parse_mode: 'Markdown',
|
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
};
|
}
|
||||||
|
|
||||||
const capitalizedInput = capitalizeFirstLetter(userInput);
|
const capitalizedInput = capitalizeFirstLetter(userInput);
|
||||||
const apiUrl = `${Resources.ponyApi}/character/${capitalizedInput}`;
|
const apiUrl = `${Resources.ponyApi}/character/${capitalizedInput}`;
|
||||||
|
@ -98,13 +96,11 @@ module.exports = (bot) => {
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(ctx.from.language_code);
|
||||||
const userInput = ctx.message.text.split(' ').slice(1).join(' ').replace(" ", "+");
|
const userInput = ctx.message.text.split(' ').slice(1).join(' ').replace(" ", "+");
|
||||||
|
|
||||||
if (!userInput) {
|
const { noEpisodeNum } = Strings.ponyApi
|
||||||
ctx.reply(Strings.ponyApi.noEpisodeNum, {
|
|
||||||
parse_mode: 'Markdown',
|
if (verifyInput(ctx, userInput, noEpisodeNum, true)) {
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
};
|
}
|
||||||
|
|
||||||
const apiUrl = `${Resources.ponyApi}/episode/by-overall/${userInput}`;
|
const apiUrl = `${Resources.ponyApi}/episode/by-overall/${userInput}`;
|
||||||
|
|
||||||
|
@ -167,11 +163,9 @@ module.exports = (bot) => {
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(ctx.from.language_code);
|
||||||
const userInput = ctx.message.text.split(' ').slice(1).join(' ').replace(" ", "+");
|
const userInput = ctx.message.text.split(' ').slice(1).join(' ').replace(" ", "+");
|
||||||
|
|
||||||
if (!userInput) {
|
const { noComicName } = Strings.ponyApi
|
||||||
ctx.reply(Strings.ponyApi.noComicName, {
|
|
||||||
parse_mode: 'Markdown',
|
if (verifyInput(ctx, userInput, noComicName)) {
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ const Resources = require('../props/resources.json');
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
const { getStrings } = require('../plugins/checklang.js');
|
const { getStrings } = require('../plugins/checklang.js');
|
||||||
const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js');
|
const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js');
|
||||||
|
const { verifyInput } = require('../plugins/verifyInput.js');
|
||||||
const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch);
|
const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch);
|
||||||
|
|
||||||
const statusEmojis = {
|
const statusEmojis = {
|
||||||
|
@ -35,12 +36,10 @@ module.exports = (bot) => {
|
||||||
const userLang = ctx.from.language_code || "en-US";
|
const userLang = ctx.from.language_code || "en-US";
|
||||||
const Strings = getStrings(userLang);
|
const Strings = getStrings(userLang);
|
||||||
const userInput = ctx.message.text.split(' ').slice(1).join(' ');
|
const userInput = ctx.message.text.split(' ').slice(1).join(' ');
|
||||||
|
const { provideLocation } = Strings.weatherStatus
|
||||||
|
|
||||||
if (!userInput) {
|
if (verifyInput(ctx, userInput, provideLocation)) {
|
||||||
return ctx.reply(Strings.weatherStatus.provideLocation, {
|
return;
|
||||||
parse_mode: "Markdown",
|
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const location = userInput;
|
const location = userInput;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue