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

Updates libs #32

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
### Instructions Windows

* Installer Git (<https://git-scm.com/downloads/>)
* Installer Node.js (<https://nodejs.org/en/download/>)
* Installer Node.js <u>**16.6.0** ou plus récent</u> (<https://nodejs.org/en/download/>)
* Faire les manipulations de la section ["Création d'une application de tests Discord"](#création-dune-application-de-tests-discord)
* Faire les manipulations de la section ["Installation locale"](#installation-locale)
* Aller dans le projet et faire la commande ``node .``
Expand Down Expand Up @@ -97,4 +97,4 @@ const member = message.channel.members.filter(user => user.id === message.author
```

---
Mis-à-jour le 11/10/2021
Mis-à-jour le 11/10/2021
24 changes: 19 additions & 5 deletions bot.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
/***
* Author: Timothy Landry
* Contributor:
* Description: First file execute when bot is launch. It's the file that log the bot in server
* and map command created by contributors.
*/

const Discord = require("discord.js");
const fs = require("fs");

const Enmap = require("enmap");

const client = new Discord.Client();
const config = require("./config.json");

const client = new Discord.Client({
intents: [Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MESSAGES,
Discord.Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.DIRECT_MESSAGES,
Discord.Intents.FLAGS.GUILD_BANS,
Discord.Intents.FLAGS.GUILD_INVITES]
});

client.config = config;
client.commands = new Enmap();

fs.readdir("./events/", (err, files) => {
if (err) return console.error(err);
Expand All @@ -16,8 +32,6 @@ fs.readdir("./events/", (err, files) => {
});
});

client.commands = new Enmap();

fs.readdir("./commands/examples/", (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
Expand Down
2 changes: 1 addition & 1 deletion commands/contributors/flag.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ exports.run = async (client, message, args) => {
.setImage(imageUrl)
.setTitle("Keep flaging young padawan!")
.setFooter(`Nice flag ${flagList[flag]}!`);
message.channel.send(embed).catch(console.error);
message.channel.send({embeds:[embed]}).catch(console.error);
});
};
55 changes: 30 additions & 25 deletions commands/contributors/flip.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
exports.run = (client, message, args) => {
/***
* Author: Michael Labrecque [[email protected]]
* Contributor:
* Description: Function that flip a coin
*/

exports.run = async (client, message, args) => {
const Discord = require("discord.js");

//Envoie l'image gif qui flip un coin et la supprime apres 2.1 sec
var str = new Discord.MessageEmbed()
var roll = new Discord.MessageEmbed()
.setTitle("Coin Flip")
.setColor("0xFF0000")
.setDescription(message.author.toString())
.setImage(client.config.images_Git.flip_coinGif);

var result = new Discord.MessageEmbed()
.setTitle("Coin Flip")
.setColor("0xFF0000")
.setDescription(message.author)
.attachFiles(client.config.images_Git.flip_coinGif)
.setImage("attachment://coin_flip.gif");
.setDescription(message.author.toString())

message.channel.send(str).then((d_msg) => d_msg.delete({ timeout: 2100 }));
//génère un nombre random entre 0 et 1 et vérifie quel est le résultat
if (Math.floor(Math.random() * 2)) {
result.setImage(client.config.images_Git.coin_pile);
} else {
result.setImage(client.config.images_Git.coin_face);
}

setTimeout(function () {
if (Math.floor(Math.random() * 2) == 0) {
//génère un nombre random entre 0 et 1 et vérifie quel est le résultat
str = new Discord.MessageEmbed()
.setTitle("Coin Flip")
.setColor("0xFF0000")
.setDescription(message.author)
.attachFiles(client.config.images_Git.coin_pile)
.setImage("attachment://pile.png");
} else {
str = new Discord.MessageEmbed()
.setTitle("Coin Flip")
.setColor("0xFF0000")
.setDescription(message.author)
.attachFiles(client.config.images_Git.coin_face)
.setImage("attachment://face.png");
}
message.channel.send(str);
}, 2500);
message.channel
.send({ embeds: [roll] })
.then((d_msg) =>
setTimeout(() => {
d_msg.delete().then(() => {
message.channel.send({ embeds: [result] });
});
}, 1500)
);
};
2 changes: 1 addition & 1 deletion commands/contributors/meme.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ exports.run = async (client, message, args) => {
.setTitle(`From /r/${random}`)
.setURL(`http://reddit.com/r/${random}`)

message.channel.send(embed);
message.channel.send({embeds:[embed]});
}
8 changes: 7 additions & 1 deletion commands/contributors/nickname.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/***
* Author: Michael Labrecque [[email protected]]
* Contributor:
* Description: Function that change nickname on the server
*/

const Discord = require("discord.js");

exports.run = async (client, message, args) => {
Expand Down Expand Up @@ -43,6 +49,6 @@ exports.run = async (client, message, args) => {
message.author.username +
" n'a pu changer son nickname. Args non spécifié"
);
chan.send(str);
chan.send({embeds:[str]});
}
};
8 changes: 7 additions & 1 deletion commands/examples/roll.js → commands/contributors/roll.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/***
* Author: Michael Labrecque [[email protected]]
* Contributor: Timothy Landry
* Description: Function that roll dices.
*/

exports.run = (client, message, args) => {
var fs = require("fs");
let input = "help";
Expand Down Expand Up @@ -58,7 +64,7 @@ exports.run = (client, message, args) => {
output = `Syntax incorrecte. Utilisez *roll help* pour plus d'informations.`;
}

message.channel.send(output).catch(console.error);
message.channel.send({content:output}).catch(console.error);
setTimeout(function () {
fs.unlink(namef, function (err) {
if (err) throw err;
Expand Down
8 changes: 7 additions & 1 deletion commands/examples/help.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/***
* Author: Timothy Landry
* Contributor: Michael Labrecque [[email protected]]
* Description: Help function that show possible command and params to use them
*/

const { MessageEmbed } = require("discord.js");

exports.run = (client, message, args) => {
Expand Down Expand Up @@ -40,5 +46,5 @@ exports.run = (client, message, args) => {
embed.setDescription(help_message);
}

message.channel.send(embed).catch(console.error);
message.channel.send({embeds:[embed]}).catch(console.error);
};
10 changes: 9 additions & 1 deletion commands/examples/ping.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
/***
* Author: Timothy Landry
* Contributor:
* Description: Simple ping function that answer with a pong message
*/

exports.run = (client, message, args) => {
message.channel.send("pong!")
message.channel.send({
content:"pong!",
ephemeral:true})
.catch(console.error);
}
6 changes: 6 additions & 0 deletions events/guildBanAdd.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/***
* Author: Michael Labrecque [[email protected]]
* Contributor:
* Description: Event that execute when a user is banned. It write the bannishment message in the server log.
*/

module.exports = async (client, guild, user) => {
const Discord = require("discord.js");

Expand Down
10 changes: 8 additions & 2 deletions events/guildMemberAdd.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/***
* Author: Michael Labrecque [[email protected]]
* Contributor:
* Description: Send a welcome DM to the new user.
*/

module.exports = (client, member) => {
const Discord = require("discord.js");

Expand All @@ -14,8 +20,8 @@ module.exports = (client, member) => {
.setColor("0xff0000")
.setDescription(
"Bienvenue sur le serveur Discord de JDIS.\n\n" +
"Ici, tu pourra échanger sur différent sujet en rapport avec la programmation, la sécurité et tout autre " +
"sujet liée à l'informatique ou l'électronique.\n\n"
"Ici, tu pourra échanger sur différent sujet en rapport avec la programmation, la sécurité et tous autres " +
"sujets liés à l'informatique ou l'électronique.\n\n"
)
.addField(
"Announcements",
Expand Down
6 changes: 6 additions & 0 deletions events/guildMemberRemove.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/***
* Author: Michael Labrecque [[email protected]]
* Contributor:
* Description: Event that execute when a user left the server. It write the message in the server log.
*/

module.exports = (client, member) => {
const Discord = require("discord.js");

Expand Down
12 changes: 11 additions & 1 deletion events/message.js → events/messageCreate.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
/***
* Author: Timothy Landry
* Contributor: Michael Labrecque [[email protected]]
* Description: Analyze every message and send message if st[eé]g string is found, return noting if
* the command prefix isn't there and execute the correct command if the prefix is present in the
* message.
*/

module.exports = (client, message) => {
if (message.author.bot) return;

if (message.content.toLowerCase().indexOf("steg")!==-1 || message.content.toLowerCase().indexOf("stég")!==-1)
{
message.channel.send(":man_gesturing_no_tone1::rage: **La Steg c'est non!** :rage::man_gesturing_no_tone1: ");
message.reply({content:":man_gesturing_no_tone1::rage: **La Steg c'est non!** :rage::man_gesturing_no_tone1: "});
}

if (message.content.indexOf(client.config.prefix) !== 0) return;

const args = message.content.slice(client.config.prefix.length).trim().split(/ +/g);
Expand Down
19 changes: 19 additions & 0 deletions events/ready.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
/***
* Author: Timothy Landry
* Contributor:
* Description: Function that execute when bot is ready.
*/

module.exports = (client) => {
client.user.setActivity('>help', { type: 'LISTENING' });

const guild = client.guilds.cache.get(client.config.guildid);
let commands;
if (guild) {
commands = guild.commands
}
else {
commands = client.application.commands
}
// commands.create({
// name: "ping",
// description: "Replies 'pong'"
// })
console.log("[event:ready.js] Bot is online");
};
Loading