diff --git a/commands/dailystats.js b/commands/dailystats.js index bc753c1d..d83b1179 100644 --- a/commands/dailystats.js +++ b/commands/dailystats.js @@ -23,7 +23,7 @@ const formatLabel = (from, to) => { return new Date(from).toDateString() } -const sendCardWithInfo = async (interaction, playerParam, page = 0, game = null, type = null) => { +const sendCardWithInfo = async (interaction, playerParam, page = 0, game = null, type = null, defaultOption = 0) => { game ??= getGameOption(interaction) return DateStats.generateDatasForCard({ @@ -35,7 +35,8 @@ const sendCardWithInfo = async (interaction, playerParam, page = 0, game = null, formatFromToDates, formatLabel, selectTranslationString: 'strings.selectDate', - type + type, + defaultOption }) } diff --git a/commands/monthstats.js b/commands/monthstats.js index e8a5a1ca..b8b8a18d 100644 --- a/commands/monthstats.js +++ b/commands/monthstats.js @@ -24,7 +24,7 @@ const formatLabel = (from, to, locale) => { return new Date(from).toLocaleDateString('en-EN', { month: 'short', year: 'numeric' }) } -const sendCardWithInfo = async (interaction, playerParam, page = 0, game = null, type = null) => { +const sendCardWithInfo = async (interaction, playerParam, page = 0, game = null, type = null, defaultOption = 0) => { game ??= getGameOption(interaction) return DateStats.generateDatasForCard({ @@ -36,7 +36,8 @@ const sendCardWithInfo = async (interaction, playerParam, page = 0, game = null, formatFromToDates, formatLabel, selectTranslationString: 'strings.selectMonth', - type + type, + defaultOption }) } diff --git a/commands/weekstats.js b/commands/weekstats.js index 54d3bd92..66037451 100644 --- a/commands/weekstats.js +++ b/commands/weekstats.js @@ -25,7 +25,7 @@ const formatLabel = (from, to, locale) => { return [new Date(from).toDateString(), '-', new Date(new Date(to).setHours(-24)).toDateString()].join(' ') } -const sendCardWithInfo = async (interaction, playerParam, page = 0, game = null, type = null) => { +const sendCardWithInfo = async (interaction, playerParam, page = 0, game = null, type = null, defaultOption = 0) => { game ??= getGameOption(interaction) return DateStats.generateDatasForCard({ @@ -37,7 +37,8 @@ const sendCardWithInfo = async (interaction, playerParam, page = 0, game = null, formatFromToDates, formatLabel, selectTranslationString: 'strings.selectWeek', - type + type, + defaultOption }) } diff --git a/commands/yearstats.js b/commands/yearstats.js index 5cafe092..a8eabb87 100644 --- a/commands/yearstats.js +++ b/commands/yearstats.js @@ -28,7 +28,7 @@ const formatLabel = (from, to, locale) => { return `${getTranslation('strings.year', locale)} ${new Date(from).getFullYear()}` } -const sendCardWithInfo = async (interaction, playerParam, page = 0, game = null, type = null) => { +const sendCardWithInfo = async (interaction, playerParam, page = 0, game = null, type = null, defaultOption = 0) => { game ??= getGameOption(interaction) return DateStats.generateDatasForCard({ @@ -40,7 +40,8 @@ const sendCardWithInfo = async (interaction, playerParam, page = 0, game = null, formatFromToDates, formatLabel, selectTranslationString: 'strings.selectYear', - type + type, + defaultOption }) } diff --git a/functions/dateStats.js b/functions/dateStats.js index c396af6e..4dbdcb71 100644 --- a/functions/dateStats.js +++ b/functions/dateStats.js @@ -151,7 +151,8 @@ const generateDatasForCard = async ({ formatFromToDates, formatLabel, selectTranslationString, - type + type, + defaultOption = 0 }) => { type ??= CustomType.TYPES.ELO @@ -200,14 +201,14 @@ const generateDatasForCard = async ({ }) const pages = getPageSlice(page) const paginationOptionsRaw = optionsValues.slice(pages.start, pages.end) - const values = paginationOptionsRaw[0].values + const values = paginationOptionsRaw[defaultOption].values const pagination = await Promise.all(paginationOptionsRaw.map(option => CustomTypeFunc.generateOption(interaction, option))) if (pagination.length === 0) return errorCard(getTranslation('error.user.noMatches', interaction.locale, { playerName: playerDatas.nickname }), interaction.locale) - pagination[0] = setOptionDefault(pagination.at(0)) + pagination[defaultOption] = setOptionDefault(pagination.at(defaultOption)) const resp = await getCardWithInfo({ interaction, diff --git a/interactions/buttons/pageDS.js b/interactions/buttons/pageDS.js index 1d43bcce..f3999b65 100644 --- a/interactions/buttons/pageDS.js +++ b/interactions/buttons/pageDS.js @@ -15,15 +15,17 @@ module.exports = { getCardByUserType(newUser, interaction) - interaction.message.components.at(0).components.at(0).options.forEach((option) => { - Interaction.deleteOne(option.data.value) - }) - interaction.message.components.at(1).components.forEach((component) => { - Interaction.deleteOne(component.data.custom_id) - }) - interaction.message.components.at(2).components.forEach((component) => { - Interaction.deleteOne(component.data.custom_id) - }) + if (!newUser) { + interaction.message.components.at(0).components.at(0).options.forEach((option) => { + Interaction.deleteOne(option.data.value) + }) + interaction.message.components.at(1).components.forEach((component) => { + Interaction.deleteOne(component.data.custom_id) + }) + interaction.message.components.at(2).components.forEach((component) => { + Interaction.deleteOne(component.data.custom_id) + }) + } return await require(`../../commands/${commandName}.js`) .sendCardWithInfo( diff --git a/interactions/buttons/uDSG.js b/interactions/buttons/uDSG.js index 706ab5d9..7894ada3 100644 --- a/interactions/buttons/uDSG.js +++ b/interactions/buttons/uDSG.js @@ -21,6 +21,17 @@ module.exports = { getCardByUserType(newUser, interaction) + if (newUser) { + return await require(`../../commands/${commandName}.js`) + .sendCardWithInfo( + interaction, + { param: json.playerId, faceitId: true }, + json.currentPage, + json.game, + json.type + ) + } + const resp = await DateStats.getCardWithInfo({ interaction, values: json, diff --git a/interactions/selectmenus/dateStatsSelector.js b/interactions/selectmenus/dateStatsSelector.js index da6c4daa..153065e2 100644 --- a/interactions/selectmenus/dateStatsSelector.js +++ b/interactions/selectmenus/dateStatsSelector.js @@ -5,11 +5,26 @@ const { updateButtons } = require('../../functions/customType') const { disabledOptions } = require('../../functions/pagination') const sendCardWithInfo = async (interaction, values, newUser = false) => { + const commandName = await interaction.message.fetchReference() + .then((message) => message.interaction.commandName) + .catch(() => interaction.message.interaction.commandName) let components = interaction.message.components const options = DateStats.updateDefaultOption(components.at(0).components, interaction.values[0]) getCardByUserType(newUser, interaction) + if (newUser) { + return await require(`../../commands/${commandName}.js`) + .sendCardWithInfo( + interaction, + { param: values.playerId, faceitId: true }, + values.currentPage, + values.game, + values.type, + options.findIndex(option => option.default) + ) + } + const resp = await DateStats.getCardWithInfo({ interaction, values, @@ -31,8 +46,8 @@ const sendCardWithInfo = async (interaction, values, newUser = false) => { module.exports = { name: 'dateStatsSelector', - async execute(interaction, json) { - return sendCardWithInfo(interaction, json) + async execute(interaction, json, newUser) { + return sendCardWithInfo(interaction, json, newUser) } }