diff --git a/src/commands/codename.js b/src/commands/codename.js
index c75dcaf..07e47e4 100644
--- a/src/commands/codename.js
+++ b/src/commands/codename.js
@@ -1,36 +1,57 @@
+const { getStrings } = require('../plugins/checklang.js');
const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js');
const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch);
const axios = require('axios');
-async function searchCodename() {
- try {
- const url = 'https://raw.githubusercontent.com/Hycon-Devices/official_devices/refs/heads/master/devices.json'
- const response = await axios.get(url);
- return response.data
- } catch(error){
- console.error("Error fetching:", error);
- return error;
- }
+async function getDeviceList() {
+ try {
+ const response = await axios.get('https://raw.githubusercontent.com/androidtrackers/certified-android-devices/master/by_device.json');
+ return response.data
+ } catch (error) {
+ const message = Strings.codenameCheck.apiErr
+ .replace('{error}', error.message);
+
+ return ctx.reply(message, {
+ parse_mode: "Markdown",
+ reply_to_message_id: ctx.message.message_id
+ });
+ }
}
module.exports = (bot) => {
- bot.command(['codename'], spamwatchMiddleware, async (ctx) => {
- const typedCodename = ctx.message.text.split(" ").slice(1).join(" ");
-
- 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)
+ bot.command(['codename', 'whatis'], spamwatchMiddleware, async (ctx) => {
+ const userInput = ctx.message.text.split(" ").slice(1).join(" ");
+ const Strings = getStrings(ctx.from.language_code);
- if(!foundPhone){
- return ctx.reply("No phones were found, please try another codename!")
- }
+ if (!userInput) {
+ ctx.reply(Strings.codenameCheck.noCodename, {
+ parse_mode: "Markdown",
+ reply_to_message_id: ctx.message.message_id
+ });
+ }
- const {brand, codename, name} = foundPhone;
- const message = `Brand: ${brand}
\nCodename: ${codename}
\nName: ${name}
`
+ const jsonRes = await getDeviceList()
+ 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
+ });
+ })
}
\ No newline at end of file
diff --git a/src/locales/english.json b/src/locales/english.json
index 292b09b..0d08166 100644
--- a/src/locales/english.json
+++ b/src/locales/english.json
@@ -56,7 +56,7 @@
"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",
"usefulCommands": "Useful commands",
- "usefulCommandsDesc": "*Useful commands*\n\n- /chatinfo: Send information about the group\n- /userinfo: Send information about yourself\n- /d | /device ``: Search for a device on GSMArena and show its specs.\n- /weather | /clima ``: See weather status for a specific location.\n- /modarchive | /tma ``: Download a module from The Mod Archive.\n- /wiki `` (WIP): Displays content from a Wikipedia page, converting some things to a more familiar format on Telegram.\n- /http ``: 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 ``: Search for a device on GSMArena and show its specs.\n/codename ``: Shows what device is based on the codename. Example: `/codename begonia`\n- /weather | /clima ``: See weather status for a specific location.\n- /modarchive | /tma ``: Download a module from The Mod Archive.\n- /wiki `` (WIP): Displays content from a Wikipedia page, converting some things to a more familiar format on Telegram.\n- /http ``: Send details about a specific HTTP code. Example: `/http 404`",
"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",
"interactiveEmojis": "Interactive emojis",
@@ -105,5 +105,12 @@
"noComicName": "Please provide the comic's name.",
"noComicFound": "No comic found.",
"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}`"
}
}
\ No newline at end of file
diff --git a/src/locales/portuguese.json b/src/locales/portuguese.json
index eb5b426..67e3add 100644
--- a/src/locales/portuguese.json
+++ b/src/locales/portuguese.json
@@ -104,5 +104,12 @@
"noComicName": "Por favor, forneça o nome da comic.",
"noComicFound": "Nenhuma comic foi encontrada.",
"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}`"
}
}