Skip to content

Commit

Permalink
fix: translations string and map issue (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustDams authored Apr 6, 2023
1 parent c794a09 commit e65a39d
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 28 deletions.
4 changes: 2 additions & 2 deletions commands/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ module.exports = {
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(getTranslation('error.user.missing', interaction.locale), interaction.locale)
else if (player1 === player2) return errorCard(getTranslation('error.user.compareSame', interaction.locale), interaction.locale)
if (!player1 || !player2) return errorCard('error.user.missing', interaction.locale)
else if (player1 === player2) return errorCard('error.user.compareSame', interaction.locale)

return sendCardWithInfo(interaction, player1, player2)
}
Expand Down
6 changes: 3 additions & 3 deletions commands/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const sendCardWithInfo = async (interaction, playerId) => {
const discordUserId = member.user.id

if (!interaction.member.permissions.has('ManageRoles') && discordUserId !== discordId)
return errorCard(getTranslation('error.user.permissions.manageRoles', lang), lang)
else if (member.user.bot) return errorCard(getTranslation('error.user.noBotLink', lang), lang)
return errorCard('error.user.permissions.manageRoles', lang)
else if (member.user.bot) return errorCard('error.user.noBotLink', lang)

const exists = await User.getWithGuild(discordUserId, null)
if (exists)
Expand All @@ -31,7 +31,7 @@ const sendCardWithInfo = async (interaction, playerId) => {

return link(interaction, playerId, discordUserId, guild.id, nickname)
})
.catch(() => errorCard(getTranslation('error.user.notFound', lang), lang))
.catch(() => errorCard('error.user.notFound', lang))
}

