This commit is contained in:
Lucas Gabriel 2025-01-23 21:14:48 -03:00
commit 552970e7aa
No known key found for this signature in database
GPG Key ID: D9B075FC6DC93985

36
src/commands/codename.js Normal file
View File

@ -0,0 +1,36 @@
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;
}
}
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)
if(!foundPhone){
return ctx.reply("No phones were found, please try another codename!")
}
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' });
})
}