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: medal command and json to recognize #85

Merged
merged 1 commit into from
May 16, 2023
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
2 changes: 2 additions & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { useOnboardingQuit } from './onboarding/onboarding_quit'
import { useOnboardingWhy } from './onboarding/onboarding_why'
import { useSpecial } from './special'
import { useDynamicVoiceTitle } from './dynamic_voice/dynamic_voice_title'
import { useMedal } from './medal'

const registerHooks = (client: He4rtClient, commands: Command[]) => {
commands.forEach(([data, cb]) => {
Expand Down Expand Up @@ -82,6 +83,7 @@ export const registerCommands = async ({ client, rest }: Context) => {
useOnboardingQuit(),
useOnboardingWhy(),
useSpecial(),
useMedal()
// useReputation()
])

Expand Down
43 changes: 43 additions & 0 deletions src/commands/medal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { ChannelType, CommandInteractionOption, GuildMember, SlashCommandBuilder } from 'discord.js'
import { Command } from '@/types'
import { MEDAL } from '@/defines/commands.json'
import medals from '@/defines/medals.json'
import { MEDAL_OPTION, NOT_EXIST, DO_NOT_HAVE, ALREADY, SUCCESS } from '-/commands/medal.json'
import { hasRole } from '../utils'

export const useMedal = (): Command => {
const data = new SlashCommandBuilder()
.setName(MEDAL.TITLE)
.setDescription(MEDAL.DESCRIPTION)
.setDMPermission(false)
.addStringOption((option) => option.addChoices({name: medals[0].name, value: medals[0].medal_role_id}).setName('medal').setDescription(MEDAL_OPTION).setRequired(true))

return [
data,
async (interaction, _) => {
const member = interaction.member as GuildMember

const medalArg = interaction.options.get('medal') as CommandInteractionOption
const medalSelected = medals.find(medal => medal.medal_role_id === medalArg.value);

if(!medalSelected) {
await interaction.reply({ content: NOT_EXIST, ephemeral: true })
return
}
if(!medalSelected.members_id.includes(member.id)) {
await interaction.reply({ content: DO_NOT_HAVE, ephemeral: true })
return
}
if(hasRole(member, medalSelected.medal_role_id)) {
await interaction.reply({ content: ALREADY, ephemeral: true })
return
}

await member.roles.remove(medals.map(medal => medal.medal_role_id).filter(role_id => role_id !== medalSelected.medal_role_id))
await member.roles.add(medalSelected.medal_role_id)
await interaction.reply({ content: SUCCESS, ephemeral: true })

return
},
]
}
4 changes: 4 additions & 0 deletions src/defines/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,9 @@
"DYNAMIC_VOICE_TITLE": {
"TITLE": "sala-titulo",
"DESCRIPTION": "(DONO): Altere o título da sala por outro."
},
"MEDAL": {
"TITLE": "medalha",
"DESCRIPTION": "Selecione sua medalha de contribuição com a comunidade."
}
}
7 changes: 7 additions & 0 deletions src/defines/localisation/commands/medal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"MEDAL_OPTION": "Selecione sua medalha que deseja ficar ao lado do seu nick.",
"NOT_EXIST": "Medalha não encontrada.",
"DO_NOT_HAVE": "Você não possui essa medalha. :(",
"ALREADY": "Você já está com essa medalha selecionada.",
"SUCCESS": "Medalha selecionada com sucesso."
}
7 changes: 7 additions & 0 deletions src/defines/medals.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"name": "He4rt",
"medal_role_id": "1107790862869614684",
Novout marked this conversation as resolved.
Show resolved Hide resolved
"members_id": ["426540070028443688", "418886000144678922", "279344988532506624", "259446744675254273", "241070790383108096", "360275732099760138", "155085013342224384", "253744065043103747", "310240335924297728", "349402457178374144", "763563330849210368", "480894052787683348", "232906166059925506", "295011455802015745", "315633936942235649", "415553620268941332", "466357449939484675", "283347054426718221", "410870008919621635", "264931012272717824", "1014231037036994673", "547097212770058243", "290680405106098176", "522080894513709089", "261991713541718017", "166340136399798272", "228956489690251264"]
}
]