Revert "ref: create separated verifyUserInput function (#34)" (#42)

This reverts commit 12ca87f4fe281be20b1eec5c2dcadc1f0fe8fce2.
This commit is contained in:
Lucas Gabriel 2025-04-19 23:52:51 -03:00 committed by GitHub
parent 3d125ffbf9
commit 8aaa60e78d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 39 additions and 28 deletions

View File

@ -3,7 +3,6 @@ const { getStrings } = require('../plugins/checklang.js');
const { isOnSpamWatch } = require('../spamwatch/spamwatch.js'); const { isOnSpamWatch } = require('../spamwatch/spamwatch.js');
const spamwatchMiddleware = require('../spamwatch/Middleware.js')(isOnSpamWatch); const spamwatchMiddleware = require('../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 {
@ -24,10 +23,12 @@ 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(verifyInput(ctx, userInput, noCodename)){ if (!userInput) {
return; ctx.reply(Strings.codenameCheck.noCodename, {
parse_mode: "Markdown",
reply_to_message_id: ctx.message.message_id
});
} }
const jsonRes = await getDeviceList() const jsonRes = await getDeviceList()

View File

@ -3,18 +3,19 @@ const { getStrings } = require('../plugins/checklang.js');
const { isOnSpamWatch } = require('../spamwatch/spamwatch.js'); const { isOnSpamWatch } = require('../spamwatch/spamwatch.js');
const spamwatchMiddleware = require('../spamwatch/Middleware.js')(isOnSpamWatch); const spamwatchMiddleware = require('../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 (verifyInput(ctx, userInput, invalidCode, true)) { if (!userInput || isNaN(userInput)) {
return; return ctx.reply(Strings.httpCodes.invalidCode, {
} 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);
@ -49,10 +50,12 @@ 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 (verifyInput(ctx, userInput, invalidCode, true)) { if (!userInput || isNaN(userInput)) {
return; return ctx.reply(Strings.httpCodes.invalidCode, {
parse_mode: 'Markdown',
reply_to_message_id: ctx.message.message_id
});
} }
const apiUrl = `${Resources.httpCatApi}${userInput}`; const apiUrl = `${Resources.httpCatApi}${userInput}`;

View File

@ -3,7 +3,6 @@ const { getStrings } = require('../plugins/checklang.js');
const { isOnSpamWatch } = require('../spamwatch/spamwatch.js'); const { isOnSpamWatch } = require('../spamwatch/spamwatch.js');
const spamwatchMiddleware = require('../spamwatch/Middleware.js')(isOnSpamWatch); const spamwatchMiddleware = require('../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);
@ -23,9 +22,12 @@ 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 (verifyInput(ctx, userInput, noCharName)) { if (!userInput) {
ctx.reply(Strings.ponyApi.noCharName, {
parse_mode: 'Markdown',
reply_to_message_id: ctx.message.message_id
});
return; return;
}; };
@ -97,9 +99,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(" ", "+");
const { noEpisodeNum } = Strings.ponyApi if (!userInput) {
ctx.reply(Strings.ponyApi.noEpisodeNum, {
if (verifyInput(ctx, userInput, noEpisodeNum, true)) { parse_mode: 'Markdown',
reply_to_message_id: ctx.message.message_id
});
return; return;
}; };
@ -165,9 +169,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(" ", "+");
const { noComicName } = Strings.ponyApi if (!userInput) {
ctx.reply(Strings.ponyApi.noComicName, {
if (verifyInput(ctx, userInput, noComicName)) { parse_mode: 'Markdown',
reply_to_message_id: ctx.message.message_id
});
return; return;
}; };

View File

@ -7,7 +7,6 @@ const axios = require('axios');
const { getStrings } = require('../plugins/checklang.js'); const { getStrings } = require('../plugins/checklang.js');
const { isOnSpamWatch } = require('../spamwatch/spamwatch.js'); const { isOnSpamWatch } = require('../spamwatch/spamwatch.js');
const spamwatchMiddleware = require('../spamwatch/Middleware.js')(isOnSpamWatch); const spamwatchMiddleware = require('../spamwatch/Middleware.js')(isOnSpamWatch);
const { verifyInput } = require('../plugins/verifyInput.js');
const statusEmojis = { const statusEmojis = {
0: '⛈', 1: '⛈', 2: '⛈', 3: '⛈', 4: '⛈', 5: '🌨', 6: '🌨', 7: '🌨', 0: '⛈', 1: '⛈', 2: '⛈', 3: '⛈', 4: '⛈', 5: '🌨', 6: '🌨', 7: '🌨',
@ -36,10 +35,12 @@ 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 (verifyInput(ctx, userInput, provideLocation)) { if (!userInput) {
return; return ctx.reply(Strings.weatherStatus.provideLocation, {
parse_mode: "Markdown",
reply_to_message_id: ctx.message.message_id
});
} }
const location = userInput; const location = userInput;