Skip to content

Commit

Permalink
Merge pull request #95 from mustafa383/master
Browse files Browse the repository at this point in the history
Function to go to a specific page
  • Loading branch information
mstww authored Oct 24, 2023
2 parents 2d2fc1e + bfc825c commit 2492155
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 6 deletions.
95 changes: 94 additions & 1 deletion discord/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {
ButtonBuilder,
ButtonStyle,
ActivityType,
ModalBuilder,
TextInputBuilder,
TextInputStyle
} from "discord.js";
import cron from "node-cron";

Expand Down Expand Up @@ -58,7 +61,8 @@ import {
skinNameAndEmoji,
valNamesToDiscordNames, WeaponTypeUuid,
WeaponType,
fetch
fetch,
calcLength
} from "../misc/util.js";
import config, { loadConfig, saveConfig } from "../misc/config.js";
import { localError, localLog, sendConsoleOutput } from "../misc/logger.js";
Expand Down Expand Up @@ -1490,6 +1494,95 @@ client.on("interactionCreate", async (interaction) => {


await message.edit(newMessage);
} else if (interaction.customId.startsWith("goToPage")) {
let [, pageId, userId, max] = interaction.customId.split('/');
let weaponTypeIndex
if(pageId === 'clwpage') [, pageId, weaponTypeIndex, userId, max] = interaction.customId.split('/');

if (userId !== interaction.user.id){
if (pageId === 'changestatspage'){
return await interaction.reply({
embeds: [basicEmbed(s(interaction).error.NOT_UR_MESSAGE_STATS)],
ephemeral: true
});
}else if (pageId === 'changealertspage'){
return await interaction.reply({
embeds: [basicEmbed(s(interaction).error.NOT_UR_ALERT)],
ephemeral: true
});
}
}

const modal = new ModalBuilder()
.setCustomId(`goToPage/${pageId}${weaponTypeIndex ? `/${weaponTypeIndex}`: ''}/${userId}/${max}`)
.setTitle(s(interaction).modal.PAGE_TITLE);

const pageInput = new TextInputBuilder()
.setMinLength(1)
.setMaxLength(calcLength(max))
.setPlaceholder(s(interaction).modal.PAGE_INPUT_PLACEHOLDER)
.setRequired(true)
.setCustomId('pageIndex')
.setLabel(s(interaction).modal.PAGE_INPUT_LABEL.f({max: max}))
.setStyle(TextInputStyle.Short);

const q1 = new ActionRowBuilder().addComponents(pageInput);
modal.addComponents(q1);
await interaction.showModal(modal);
}
} catch (e) {
await handleError(e, interaction);
}
} else if (interaction.isModalSubmit()){
try {
if (interaction.customId.startsWith("goToPage")) {
let [, pageId, userId, max] = interaction.customId.split('/');
let weaponTypeIndex
if(pageId === 'clwpage') [, pageId, weaponTypeIndex, userId, max] = interaction.customId.split('/');
const pageIndex = interaction.fields.getTextInputValue('pageIndex');

if(isNaN(Number(pageIndex))){
return await interaction.reply({
embeds: [basicEmbed(s(interaction).error.NOT_A_NUMBER)],
ephemeral: true
});
}else if(Number(pageIndex) > max || Number(pageIndex) <= 0){
return await interaction.reply({
embeds: [basicEmbed(s(interaction).error.INVALID_PAGE_NUMBER.f({max: max}))],
ephemeral: true
});
}

switch (pageId) {
case "clpage": clpage(); break;
case "clwpage": clwpage(); break;
case "changealertspage": await interaction.update(await alertsPageEmbed(interaction, await filteredAlertsForUser(interaction), parseInt(pageIndex-1), await VPEmoji(interaction))); break;
case "changestatspage": await interaction.update(await allStatsEmbed(interaction, await getOverallStats(), parseInt(pageIndex-1)));break;
}

async function clpage() {
let user;
if (userId !== interaction.user.id) user = getUser(userId);
else user = valorantUser;

const loadoutResponse = await getLoadout(user);
if (!loadoutResponse.success) return await interaction.reply(authFailureMessage(interaction, loadoutResponse, s(interaction).error.AUTH_ERROR_COLLECTION, userId !== interaction.user.id));

await interaction.update(await skinCollectionPageEmbed(interaction, userId, user, loadoutResponse, parseInt(pageIndex-1)));
}

async function clwpage() {
const weaponType = Object.values(WeaponTypeUuid)[parseInt(weaponTypeIndex)];

let user;
if (userId !== interaction.user.id) user = getUser(userId);
else user = valorantUser;

const skinsResponse = await getSkins(user);
if (!skinsResponse.success) return await interaction.reply(authFailureMessage(interaction, skinsResponse, s(interaction).error.AUTH_ERROR_COLLECTION, userId !== interaction.user.id));

await interaction.update(await collectionOfWeaponEmbed(interaction, userId, user, weaponType, skinsResponse.skins, parseInt(pageIndex-1)));
}
}
} catch (e) {
await handleError(e, interaction);
Expand Down
3 changes: 2 additions & 1 deletion discord/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -920,11 +920,12 @@ const priceDescription = (VPemojiString, price) => {
const pageButtons = (pageId, userId, current, max) => {
const leftButton = new ButtonBuilder().setStyle(ButtonStyle.Secondary).setEmoji("◀").setCustomId(`${pageId}/${userId}/${current - 1}`);
const rightButton = new ButtonBuilder().setStyle(ButtonStyle.Secondary).setEmoji("▶").setCustomId(`${pageId}/${userId}/${current + 1}`);
const goToPageButton = new ButtonBuilder().setStyle(ButtonStyle.Secondary).setEmoji("🔍").setCustomId(`goToPage/${pageId}/${userId}/${max}`);

if(current === 0) leftButton.setEmoji("⏪");
if(current === max - 1) rightButton.setEmoji("⏩");

return new ActionRowBuilder().setComponents(leftButton, rightButton);
return new ActionRowBuilder().setComponents(leftButton, rightButton, goToPageButton);
}

export const switchAccountButtons = (interaction, customId, oneAccountButton=false, accessory = false, id=interaction?.user?.id || interaction) => {
Expand Down
9 changes: 8 additions & 1 deletion languages/en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
"ACCOUNT_NUMBER_TOO_HIGH": "**You only have {n} accounts!**",
"TOO_MANY_ACCOUNTS": "**You can only have maximum {n} accounts on the bot!** `/forget` some accounts and try again.",
"GENERIC_ERROR": ":no_entry_sign: **There was an error trying to do that!** I blame Riot.\n`{e}`",
"QUEUE_WAIT": "Many people are using the bot! Please wait... (estimated: <t:{t}:R>)"
"QUEUE_WAIT": "Many people are using the bot! Please wait... (estimated: <t:{t}:R>)",
"NOT_A_NUMBER": "This is not a number, please enter a valid number.",
"INVALID_PAGE_NUMBER": "Invalid page number, please enter a value between **1 - {max}**"
},
"info":{
"SHOP_HEADER": "Daily shop for **{u}** (new shop <t:{t}:R>)",
Expand Down Expand Up @@ -179,5 +181,10 @@
"othersCanViewColl": "Allow others to use /collection with your username",
"othersCanUseAccountButtons": "Allow others to press buttons on your /shop",
"locale": "Language"
},
"modal": {
"PAGE_TITLE": "Page Navigator",
"PAGE_INPUT_PLACEHOLDER": "Please only input a number.",
"PAGE_INPUT_LABEL": "Go to page (1-{max})"
}
}
16 changes: 13 additions & 3 deletions languages/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
"ACCOUNT_NUMBER_TOO_HIGH": "**{n} tane hesaba sahipsin!**",
"TOO_MANY_ACCOUNTS": "**Botta maksimum {n} hesabınız olabilir!** `/forget` komutuyla bazı hesaplarınızı sildikten sonra tekrar deneyin.",
"GENERIC_ERROR": ":no_entry_sign: **Bunu yapmaya çalışırken bir hata oluştu!** Riot'u suçluyorum.\n`{e}`",
"SHARDS_LOADING": "Bot hala başlatılıyor! Lütfen birkaç saniye bekleyin ve tekrar deneyin. ( Shard yükleniyor...)",
"QUEUE_WAIT": "Şu anda birçok kişi botu kullanıyor! Lütfen bekleyin... (tahmini süre: <t:{t}:R>)",
"NO_MORE_ACCESSORIES": "Zaten bütün aksesuarlara sahipsin! :sunglasses:"
"NOT_A_NUMBER": "Bu bir sayı değil, lütfen geçerli bir sayı girin.",
"INVALID_PAGE_NUMBER": "Geçersiz sayfa, lütfen **1 - {max}** arasında bir değer girin."
},
"info": {
"SHOP_HEADER": "**{u}** için günlük mağaza (Yeni mağaza <t:{t}:R>)",
Expand All @@ -75,6 +75,7 @@
"INFO_OWNER": "Sahip",
"INFO_STATUS": "Durum",
"INFO_RUNNING": "<t:{t1}:f> (<t:{t2}:R> çalışmaya başladı)",
"INFO_SOURCE": "Kaynak kodu",
"NMARKET_HEADER": "**{u}** için Gece Pazarı (<t:{t}:R> Sona eriyor)",
"WALLET_HEADER": "**{u}** Cüzdanı:",
"VPOINTS": "VALORANT Puanı",
Expand All @@ -86,6 +87,7 @@
"ALERT_SET": "**{s}** için bildirim başarıyla ayarlandı!",
"ALERT_BP_SKIN": "\n***Not:** Bu bir savaş bileti kaplaması, bu yüzden mağazanda görünmeyecek!*",
"ALERT_IN_CHANNEL": "<#{c}> kanalında",
"ALERT_IN_CHANNEL_NAME": "#{c} kanalında",
"ALERT_IN_DM_CHANNEL": "Direkt mesajlarda",
"ONE_ALERT": "Ayarlanmış bir bildiriminiz var:",
"MULTIPLE_ALERTS": "Şu anda kurduğunuz bildirimler:",
Expand Down Expand Up @@ -130,7 +132,9 @@
"LAST_UPDATED": "Son güncelleme <t:{t}:R>",
"UNHANDLED_COMMAND": "Yer a wizard harry!",
"SELECT_SKIN_WITH_LEVEL":"Gösterilecek kaplamayı seçin:",
"SELECT_LEVEL_OF_SKIN":"Kaplama seviyesini seçin:"
"SELECT_LEVEL_OF_SKIN":"Kaplama seviyesini seçin:",
"SHARDS_LOADING": "Bot hala başlatılıyor! Lütfen birkaç saniye bekleyin ve tekrar deneyin. ( Shard yükleniyor...)",
"NO_MORE_ACCESSORIES": "Zaten bütün aksesuarlara sahipsin! :sunglasses:"
},
"battlepass": {
"CALCULATIONS_TITLE": "\uD83D\uDCC8 Savaş bileti hesaplaması",
Expand Down Expand Up @@ -171,10 +175,16 @@
"SET_QUESTION": "**{s}** ayarını ne yapmak istiyorsunuz?",
"CONFIRMATION": "**{s}** ayarı artık **{v}** olarak ayarlandı.",
"dailyShop": "Mağazamı her gün gönder",
"pingOnAutoDailyShop": "Mağazamı otomatik olarak gönderdiğinizde beni @etiketleyin",
"hideIgn": "Oyun içi adı gizle",
"othersCanViewShop": "Başkalarının kullanıcı adınızla /shop kullanmasına izin verin",
"othersCanViewColl": "Başkalarının kullanıcı adınızla /collection kullanmasına izin verin",
"othersCanUseAccountButtons": "Başkalarının /shop gibi komutlarda sizin hesap butonlarınızı kullanmasına izin verin",
"locale": "Dil"
},
"modal": {
"PAGE_TITLE": "Sayfa Gezgini",
"PAGE_INPUT_PLACEHOLDER": "Lütfen sadece sayı girin.",
"PAGE_INPUT_LABEL": "Sayfaya git (1-{max})"
}
}
5 changes: 5 additions & 0 deletions misc/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,3 +633,8 @@ export const ensureUsersFolder = () => {
}

export const findKeyOfValue = (obj, value) => Object.keys(obj).find(key => obj[key] === value);

export const calcLength = (any) => {
if(!isNaN(any)) any = any.toString();
return any.length;
}

0 comments on commit 2492155

Please sign in to comment.