Add comments to role, rules commands, and the events
This commit is contained in:
parent
2e13b4d861
commit
6a7e52b0ca
7 changed files with 82 additions and 10 deletions
|
@ -1,32 +1,46 @@
|
||||||
|
// Required components
|
||||||
const { command } = require('vylbot-core');
|
const { command } = require('vylbot-core');
|
||||||
const { MessageEmbed } = require('discord.js');
|
const { MessageEmbed } = require('discord.js');
|
||||||
|
|
||||||
|
// Command variables
|
||||||
const embedColor = "0x3050ba";
|
const embedColor = "0x3050ba";
|
||||||
|
|
||||||
|
// Command class
|
||||||
class role extends command {
|
class role extends command {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
// Set the command's run method, description, category, and example usage
|
||||||
super("role");
|
super("role");
|
||||||
super.description = "Toggles a role for the user to gain/remove";
|
super.description = "Toggles a role for the user to gain/remove";
|
||||||
super.category = "General";
|
super.category = "General";
|
||||||
super.usage = "[name]";
|
super.usage = "[name]";
|
||||||
|
|
||||||
|
// Require in the config the 'assignable roles' array
|
||||||
super.requiredConfigs = "assignable";
|
super.requiredConfigs = "assignable";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run method
|
||||||
role(context) {
|
role(context) {
|
||||||
|
// Get the array containing the assignable roles
|
||||||
let roles = context.client.config.role.assignable;
|
let roles = context.client.config.role.assignable;
|
||||||
let requestedRole = "";
|
let requestedRole = "";
|
||||||
|
|
||||||
|
// If the arguments specifys a specific role
|
||||||
if (context.arguments.length > 0) {
|
if (context.arguments.length > 0) {
|
||||||
|
// Loop through all the assignable roles and check against the first parameter
|
||||||
|
// Save the role name if they match, i.e. the role can be assignable
|
||||||
for (let i = 0; i < roles.length; i++) {
|
for (let i = 0; i < roles.length; i++) {
|
||||||
if (roles[i].toLowerCase() == context.arguments[0].toLowerCase()) {
|
if (roles[i].toLowerCase() == context.arguments[0].toLowerCase()) {
|
||||||
requestedRole = roles[i];
|
requestedRole = roles[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If a matching assignable role was found
|
||||||
if (requestedRole != "") {
|
if (requestedRole != "") {
|
||||||
|
// Get the role object from the server with the role name
|
||||||
let role = context.message.guild.roles.cache.find(r => r.name == requestedRole);
|
let role = context.message.guild.roles.cache.find(r => r.name == requestedRole);
|
||||||
|
|
||||||
|
// If the user already has the role, remove the role from them and send an embed
|
||||||
|
// Otherwise, add the role and send an embed
|
||||||
if (context.message.member.roles.cache.find(r => r.name == requestedRole)) {
|
if (context.message.member.roles.cache.find(r => r.name == requestedRole)) {
|
||||||
context.message.member.roles.remove(role).then(() => {
|
context.message.member.roles.remove(role).then(() => {
|
||||||
let embed = new MessageEmbed()
|
let embed = new MessageEmbed()
|
||||||
|
@ -43,7 +57,7 @@ class role extends command {
|
||||||
|
|
||||||
context.message.channel.send(errorEmbed);
|
context.message.channel.send(errorEmbed);
|
||||||
});
|
});
|
||||||
} else {
|
} else { // If the user doesn't have the role
|
||||||
context.message.member.roles.add(role).then(() => {
|
context.message.member.roles.add(role).then(() => {
|
||||||
let embed = new MessageEmbed()
|
let embed = new MessageEmbed()
|
||||||
.setColor(embedColor)
|
.setColor(embedColor)
|
||||||
|
@ -60,25 +74,29 @@ class role extends command {
|
||||||
context.message.channel.send(errorEmbed);
|
context.message.channel.send(errorEmbed);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else { // If the role can't be found, send an error embed
|
||||||
let embed = new MessageEmbed()
|
let embed = new MessageEmbed()
|
||||||
.setColor(embedColor)
|
.setColor(embedColor)
|
||||||
.setDescription("This role does not exist, see assignable roles with the role command (no arguments)");
|
.setDescription("This role does not exist, see assignable roles with the role command (no arguments)");
|
||||||
|
|
||||||
context.message.channel.send(embed);
|
context.message.channel.send(embed);
|
||||||
}
|
}
|
||||||
} else {
|
} else { // If no role was specified, Send a list of the roles you can assign
|
||||||
|
// The start of the embed text
|
||||||
let rolesString = `Do ${context.client.config.prefix}role <role> to get the role!\n`;
|
let rolesString = `Do ${context.client.config.prefix}role <role> to get the role!\n`;
|
||||||
|
|
||||||
|
// Loop through all the roles, and add them to the embed text
|
||||||
for (let i = 0; i < roles.length; i++) {
|
for (let i = 0; i < roles.length; i++) {
|
||||||
rolesString += `${roles[i]}\n`;
|
rolesString += `${roles[i]}\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create an embed containing the text
|
||||||
let embed = new MessageEmbed()
|
let embed = new MessageEmbed()
|
||||||
.setTitle("Roles")
|
.setTitle("Roles")
|
||||||
.setColor(embedColor)
|
.setColor(embedColor)
|
||||||
.setDescription(rolesString);
|
.setDescription(rolesString);
|
||||||
|
|
||||||
|
// Send the embed
|
||||||
context.message.channel.send(embed);
|
context.message.channel.send(embed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,53 +1,68 @@
|
||||||
|
// Required components
|
||||||
const { command } = require('vylbot-core');
|
const { command } = require('vylbot-core');
|
||||||
const { MessageEmbed } = require('discord.js');
|
const { MessageEmbed } = require('discord.js');
|
||||||
const { existsSync, readFileSync } = require('fs');
|
const { existsSync, readFileSync } = require('fs');
|
||||||
|
|
||||||
|
// Command variables
|
||||||
const embedColor = "0x3050ba";
|
const embedColor = "0x3050ba";
|
||||||
|
|
||||||
|
// Command class
|
||||||
class rules extends command {
|
class rules extends command {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
// Set the command's run method, description, and category
|
||||||
super("rules");
|
super("rules");
|
||||||
super.description = "Generates the rules embeds from the rules.txt file";
|
super.description = "Generates the rules embeds from the rules.txt file";
|
||||||
super.category = "Administration";
|
super.category = "Administration";
|
||||||
|
|
||||||
|
// Require in the config the name of the admin role and the rules file name
|
||||||
super.requiredConfigs = "adminrole";
|
super.requiredConfigs = "adminrole";
|
||||||
super.requiredConfigs = "rulesfile";
|
super.requiredConfigs = "rulesfile";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run method
|
||||||
rules(context) {
|
rules(context) {
|
||||||
|
// If the user is an Admin (has the admin role)
|
||||||
if (context.message.member.roles.cache.find(role => role.name == context.client.config.rules.adminrole)) {
|
if (context.message.member.roles.cache.find(role => role.name == context.client.config.rules.adminrole)) {
|
||||||
|
// If the rulesfile exists
|
||||||
if (existsSync(context.client.config.rules.rulesfile)) {
|
if (existsSync(context.client.config.rules.rulesfile)) {
|
||||||
|
// Get the contents of the rules file, and split it by "> "
|
||||||
|
// Each embed in the rules is set by the "> " syntax
|
||||||
let rulesText = readFileSync(context.client.config.rules.rulesfile).toString();
|
let rulesText = readFileSync(context.client.config.rules.rulesfile).toString();
|
||||||
rulesText = rulesText.split("> ");
|
rulesText = rulesText.split("> ");
|
||||||
|
|
||||||
|
// Loop through each embed to be sent
|
||||||
for (let i = 0; i < rulesText.length; i++) {
|
for (let i = 0; i < rulesText.length; i++) {
|
||||||
|
// If the first line after "> " has a "#", create and embed with an image of the url specified after
|
||||||
if (rulesText[i].charAt(0) == '#') {
|
if (rulesText[i].charAt(0) == '#') {
|
||||||
let embed = new MessageEmbed()
|
let embed = new MessageEmbed()
|
||||||
.setColor(embedColor)
|
.setColor(embedColor)
|
||||||
.setImage(rulesText[i].substring(1));
|
.setImage(rulesText[i].substring(1));
|
||||||
|
|
||||||
context.message.channel.send(embed);
|
context.message.channel.send(embed);
|
||||||
} else {
|
} else { // If the file doesn't have a "#" at the start
|
||||||
|
// Split the embed into different lines, set the first line as the title, and the rest as the description
|
||||||
let rulesLines = rulesText[i].split("\n");
|
let rulesLines = rulesText[i].split("\n");
|
||||||
let rulesTitle = rulesLines[0];
|
let rulesTitle = rulesLines[0];
|
||||||
let rulesDescription = rulesLines.slice(1).join("\n");
|
let rulesDescription = rulesLines.slice(1).join("\n");
|
||||||
|
|
||||||
|
// Create the embed with the specified information above
|
||||||
let embed = new MessageEmbed()
|
let embed = new MessageEmbed()
|
||||||
.setTitle(rulesTitle)
|
.setTitle(rulesTitle)
|
||||||
.setColor(embedColor)
|
.setColor(embedColor)
|
||||||
.setDescription(rulesDescription);
|
.setDescription(rulesDescription);
|
||||||
|
|
||||||
|
// Send the embed
|
||||||
context.message.channel.send(embed);
|
context.message.channel.send(embed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else { // If the rules file doesn't exist
|
||||||
let errorEmbed = new MessageEmbed()
|
let errorEmbed = new MessageEmbed()
|
||||||
.setColor(embedColor)
|
.setColor(embedColor)
|
||||||
.setDescription(`${context.client.config.rules.rulesfile} doesn't exist`);
|
.setDescription(`${context.client.config.rules.rulesfile} doesn't exist`);
|
||||||
|
|
||||||
context.message.channel.send(errorEmbed);
|
context.message.channel.send(errorEmbed);
|
||||||
}
|
}
|
||||||
} else {
|
} else { // If the user doesn't have the Admin role
|
||||||
let errorEmbed = new MessageEmbed()
|
let errorEmbed = new MessageEmbed()
|
||||||
.setColor(embedColor)
|
.setColor(embedColor)
|
||||||
.setDescription("You do not have permission to run this command");
|
.setDescription("You do not have permission to run this command");
|
||||||
|
|
|
@ -1,15 +1,21 @@
|
||||||
|
// Required components
|
||||||
const { event } = require('vylbot-core');
|
const { event } = require('vylbot-core');
|
||||||
const { MessageEmbed } = require('discord.js');
|
const { MessageEmbed } = require('discord.js');
|
||||||
|
|
||||||
|
// Event variables
|
||||||
const embedColor = "0x3050ba";
|
const embedColor = "0x3050ba";
|
||||||
const logchannel = "logs";
|
const logchannel = "logs";
|
||||||
|
|
||||||
|
// Event class
|
||||||
class guildmemberadd extends event {
|
class guildmemberadd extends event {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
// Set the event's run method
|
||||||
super("guildmemberadd");
|
super("guildmemberadd");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run method
|
||||||
guildmemberadd(member) {
|
guildmemberadd(member) {
|
||||||
|
// Create an embed with the user who joined's information
|
||||||
let embed = new MessageEmbed()
|
let embed = new MessageEmbed()
|
||||||
.setTitle("Member Joined")
|
.setTitle("Member Joined")
|
||||||
.setColor(embedColor)
|
.setColor(embedColor)
|
||||||
|
@ -18,6 +24,7 @@ class guildmemberadd extends event {
|
||||||
.setFooter(`User ID: ${member.user.id}`)
|
.setFooter(`User ID: ${member.user.id}`)
|
||||||
.setThumbnail(member.user.displayAvatarURL({ type: 'png', dynamic: true }));
|
.setThumbnail(member.user.displayAvatarURL({ type: 'png', dynamic: true }));
|
||||||
|
|
||||||
|
// Send the embed in the mod's log channel
|
||||||
member.guild.channels.cache.find(channel => channel.name == logchannel).send(embed);
|
member.guild.channels.cache.find(channel => channel.name == logchannel).send(embed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,21 @@
|
||||||
|
// Required components
|
||||||
const { event } = require('vylbot-core');
|
const { event } = require('vylbot-core');
|
||||||
const { MessageEmbed } = require('discord.js');
|
const { MessageEmbed } = require('discord.js');
|
||||||
|
|
||||||
|
// Event variables
|
||||||
const embedColor = "0x3050ba";
|
const embedColor = "0x3050ba";
|
||||||
const logchannel = "logs";
|
const logchannel = "logs";
|
||||||
|
|
||||||
|
// Event class
|
||||||
class guildmemberremove extends event {
|
class guildmemberremove extends event {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
// Set the event's run method
|
||||||
super("guildmemberremove");
|
super("guildmemberremove");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run method
|
||||||
guildmemberremove(member) {
|
guildmemberremove(member) {
|
||||||
|
// Create an embed with the user's information
|
||||||
let embed = new MessageEmbed()
|
let embed = new MessageEmbed()
|
||||||
.setTitle("Member Left")
|
.setTitle("Member Left")
|
||||||
.setColor(embedColor)
|
.setColor(embedColor)
|
||||||
|
@ -18,6 +24,7 @@ class guildmemberremove extends event {
|
||||||
.setFooter(`User ID: ${member.user.id}`)
|
.setFooter(`User ID: ${member.user.id}`)
|
||||||
.setThumbnail(member.user.displayAvatarURL({ type: 'png', dynamic: true }));
|
.setThumbnail(member.user.displayAvatarURL({ type: 'png', dynamic: true }));
|
||||||
|
|
||||||
|
// Send the embed in the log channel
|
||||||
member.guild.channels.cache.find(channel => channel.name == logchannel).send(embed);
|
member.guild.channels.cache.find(channel => channel.name == logchannel).send(embed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,29 @@
|
||||||
|
// Required components
|
||||||
const { event } = require('vylbot-core');
|
const { event } = require('vylbot-core');
|
||||||
const { MessageEmbed } = require('discord.js');
|
const { MessageEmbed } = require('discord.js');
|
||||||
|
|
||||||
|
// Event variables
|
||||||
const embedColor = "0x3050ba";
|
const embedColor = "0x3050ba";
|
||||||
const logchannel = "logs";
|
const logchannel = "logs";
|
||||||
|
|
||||||
|
// Event class
|
||||||
class guildmemberupdate extends event {
|
class guildmemberupdate extends event {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
// Set the event's run method
|
||||||
super("guildmemberupdate");
|
super("guildmemberupdate");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run method
|
||||||
guildmemberupdate(oldMember, newMember) {
|
guildmemberupdate(oldMember, newMember) {
|
||||||
|
// If the user's nickname was changed
|
||||||
if (oldMember.nickname != newMember.nickname) {
|
if (oldMember.nickname != newMember.nickname) {
|
||||||
|
// Get the user's name with tag, their old nickname and their new nickname
|
||||||
|
// If they didn't have a nickname or they removed it, set it to "none" in italics
|
||||||
let memberName = newMember.user.tag;
|
let memberName = newMember.user.tag;
|
||||||
let oldNickname = oldMember.nickname || "*none*";
|
let oldNickname = oldMember.nickname || "*none*";
|
||||||
let newNickname = newMember.nickname || "*none*";
|
let newNickname = newMember.nickname || "*none*";
|
||||||
|
|
||||||
|
// Create the embed with the user's information
|
||||||
let embed = new MessageEmbed()
|
let embed = new MessageEmbed()
|
||||||
.setTitle("Nickname Changed")
|
.setTitle("Nickname Changed")
|
||||||
.setColor(embedColor)
|
.setColor(embedColor)
|
||||||
|
@ -24,6 +33,7 @@ class guildmemberupdate extends event {
|
||||||
.setFooter(`User ID: ${newMember.user.id}`)
|
.setFooter(`User ID: ${newMember.user.id}`)
|
||||||
.setThumbnail(newMember.user.displayAvatarURL({ type: 'png', dynamic: true }));
|
.setThumbnail(newMember.user.displayAvatarURL({ type: 'png', dynamic: true }));
|
||||||
|
|
||||||
|
// Send the embed in the log channel
|
||||||
newMember.guild.channels.cache.find(channel => channel.name == lgochannel).send(embed);
|
newMember.guild.channels.cache.find(channel => channel.name == lgochannel).send(embed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,21 @@
|
||||||
|
// Required components
|
||||||
const { event } = require('vylbot-core');
|
const { event } = require('vylbot-core');
|
||||||
const { MessageEmbed } = require('discord.js');
|
const { MessageEmbed } = require('discord.js');
|
||||||
|
|
||||||
|
// Event variables
|
||||||
const embedColor = "0x3050ba";
|
const embedColor = "0x3050ba";
|
||||||
const logchannel = "logs";
|
const logchannel = "logs";
|
||||||
|
|
||||||
|
// Event class
|
||||||
class messagedelete extends event {
|
class messagedelete extends event {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
// The event's run method
|
||||||
super("messagedelete");
|
super("messagedelete");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run method
|
||||||
messagedelete(message) {
|
messagedelete(message) {
|
||||||
|
// Create an embed with the message's information
|
||||||
let embed = new MessageEmbed()
|
let embed = new MessageEmbed()
|
||||||
.setTitle("Message Deleted")
|
.setTitle("Message Deleted")
|
||||||
.setColor(embedColor)
|
.setColor(embedColor)
|
||||||
|
@ -18,6 +24,7 @@ class messagedelete extends event {
|
||||||
.addField("Content", `\`\`\`${message.content || "*none*"}\`\`\``)
|
.addField("Content", `\`\`\`${message.content || "*none*"}\`\`\``)
|
||||||
.setThumbnail(message.author.displayAvatarURL({ type: 'png', dynamic: true }));
|
.setThumbnail(message.author.displayAvatarURL({ type: 'png', dynamic: true }));
|
||||||
|
|
||||||
|
// Send the embed in the logging channel
|
||||||
message.guild.channels.cache.find(channel => channel.name == logchannel).send(embed);
|
message.guild.channels.cache.find(channel => channel.name == logchannel).send(embed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,25 @@
|
||||||
|
// Required components
|
||||||
const { event } = require('vylbot-core');
|
const { event } = require('vylbot-core');
|
||||||
const { MessageEmbed } = require('discord.js');
|
const { MessageEmbed } = require('discord.js');
|
||||||
|
|
||||||
|
// Event variables
|
||||||
const embedColor = "0x3050ba";
|
const embedColor = "0x3050ba";
|
||||||
const logchannel = "logs";
|
const logchannel = "logs";
|
||||||
|
|
||||||
|
// Event class
|
||||||
class messageupdate extends event {
|
class messageupdate extends event {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
// Set the event's run method
|
||||||
super("messageupdate");
|
super("messageupdate");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run method
|
||||||
messageupdate(oldMessage, newMessage) {
|
messageupdate(oldMessage, newMessage) {
|
||||||
|
// If the user is a bot or the content didn't change, return
|
||||||
if (newMessage.author.bot) return;
|
if (newMessage.author.bot) return;
|
||||||
if (oldMessage.content == newMessage.content) return;
|
if (oldMessage.content == newMessage.content) return;
|
||||||
|
|
||||||
|
// Create an embed with the message's information
|
||||||
let embed = new MessageEmbed()
|
let embed = new MessageEmbed()
|
||||||
.setTitle("Message Embed")
|
.setTitle("Message Embed")
|
||||||
.setColor(embedColor)
|
.setColor(embedColor)
|
||||||
|
@ -22,6 +29,7 @@ class messageupdate extends event {
|
||||||
.addField("After", `\`\`\`${newMessage.content || "*none*"}\`\`\``)
|
.addField("After", `\`\`\`${newMessage.content || "*none*"}\`\`\``)
|
||||||
.setThumbnail(newMessage.author.displayAvatarURL({ type: 'png', dynamic: true }));
|
.setThumbnail(newMessage.author.displayAvatarURL({ type: 'png', dynamic: true }));
|
||||||
|
|
||||||
|
// Send the embed into the log channel
|
||||||
newMessage.guild.channels.cache.find(channel => channel.name == logchannel).send(embed);
|
newMessage.guild.channels.cache.find(channel => channel.name == logchannel).send(embed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue