Skip to content

Commit

Permalink
feat: new user
Browse files Browse the repository at this point in the history
  • Loading branch information
JustDams committed Oct 27, 2023
1 parent fd94712 commit 8702ac4
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 22 deletions.
5 changes: 3 additions & 2 deletions commands/dailystats.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -35,7 +35,8 @@ const sendCardWithInfo = async (interaction, playerParam, page = 0, game = null,
formatFromToDates,
formatLabel,
selectTranslationString: 'strings.selectDate',
type
type,
defaultOption
})
}

Expand Down
5 changes: 3 additions & 2 deletions commands/monthstats.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -36,7 +36,8 @@ const sendCardWithInfo = async (interaction, playerParam, page = 0, game = null,
formatFromToDates,
formatLabel,
selectTranslationString: 'strings.selectMonth',
type
type,
defaultOption
})
}

Expand Down
5 changes: 3 additions & 2 deletions commands/weekstats.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -37,7 +37,8 @@ const sendCardWithInfo = async (interaction, playerParam, page = 0, game = null,
formatFromToDates,
formatLabel,
selectTranslationString: 'strings.selectWeek',
type
type,
defaultOption
})
}

Expand Down
5 changes: 3 additions & 2 deletions commands/yearstats.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -40,7 +40,8 @@ const sendCardWithInfo = async (interaction, playerParam, page = 0, game = null,
formatFromToDates,
formatLabel,
selectTranslationString: 'strings.selectYear',
type
type,
defaultOption
})
}

Expand Down
7 changes: 4 additions & 3 deletions functions/dateStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ const generateDatasForCard = async ({
formatFromToDates,
formatLabel,
selectTranslationString,
type
type,
defaultOption = 0
}) => {
type ??= CustomType.TYPES.ELO

Expand Down Expand Up @@ -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,
Expand Down
20 changes: 11 additions & 9 deletions interactions/buttons/pageDS.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 11 additions & 0 deletions interactions/buttons/uDSG.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 17 additions & 2 deletions interactions/selectmenus/dateStatsSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
}
}

Expand Down

0 comments on commit 8702ac4

Please sign in to comment.