mirror of
https://github.com/abocn/TelegramBot.git
synced 2025-03-10 12:49: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 { 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) {
|
||||||
console.error("Error fetching:", error);
|
const message = Strings.codenameCheck.apiErr
|
||||||
return error;
|
.replace('{error}', error.message);
|
||||||
|
|
||||||
|
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) {
|
if (!userInput) {
|
||||||
return ctx.reply("Please provide a codename.", { reply_to_message_id: ctx.message.message_id });
|
ctx.reply(Strings.codenameCheck.noCodename, {
|
||||||
|
parse_mode: "Markdown",
|
||||||
|
reply_to_message_id: ctx.message.message_id
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestedPhones = await searchCodename(typedCodename);
|
const jsonRes = await getDeviceList()
|
||||||
const foundPhone = requestedPhones.find((element) => element.codename === typedCodename)
|
const phoneSearch = Object.keys(jsonRes).find((codename) => codename === userInput);
|
||||||
|
|
||||||
if(!foundPhone){
|
if (!phoneSearch) {
|
||||||
return ctx.reply("No phones were found, please try another codename!")
|
return ctx.reply(Strings.codenameCheck.notFound, {
|
||||||
|
parse_mode: "Markdown",
|
||||||
|
reply_to_message_id: ctx.message.message_id
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const {brand, codename, name} = foundPhone;
|
const deviceDetails = jsonRes[phoneSearch];
|
||||||
const message = `<b>Brand:</b> <code>${brand}</code>\n<b>Codename:</b> <code>${codename}</code>\n<b>Name:</b> <code>${name}</code>`
|
const device = deviceDetails.find((item) => item.brand) || deviceDetails[0];
|
||||||
|
const { brand = "Unknown", name = "Unknown", model = "Unknown" } = device;
|
||||||
return ctx.reply(message, { reply_to_message_id: ctx.message.message_id, parse_mode: 'HTML' });
|
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",
|
"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}`"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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}`"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user