Remake of codename check

This commit is contained in:
Lucas Gabriel 2025-01-23 22:09:05 -03:00
parent 552970e7aa
commit 09ddd96572
No known key found for this signature in database
GPG Key ID: D9B075FC6DC93985
3 changed files with 61 additions and 26 deletions

View File

@ -1,36 +1,57 @@
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');
async function searchCodename() { async function getDeviceList() {
try { try {
const url = 'https://raw.githubusercontent.com/Hycon-Devices/official_devices/refs/heads/master/devices.json' const response = await axios.get('https://raw.githubusercontent.com/androidtrackers/certified-android-devices/master/by_device.json');
const response = await axios.get(url); return response.data
return response.data } catch (error) {
} catch(error){ const message = Strings.codenameCheck.apiErr
console.error("Error fetching:", error); .replace('{error}', error.message);
return error;
} return ctx.reply(message, {
parse_mode: "Markdown",
reply_to_message_id: ctx.message.message_id
});
}
} }
module.exports = (bot) => { module.exports = (bot) => {
bot.command(['codename'], spamwatchMiddleware, async (ctx) => { bot.command(['codename', 'whatis'], spamwatchMiddleware, async (ctx) => {
const typedCodename = ctx.message.text.split(" ").slice(1).join(" "); const userInput = ctx.message.text.split(" ").slice(1).join(" ");
const Strings = getStrings(ctx.from.language_code);
if (!typedCodename) {
return ctx.reply("Please provide a codename.", { reply_to_message_id: ctx.message.message_id });
}
const requestedPhones = await searchCodename(typedCodename);
const foundPhone = requestedPhones.find((element) => element.codename === typedCodename)
if(!foundPhone){ if (!userInput) {
return ctx.reply("No phones were found, please try another codename!") ctx.reply(Strings.codenameCheck.noCodename, {
} parse_mode: "Markdown",
reply_to_message_id: ctx.message.message_id
});
}
const {brand, codename, name} = foundPhone; const jsonRes = await getDeviceList()
const message = `<b>Brand:</b> <code>${brand}</code>\n<b>Codename:</b> <code>${codename}</code>\n<b>Name:</b> <code>${name}</code>` const phoneSearch = Object.keys(jsonRes).find((codename) => codename === userInput);
return ctx.reply(message, { reply_to_message_id: ctx.message.message_id, parse_mode: 'HTML' }); if (!phoneSearch) {
}) return ctx.reply(Strings.codenameCheck.notFound, {
parse_mode: "Markdown",
reply_to_message_id: ctx.message.message_id
});
}
const deviceDetails = jsonRes[phoneSearch];
const device = deviceDetails.find((item) => item.brand) || deviceDetails[0];
const { brand = "Unknown", name = "Unknown", model = "Unknown" } = device;
const message = Strings.codenameCheck.resultMsg
.replace('{brand}', device.brand)
.replace('{codename}', userInput)
.replace('{model}', device.model)
.replace('{name}', device.name);
console.log(message)
return ctx.reply(message, {
parse_mode: 'Markdown',
reply_to_message_id: ctx.message.message_id
});
})
} }

View File

@ -56,7 +56,7 @@
"mainCommands": "Main commands", "mainCommands": "Main commands",
"mainCommandsDesc": "*Main commands*\n\n- /help: Show bot's help\n- /start: Start the bot\n- /privacy: Read the bot's Privacy Policy", "mainCommandsDesc": "*Main commands*\n\n- /help: Show bot's help\n- /start: Start the bot\n- /privacy: Read the bot's Privacy Policy",
"usefulCommands": "Useful commands", "usefulCommands": "Useful commands",
"usefulCommandsDesc": "*Useful commands*\n\n- /chatinfo: Send information about the group\n- /userinfo: Send information about yourself\n- /d | /device `<model>`: Search for a device on GSMArena and show its specs.\n- /weather | /clima `<city>`: See weather status for a specific location.\n- /modarchive | /tma `<module id>`: Download a module from The Mod Archive.\n- /wiki `<wiki page>` (WIP): Displays content from a Wikipedia page, converting some things to a more familiar format on Telegram.\n- /http `<HTTP code>`: Send details about a specific HTTP code. Example: `/http 404`", "usefulCommandsDesc": "*Useful commands*\n\n- /chatinfo: Send information about the group\n- /userinfo: Send information about yourself\n- /d | /device `<model>`: Search for a device on GSMArena and show its specs.\n/codename `<device codename>`: Shows what device is based on the codename. Example: `/codename begonia`\n- /weather | /clima `<city>`: See weather status for a specific location.\n- /modarchive | /tma `<module id>`: Download a module from The Mod Archive.\n- /wiki `<wiki page>` (WIP): Displays content from a Wikipedia page, converting some things to a more familiar format on Telegram.\n- /http `<HTTP code>`: Send details about a specific HTTP code. Example: `/http 404`",
"funnyCommands": "Funny commands", "funnyCommands": "Funny commands",
"funnyCommandsDesc": "*Funny commands*\n\n- /gay: Check if you are gay\n- /furry: Check if you are a furry\n- /random: Pick a random number between 0-10", "funnyCommandsDesc": "*Funny commands*\n\n- /gay: Check if you are gay\n- /furry: Check if you are a furry\n- /random: Pick a random number between 0-10",
"interactiveEmojis": "Interactive emojis", "interactiveEmojis": "Interactive emojis",
@ -105,5 +105,12 @@
"noComicName": "Please provide the comic's name.", "noComicName": "Please provide the comic's name.",
"noComicFound": "No comic found.", "noComicFound": "No comic found.",
"apiErr": "An error occurred while fetching data from the API." "apiErr": "An error occurred while fetching data from the API."
},
"codenameCheck": {
"noCodename": "Please provide a codename to search.",
"invalidCodename": "Invalid codename.",
"notFound": "Phone not found.",
"resultMsg": "*Name:* `{name}`\n*Brand:* `{brand}`\n*Model:* `{model}`\n*Codename:* `{codename}`",
"apiErr": "An error occurred while fetching data from the API.\n\n`{err}`"
} }
} }

View File

@ -104,5 +104,12 @@
"noComicName": "Por favor, forneça o nome da comic.", "noComicName": "Por favor, forneça o nome da comic.",
"noComicFound": "Nenhuma comic foi encontrada.", "noComicFound": "Nenhuma comic foi encontrada.",
"apiErr": "Ocorreu um erro ao buscar dados da API." "apiErr": "Ocorreu um erro ao buscar dados da API."
},
"codenameCheck": {
"noCodename": "Por favor, forneça um codinome para pesquisar.",
"invalidCodename": "Codinome inválido.",
"notFound": "Celular não encontrado.",
"resultMsg": "*Nome:* `{name}`\n*Marca:* `{brand}`\n*Modelo:* `{model}`\n*Codinome:* `{codename}`",
"apiErr": "Ocorreu um erro ao buscar os dados da API.\n\n`{err}`"
} }
} }