Skip to content

Commit

Permalink
feat/translation (#290)
Browse files Browse the repository at this point in the history
* ✨ feat: starting translations

* translation in progress

* update getTranslation

* more progress

* fix: string

* feat: translation help && info

* feat: invite translation

* feat: join translation

* feat: last translation

* fix: translation string

* feat: translation on datestats related

* feat: link translation

* feat: options tranlations

* update destructured by structured clone

* feat: map translation

* feat: roles translation

* feat: week and year translation

* feat: functions translation

* add: ,

* feat: pagination translation
  • Loading branch information
JustDams authored Mar 22, 2023
1 parent 00c567e commit aec5f3e
Show file tree
Hide file tree
Showing 48 changed files with 896 additions and 314 deletions.
90 changes: 42 additions & 48 deletions commands/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const CustomTypeFunc = require('../functions/customType')
const CustomType = require('../templates/customType')
const Graph = require('../functions/graph')
const errorCard = require('../templates/errorCard')
const { getMapChoice } = require('../functions/map')
const { getTranslations, getTranslation } = require('../languages/setup')
const { getMapOption } = require('../functions/map')

const compareStats = (stats1, stats2, positive = true) => {
if (positive) {
Expand Down Expand Up @@ -77,7 +78,10 @@ const sendCardWithInfo = async (interaction, player1Id, player2Id, type = Custom
name: firstUserDatas.playerDatas.nickname,
iconURL: firstUserDatas.playerDatas.avatar || null
})
.setDescription(`Comparison between [${firstUserDatas.playerDatas.nickname}](https://www.faceit.com/en/players/${firstUserDatas.playerDatas.nickname}) and [${secondUserDatas.playerDatas.nickname}](https://www.faceit.com/en/players/${secondUserDatas.playerDatas.nickname})`)
.setDescription(getTranslation('strings.compare', interaction.locale, {
playerName1: `[${firstUserDatas.playerDatas.nickname}](https://www.faceit.com/en/players/${firstUserDatas.playerDatas.nickname})`,
playerName2: `[${secondUserDatas.playerDatas.nickname}](https://www.faceit.com/en/players/${secondUserDatas.playerDatas.nickname})`
}))
.setColor(color.primary)
.addFields(
...head,
Expand All @@ -96,99 +100,88 @@ const sendCardWithInfo = async (interaction, player1Id, player2Id, type = Custom
{
name: 'Elo',
value: `**${firstUserDatas.playerDatas.games.csgo.faceit_elo}** - \
${secondUserDatas.playerDatas.games.csgo.faceit_elo} ${compareStats(firstUserDatas.playerDatas.games.csgo.faceit_elo,
secondUserDatas.playerDatas.games.csgo.faceit_elo)}`,
${secondUserDatas.playerDatas.games.csgo.faceit_elo} ${compareStats(firstUserDatas.playerDatas.games.csgo.faceit_elo, secondUserDatas.playerDatas.games.csgo.faceit_elo)}`,
inline: true
},
{
name: 'Average MVPs',
value: `**${dateStatsDatas.at(0)['Average MVPs']}** - \
${dateStatsDatas.at(1)['Average MVPs']} ${compareStats(dateStatsDatas.at(0)['Average MVPs'],
dateStatsDatas.at(1)['Average MVPs'])}`,
${dateStatsDatas.at(1)['Average MVPs']} ${compareStats(dateStatsDatas.at(0)['Average MVPs'], dateStatsDatas.at(1)['Average MVPs'])}`,
inline: true
},
{
name: 'K/D', value: `**${dateStatsDatas.at(0).kd}** - \
${dateStatsDatas.at(1).kd} ${compareStats(dateStatsDatas.at(0).kd,
dateStatsDatas.at(1).kd)}`, inline: true
${dateStatsDatas.at(1).kd} ${compareStats(dateStatsDatas.at(0).kd, dateStatsDatas.at(1).kd)}`, inline: true
},
{
name: 'Kills', value: `**${dateStatsDatas.at(0).kills}** - \
${dateStatsDatas.at(1).kills} ${compareStats(dateStatsDatas.at(0).kills,
dateStatsDatas.at(1).kills)}`, inline: true
${dateStatsDatas.at(1).kills} ${compareStats(dateStatsDatas.at(0).kills, dateStatsDatas.at(1).kills)}`, inline: true
},
{
name: 'Deaths', value: `**${dateStatsDatas.at(0).deaths}** - \
${dateStatsDatas.at(1).deaths} ${compareStats(dateStatsDatas.at(0).deaths,
dateStatsDatas.at(1).deaths, false)}`, inline: true
${dateStatsDatas.at(1).deaths} ${compareStats(dateStatsDatas.at(0).deaths, dateStatsDatas.at(1).deaths, false)}`, inline: true
},
{
name: 'Average K/D',
value: `**${dateStatsDatas.at(0)['Average K/D']}** - \
${dateStatsDatas.at(1)['Average K/D']} ${compareStats(dateStatsDatas.at(0)['Average K/D'],
dateStatsDatas.at(1)['Average K/D'])}`,
${dateStatsDatas.at(1)['Average K/D']} ${compareStats(dateStatsDatas.at(0)['Average K/D'], dateStatsDatas.at(1)['Average K/D'])}`,
inline: true
},
{
name: 'Average K/R',
value: `**${dateStatsDatas.at(0)['Average K/R']}** - \
${dateStatsDatas.at(1)['Average K/R']} ${compareStats(dateStatsDatas.at(0)['Average K/R'],
dateStatsDatas.at(1)['Average K/R'])}`,
${dateStatsDatas.at(1)['Average K/R']} ${compareStats(dateStatsDatas.at(0)['Average K/R'], dateStatsDatas.at(1)['Average K/R'])}`,
inline: true
},
{
name: 'Average HS',
value: `**${dateStatsDatas.at(0)['Average HS']}%** - \
${dateStatsDatas.at(1)['Average HS']}% ${compareStats(dateStatsDatas.at(0)['Average HS'],
dateStatsDatas.at(1)['Average HS'])}`,
${dateStatsDatas.at(1)['Average HS']}% ${compareStats(dateStatsDatas.at(0)['Average HS'], dateStatsDatas.at(1)['Average HS'])}`,
inline: true
},
{
name: 'Average Kills',
value: `**${dateStatsDatas.at(0)['Average Kills']}** - \
${dateStatsDatas.at(1)['Average Kills']} ${compareStats(dateStatsDatas.at(0)['Average Kills'],
dateStatsDatas.at(1)['Average Kills'])}`,
${dateStatsDatas.at(1)['Average Kills']} ${compareStats(dateStatsDatas.at(0)['Average Kills'], dateStatsDatas.at(1)['Average Kills'])}`,
inline: true
},
{
name: 'Average Deaths',
value: `**${dateStatsDatas.at(0)['Average Deaths']}** - \
${dateStatsDatas.at(1)['Average Deaths']} ${compareStats(dateStatsDatas.at(0)['Average Deaths'],
dateStatsDatas.at(1)['Average Deaths'], false)}`,
${dateStatsDatas.at(1)['Average Deaths']} ${compareStats(dateStatsDatas.at(0)['Average Deaths'], dateStatsDatas.at(1)['Average Deaths'], false)}`,
inline: true
},
{
name: 'Average Assists',
value: `**${dateStatsDatas.at(0)['Average Assists']}** - \
${dateStatsDatas.at(1)['Average Assists']} ${compareStats(dateStatsDatas.at(0)['Average Assists'],
dateStatsDatas.at(1)['Average Assists'])}`,
${dateStatsDatas.at(1)['Average Assists']} ${compareStats(dateStatsDatas.at(0)['Average Assists'], dateStatsDatas.at(1)['Average Assists'])}`,
inline: true
},
{
name: 'Red K/D',
value: `**${dateStatsDatas.at(0)['Red K/D']}** - \
${dateStatsDatas.at(1)['Red K/D']} ${compareStats(dateStatsDatas.at(0)['Red K/D'],
dateStatsDatas.at(1)['Red K/D'], false)}`,
${dateStatsDatas.at(1)['Red K/D']} ${compareStats(dateStatsDatas.at(0)['Red K/D'], dateStatsDatas.at(1)['Red K/D'], false)}`,
inline: true
},
{
name: 'Orange K/D',
value: `**${dateStatsDatas.at(0)['Orange K/D']}** - \
${dateStatsDatas.at(1)['Orange K/D']} ${compareStats(dateStatsDatas.at(0)['Orange K/D'],
dateStatsDatas.at(1)['Orange K/D'], false)}`,
${dateStatsDatas.at(1)['Orange K/D']} ${compareStats(dateStatsDatas.at(0)['Orange K/D'], dateStatsDatas.at(1)['Orange K/D'], false)}`,
inline: true
},
{
name: 'Green K/D',
value: `**${dateStatsDatas.at(0)['Green K/D']}** - \
${dateStatsDatas.at(1)['Green K/D']} ${compareStats(dateStatsDatas.at(0)['Green K/D'],
dateStatsDatas.at(1)['Green K/D'])}`,
${dateStatsDatas.at(1)['Green K/D']} ${compareStats(dateStatsDatas.at(0)['Green K/D'], dateStatsDatas.at(1)['Green K/D'])}`,
inline: true
})
.setImage('attachment://graph.png')

const options = [{
label: `Compare ${firstUserDatas.playerDatas.nickname} and ${secondUserDatas.playerDatas.nickname}`,
label: getTranslation('strings.compare', interaction.locale, {
playerName1: firstUserDatas.playerDatas.nickname,
playerName2: secondUserDatas.playerDatas.nickname
}),
value: JSON.stringify({
p1: firstUserDatas.playerId,
p2: secondUserDatas.playerId,
Expand All @@ -210,7 +203,7 @@ const sendCardWithInfo = async (interaction, player1Id, player2Id, type = Custom
user.playerDatas.nickname,
type,
playerColor[i],
Graph.getGraph(type, user.playerHistory, user.playerDatas.games.csgo.faceit_elo, maxMatch, true).reverse()
Graph.getGraph(interaction, type, user.playerHistory, user.playerDatas.games.csgo.faceit_elo, maxMatch, true).reverse()
])

const graphBuffer = Graph.getChart(
Expand All @@ -234,10 +227,12 @@ const sendCardWithInfo = async (interaction, player1Id, player2Id, type = Custom
new Discord.ActionRowBuilder()
.addComponents([
CustomTypeFunc.generateButtons(
interaction,
{ ...buttonValues, n: 1 },
CustomType.TYPES.KD,
type === CustomType.TYPES.KD),
CustomTypeFunc.generateButtons(
interaction,
{ ...buttonValues, n: 2 },
CustomType.TYPES.ELO,
type === CustomType.TYPES.ELO)
Expand All @@ -250,57 +245,56 @@ module.exports = {
name: 'compare',
options: [{
name: 'match_number',
description: 'Number of matches to display. Default: 20',
description: getTranslation('options.matchNumber', 'en-US'),
descriptionLocalizations: getTranslations('options.matchNumber'),
required: false,
type: Discord.ApplicationCommandOptionType.Integer,
slash: true,
},
{
name: 'first_user_steam',
description: 'steam parameter / @user / empty to match your linked account',
description: getTranslation('options.steamParameter', 'en-US'),
descriptionLocalizations: getTranslations('options.steamParameter'),
required: false,
type: Discord.ApplicationCommandOptionType.String,
slash: true
},
{
name: 'first_user_faceit',
description: 'faceit nickname / @user / empty to match your linked account',
description: getTranslation('options.faceitParameter', 'en-US'),
descriptionLocalizations: getTranslations('options.faceitParameter'),
required: false,
type: Discord.ApplicationCommandOptionType.String,
slash: true
},
{
name: 'second_user_steam',
description: 'steam parameter / @user / empty to match your linked account',
description: getTranslation('options.steamParameter', 'en-US'),
descriptionLocalizations: getTranslations('options.steamParameter'),
required: false,
type: Discord.ApplicationCommandOptionType.String,
slash: true
},
{
name: 'second_user_faceit',
description: 'faceit nickname / @user / empty to match your linked account',
description: getTranslation('options.faceitParameter', 'en-US'),
descriptionLocalizations: getTranslations('options.faceitParameter'),
required: false,
type: Discord.ApplicationCommandOptionType.String,
slash: true
},
{
name: 'map',
description: 'Map name',
required: false,
type: Discord.ApplicationCommandOptionType.String,
slash: true,
choices: getMapChoice()
},],
description: 'Compare both user stats.',
getMapOption(),],
description: getTranslation('command.compare.description', 'en-US'),
descriptionLocalizations: getTranslations('command.compare.description'),
usage: '<match_number> {<first_user_steam> <first_user_faceit>} [<second_user_steam> <second_user_faceit>] <map>',
example: 'match_number: 100 first_user_steam: justdams second_user_steam: sheraw map: Vertigo',
type: 'stats',
async execute(interaction) {
const player1 = (await getUsers(interaction, 1, 'first_user_steam', 'first_user_faceit'))?.at(0)?.param
const player2 = (await getUsers(interaction, 1, 'second_user_steam', 'second_user_faceit'))?.at(0)?.param

if (!player1 || !player2) return errorCard('There is a user missing.')
else if (player1 === player2) return errorCard('Both users are the same !')
if (!player1 || !player2) return errorCard(getTranslation('error.user.missing', interaction.locale), interaction.locale)
else if (player1 === player2) return errorCard(getTranslation('error.user.compareSame', interaction.locale), interaction.locale)

return sendCardWithInfo(interaction, player1, player2)
}
Expand Down
15 changes: 10 additions & 5 deletions commands/dailystats.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { getCardsConditions } = require('../functions/commands')
const CustomType = require('../templates/customType')
const Options = require('../templates/options')
const { getPageSlice, getMaxPage } = require('../functions/pagination')
const { getTranslations, getTranslation } = require('../languages/setup')

const getDay = date => {
date = new Date(date)
Expand All @@ -26,7 +27,7 @@ const sendCardWithInfo = async (interaction, playerId, page = 0) => {

let option = new Discord.StringSelectMenuOptionBuilder()
.setLabel(from.toDateString())
.setDescription(`${date.number} match played`)
.setDescription(getTranslation('strings.matchPlayed', interaction.locale, { matchNumber: date.number }))
.setValue(JSON.stringify({
s: playerId,
f: from.getTime() / 1000,
Expand All @@ -40,18 +41,21 @@ const sendCardWithInfo = async (interaction, playerId, page = 0) => {
const pages = getPageSlice(page)
const pagination = options.slice(pages.start, pages.end)

if (pagination.length === 0) return errorCard(`Couldn't get matches of ${playerDatas.nickname}`)
if (pagination.length === 0) return errorCard(getTranslation('error.user.noMatches', interaction.locale, {
playerName: playerDatas.nickname
}), interaction.locale)

pagination[0] = DateStats.setOptionDefault(pagination.at(0))

const row = new Discord.ActionRowBuilder()
.addComponents(
new Discord.StringSelectMenuBuilder()
.setCustomId('dateStatsSelector')
.setPlaceholder('Select a day')
.setPlaceholder(getTranslation('strings.selectDate', interaction.locale))
.addOptions(pagination))

return DateStats.getCardWithInfo(row,
return DateStats.getCardWithInfo(interaction,
row,
JSON.parse(pagination[0].data.value),
CustomType.TYPES.ELO,
'uDSG',
Expand All @@ -63,7 +67,8 @@ const sendCardWithInfo = async (interaction, playerId, page = 0) => {
module.exports = {
name: 'dailystats',
options: Options.stats,
description: 'Displays the stats of the choosen day. With elo graph of the day.',
description: getTranslation('command.dailystats.description', 'en-US'),
descriptionLocalizations: getTranslations('command.dailystats.description'),
usage: Options.usage,
example: 'steam_parameters: justdams',
type: 'stats',
Expand Down
28 changes: 13 additions & 15 deletions commands/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,29 @@ const { ApplicationCommandOptionType } = require('discord.js')
const Options = require('../templates/options')
const { getUsers, getInteractionOption } = require('../functions/commands')
const { sendCardWithInfo } = require('./last')
const { getMapChoice } = require('../functions/map')
const { getMapOption } = require('../functions/map')
const { getTranslations, getTranslation } = require('../languages/setup')

const getOptions = () => {
const options = [...Options.stats]
const options = structuredClone(Options.stats)
options.unshift({
name: 'player_aimed',
description: 'steam_params / faceit_params / @user / empty if linked. History of the player you want to search in.',
description: getTranslation('options.playerAimed', 'en-US'),
descriptionLocalizations: getTranslations('options.playerAimed'),
required: false,
type: ApplicationCommandOptionType.String,
slash: true
}, {
name: 'map',
description: 'Specify a map to get the stats related',
required: false,
type: ApplicationCommandOptionType.String,
slash: true,
choices: getMapChoice()
}, {
}, getMapOption(), {
name: 'excluded_steam_parameters',
description: 'If you want to exclude steam parameters from the search',
description: getTranslation('options.excludedSteamParameters', 'en-US'),
descriptionLocalizations: getTranslations('options.excludedSteamParameters'),
required: false,
type: ApplicationCommandOptionType.String,
slash: true
}, {
name: 'excluded_faceit_parameters',
description: 'If you want to exclude faceit parameters from the search',
description: getTranslation('options.excludedFaceitParameters', 'en-US'),
descriptionLocalizations: getTranslations('options.excludedFaceitParameters'),
required: false,
type: ApplicationCommandOptionType.String,
slash: true
Expand All @@ -39,7 +36,8 @@ const getOptions = () => {
module.exports = {
name: 'find',
options: getOptions(),
description: 'Find the games that includes the player requested (up to 5)',
description: getTranslation('command.find.description', 'en-US'),
descriptionLocalizations: getTranslations('command.find.description'),
usage: '{player_aimed} [<steam_parameters> <faceit_parameters> <team>] <map> <excluded_steam_parameters> <excluded_faceit_parameters>',
example: 'player_aimed: justdams steam_parameters: weder77 faceit_parameters: sheraw excluded_faceit_parameters: KanzakiR3D map: Vertigo',
type: 'stats',
Expand All @@ -56,7 +54,7 @@ module.exports = {
const excludedFaceit = getInteractionOption(interaction, 'excluded_faceit_parameters')

if (!excludedSteam && !excludedFaceit) excludedUsers = excludedUsers.filter(e => e.normalize() !== playerAimed.normalize())
if (excludedUsers.some(e => users.includes(e)) || excludedUsers.includes(playerAimed)) throw 'You can\'t exclude a player you are searching for.'
if (excludedUsers.some(e => users.includes(e)) || excludedUsers.includes(playerAimed)) throw getTranslation('error.user.excluded', interaction.locale)

return sendCardWithInfo(interaction, playerAimed, null, 0, users.filter(e => e.normalize() !== playerAimed.normalize()), null, excludedUsers)
}
Expand Down
Loading

0 comments on commit aec5f3e

Please sign in to comment.