mirror of
https://github.com/abocn/TelegramBot.git
synced 2025-03-10 04:39:57 +00:00
Remake of codename check
This commit is contained in:
parent
552970e7aa
commit
09ddd96572
@ -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(" ");
|
||||
bot.command(['codename', 'whatis'], spamwatchMiddleware, async (ctx) => {
|
||||
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 });
|
||||
}
|
||||
if (!userInput) {
|
||||
ctx.reply(Strings.codenameCheck.noCodename, {
|
||||
parse_mode: "Markdown",
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
});
|
||||
}
|
||||
|
||||
const requestedPhones = await searchCodename(typedCodename);
|
||||
const foundPhone = requestedPhones.find((element) => element.codename === typedCodename)
|
||||
const jsonRes = await getDeviceList()
|
||||
const phoneSearch = Object.keys(jsonRes).find((codename) => codename === userInput);
|
||||
|
||||
if(!foundPhone){
|
||||
return ctx.reply("No phones were found, please try another codename!")
|
||||
}
|
||||
if (!phoneSearch) {
|
||||
return ctx.reply(Strings.codenameCheck.notFound, {
|
||||
parse_mode: "Markdown",
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
});
|
||||
}
|
||||
|
||||
const {brand, codename, name} = foundPhone;
|
||||
const message = `<b>Brand:</b> <code>${brand}</code>\n<b>Codename:</b> <code>${codename}</code>\n<b>Name:</b> <code>${name}</code>`
|
||||
|
||||
return ctx.reply(message, { reply_to_message_id: ctx.message.message_id, parse_mode: 'HTML' });
|
||||
})
|
||||
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
|
||||
});
|
||||
})
|
||||
}
|
@ -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 `<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",
|
||||
"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}`"
|
||||
}
|
||||
}
|
@ -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}`"
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user