Skip to content

Commit

Permalink
fixups, getting ready for prod (#18)
Browse files Browse the repository at this point in the history
* fix gsm command

* misc fixups, fixed gsmV2 and codename commands
  • Loading branch information
cubecatdoesthings authored Dec 24, 2024
1 parent 6436ec1 commit 8fbf1f2
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 56 deletions.
68 changes: 40 additions & 28 deletions commands/android/codename.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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 });
}
},
};
57 changes: 31 additions & 26 deletions commands/android/gsmV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
}
Expand All @@ -62,6 +67,8 @@ function formatDescription(specs, excludeFields) {
}
}

description = description.replace(/Cover camera:/g, '**Cover camera:**');

return description;
}

Expand All @@ -76,18 +83,23 @@ 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)
.setPlaceholder('Select a model');

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;
}
Expand All @@ -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],
Expand All @@ -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}`);
Expand All @@ -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', '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', 'Features'];
const description = formatDescription(specs, excludeFields);
embed.setDescription(description);

Expand All @@ -173,8 +181,5 @@ module.exports = {
});
}
}



},
};
6 changes: 6 additions & 0 deletions commands/mod/helper/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion db/warns.csv
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@
"1145477822123626596","FAGGOT","kUb8R8501K"
"1145477822123626596","test","PzxwHDYxeu"
"959418796609781791","gay furry porn consumer","chMYMVLSoa"
"942069644691390474","pings @everyone","sx5UNo5BfR"
"942069644691390474","pings @everyone","sx5UNo5BfR"
"222340382602559498","annoying","VKa8M7toHM"
"222340382602559498","annoying","gnt660UqXF"
"1145477822123626596","kys","RP10J2gDZP"
"1145477822123626596","mmmm","nurFColQoM"
8 changes: 7 additions & 1 deletion events/helper/badwords.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
"midget",
"tranny",
"nigg",
"sandnigger"
"sandnigger",
"fag",
"faggot",
"trannie",
"kill yourself",
"killyourself",
"kys"
]
}

0 comments on commit 8fbf1f2

Please sign in to comment.