Skip to content

Commit

Permalink
refactor/help usage (#285)
Browse files Browse the repository at this point in the history
* fix: laststats steam_params

* feat: faceit urls

* refactor: help usage
  • Loading branch information
JustDams authored Mar 10, 2023
1 parent f5cb45e commit fdd1943
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 30 deletions.
3 changes: 2 additions & 1 deletion commands/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ module.exports = {
choices: getMapChoice()
},],
description: 'Compare both user stats.',
usage: 'match_number: number, default 20 AND first_user_steam:steam parameter OR first_user_faceit:faceit nickname OR @user AND second_user_steam:steam parameter OR second_user_faceit:faceit nickname OR @user, map: map name',
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
Expand Down
1 change: 1 addition & 0 deletions commands/dailystats.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ module.exports = {
options: Options.stats,
description: 'Displays the stats of the choosen day. With elo graph of the day.',
usage: Options.usage,
example: 'steam_parameters: justdams',
type: 'stats',
async execute(interaction) {
return getCardsConditions(interaction, sendCardWithInfo)
Expand Down
21 changes: 13 additions & 8 deletions commands/find.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const { ApplicationCommandOptionType } = require('discord.js')
const Options = require('../templates/options')
const { getUsers } = require('../functions/commands')
const { getUsers, getInteractionOption } = require('../functions/commands')
const { sendCardWithInfo } = require('./last')
const { getMapChoice } = require('../functions/map')

const getOptions = () => {
const options = [...Options.stats]
options.unshift({
name: 'player_aimed',
description: 'steam_params / faceit_params / @user / empty if linked.',
description: 'steam_params / faceit_params / @user / empty if linked. History of the player you want to search in.',
required: false,
type: ApplicationCommandOptionType.String,
slash: true
Expand Down Expand Up @@ -39,19 +39,24 @@ const getOptions = () => {
module.exports = {
name: 'find',
options: getOptions(),
description: 'Find the games that includes the player requested (up to 5), last 1000 games.',
usage: `player_aimed:the history in which one you are searching AND ${Options.usage} AND map:the map you want to search AND excluded_steam_parameters:the steam parameters you want to exclude AND excluded_faceit_parameters:the faceit parameters you want to exclude`,
description: 'Find the games that includes the player requested (up to 5)',
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',
async execute(interaction) {
const playerAimed = (await getUsers(interaction, 1, 'player_aimed', 'player_aimed', false))[0].param
const playerAimed = (await getUsers(interaction, 2, 'player_aimed', 'player_aimed', false))
.find(e => e.param.match(/^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$/i))
?.param

const users = (await getUsers(interaction, 5)).map(p => p.param).filter((e, i, a) => a.indexOf(e) === i)
let excludedUsers = (await getUsers(interaction, 10, 'excluded_steam_parameters', 'excluded_faceit_parameters', false))
.map(p => p.param).filter((e, i, a) => a.indexOf(e) === i)

excludedUsers = excludedUsers.filter(e => e.normalize() !== playerAimed.normalize())
const excludedSteam = getInteractionOption(interaction, 'excluded_steam_parameters')
const excludedFaceit = getInteractionOption(interaction, 'excluded_faceit_parameters')

if (excludedUsers.includes(playerAimed)) throw 'You can\'t exclude a player you are searching for.'
if (excludedUsers.some(e => users.includes(e))) throw 'You can\'t exclude a player you are searching for.'
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.'

return sendCardWithInfo(interaction, playerAimed, null, 0, users.filter(e => e.normalize() !== playerAimed.normalize()), null, excludedUsers)
}
Expand Down
10 changes: 6 additions & 4 deletions commands/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ const getCommandsHelp = (commandName, card) => {

command.options.forEach(o => { if (o.description) optionsDesc += `\`${o.name}\`: ${o.description}\n` })

card.setDescription(`Information about the ${command.name} command`)
card.setDescription(`Information about the ${command.name} command \n \`<>\`: optional, \`[]\`: required, \`{}\`: required if not linked`)
.addFields({ name: 'Description', value: command.description },
{ name: 'Options', value: optionsDesc.length > 0 ? optionsDesc : 'This command does not require any options' },
{ name: 'Usage', value: `/${command.name} ${command.usage}` })
{ name: 'Usage', value: `\`/${command.name} ${command.usage}\`` })

if (command?.example) card.addFields({ name: 'Example', value: `\`/${command.name} ${command.example}\`` })

return { embeds: [card] }
}
Expand All @@ -56,15 +58,15 @@ module.exports = {
}
],
description: 'Display the command list.',
usage: 'command name',
usage: '<command>',
type: 'system',
async execute(interaction) {
const command = getInteractionOption(interaction, 'command')?.trim().split(' ')[0]

const helpCard = new Discord.EmbedBuilder()
.setColor(color.primary)
.setTitle('Commands')
.setDescription('`/help {command}` for more info on a specific command')
.setDescription('`/help <command>` for more info on a specific command')
.setFooter({ text: `${name} Help` })

if (command) return getCommandsHelp(command, helpCard)
Expand Down
3 changes: 2 additions & 1 deletion commands/last.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ module.exports = {
name: 'last',
options: getOptions(),
description: 'Get the stats of last game.',
usage: `${Options.usage} AND map name`,
usage: `${Options.usage} <map>`,
example: 'steam_parameters: justdams',
type: 'stats',
async execute(interaction) {
return getCardsConditions(interaction, sendCardWithInfo)
Expand Down
3 changes: 2 additions & 1 deletion commands/laststats.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ module.exports = {
name: 'laststats',
options: getOptions(),
description: 'Displays the stats of the x last match. With elo graph of the x last match.',
usage: `match_number:number of matches to display AND ${Options.usage}`,
usage: `${Options.usage} <match_number> <map> ${Options.dateRangeUsage}`,
example: 'steam_parameters: justdams match_number: 1000 from_date: 01/01/2022 to_date: 01/01/2023',
type: 'stats',
async execute(interaction) {
return getCardsConditions(interaction, sendCardWithInfo)
Expand Down
7 changes: 4 additions & 3 deletions commands/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module.exports = {
slash: true
},
{
name: 'faceit_parameters',
name: 'faceit_parameter',
description: 'faceit nickname / @user',
required: false,
type: Discord.ApplicationCommandOptionType.String,
Expand All @@ -83,9 +83,10 @@ module.exports = {
}
],
description: 'Link a steam profile to the discord user, to get your stats directly (no parameters needed).',
usage: 'steam_parameter:steam param or @user or CSGO status (max 1 user) OR faceit_parameters:faceit nickname (max 1) AND discord_user: @user',
usage: '[<steam_parameter> <faceit_parameter>] <discord_user> <nickname>',
example: 'steam_parameter: justdams',
type: 'utility',
async execute(interaction) {
return getCardsConditions(interaction, sendCardWithInfo, 1, 'steam_parameter')
return getCardsConditions(interaction, sendCardWithInfo, 1, 'steam_parameter', 'faceit_parameter')
}
}
3 changes: 2 additions & 1 deletion commands/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ module.exports = {
name: 'map',
options: getOptions(),
description: 'Displays the stats of the choosen map.',
usage: `map:choose a map name AND ${Options.usage}`,
usage: `${Options.usage} <map>`,
example: 'steam_parameters: justdams map: Vertigo',
type: 'stats',
async execute(interaction) {
return getCardsConditions(interaction, sendCardWithInfo)
Expand Down
9 changes: 7 additions & 2 deletions commands/team.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const Discord = require('discord.js')
const Team = require('../database/team')
const UserTeam = require('../database/userTeam')
const Steam = require('../functions/steam')
const Player = require('../functions/player')
const User = require('../database/user')
const errorCard = require('../templates/errorCard')
Expand Down Expand Up @@ -212,7 +211,13 @@ module.exports = {
}
],
description: 'Create a team and link up to 5 users to it (limited to 1 team by discord account).',
usage: `\n- \`${CREATE}\` [team name]\n- \`${DELETE}\`\n- \`${UPDATE}\` [access] {name}\n- \`${INFO}\`\n- \`${ADD_USER}\` [steamID / steam custom ID / url of one steam profile / @user / CSGO status OR faceit nicknames]\n- \`${REMOVE_USER}\` [steamID / steam custom ID / url of one steam profile / @user / CSGO status OR faceit nicknames]`,
usage: `
- ${CREATE} [team name]
- ${DELETE}
- ${UPDATE} [access] <name>
- ${INFO}
- ${ADD_USER} [<steam_parameters> <faceit_parameters>]
- ${REMOVE_USER} [<steam_parameters> <faceit_parameters>]`,
type: 'utility',
async execute(interaction) {
const user = interaction.user.id
Expand Down
1 change: 1 addition & 0 deletions commands/weekstats.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ module.exports = {
options: Options.stats,
description: 'Displays the stats of the choosen week. With elo graph of the week.',
usage: Options.usage,
example: 'steam_parameters: justdams',
type: 'stats',
async execute(interaction) {
return getCardsConditions(interaction, sendCardWithInfo)
Expand Down
1 change: 1 addition & 0 deletions commands/yearstats.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ module.exports = {
options: Options.stats,
description: 'Displays the stats of the choosen year. With elo graph of the year.',
usage: Options.usage,
example: 'steam_parameters: justdams',
type: 'stats',
async execute(interaction) {
return getCardsConditions(interaction, sendCardWithInfo)
Expand Down
13 changes: 8 additions & 5 deletions functions/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,14 @@ const getUsers = async (
}
if (faceitParameters) {
await Promise.all(faceitParameters
.map(async nickname => await Player.getDatasFromNickname(nickname)
.catch(async () => {
const player = await Player.searchPlayer(nickname).catch(e => e)
return player.items?.at(0) || nickname
}))
.map(async nickname => {
nickname = nickname.split('/').filter(e => e).pop()
return await Player.getDatasFromNickname(nickname)
.catch(async () => {
const player = await Player.searchPlayer(nickname).catch(e => e)
return player.items?.at(0) || nickname
})
})
).then(params => {
parameters.push(...params.map(e => {
return {
Expand Down
1 change: 1 addition & 0 deletions functions/faceit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const fetchData = async (url, error) => axios.get(url, {
.then(res => res.data)
.catch(e => {
console.error(e.response.status, e.response.statusText, url)
if (e.response.status === 500) throw 'Faceit: internal server error.'
throw error
})

Expand Down
10 changes: 6 additions & 4 deletions templates/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { ApplicationCommandOptionType } = require('discord.js')
const stats = [
{
name: 'steam_parameters',
description: 'steamIDs / steam custom IDs / url of one or more steam profiles / @users / CSGO status.',
description: 'steamIDs / steam custom IDs / steam profile urls / @users / CSGO status.',
required: false,
type: ApplicationCommandOptionType.String,
slash: true
Expand All @@ -17,7 +17,7 @@ const stats = [
},
{
name: 'faceit_parameters',
description: 'faceit nicknames / @users',
description: 'faceit nicknames / faceit urls / @users',
required: false,
type: ApplicationCommandOptionType.String,
slash: true
Expand All @@ -41,10 +41,12 @@ const dateRange = [
}
]

const usage = 'steam_parameters:multiple steam params and @user OR CSGO status AND team:team slug (max 1) AND faceit_parameters:multiple faceit nicknames and @user'
const usage = '{<steam_parameters> <faceit_parameters> <team>}'
const dateRangeUsage = '<from_date> <to_date>'

module.exports = {
stats,
usage,
dateRange
dateRange,
dateRangeUsage
}

0 comments on commit fdd1943

Please sign in to comment.