Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

feat: use standardjs #6

Open
wants to merge 1 commit 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
151 changes: 75 additions & 76 deletions core/commands.js
Original file line number Diff line number Diff line change
@@ -1,91 +1,90 @@
var config = require("../bot.json");
let Logger = require("../lib/logger");
let Logger = require('../lib/logger')

var commandlist = [];
var commandlist = []

module.exports = {
/**
/**
* Create the message listener
*
* @param {Discord.Client|module:discord.js.Client} client
*/
initMessageListener: function (client) {
client.on("message", msg => {
commandlist.forEach(command => {
if (msg.content == command.command) {
switch (command.action) {
case "send_message":
msg.channel.send(command.message);
break;
case "send_dm":
msg.author.send(command.message);
break;
case "switch_role":
if (msg.guild.roles.get(command.role_id)) {
if (!msg.member.roles.has(command.role_id)) {
msg.member.addRole(msg.guild.roles.get(command.role_id));
console.log("[ROLE] Role " + msg.guild.roles.get(command.role_id).name + " has been added to " + msg.author.username);
} else {
msg.member.removeRole(msg.guild.roles.get(command.role_id));
console.log("[ROLE] Role " + msg.guild.roles.get(command.role_id).name + " has been removed to " + msg.author.username);
}
} else {
Logger.error("(" + command.command + ") This role doesn't exist!");
}
break;
case "add_role":
if (msg.guild.roles.get(command.role_id)) {
if (!msg.member.roles.has(command.role_id)) {
msg.member.addRole(msg.guild.roles.get(command.role_id));
Logger.info("Role " + msg.guild.roles.get(command.role_id).name + " has been added to " + msg.author.username);
} else {
msg.channel.send(":lock: **You already have this role.**")
}
} else {
Logger.error("(" + command.command + ") This role doesn't exist!");
}
break;
case "remove_role":
if (msg.guild.roles.get(command.role_id)) {
if (msg.member.roles.has(command.role_id)) {
msg.member.removeRole(msg.guild.roles.get(command.role_id));
Logger.info("Role " + msg.guild.roles.get(command.role_id).name + " has been removed to " + msg.author.username);
} else {
msg.channel.send(":lock: **You don't have this role.**");
}
} else {
Logger.error("(" + command.command + ") This role doesn't exist!");
}
break;
case "purge":
if (msg.guild.member(client.user).hasPermission("MANAGE_MESSAGES")) {
msg.channel.bulkDelete(100);
}
break;
default:
break;
}
initMessageListener: function (client) {
client.on('message', msg => {
commandlist.forEach(command => {
if (msg.content === command.command) {
switch (command.action) {
case 'send_message':
msg.channel.send(command.message)
break
case 'send_dm':
msg.author.send(command.message)
break
case 'switch_role':
if (msg.guild.roles.get(command.role_id)) {
if (!msg.member.roles.has(command.role_id)) {
msg.member.addRole(msg.guild.roles.get(command.role_id))
console.log('[ROLE] Role ' + msg.guild.roles.get(command.role_id).name + ' has been added to ' + msg.author.username)
} else {
msg.member.removeRole(msg.guild.roles.get(command.role_id))
console.log('[ROLE] Role ' + msg.guild.roles.get(command.role_id).name + ' has been removed to ' + msg.author.username)
}
});
});
},
} else {
Logger.error('(' + command.command + ") This role doesn't exist!")
}
break
case 'add_role':
if (msg.guild.roles.get(command.role_id)) {
if (!msg.member.roles.has(command.role_id)) {
msg.member.addRole(msg.guild.roles.get(command.role_id))
Logger.info('Role ' + msg.guild.roles.get(command.role_id).name + ' has been added to ' + msg.author.username)
} else {
msg.channel.send(':lock: **You already have this role.**')
}
} else {
Logger.error('(' + command.command + ") This role doesn't exist!")
}
break
case 'remove_role':
if (msg.guild.roles.get(command.role_id)) {
if (msg.member.roles.has(command.role_id)) {
msg.member.removeRole(msg.guild.roles.get(command.role_id))
Logger.info('Role ' + msg.guild.roles.get(command.role_id).name + ' has been removed to ' + msg.author.username)
} else {
msg.channel.send(":lock: **You don't have this role.**")
}
} else {
Logger.error('(' + command.command + ") This role doesn't exist!")
}
break
case 'purge':
if (msg.guild.member(client.user).hasPermission('MANAGE_MESSAGES')) {
msg.channel.bulkDelete(100)
}
break
default:
break
}
}
})
})
},

/**
/**
* Add the command to the commands array
*
* @param {string} command
*
* @param {string} command
*/
registerCommand: function (command) {
commandlist.push(command);
Logger.info("Command " + command.command + " has been successfully registered !");
},
registerCommand: function (command) {
commandlist.push(command)
Logger.info('Command ' + command.command + ' has been successfully registered !')
},

/**
/**
* UNUSABLE FUNCTION
*
* @param {string} command
*
* @param {string} command
*/
deleteCommand: function (command) {
deleteCommand: function (command) {

}
}
}
}
38 changes: 19 additions & 19 deletions core/events.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
let Logger = require("../lib/logger");
let Logger = require('../lib/logger')

