-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
93 lines (79 loc) · 2.73 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Import des bibliothèques
const fs = require('fs');
const { Client, Intents } = require('discord.js');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
// Chargement de la configuration
require('dotenv').config();
// Chargement des plugins
fs.readdirSync( './plugin/' )
.forEach( plugin => require(`./plugin/${plugin}`) );
const bot = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const rest = new REST({ version: '9' }).setToken( process.env.DISCORD_TOKEN );
bot.on('ready', () => console.log('bot : Ready !') );
bot.login(process.env.DISCORD_TOKEN);
bot.sondages = {};
// Mise à jour des commandes
new Promise( (resolve, reject) => {
fs.readdir( './commands/' , {} , (_,liste) =>
rest.put(
Routes.applicationGuildCommands(
process.env.DISCORD_APPLICATION_ID,
(
( process.env.ENV==='prod' )
?
process.env.DISCORD_SERVER_RELEASE_ID
:
process.env.DISCORD_SERVER_TEST_ID
)
),
{ body: liste.map( fichier => require(`./commands/${fichier}/syntax.json`) ) }
)
.then( function() {
resolve()
} )
.catch( function(err) {
reject(err)
} )
)
})
.then( () => console.log( 'SlashCommands updated !' ) )
.catch( (err) => { console.error('SlashCommands an error occured during command syntax update ! ',err); } )
let commands = {};
let interaction = {};
bot.on('interactionCreate', async interaction => {
try {
if( interaction.type == 'APPLICATION_COMMAND' ) {
console.log(`SlashCommand ${interaction.commandName} ask by ${interaction.member}` );
if( commands[interaction.commandName] === undefined ) {
commands[interaction.commandName] = require(`./commands/${interaction.commandName}/run.js`);
}
try {
await commands[interaction.commandName](interaction,bot);
} catch( err ) {
console.error('Interaction Erreur lors du traitement d\'une slash command',{err,interaction});
}
} else if( interaction.type == 'MESSAGE_COMPONENT' ) {
let interactionName = interaction.customId.split`_`[0];
if( interaction[interactionName] === undefined ) {
interaction[interactionName] = require(`./interaction/${interactionName}.js`);
}
try {
await interaction[interactionName](interaction,bot);
} catch ( err ) {
console.error('Interaction Erreur lors du traitement d\'un composant de message',{err,interaction});
}
}
} catch(err) {
console.error('Interaction Erreur lors du traitement d\'une interaction,',{err,interaction});
}
} );
//////
const sqlite3 = require('sqlite3');
const db = new sqlite3.Database('/data/db');
db.serialize(function() {
db.run('CREATE TABLE IF NOT EXISTS pcicoin (discord_id TEXT PRIMARY KEY, amount INTEGER)');
});
/////
process.db = db;
process.bot = bot;