Skip to content

Commit

Permalink
improved /licence possible replies
Browse files Browse the repository at this point in the history
  • Loading branch information
BodomBeach committed May 30, 2024
1 parent dffe879 commit 56e8401
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules/
.vscode/
.env
logs/app.log
db/
db/q
tmp
Empty file added db.sqlite
Empty file.
Binary file added db/db.sqlite
Binary file not shown.
18 changes: 12 additions & 6 deletions src/events/commands/licence.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@ const invoke = async (interaction) => {
await interaction.deferReply({ ephemeral: true });

const db = new sqlite3.Database('db/db.sqlite')

// params
const username = interaction.user.username
const licenseNumber = interaction.options.getString('numero_licence')
const currentYear = new Date().getFullYear()
const structureId = process.env.STRUCTURE_ID
const targetRole = interaction.guild.roles.cache.find(role => role.name == 'Licencié ' + currentYear)

console.log(`${interaction.user.username} used /licence ${licenseNumber}`);

// Check if user already has role
if (interaction.member.roles.cache.hasAny(targetRole.id)) {
await interaction.editReply(`Tu as déjà le rôle **${targetRole}**. Reviens me voir l'année prochaine pour réactiver ta licence :wink:`);
return
}

// Check if user already has a licence activated for current year
const alreadyActivated = await asyncGet(db, 'SELECT * FROM licenses WHERE username = ? AND year = ?', [username, currentYear])
if (alreadyActivated) {
Expand All @@ -46,7 +51,7 @@ const invoke = async (interaction) => {
console.log('FFVL response', response);
if (response.data == 1) {

interaction.member.roles.add(interaction.guild.roles.cache.find(role => role.name == 'Licencié ' + currentYear))
await interaction.member.roles.add(interaction.guild.roles.cache.find(role => role.name == 'Licencié ' + currentYear))
// Insert row into db
db.run(`INSERT INTO licenses(username, license_number, year) VALUES(?, ?, ?);`, [username, licenseNumber, currentYear], function (err) {
if (err) { console.log(err.message); }
Expand All @@ -66,10 +71,11 @@ const invoke = async (interaction) => {

const successMessage = (year) => {
return `
Bien joué, ton numéro de licence a bien été activé :partying_face:
Tu as désormais le rôle **Licencié ${year}** et tu a accès à tous les salons :duck:
:white_check_mark: Bien joué, ton numéro de licence a bien été activé
:partying_face: Tu as désormais le rôle **Licencié ${year}** et tu a accès à tous les salons :duck:
Voici quelques astuces pour t'aider à t'y retrouver dans le discord.
Voici quelques astuces pour t'aider à t'y retrouver dans le discord :arrow_down:
`
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/helpMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class HelpMessage {
const devbotChannel = await this.parseChannel('🤖dév-bots')

return `
:duck: **__Guide d'utilisation du discord__ ** :duck:
:information_source: **__Guide d'utilisation du discord__ **
- Tu veux planifier une sortie future, c'est par ici ${regleChannel}
- Tu décides d'aller voler au dernier moment (le jour même), pas besoin de créer un salon dédié, il suffit de poster un message dans ${spontChannel}
Expand Down

0 comments on commit 56e8401

Please sign in to comment.