Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

damn #13

Merged
merged 16 commits into from
Jun 8, 2024
Merged

damn #13

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions commands/android/xfu.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,33 @@ module.exports = {

const romVersions = await getROMVersions(device, romType);


if (romVersions.length === 0) {
return interaction.reply(`No ${romType} ROMs found for ${device}.`);
}

const romTypeTitle = romType.charAt(0).toUpperCase() + romType.slice(1);

// Group ROM versions by deviceName and branch
const groupedVersions = romVersions.reduce((acc, { deviceName, branch, romName, downloadLink }) => {
const key = `${deviceName} ${branch}`;
if (!acc[key]) {
acc[key] = [];
}
acc[key].push({ romName, downloadLink });
return acc;
}, {});

const embed = new EmbedBuilder()
.setColor(0x0099FF)
.setTitle(`${romTypeTitle} ROM Versions for ${device}`)
.setFooter({text: 'Info from xiaomifirmwareupdater.com', iconURL: 'https://xiaomifirmwareupdater.com/images/xfu.png'})
.addFields(
romVersions.map(({ deviceName, branch, romName }) => ({
name: `${deviceName} ${branch}`,
value: romName
}))
)
.setFooter({ text: 'Info from xmfirmwareupdater.com', iconURL: 'https://xmfirmwareupdater.com/images/xfu.png' });

// Add fields to embed
for (const [key, versions] of Object.entries(groupedVersions)) {
const value = versions.map(({ romName, downloadLink }) => `${romName}\n[Download](${downloadLink})`).join('\n\n');
embed.addFields({ name: key, value, inline: true });
}

interaction.reply({ embeds: [embed] });
} catch (error) {
Expand Down
23 changes: 13 additions & 10 deletions commands/mod/helper/romLookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ const cheerio = require('cheerio');

async function getROMVersions(device, romType) {
const deviceFormatted = device.replace(/ /g, '%20');
const miuiUrl = `https://xiaomifirmwareupdater.com/miui/${deviceFormatted}`;
const hyperosUrl = `https://xiaomifirmwareupdater.com/hyperos/${deviceFormatted}`;

const baseUrl = 'https://xmfirmwareupdater.com';
const miuiUrl = `${baseUrl}/miui/${deviceFormatted}`;
const hyperosUrl = `${baseUrl}/hyperos/${deviceFormatted}`;

let response;
let html;
let romVersions = [];
const romVersions = [];

try {
response = await axios.get(hyperosUrl);
Expand All @@ -23,17 +25,18 @@ async function getROMVersions(device, romType) {
html = response.data;
const $ = cheerio.load(html);

const tableRows = $('#miui tbody tr');
tableRows.each((index, element) => {
$('#miui tbody tr').each((index, element) => {
const tds = $(element).find('td');
const deviceName = $(tds[0]).text();
const branch = $(tds[1]).text();
const type = $(tds[2]).text();
const rom = $(tds[3]).text();
const deviceName = $(tds[0]).text().trim();
const branch = $(tds[1]).text().trim();
const type = $(tds[2]).text().trim();
const rom = $(tds[3]).text().trim();
const linkElement = $(tds[7]).find('a');
const downloadLink = linkElement.length ? `${baseUrl}${encodeURI(linkElement.attr('href'))}` : 'No link available';

if (type.toLowerCase().includes(romType)) {
const romName = rom.replace(/ (Fastboot|Recovery)$/i, '');
romVersions.push({ deviceName, branch, romName });
romVersions.push({ deviceName, branch, romName, downloadLink });
}
});

Expand Down
3 changes: 1 addition & 2 deletions index.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this cannot continue

Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ client.on("ready", () => {

const channel = client.channels.cache.get('1231228286148018321');
if (channel) {
channel.send('dont mess with me again… 😈 baka… 😈');
channel.send('# It\'s either Spanish or Vanish, <@1145477822123626596>.');
channel.send('Working');
} else {
console.error('Could not find the specified channel.');
}
Expand Down