return link(interaction, playerId, discordId, null, nickname)
Expand Down
4 changes: 2 additions & 2 deletions commands/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const sendCardWithInfo = async (interaction, playerId) => {
if (!options.filter(e => e.data.label === label).length > 0) {
const option = new Discord.StringSelectMenuOptionBuilder()
.setLabel(label)
.setDescription(`Games ${e.stats.Matches} (${e.stats['Win Rate %']}%)`)
.setDescription(getTranslation('strings.matchPlayed', interaction.locale, { matchNumber: `${e.stats.Matches} (${e.stats['Win Rate %']}%)` }))
.setValue(JSON.stringify(values))
.setDefault(`${map} 5v5` === label)

Expand All @@ -45,7 +45,7 @@ const sendCardWithInfo = async (interaction, playerId) => {
)

return {
...await mapSelector.sendCardWithInfo(playerId, map, '5v5'),
...await mapSelector.sendCardWithInfo(interaction, playerId, map, '5v5'),
content: map ? ' ' : getTranslation('strings.selectMapDescription', interaction.locale, { playerName: playerDatas.nickname }),
components: [row]
}
Expand Down
8 changes: 5 additions & 3 deletions commands/monthstats.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const sendCardWithInfo = async (interaction, playerId, page = 0) => {

let option = new Discord.StringSelectMenuOptionBuilder()
.setLabel(`${from.toLocaleDateString('en-EN', { month: 'short', year: 'numeric' })}`)
.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 @@ -42,15 +42,17 @@ 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}`, interaction.locale)
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 month')
.setPlaceholder(getTranslation('strings.selectMonth', interaction.locale))
.addOptions(pagination))

return DateStats.getCardWithInfo(interaction,
Expand Down
6 changes: 3 additions & 3 deletions commands/roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,14 @@ module.exports = {
type: 'utility',
async execute(interaction) {
if (!interaction.member.permissions.has('ManageRoles'))
return errorCard(getTranslation('error.user.permissions.manageRoles', interaction.locale))
return errorCard('error.user.permissions.manageRoles', interaction.locale)

if (!interaction.channel.permissionsFor(interaction.client.user).has('ManageRoles'))
return errorCard(getTranslation('error.bot.manageRoles', interaction.locale))
return errorCard('error.bot.manageRoles', interaction.locale)

if (isInteractionSubcommandEqual(interaction, SETUP)) return await setupRoles(interaction)
if (isInteractionSubcommandEqual(interaction, GENERATE)) return await generateRoles(interaction)
if (isInteractionSubcommandEqual(interaction, REMOVE)) return await removeRoles(interaction)
.then(() => successCard(getTranslation('success.command.removeRoles', interaction.locale), interaction.locale))
.then(() => successCard('success.command.removeRoles', interaction.locale))
}
}
16 changes: 8 additions & 8 deletions commands/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ const ADD_USER = 'add_user'
const REMOVE_USER = 'remove_user'

const createTeam = async (interaction, currentTeam, user) => {
if (currentTeam) return errorCard(getTranslation('error.command.alreadyOwnTeam', interaction.locale))
if (currentTeam) return errorCard('error.command.alreadyOwnTeam', interaction.locale)
const teamName = getInteractionOption(interaction, 'name')
const teamSlug = teamName.toLowerCase().replace(/\s/g, '-')
if (teamName.length > maxLengthTeamName) return errorCard(getTranslation('error.command.teamNameTooLong', interaction.locale))
else if (await Team.getTeamSlug(teamSlug)) return errorCard(getTranslation('error.command.teamNameAlreadyExist', interaction.locale))
if (teamName.length > maxLengthTeamName) return errorCard('error.command.teamNameTooLong', interaction.locale)
else if (await Team.getTeamSlug(teamSlug)) return errorCard('error.command.teamNameAlreadyExist', interaction.locale)
const access = getInteractionOption(interaction, 'access')
Team.create(teamName, teamSlug, user, access)

Expand All @@ -41,7 +41,7 @@ const infoTeam = async (interaction, currentTeam, user) => {
userTeams.push(...await Promise.all(currentUserTeams.map(async (userTeam) => await Team.getTeamSlug(userTeam.slug))))
}
if (currentTeam) userTeams.push(currentTeam)
if (userTeams.length === 0) return errorCard(getTranslation('error.user.noTeam', interaction.locale))
if (userTeams.length === 0) return errorCard('error.user.noTeam', interaction.locale)

const options = Array.from(new Set(userTeams.map(JSON.stringify)))
.map(JSON.parse)
Expand Down Expand Up @@ -76,7 +76,7 @@ const infoTeam = async (interaction, currentTeam, user) => {
const updateTeam = async (interaction, currentTeam) => {
const teamName = getInteractionOption(interaction, 'name')
const teamSlug = teamName?.toLowerCase().replace(/\s/g, '-')
if (teamName && await Team.getTeamSlug(teamSlug)) return errorCard(getTranslation('error.command.teamNameAlreadyExists', interaction.locale))
if (teamName && await Team.getTeamSlug(teamSlug)) return errorCard('error.command.teamNameAlreadyExists', interaction.locale)
else if (teamName) await UserTeam.updateMany(currentTeam.slug, teamSlug)
const access = getInteractionOption(interaction, 'access')
Team.update(currentTeam.slug, teamName || currentTeam.name, teamSlug || currentTeam.slug, access)
Expand Down Expand Up @@ -270,16 +270,16 @@ module.exports = {
const currentTeam = await Team.getCreatorTeam(user)

if (!currentTeam && !isInteractionSubcommandEqual(interaction, CREATE) &&
!isInteractionSubcommandEqual(interaction, INFO)) return errorCard(getTranslation('error.user.teamOwn', interaction.locale))
!isInteractionSubcommandEqual(interaction, INFO)) return errorCard('error.user.teamOwn', interaction.locale)
else if (isInteractionSubcommandEqual(interaction, CREATE)) return createTeam(interaction, currentTeam, user)
else if (isInteractionSubcommandEqual(interaction, INFO)) return infoTeam(interaction, currentTeam, user)
else if (isInteractionSubcommandEqual(interaction, UPDATE)) return updateTeam(interaction, currentTeam, user)
else if (isInteractionSubcommandEqual(interaction, DELETE)) return deleteTeam(interaction, currentTeam, user)
else if (isInteractionSubcommandEqual(interaction, ADD_USER)) {
const teamUsers = await UserTeam.getTeamUsers(currentTeam.slug)
if (teamUsers.length >= 5) return errorCard(getTranslation('error.user.teamFull', interaction.locale))
if (teamUsers.length >= 5) return errorCard('error.user.teamFull', interaction.locale)
return getCardsConditions(interaction, addUser, 5 - teamUsers.length)
} else if (isInteractionSubcommandEqual(interaction, REMOVE_USER)) return getCardsConditions(interaction, removeUser, 5)
else return errorCard(getTranslation('error.command.notFound', interaction.locale))
else return errorCard('error.command.notFound', interaction.locale)
}
}
2 changes: 1 addition & 1 deletion events/interactionCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = {
interaction
.followUp({
content: ' ',
...errorCard(getTranslation('error.bot.channelNotAccessible', interaction.locale), interaction.locale),
...errorCard('error.bot.channelNotAccessible', interaction.locale),
})
.catch(console.error)
})
Expand Down
2 changes: 1 addition & 1 deletion events/messageCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ module.exports = {
async execute(message) {
if (!message.content.toLowerCase().startsWith(prefix) || message.author.bot) return
else if (message.client.antispam.isIgnored(message.author.id, message.createdAt, message.channel)) return
else message.reply(noMention(errorCard(getTranslation('error.bot.messageEvent', message.interaction?.locale), message.interaction?.locale))).catch(console.error)
else message.reply(noMention(errorCard('error.bot.messageEvent', message.interaction?.locale))).catch(console.error)
}
}
2 changes: 1 addition & 1 deletion functions/dateStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const generatePlayerStats = playerHistory => {
playerStats['Average Assists'] = getAverage(playerStats['Average Assists'], playerStats.games)
playerStats.kd = getAverage(playerStats.kills, playerStats.deaths)

const elo = playerHistory.filter(e => e.elo).map(e => e.elo)
const elo = playerHistory.filter(e => e.elo).map(e => e.elo).filter(e => e !== undefined)

playerStats['Highest Elo'] = Math.max(...elo).toString()
playerStats['Lowest Elo'] = Math.min(...elo).toString()
Expand Down
9 changes: 6 additions & 3 deletions interactions/selectmenus/mapSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ const Graph = require('../../functions/graph')
const DateStats = require('../../functions/dateStats')
const loadingCard = require('../../templates/loadingCard')
const errorCard = require('../../templates/errorCard')
const { getTranslation } = require('../../languages/setup')

const sendCardWithInfo = async (playerId, map, mode) => {
const sendCardWithInfo = async (interaction, playerId, map, mode) => {
if (!map) return
const playerDatas = await Player.getDatas(playerId)
const playerStats = await Player.getStats(playerId)
Expand All @@ -30,7 +31,9 @@ const sendCardWithInfo = async (playerId, map, mode) => {
const mapThumbnail = `./images/maps/${map}.jpg`
const playerMapStats = playerStats.segments.filter(e => e.label === map && e.mode == mode)

if (playerMapStats.length === 0) return errorCard(`**${playerDatas.nickname}** has not played this map.`, interaction.locale)
if (playerMapStats.length === 0) return errorCard(getTranslation('error.user.mapNotPlayed', {
playerName: playerDatas.nickname,
}), interaction.locale)

const cards = playerMapStats.map(m => {
if (fs.existsSync(mapThumbnail)) filesAtt.push(new Discord.AttachmentBuilder(mapThumbnail, { name: `${map}.jpg` }))
Expand Down Expand Up @@ -88,7 +91,7 @@ module.exports = {
loadingCard(interaction)

return {
...await sendCardWithInfo(values.s, values.m, values.v),
...await sendCardWithInfo(interaction, values.s, values.m, values.v),
content: null,
components: [components]
}
Expand Down
2 changes: 1 addition & 1 deletion interactions/selectmenus/teamInfosSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = {
if (currentTeam.creator !== interaction.user.id && currentUser) {
const userIsPartOfTeam = teamUsers.find(user => user.faceitId === currentUser.faceitId)
if (!userIsPartOfTeam) return {
...errorCard(getTranslation('error.command.teamNoAccess', interaction.locale), interaction.locale),
...errorCard('error.command.teamNoAccess', interaction.locale),
components: [
components
]
Expand Down
2 changes: 2 additions & 0 deletions languages/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ module.exports = {
selectWeek: '',
year: '',
selectYear: '',
selectMonth: '',
loading: '',
pagination: {
next: '',
Expand Down Expand Up @@ -164,6 +165,7 @@ module.exports = {
noBotLink: '',
globalLink: '',
notFound: '',
mapNotPlayed: '',
},
execution: {
command: '',
Expand Down
2 changes: 2 additions & 0 deletions languages/en-US/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ base.strings.selectMapDescription = 'Select one of the following maps to get the
base.strings.selectWeek = 'Select a week'
base.strings.year = 'Year'
base.strings.selectYear = 'Select a year'
base.strings.selectMonth = 'Select a month'
base.strings.loading = 'Loading'
base.strings.pagination = {
prev: 'Previous Page',
Expand Down Expand Up @@ -130,6 +131,7 @@ base.error.user.noMatchFoundWithOthers = 'Couldn\'t find any matches where **{pl
base.error.user.noBotLink = 'Sorry, but bots aren\'t really my type'
base.error.user.globalLink = '{discord} already has a global link'
base.error.user.notFound = 'The requested user is not on this server'
base.error.user.mapNotPlayed = 'The player **{playerName}** hasn\'t played on this map'
base.error.execution.command = 'An error occurred while executing the command'
base.error.execution.selectmenu = 'An error occurred while executing the select menu'
base.error.execution.button = 'An error occurred while executing the button'
Expand Down
1 change: 1 addition & 0 deletions templates/errorCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const Discord = require('discord.js')
const { getTranslation } = require('../languages/setup')

module.exports = (description, lang) => {
console.log(description)
if (!description.includes(' ') && description.includes('.')) description = getTranslation(description, lang)

return {
Expand Down

0 comments on commit e65a39d

Please sign in to comment.