From c36bbd3ad4e12dabdd30bee1735324243fd8c835 Mon Sep 17 00:00:00 2001 From: cubecatdoesthings Date: Mon, 23 Dec 2024 21:22:19 +0200 Subject: [PATCH 1/2] fix gsm command --- commands/android/gsmV2.js | 57 +++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/commands/android/gsmV2.js b/commands/android/gsmV2.js index 00d7edf..c92d109 100644 --- a/commands/android/gsmV2.js +++ b/commands/android/gsmV2.js @@ -54,6 +54,11 @@ function formatDescription(specs, excludeFields) { description += `${value}\n`; } else if (key === 'Technology') { description += `**Networks:** ${value}\n`; + } else if (key === 'Dimensions' && value.includes('Folded:')) { + const dimensions = value.split('Folded:'); + description += `**${key}:**\n${dimensions[0].trim()}\nFolded: ${dimensions[1].trim()}\n`; + } else if (key === 'Dimensions') { + description += `**${key}:** ${value}\n`; } else { description += `**${key}:** ${value}\n`; } @@ -62,6 +67,8 @@ function formatDescription(specs, excludeFields) { } } + description = description.replace(/Cover camera:/g, '**Cover camera:**'); + return description; } @@ -76,8 +83,7 @@ module.exports = { async execute(interaction) { const { parseResults } = require('./gsmSearch'); const device = interaction.options.getString('device'); - interaction.deferReply(); - + await interaction.deferReply(); // Defer the reply const dropdown = new StringSelectMenuBuilder() .setCustomId(interaction.id) @@ -85,9 +91,15 @@ module.exports = { const results = await parseResults(device); + if (results.length === 0) { + await interaction.editReply({ + content: 'No devices found. Please try a different search term.', + components: [], + }); + return; + } for (let i = 0; i < results.length; i++) { - if (i + 1 >= 26) { break; } @@ -96,13 +108,12 @@ module.exports = { .setLabel(results[i].name) .setValue(results[i].link) ); - } const row = new ActionRowBuilder() - .addComponents(dropdown); + .addComponents(dropdown); - if (results.length > 1){ + if (results.length > 1) { const reply = await interaction.editReply({ content: `Choose a device`, components: [row], @@ -113,17 +124,16 @@ module.exports = { filter: (i) => i.user.id === interaction.user.id && i.customId === interaction.id, time: 30_000, }); - - collector.on('collect', interaction => { + + collector.on('collect', async interaction => { if (!interaction.values.length) { - interaction.reply('something went VERY wrong please file an issue and contact either developer'); + await interaction.reply('something went VERY wrong please file an issue and contact either developer'); return; } - + handleCollectorInteraction(interaction); - }); - + async function handleCollectorInteraction(interaction) { try { console.log(`values: ${interaction.values}`); @@ -133,36 +143,34 @@ module.exports = { .setTitle(specs.name) .setURL(interaction.values[0]) .setColor(0x00AE86) - .setThumbnail(specs.imageUrl); - - const excludeFields = ['GPRS', 'EDGE', '2G bands', '3G bands', '4G bands', '5G bands', 'Speed', 'CPU', 'GPU', 'NFC', 'Price', 'Video', 'Loudspeaker', '3.5mm jack', 'Radio', 'SAR', 'SAR EU', 'WLAN', 'Positioning', 'SIM', 'Card slot', 'Charging', 'Sensors', 'Announced', 'Protection']; - + .setThumbnail(specs.imageUrl) + .setFooter({ text: 'Powered by GSMArena' }); // Ensure footer is set + + const excludeFields = ['GPRS', 'EDGE', '2G bands', '3G bands', '4G bands', '5G bands', 'Speed', 'CPU', 'GPU', 'NFC', 'Price', 'Video', 'Loudspeaker', '3.5mm jack', 'Radio', 'SAR', 'SAR EU', 'WLAN', 'Positioning', 'SIM', 'Card slot', 'Charging', 'Sensors', 'Announced', 'Protection', 'Features']; const description = formatDescription(specs, excludeFields); embed.setDescription(description); - + await interaction.update({ components: [], embeds: [embed], content: '', }); } - } catch (error) { console.log('Error fetching device info:', error); } } - - } else if (results.length = 1) { + } else if (results.length === 1) { const specs = await scrapePhoneSpecs(results[0].link); if (specs) { const embed = new EmbedBuilder() .setTitle(specs.name) .setURL(results[0].link) .setColor(0x00AE86) - .setThumbnail(specs.imageUrl); - - const excludeFields = ['GPRS', 'EDGE', '2G bands', '3G bands', '4G bands', '5G bands', 'Speed', 'CPU', 'GPU', 'NFC', 'Price', 'Video', 'Loudspeaker', '3.5mm jack', 'Radio', 'SAR', 'SAR EU', 'WLAN', 'Positioning', 'SIM', 'Card slot', 'Charging', 'Sensors', 'Announced', 'Protection']; + .setThumbnail(specs.imageUrl) + .setFooter({ text: 'Powered by GSMArena' }); // Ensure footer is set + const excludeFields = ['GPRS', 'EDGE', '2G bands', '3G bands', '4G bands', '5G bands', 'Speed', 'CPU', 'GPU', 'NFC', 'Price', 'Video', 'Loudspeaker', '3.5mm jack', 'Radio', 'SAR', 'SAR EU', 'WLAN', 'Positioning', 'SIM', 'Card slot', 'Charging', 'Sensors', 'Announced', 'Protection', 'Features']; const description = formatDescription(specs, excludeFields); embed.setDescription(description); @@ -173,8 +181,5 @@ module.exports = { }); } } - - - }, }; \ No newline at end of file From bf9eebf26cdd60bdff84f2936804dcf2cbb8e5b2 Mon Sep 17 00:00:00 2001 From: cubecatdoesthings Date: Tue, 24 Dec 2024 15:59:42 +0200 Subject: [PATCH 2/2] misc fixups, fixed gsmV2 and codename commands --- commands/android/codename.js | 68 +++++++++++++++++++++--------------- commands/android/gsmV2.js | 4 +-- commands/mod/helper/log.js | 6 ++++ db/warns.csv | 6 +++- events/helper/badwords.json | 8 ++++- 5 files changed, 60 insertions(+), 32 deletions(-) diff --git a/commands/android/codename.js b/commands/android/codename.js index 4960f3a..ffeaf73 100644 --- a/commands/android/codename.js +++ b/commands/android/codename.js @@ -2,9 +2,9 @@ const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const axios = require('axios'); module.exports = { - data: new SlashCommandBuilder() - .setName('codename') - .setDescription('Find an Android device\'s codename') + data: new SlashCommandBuilder() + .setName('codename') + .setDescription('Find an Android device\'s codename') .addStringOption(option => option.setName('brand') .setDescription('The device\'s brand') @@ -15,43 +15,55 @@ module.exports = { .setDescription('The device to lookup') .setRequired(true) ), - async execute(interaction) { + async execute(interaction) { const brand = interaction.options.getString('brand'); const device = interaction.options.getString('device'); const url = 'https://raw.githubusercontent.com/androidtrackers/certified-android-devices/master/by_brand.json'; let counter = 0; - const json = await axios.get(`${url}`); - const jsonData = json.data; + try { + const json = await axios.get(`${url}`); + const jsonData = json.data; - const lowerCaseKeys = Object.keys(jsonData).reduce((acc, key) => { - acc[key.toLowerCase()] = key; - return acc; - }, {}); + const lowerCaseKeys = Object.keys(jsonData).reduce((acc, key) => { + acc[key.toLowerCase()] = key; + return acc; + }, {}); - brandJson = jsonData[lowerCaseKeys[`${brand}`.toLowerCase()]] - const deviceJson = brandJson - .filter(item => item.name.toLowerCase().includes(device.toLowerCase())) - .map(item => ({ name: item.name, device: item.device })); + const brandJson = jsonData[lowerCaseKeys[`${brand}`.toLowerCase()]]; + if (!brandJson) { + await interaction.reply({ content: `No data found for brand: ${brand}`, ephemeral: false }); + return; + } - const uniqueDevices = deviceJson - .map(({ name, device }) => ({ name, device })) - .filter((value, index, self) => self.findIndex(item => item.name === value.name && item.device === value.device) === index); + const deviceJson = brandJson + .filter(item => item.name.toLowerCase().includes(device.toLowerCase())) + .map(item => ({ name: item.name, device: item.device })); - const embed = new EmbedBuilder() - .setTitle(`Codename(s) for \'${brand} ${device}\'`) - .setColor('#2eb237'); + const uniqueDevices = deviceJson + .map(({ name, device }) => ({ name, device })) + .filter((value, index, self) => self.findIndex(item => item.name === value.name && item.device === value.device) === index); - uniqueDevices.forEach(item => { - if (counter < 25) { - embed.addFields({ name: item.name, value: `\`${item.device}\``, inline: true }); - counter++; - } else { + if (uniqueDevices.length === 0) { + await interaction.reply({ content: `No codenames found for ${brand} ${device}`, ephemeral: false }); return; } - }); + const embed = new EmbedBuilder() + .setTitle(`Codename(s) for '${brand} ${device}'`) + .setColor('#2eb237'); + + uniqueDevices.forEach(item => { + if (counter < 25) { + embed.addFields({ name: item.name, value: item.device }); + counter++; + } + }); - interaction.reply({ embeds: [embed] }); - }, + await interaction.reply({ embeds: [embed] }); + } catch (error) { + console.error('Error fetching codenames:', error); + await interaction.reply({ content: 'An error occurred while fetching the codenames. Please try again later.', ephemeral: true }); + } + }, }; diff --git a/commands/android/gsmV2.js b/commands/android/gsmV2.js index c92d109..27c66a1 100644 --- a/commands/android/gsmV2.js +++ b/commands/android/gsmV2.js @@ -146,7 +146,7 @@ module.exports = { .setThumbnail(specs.imageUrl) .setFooter({ text: 'Powered by GSMArena' }); // Ensure footer is set - const excludeFields = ['GPRS', 'EDGE', '2G bands', '3G bands', '4G bands', '5G bands', 'Speed', 'CPU', 'GPU', 'NFC', 'Price', 'Video', 'Loudspeaker', '3.5mm jack', 'Radio', 'SAR', 'SAR EU', 'WLAN', 'Positioning', 'SIM', 'Card slot', 'Charging', 'Sensors', 'Announced', 'Protection', 'Features']; + const excludeFields = ['GPRS', 'EDGE', '2G bands', '3G bands', '4G bands', '5G bands', 'Speed', 'CPU', 'GPU', 'NFC', 'Price', 'Video', 'Loudspeaker', '3.5mm jack', 'Radio', 'SAR', 'SAR EU', 'WLAN', 'Positioning', 'SIM', 'Card slot', 'Charging', 'Sensors', 'Announced', 'Features']; const description = formatDescription(specs, excludeFields); embed.setDescription(description); @@ -170,7 +170,7 @@ module.exports = { .setThumbnail(specs.imageUrl) .setFooter({ text: 'Powered by GSMArena' }); // Ensure footer is set - const excludeFields = ['GPRS', 'EDGE', '2G bands', '3G bands', '4G bands', '5G bands', 'Speed', 'CPU', 'GPU', 'NFC', 'Price', 'Video', 'Loudspeaker', '3.5mm jack', 'Radio', 'SAR', 'SAR EU', 'WLAN', 'Positioning', 'SIM', 'Card slot', 'Charging', 'Sensors', 'Announced', 'Protection', 'Features']; + const excludeFields = ['GPRS', 'EDGE', '2G bands', '3G bands', '4G bands', '5G bands', 'Speed', 'CPU', 'GPU', 'NFC', 'Price', 'Video', 'Loudspeaker', '3.5mm jack', 'Radio', 'SAR', 'SAR EU', 'WLAN', 'Positioning', 'SIM', 'Card slot', 'Charging', 'Sensors', 'Announced', 'Features']; const description = formatDescription(specs, excludeFields); embed.setDescription(description); diff --git a/commands/mod/helper/log.js b/commands/mod/helper/log.js index afef65a..a599d73 100644 --- a/commands/mod/helper/log.js +++ b/commands/mod/helper/log.js @@ -59,6 +59,12 @@ async function log(interaction, type, content, target, reason, duration, muted) } catch (error) { logsChannel = 0; console.error(error); + } finally { + settings.close((err) => { + if (err) { + console.error(`Error closing the settings database: ${err.message}`); + } + }); } if (logs == 0) { diff --git a/db/warns.csv b/db/warns.csv index 54b3e9c..646bc72 100644 --- a/db/warns.csv +++ b/db/warns.csv @@ -13,4 +13,8 @@ "1145477822123626596","FAGGOT","kUb8R8501K" "1145477822123626596","test","PzxwHDYxeu" "959418796609781791","gay furry porn consumer","chMYMVLSoa" -"942069644691390474","pings @everyone","sx5UNo5BfR" \ No newline at end of file +"942069644691390474","pings @everyone","sx5UNo5BfR" +"222340382602559498","annoying","VKa8M7toHM" +"222340382602559498","annoying","gnt660UqXF" +"1145477822123626596","kys","RP10J2gDZP" +"1145477822123626596","mmmm","nurFColQoM" \ No newline at end of file diff --git a/events/helper/badwords.json b/events/helper/badwords.json index 7f39b11..3a34612 100644 --- a/events/helper/badwords.json +++ b/events/helper/badwords.json @@ -8,6 +8,12 @@ "midget", "tranny", "nigg", - "sandnigger" + "sandnigger", + "fag", + "faggot", + "trannie", + "kill yourself", + "killyourself", + "kys" ] }