Push du programme

This commit is contained in:
Lantium 2022-03-04 14:26:14 +01:00
parent bf2efcc1ed
commit e49f26cbf5
13 changed files with 1453 additions and 3 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules/
config.js

18
README.md Normal file
View File

@ -0,0 +1,18 @@
# Description
Ce bot permet de télécharger des fichiers .pdf de Google Drive et de les envoyer dans un salon discord
# Initialisation :
- npm i
- node . | node main.js
# Utilisation :
- Pour télécharger un fichier, renseignez soit le lien google drive ou juste l'ID au choix
- Pour la commande de reboot, n'oubliez pas de renseigner l'ID de l'utilisateur dans le fichier config.json
-
# Problème =>
Contactez moi sur discord : lantium#9204

View File

@ -0,0 +1,17 @@
module.exports = {
name: 'reboot',
aliases: [],
utilisation: '{prefix}reboot',
async execute(client, message) {
const Members = client.config.admin;
if (!Members.includes(message.author.id))
return message.channel.send("Cette commande est réservé au développeur de LanBot");
await message.channel.send("Reboot en cours...");
await process.exit();
},
};

24
commands/core/help.js Normal file
View File

@ -0,0 +1,24 @@
const { MessageEmbed } = require('discord.js');
module.exports = {
name: 'help',
aliases: ['h'],
showHelp: false,
utilisation: '{prefix}help',
execute(client, message, args) {
const embed = new MessageEmbed();
embed.setColor('RED');
embed.setAuthor(client.user.username, client.user.displayAvatarURL({ size: 1024, dynamic: true }));
const commands = client.commands.filter(x => x.showHelp !== false);
embed.setDescription('Bienvenue sur la page d\'aide !');
embed.addField(`Actifs - ${commands.size}`, commands.map(x => `\`${x.name}${x.aliases[0] ? ` (${x.aliases.map(y => y).join(', ')})\`` : '\`'}`).join(' | '));
embed.setTimestamp();
message.channel.send({ embeds: [embed] });
},
};

47
commands/core/menuadd.js Normal file
View File

@ -0,0 +1,47 @@
const { MessageAttachment } = require("discord.js");
const wget = require("node-wget");
const fs = require("fs");
module.exports = {
name: "menu",
aliases: ["menu", "menuadd"],
utilisation: [
"Pour télécharger un fichier, renseignez soit le lien google drive ou juste l'ID",
"{prefix}menu <link_GDrive>",
"{prefix}menuadd <ID>"
],
async execute(client, message, args) {
if (!args[0])
return message.channel.send("Merci de me préciser un lien ! ");
const id = args[0].split("/")[5];
wget(
{
url: `https://drive.google.com/uc?export=download&id=${id}`,
dest: "./Files/menu.pdf", // destination path or path with filenname, default is ./
},
function (error, response, body) {
if (error) {
console.log("--- error:");
console.log(error); // error encountered
}
}
);
// attendre que le fichier menu.pdf soit téléchargé puis l'envoyer dans le salon
setTimeout(() => {
const attachment = new MessageAttachment("./Files/menu.pdf");
message.channel.send({ files: [attachment] });
}, 5000);
// supprimer le fichier menu.pdf
setTimeout(() => {
fs.unlink("./Files/menu.pdf", (err) => {
if (err) throw err;
console.log("File deleted!");
});
}, 10000);
},
};

14
commands/core/ping.js Normal file
View File

@ -0,0 +1,14 @@
module.exports = {
name: 'ping',
aliases: [],
utilisation: '{prefix}ping',
async execute(client, message) {
const msg = await message.channel.send("Pong ! ");
msg.edit(
`Pong !
Latence du bot: ${msg.createdTimestamp - message.createdTimestamp}ms
Latence de l'API: ${Math.round(client.ws.ping)}ms`
)
},
};

15
events/messageCreate.js Normal file
View File

@ -0,0 +1,15 @@
module.exports = (client, message) => {
if (message.author.bot || message.channel.type === 'dm') return;
const prefix = client.config.app.prefix;
if (message.content.indexOf(prefix) !== 0) return;
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
const cmd = client.commands.get(command) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(command));
if (cmd) cmd.execute(client, message, args);
};

13
events/ready.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = async (client) => {
console.log(`${client.user.tag} oberve les ${client.guilds.cache.map(g => g.memberCount).reduce((a,b) => a + b)} utilisateur du serveur !`)
let activites = ['Créer par Lantium#9402 !',`Downloader prêt !` ], i = 0;
setInterval(() => client.user.setPresence({
activities: [{
name: `${activites [i++ % activites.length]}`,
type: 'PLAYING'
}],
status: 'online' }),
5000);
};

View File

18
main.js Normal file
View File

@ -0,0 +1,18 @@
const { Client, Intents } = require('discord.js');
global.client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_VOICE_STATES
],
disableMentions: 'everyone',
});
client.config = require('./config');
require('./src/loader');
client.login(client.config.app.token);

1250
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -2,14 +2,18 @@
"name": "landiscscrapy",
"version": "1.0.0",
"description": "Bot Discord pour DL les fichiers GDrive et les envoyer sur Discord",
"main": "index.js",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"start": "node ."
},
"repository": {
"type": "git",
"url": "https://gitlab.ataxya.net/lantium/landiscordscrapy"
},
"author": "lantium#9402",
"license": "ISC"
"license": "ISC",
"dependencies": {
"discord.js": "^13.6.0",
"node-wget": "^0.4.2"
}
}

28
src/loader.js Normal file
View File

@ -0,0 +1,28 @@
const { readdirSync } = require('fs');
const { Collection } = require('discord.js');
client.commands = new Collection();
const events = readdirSync('./events/').filter(file => file.endsWith('.js'));
console.log(`Changement des évènements...`);
for (const file of events) {
const event = require(`../events/${file}`);
console.log(`-> Évènement chargés ${file.split('.')[0]}`);
client.on(file.split('.')[0], event.bind(null, client));
delete require.cache[require.resolve(`../events/${file}`)];
};
console.log(`Changement des commandes...`);
readdirSync('./commands/').forEach(dirs => {
const commands = readdirSync(`./commands/${dirs}`).filter(files => files.endsWith('.js'));
for (const file of commands) {
const command = require(`../commands/${dirs}/${file}`);
console.log(`-> Commandes chargés ${command.name.toLowerCase()}`);
client.commands.set(command.name.toLowerCase(), command);
delete require.cache[require.resolve(`../commands/${dirs}/${file}`)];
};
});