Skip to content

Commit

Permalink
feat/map option datestats (#430)
Browse files Browse the repository at this point in the history
* feat: hide damages, adr and entries since faceit removed those from the endpoint used by the backend

* feat: map option on datestats commands
  • Loading branch information
JustDams authored Sep 13, 2024
1 parent 0c79d78 commit 44e987b
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 28 deletions.
16 changes: 11 additions & 5 deletions commands/dailystats.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const DateStats = require('../functions/dateStats')
const { getCardsConditions } = require('../functions/commands')
const Options = require('../templates/options')
const { getTranslations, getTranslation } = require('../languages/setup')
const { getGameOption } = require('../functions/utility')
const { getGameOption, getInteractionOption } = require('../functions/utility')
const { getMapOption } = require('../functions/map')

const getDay = date => {
date = new Date(date)
Expand All @@ -24,8 +25,9 @@ const formatLabel = (from, to) => {
return new Date(from).toDateString()
}

const sendCardWithInfo = async (interaction, playerParam, page = 0, game = null, type = null, defaultOption = 0) => {
const sendCardWithInfo = async (interaction, playerParam, page = 0, game = null, type = null, defaultOption = 0, map = null) => {
game ??= getGameOption(interaction)
map ??= getInteractionOption(interaction, 'map') ?? ''

return DateStats.generateDatasForCard({
interaction,
Expand All @@ -37,16 +39,20 @@ const sendCardWithInfo = async (interaction, playerParam, page = 0, game = null,
formatLabel,
selectTranslationString: 'strings.selectDate',
type,
defaultOption
defaultOption,
map
})
}

module.exports = {
name: 'dailystats',
options: Options.stats,
options: [
...Options.stats,
getMapOption()
],
description: getTranslation('command.dailystats.description', 'en-US'),
descriptionLocalizations: getTranslations('command.dailystats.description'),
usage: Options.usage,
usage: `${Options.usage} <map>`,
example: 'steam_parameters: justdams',
type: 'stats',
async execute(interaction) {
Expand Down
16 changes: 11 additions & 5 deletions commands/monthstats.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const DateStats = require('../functions/dateStats')
const { getCardsConditions } = require('../functions/commands')
const Options = require('../templates/options')
const { getTranslations, getTranslation } = require('../languages/setup')
const { getGameOption } = require('../functions/utility')
const { getGameOption, getInteractionOption } = require('../functions/utility')
const { getMapOption } = require('../functions/map')

const getFirstDay = (x) => {
const a = new Date(x)
Expand All @@ -25,8 +26,9 @@ 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, defaultOption = 0) => {
const sendCardWithInfo = async (interaction, playerParam, page = 0, game = null, type = null, defaultOption = 0, map = null) => {
game ??= getGameOption(interaction)
map ??= getInteractionOption(interaction, 'map') ?? ''

return DateStats.generateDatasForCard({
interaction,
Expand All @@ -38,16 +40,20 @@ const sendCardWithInfo = async (interaction, playerParam, page = 0, game = null,
formatLabel,
selectTranslationString: 'strings.selectMonth',
type,
defaultOption
defaultOption,
map
})
}

module.exports = {
name: 'monthstats',
options: Options.stats,
options: [
...Options.stats,
getMapOption()
],
description: getTranslation('command.monthstats.description', 'en-US'),
descriptionLocalizations: getTranslations('command.monthstats.description'),
usage: Options.usage,
usage: `${Options.usage} <map>`,
type: 'stats',
async execute(interaction) {
return getCardsConditions({
Expand Down
16 changes: 11 additions & 5 deletions commands/weekstats.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const DateStats = require('../functions/dateStats')
const { getCardsConditions } = require('../functions/commands')
const Options = require('../templates/options')
const { getTranslation, getTranslations } = require('../languages/setup')
const { getGameOption } = require('../functions/utility')
const { getGameOption, getInteractionOption } = require('../functions/utility')
const { getMapOption } = require('../functions/map')

const getMonday = date => {
const week = [6, 0, 1, 2, 3, 4, 5]
Expand All @@ -26,8 +27,9 @@ 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, defaultOption = 0) => {
const sendCardWithInfo = async (interaction, playerParam, page = 0, game = null, type = null, defaultOption = 0, map = null) => {
game ??= getGameOption(interaction)
map ??= getInteractionOption(interaction, 'map') ?? ''

return DateStats.generateDatasForCard({
interaction,
Expand All @@ -39,16 +41,20 @@ const sendCardWithInfo = async (interaction, playerParam, page = 0, game = null,
formatLabel,
selectTranslationString: 'strings.selectWeek',
type,
defaultOption
defaultOption,
map
})
}

module.exports = {
name: 'weekstats',
options: Options.stats,
options: [
...Options.stats,
getMapOption()
],
description: getTranslation('command.weekstats.description', 'en-US'),
descriptionLocalizations: getTranslations('command.weekstats.description'),
usage: Options.usage,
usage: `${Options.usage} <map>`,
example: 'steam_parameters: justdams',
type: 'stats',
async execute(interaction) {
Expand Down
16 changes: 11 additions & 5 deletions commands/yearstats.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const DateStats = require('../functions/dateStats')
const { getCardsConditions } = require('../functions/commands')
const Options = require('../templates/options')
const { getTranslation, getTranslations } = require('../languages/setup')
const { getGameOption } = require('../functions/utility')
const { getGameOption, getInteractionOption } = require('../functions/utility')
const { getMapOption } = require('../functions/map')

const getYear = date => {
date = new Date(date)
Expand All @@ -29,8 +30,9 @@ 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, defaultOption = 0) => {
const sendCardWithInfo = async (interaction, playerParam, page = 0, game = null, type = null, defaultOption = 0, map = null) => {
game ??= getGameOption(interaction)
map ??= getInteractionOption(interaction, 'map') ?? ''

return DateStats.generateDatasForCard({
interaction,
Expand All @@ -42,16 +44,20 @@ const sendCardWithInfo = async (interaction, playerParam, page = 0, game = null,
formatLabel,
selectTranslationString: 'strings.selectYear',
type,
defaultOption
defaultOption,
map
})
}

module.exports = {
name: 'yearstats',
options: Options.stats,
options: [
...Options.stats,
getMapOption()
],
description: getTranslation('command.yearstats.description', 'en-US'),
descriptionLocalizations: getTranslations('command.yearstats.description'),
usage: Options.usage,
usage: `${Options.usage} <map>`,
example: 'steam_parameters: justdams',
type: 'stats',
async execute(interaction) {
Expand Down
9 changes: 5 additions & 4 deletions functions/dateStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const getCardWithInfo = async ({
name: 'From - To', value: [new Date(startDate).toDateString(), '\n', new Date(endDateToRealTimeStamp).toDateString()].join(' '),
inline: !!map
})
else head.push({ name: 'From', value: new Date(startDate).toDateString(), inline: false })
else head.push({ name: 'From', value: new Date(startDate).toDateString(), inline: !!map })
if (map) head.push({ name: 'Map', value: map, inline: true }, { name: '\u200b', value: '\u200b', inline: true })

const card = new Discord.EmbedBuilder()
Expand Down Expand Up @@ -120,7 +120,8 @@ const generateDatasForCard = async ({
formatLabel,
selectTranslationString,
type,
defaultOption = 0
defaultOption = 0,
map = ''
}) => {
type ??= CustomType.TYPES.ELO

Expand All @@ -130,7 +131,8 @@ const generateDatasForCard = async ({
} = await getStats({
playerParam,
matchNumber: 0,
game
game,
map
})

if (!playerHistory.length) throw getTranslation('error.user.noMatches', interaction.locale, {
Expand All @@ -141,7 +143,6 @@ const generateDatasForCard = async ({
const optionsValues = []
const dates = await getDates(playerHistory, functionToGetDates)
const maxMatch = 0
const map = ''

dates.forEach(date => {
const {
Expand Down
1 change: 0 additions & 1 deletion functions/roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ const handleRoleErrors = (err, role) => {
}

const logRoleUpdate = (client, member, role, guildDatas, playerElo, action) => {
console.log(role)
client.guilds.fetch(logGuild)
.then(guild => guild.channels.fetch(logChannel))
.then(channel => channel.send({
Expand Down
4 changes: 3 additions & 1 deletion interactions/buttons/pageDS.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ module.exports = {
{ param: json.playerId, faceitId: true },
json.targetPage,
json.game,
json.chartType
json.chartTypen,
0,
json.map
)
}
}
2 changes: 1 addition & 1 deletion scripts/check_guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ client.on('ready', async () => {
const guild = await client.guilds.fetch(guildId)

if (!guild) return
console.log('Guild found:', guild.name)
console.info('Guild found:', guild.name)

await updateRoles(client, null, guildId)
})
2 changes: 1 addition & 1 deletion scripts/register_roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ axios.put(url, body, {
Authorization: `Bot ${process.env.TOKEN}`,
},
}).then((res) => {
console.log(res.data)
console.info(res.data)
}).catch((err) => {
console.error(err)
})

0 comments on commit 44e987b

Please sign in to comment.