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

feat/map option datestats #430

Merged
merged 2 commits into from
Sep 13, 2024
Merged
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
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
8 changes: 5 additions & 3 deletions commands/last.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ const getMatchItems = async (interaction, playerDatas, steamDatas, playerHistory
{ name: 'Kills', value: roundStats.i6, inline: true },
{ name: 'Deaths', value: roundStats.i8, inline: true },
{ name: 'Assists', value: roundStats.i7, inline: true },
{ name: 'Damages', value: roundStats?.i20 ?? 'N/A', inline: true },
{ name: 'ADR', value: roundStats?.c10 ?? 'N/A', inline: true },
{ name: 'Entries (WR)', value: entries, inline: true },)
// Removed from faceit endpoint used by the api
// { name: 'Damages', value: roundStats?.i20 ?? 'N/A', inline: true },
// { name: 'ADR', value: roundStats?.c10 ?? 'N/A', inline: true },
// { name: 'Entries (WR)', value: entries, inline: true },
)
.setThumbnail(`attachment://${faceitElo}${i}.png`)
.setImage(`attachment://${mapName}.jpg`)
.setColor(result ? color.won : color.lost)
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
16 changes: 9 additions & 7 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 Expand Up @@ -245,9 +246,10 @@ const generateDateStatsFields = (playerLastStats, head) => {
{ name: 'Avg Kills', value: playerLastStats['Average Kills'].toFixed(2), inline: true },
{ name: 'Avg Deaths', value: playerLastStats['Average Deaths'].toFixed(2), inline: true },
{ name: 'Avg Assists', value: playerLastStats['Average Assists'].toFixed(2), inline: true },
{ name: 'Avg Damages', value: playerLastStats['Average Damages']?.toString() ?? 'N/A', inline: true },
{ name: 'Avg ADR', value: playerLastStats['Average ADR']?.toString() ?? 'N/A', inline: true },
{ name: 'Avg Entries (WR)', value: entries, inline: true },
// Removed from faceit endpoint used by the api
// { name: 'Avg Damages', value: playerLastStats['Average Damages']?.toString() ?? 'N/A', inline: true },
// { name: 'Avg ADR', value: playerLastStats['Average ADR']?.toString() ?? 'N/A', inline: true },
// { name: 'Avg Entries (WR)', value: entries, inline: true },
{ name: 'Red K/D', value: playerLastStats['Red K/D'].toString(), inline: true },
{ name: 'Orange K/D', value: playerLastStats['Orange K/D'].toString(), inline: true },
{ name: 'Green K/D', value: playerLastStats['Green K/D'].toString(), inline: true },
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)
})
Loading