-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature-licence' into staging
- Loading branch information
Showing
14 changed files
with
1,099 additions
and
15 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); | ||
const { HelpMessage } = require('../../utils/helpMessage.js'); | ||
|
||
// Creates an Object in JSON with the data required by Discord's API to create a SlashCommand | ||
const create = () => { | ||
const command = new SlashCommandBuilder() | ||
.setName('help') | ||
.setDescription('Affiche le guide d\`utilisation du discord') | ||
return command.toJSON(); | ||
}; | ||
|
||
const invoke = async (interaction) => { | ||
const message = await new HelpMessage(interaction.guild).execute() | ||
await interaction.reply({ content: message , ephemeral: true }) | ||
}; | ||
|
||
module.exports = { create, invoke }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); | ||
const { HelpMessage } = require('../../utils/helpMessage.js'); | ||
const axios = require('axios'); | ||
const sqlite3 = require('sqlite3').verbose(); | ||
|
||
// Creates an Object in JSON with the data required by Discord's API to create a SlashCommand | ||
const create = () => { | ||
const command = new SlashCommandBuilder() | ||
.setName('licence') | ||
.setDescription('Active ta licence FFVL pour obtenir l\'accès complet au Discord') | ||
.addStringOption(option => | ||
option.setName('numero_licence') | ||
.setDescription('Ton numéro de licence FFVL (https://intranet.ffvl.fr)') | ||
.setRequired(true)); | ||
return command.toJSON(); | ||
}; | ||
|
||
const invoke = async (interaction) => { | ||
await interaction.deferReply({ ephemeral: true }); | ||
|
||
const db = new sqlite3.Database('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 | ||
|
||
console.log(`${interaction.user.username} used /licence ${licenseNumber}`); | ||
|
||
// 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) { | ||
await interaction.editReply(`Ton compte Discord est déjà associé à la licence **${alreadyActivated.license_number}**. En cas de problème, tu peux contacter un admin.`); | ||
return | ||
} | ||
|
||
// Check if licence number is already taken by someone else | ||
const licenseTaken = await asyncGet(db, 'SELECT * FROM licenses WHERE license_number = ?', [licenseNumber]) | ||
if (licenseTaken) { | ||
await interaction.editReply(`La licence **${licenseNumber}** est déjà associée à un autre utilisateur. En cas de problème, tu peux contacter un admin.`); | ||
return | ||
} | ||
console.log(`https://data.ffvl.fr/php/verif_lic_adh.php?num=${licenseNumber}&stru=${structureId}`); | ||
const response = await axios.get(`https://data.ffvl.fr/php/verif_lic_adh.php?num=${licenseNumber}&stru=${structureId}`) | ||
console.log('FFVL response', response); | ||
if (response.data == 1) { | ||
|
||
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); } | ||
console.log(`License succesfully activated for user ${username}`); | ||
}); | ||
|
||
await interaction.editReply({ content: successMessage(currentYear), ephemeral: true }) | ||
const helpMessage = await new HelpMessage(interaction.guild).execute() | ||
await interaction.followUp({ content: helpMessage, ephemeral: true }); | ||
|
||
} else { | ||
console.log(`License not found ${username}`); | ||
await interaction.editReply({ content: failureMessage(currentYear), ephemeral: true }) | ||
} | ||
|
||
}; | ||
|
||
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: | ||
Voici quelques astuces pour t'aider à t'y retrouver dans le discord. | ||
` | ||
} | ||
|
||
const failureMessage = (year) => { | ||
return ` | ||
Une erreur est survenue avec ce numéro de licence :thinking: | ||
Soit ce numéro de licence n'existe pas à la FFVL | ||
Soit le numéro existe mais la cotisation au Duck n'a pas été enregistrée pour l'année ${year} | ||
En cas de problème, tu peux contacter un admin. | ||
` | ||
} | ||
|
||
const asyncGet = (db, sql, params) => { | ||
return new Promise((resolve, reject) => { | ||
db.get(sql, params, (err, row) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(row); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
module.exports = { create, invoke }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const once = false; | ||
const name = 'messageCreate'; | ||
|
||
async function invoke(interaction) { | ||
|
||
const welcomeChannel = interaction.guild.channels.cache.find(channel => channel.name === 'bienvenue-et-regles'); | ||
|
||
// Ignore messages from bots | ||
if (interaction.author.bot) return; | ||
|
||
// Delete any message that is not a /command in the welcome channel. This is the only way to allow only commands in this channel | ||
if (interaction.channel === welcomeChannel) { | ||
await interaction.delete(); | ||
} | ||
return; | ||
} | ||
|
||
module.exports = { once, name, invoke }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
class HelpMessage { | ||
|
||
constructor(guild) { | ||
this.guild = guild | ||
} | ||
|
||
execute = async () => { | ||
|
||
const regleChannel = await this.parseChannel('📌règles-sorties') | ||
const spontChannel = await this.parseChannel('🍀sorties-spontanées') | ||
const blablaChannel = await this.parseChannel('👥bla-bla-parapente') | ||
const orgaChannel = await this.parseChannel('🔧organisation-du-serveur') | ||
const devbotChannel = await this.parseChannel('🤖dév-bots') | ||
|
||
return ` | ||
:duck: **__Guide d'utilisation du discord__ ** :duck: | ||
- 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} | ||
- Tu veux discuter ou poser une question sur un sujet spécifique ? Il existe surement un salon qui correspond dans la catégorie **🐤 GENERAL** | ||
- Dans **⛰ SITES DE VOL**, nous mettons à jour les informations importantes de chaque site, n'hésite pas à consulter ces salons lorsque tu prépares tes vols. | ||
- Tu ne trouves pas le bon salon ? Tu peux toujours parler dans ${blablaChannel}, où le spam est autorisé ! | ||
- Tu reçois trop de notifications ? Discord possède plein d'options pour régler les notifications comme il te plait, ce guide pourra t'aider : <placeholder> | ||
- Tu peux inviter des amis au discord sans restriction. | ||
- Envie d'aider à l'amélioration du serveur, rejoins ${orgaChannel} | ||
- Envie de contribuer à l'amélioration du bot, rejoins ${devbotChannel} | ||
- \`Ctrl + /\` affiche la liste des raccourcis utiles (ordinateur uniquement) | ||
À tout moment, tu peux utiliser la commande **\`/help\`** pour retrouver ce guide. | ||
` | ||
} | ||
|
||
parseChannel = async (string) => { | ||
const channel = this.guild.channels.cache.find(channel => channel.name === string) | ||
|
||
// fallback to string if channel is not found | ||
return channel ? `<#${channel.id}>` : '#' + string; | ||
} | ||
|
||
} | ||
module.exports = { HelpMessage } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const sqlite3 = require('sqlite3').verbose(); | ||
|
||
const db = new sqlite3.Database('db.sqlite', (err) => { | ||
if (err) { | ||
console.error("Error opening database:", err.message); | ||
return; | ||
} | ||
|
||
db.serialize(() => { | ||
db.run(` | ||
CREATE TABLE IF NOT EXISTS licenses ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
username TEXT NOT NULL, | ||
license_number TEXT UNIQUE NOT NULL, | ||
year INTEGER NOT NULL | ||
) | ||
`, (err) => { | ||
if (err) { | ||
console.error("Error creating table:", err.message); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
db.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
async function initMessages(client) { | ||
|
||
const guild = client.guilds.cache.get(process.env.GUILD_ID); | ||
welcomeMessage = ` | ||
**Bienvenue sur le serveur discord du Duck :duck:** | ||
Ce serveur discord est là pour nous permettre de planifier et d'organiser des sorties, événements club et compétitions. | ||
C'est aussi un endroit où l'on peut discuter de tous les sujets qui concernent le club, le parapente et plus encore ! | ||
Avant toute chose, nous t'invitons à compléter les 2 étapes ci-dessous pour profiter pleinement du discord. | ||
**__1 - Configure ton Prénom NOM__** | ||
Pour des raisons de sécurité lors des sorties club et pour assurer une bonne communication entre les membres, il faut renseigner ton nom et prénom usuels. Si tu as plusieurs serveurs discord, ne t'inquiète pas, ce nouveau **Prénom NOM** sera visible uniquement sur le discord du Duck et tu garderas ton pseudonyme sur les autres serveurs. | ||
Voilà comment faire : | ||
- Option 1 :arrow_forward: Tape la commande **\`/nick\` \`<Prénom>\` \`<NOM>\`** dans le champ de texte en bas de cette page. | ||
- Option 2 :arrow_forward: https://br.atsit.in/fr/?p=12704 | ||
**__2 - Active ta licence__** | ||
Pour avoir accès à tous les salons, tu dois avoir cotisé au Duck pour l'année en cours et activer ta licence FFVL sur discord. | ||
Pour cela, il suffit de taper la commande **\`/licence\`** suivi de ton [numéro de licence FFVL](https://intranet.ffvl.fr) : | ||
Exemple : **\`/licence\` \`0315897E\`** | ||
Notre bot vérifiera que ta cotisation est à jour et te donnera accès au reste des salons ! | ||
Si tu rencontres un problème, n'hésite pas à contacter un admin du serveur. | ||
` | ||
const welcomeChannel = client.channels.cache.find(channel => channel.name === 'bienvenue-et-regles'); | ||
let messages = await welcomeChannel.messages.fetch({ limit: 1 }); | ||
|
||
// Create or edit existing embed | ||
if (messages.size === 0) { | ||
welcomeChannel.send(welcomeMessage); | ||
} else { | ||
messages.first().edit(welcomeMessage); | ||
}; | ||
console.log('initialized welcome message'); | ||
} | ||
|
||
module.exports = { initMessages } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// This service update permissions on all channels programatically (doing it manually is time consuming and error prone) | ||
// Basically, it just hide most channels to role "@everyone" (except a few channels) whereas all other roles can see everything | ||
|
||
function updatePermissions(client) { | ||
const allowedChannels = ['👥bla-bla-parapente', 'bienvenue']; | ||
|
||
const guild = client.guilds.cache.get(process.env.GUILD_ID); | ||
const channels = guild.channels.cache.filter(channel => !allowedChannels.includes(channel.name)) | ||
// Fetch all channels in the guild | ||
|
||
channels.forEach(channel => { | ||
// Update the permissions for the @everyone role in each channel | ||
channel.permissionOverwrites.create(guild.roles.everyone, { ViewChannel: false }); | ||
console.log(1); | ||
}); | ||
|
||
console.log('Updated permissions'); | ||
} | ||
|
||
module.exports = {updatePermissions} |