module.exports = {

/**
/**
* Setup the welcome message on Discord Private Message
*
* @param {Discord.Client|module:discord.js.Client} client
* @param {string} message
*
*
* @returns {void}
*/
initDmWelcome: function (client, message) {
client.on("guildMemberAdd", member => {
member.user.send(message.replace("{user}", member.user));
Logger.info("Welcome is now setup !");
});
},
initDmWelcome: function (client, message) {
client.on('guildMemberAdd', member => {
member.user.send(message.replace('{user}', member.user))
Logger.info('Welcome is now setup !')
})
},

/**
/**
* Setup the welcome message on Discord Private Message
*
*
* @param {Discord.Client|module:discord.js.Client} client
* @param channel
* @param {string} message
*
*
* @returns {void}
*/
initChannelWelcome: function (client, channel, message) {
client.on("guildMemberAdd", member => {
client.channels.get(channel).send(message.replace("{user}", member.user).replace("{guild}", member.guild.name).replace("{id}", member.user.id));
Logger.info("[INFO] Join message is now setup !");
});
}
}
initChannelWelcome: function (client, channel, message) {
client.on('guildMemberAdd', member => {
client.channels.get(channel).send(message.replace('{user}', member.user).replace('{guild}', member.guild.name).replace('{id}', member.user.id))
Logger.info('[INFO] Join message is now setup !')
})
}
}
63 changes: 31 additions & 32 deletions core/reactionmsg.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
module.exports = {

/**
* Assign the roles to the reaction on the message
*
* @param {Discord.Client} client
* @param {string} channel
* @param {string} message
* @param {string} reaction
* @param {string} role
*
* @returns {void}
*/
createReactionMessage: (client, channel, message, reaction, role) => {
/**
* Assign the roles to the reaction on the message
*
* @param {Discord.Client} client
* @param {string} channel
* @param {string} message
* @param {string} reaction
* @param {string} role
*
* @returns {void}
*/
createReactionMessage: (client, channel, message, reaction, role) => {
client.channels.get(channel).fetchMessage(message)
.then(msg => msg.react(reaction))
.catch(console.error)

client.channels.get(channel).fetchMessage(message)
.then(msg => msg.react(reaction))
.catch(console.error);
client.on('messageReactionAdd', (msgreact, user) => {
if (msgreact.message.id === message) {
if (msgreact.emoji === reaction) {
msgreact.message.guild.members.get(user.id).addRole(msgreact.message.guild.roles.get(role))
}
}
})

client.on("messageReactionAdd", (msgreact, user) => {
if (msgreact.message.id === message) {
if (msgreact.emoji == reaction) {
msgreact.message.guild.members.get(user.id).addRole(msgreact.message.guild.roles.get(role));
}
}
});

client.on("messageReactionRemove", (msgreact, user) => {
if (msgreact.message.id === message) {
if (msgreact.emoji == reaction) {
msgreact.message.guild.members.get(user.id).removeRole(msgreact.message.guild.roles.get(role));
}
}
});
}
}
client.on('messageReactionRemove', (msgreact, user) => {
if (msgreact.message.id === message) {
if (msgreact.emoji === reaction) {
msgreact.message.guild.members.get(user.id).removeRole(msgreact.message.guild.roles.get(role))
}
}
})
}
}
Loading