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

Added slash command support & custom messages to other stuff #64

Merged
merged 12 commits into from
Sep 27, 2021
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions src/classes/v12/buttonroles.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ class ButtonRoles {
* @param {String} channelID - the id of the channel you want to send the message to.
* @returns {Message} - The message sent
*/
static async create({ message, content, role, channelID }) {
if (!message) throw new TypeError('Provide the Discord Message');
if (!(message instanceof Message)) throw Error('Provide a valid message');
static async create(client, { content, role, channelID }) {
if (!client) throw new TypeError('Provide the Discord Client');
if (!content) throw new Error('Provide content!');
if (!(content instanceof MessageEmbed) || !typeof content == 'string') throw Error('Provide valid content');
if (!role) throw new Error('Role not provided!');
Expand Down Expand Up @@ -78,8 +77,8 @@ class ButtonRoles {
row.addComponents(buttons.slice(0 + (i * 5), 5 + (i * 5)));
});
return await (content instanceof MessageEmbed
? message.client.channels.cache.get(channelID).send({ embed: content, components: rows })
: message.client.channels.cache.get(channelID).send(content, { components: rows }));
? client.channels.cache.get(channelID).send({ embed: content, components: rows })
: client.channels.cache.get(channelID).send(content, { components: rows }));
}

/**
Expand Down
21 changes: 10 additions & 11 deletions src/classes/v12/dropdownroles.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
const { MessageActionRow, MessageMenuOption, MessageMenu } = require('discord-buttons');
const { MessageEmbed, Client } = require('discord.js');
const defaultManagerOptions = {
addMessage: 'I have added the <@&{role}> role to you!',
removeMessage: 'I have removed the <@&{role}> role from you!',
};
const merge = require('deepmerge');
class dropdownroles {
const { client } = require('../v13/giveaways');
class dropdownroles {
constructor() {
this.roles = [];
return this;
Expand Down Expand Up @@ -41,12 +37,12 @@ class dropdownroles {
* @param {String} role - The role ID of the role
* @param {String} channelID - The channel ID that will be recieving the dropdown
*/
static async create({ message, content, role, channelID }) {
static async create(client, { content, role, channelID }) {
if (!client) throw new TypeError('Provide the Discord Client');
// if(!message.client.customMessages || !message.client.customMessages.dropdownrolesMessages) message.client.customMessages.dropdownrolesMessages = defaultManagerOptions;
if(!message) throw new TypeError('please provide the Discord Message');
if(!content) throw new Error('please provide content!');
if(!role) throw new Error('role not provided!');
if(!channelID) throw new Error('channelID not provided!');
if(!channelID) throw new Error('channel ID not provided!');
const dropdownsOptions = [];
// Promise.resolve(role).then(console.log);
// console.log(role);
Expand All @@ -58,9 +54,12 @@ class dropdownroles {
dropdown.options = dropdownsOptions;
// console.log(dropdown);
const row = new MessageActionRow().addComponent(dropdown);
content instanceof MessageEmbed ? message.client.channels.cache.get(channelID).send({ embed: content, components: [row] }) : message.client.channels.cache.get(channelID).send(content, { components: [row] });
if(typeof content === 'object') {
client.channels.cache.get(channelID).send({ embed: content, components: [row] })
} else {
client.channels.cache.get(channelID).send(content, { components: [row] });
}
}
}


module.exports = dropdownroles;
32 changes: 30 additions & 2 deletions src/classes/v12/functions/handleButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,35 @@ let win;
const schema = require('../../../models/giveawayschema');
const { MessageButton } = require('discord-buttons');
const giveaways = require('../giveaways');

const defaultButtonRolesMessages = {
addMessage: 'I have added the {role} role to you!',
removeMessage: 'I have removed the {role} role from you!',
};
const defaultGiveawayMessages = {
dmWinner: true,
giveaway: '🎉🎉 **GIVEAWAY MOMENT** 🎉🎉',
giveawayDescription: '🎁 Prize: **{prize}**\n🎊 Hosted by: {hostedBy}\n⏲️ Winner(s): `{winners}`\n\nRequirements: {requirements}',
endedGiveawayDescription: '🎁 Prize: **{prize}**\n🎊 Hosted by: {hostedBy}\n⏲️ Winner(s): {winners}',
giveawayFooterImage: 'https://cdn.discordapp.com/emojis/843076397345144863.png',
winMessage: '{winners} you won {prize} Congratulations! Hosted by {hostedBy}',
rerolledMessage: 'Rerolled! {winner} is the new winner of the giveaway!', // only {winner} placeholder
toParticipate: '**Click the Enter button to enter the giveaway!**',
newParticipant: 'You have successfully entered for this giveaway', // no placeholders | ephemeral
alreadyParticipated: 'you already entered this giveaway!', // no placeholders | ephemeral
noParticipants: 'There are not enough people in the giveaway!', // no placeholders
noRole: 'You do not have the required role(s)\n{requiredRoles}\n for the giveaway!', // only {requiredRoles} | ephemeral
dmMessage: 'You have won a giveaway in **{guildName}**!\nPrize: [{prize}]({giveawayURL})',
noWinner: 'Not enough people participated in this giveaway.', // no {winner} placerholder
alreadyEnded: 'The giveaway has already ended!', // no {winner} placeholder
dropWin: '{winner} Won The Drop!!', // only {winner} placeholder
};

module.exports = async (client, button) => {
if (!client.customMessages || !client.customMessages.buttonRolesMessages) client.customMessages = {
buttonRolesMessages: defaultButtonRolesMessages,
giveawayMessages: defaultGiveawayMessages
};
await button.clicker.fetch();
const id = button.id;
if (id.startsWith('giveaways')) {
Expand Down Expand Up @@ -53,11 +81,11 @@ module.exports = async (client, button) => {
const role = id.split(':')[1];
if (button.clicker.member.roles.cache.has(role)) {
button.clicker.member.roles.remove(role);
button.reply.send(`I have removed the <@&${role}> role from you!`, true);
button.reply.send(client.customMessages.buttonRolesMessages.removeMessage.replace(/{role}/g, `<@&${role}>`), true);
}
else {
button.clicker.member.roles.add(role);
button.reply.send(`I have added the <@&${role}> role to you!`, true);
button.reply.send(client.customMessages.buttonRolesMessages.addMessage.replace(/{role}/g, `<@&${role}>`), true);
}
}
};
11 changes: 9 additions & 2 deletions src/classes/v12/functions/handleMenus.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
const applications = require('../applications');
const Discord = require('discord.js');
const ms = require('ms');
const defaultDropdownRolesMessages = {
addMessage: 'I have added the {role} role to you!',
removeMessage: 'I have removed the {role} role from you!',
};

module.exports = async (client, menu) => {
if (!client.customMessages || !client.customMessages.dropdownRolesMessages) client.customMessages = {
dropdownRolesMessages: defaultDropdownRolesMessages
};
await menu.clicker.fetch();
if (menu.id == 'app') {
const app = menu.values[0];
Expand Down Expand Up @@ -56,11 +63,11 @@ module.exports = async (client, menu) => {
const role = menu.values[0];
if (menu.clicker.member.roles.cache.has(role)) {
menu.clicker.member.roles.remove(role);
menu.reply.send(`I have removed the <@&${role}> role from you!`, true);
menu.reply.send(client.customMessages.dropdownRolesMessages.removeMessage.replace(/{role}/g, `<@&${role}>`), true);
}
else {
menu.clicker.member.roles.add(role);
menu.reply.send(`I have added the <@&${role}> role to you!`, true);
menu.reply.send(client.customMessages.dropdownRolesMessages.addMessage.replace(/{role}/g, `<@&${role}>`), true);
}
}
};
39 changes: 23 additions & 16 deletions src/classes/v12/giveaways.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const Discord = require('discord.js');
const mongoose = require('mongoose');
const ms = require('ms');
const merge = require('deepmerge');
const defaultManagerOptions = {
const defaultGiveawayMessages = {
dmWinner: true,
giveaway: '🎉🎉 **GIVEAWAY MOMENT** 🎉🎉',
giveawayDescription: '🎁 Prize: **{prize}**\n🎊 Hosted by: {hostedBy}\n⏲️ Winner(s): `{winners}`\n\nRequirements: {requirements}',
Expand Down Expand Up @@ -39,11 +39,13 @@ class giveaways {
};
}

static async create({
message, prize, host, winners, endAfter, requirements, channel,
static async create(client, {
prize, host, winners, endAfter, requirements, channel,
}) {
if(!message.client.customMessages.giveawayMessages) message.client.customMessages.giveawayMessages = defaultManagerOptions;
if (!message) throw new Error('NuggiesError: message wasnt provided while creating giveaway!');
if (!client) throw new Error('NuggiesError: client wasnt provided while creating giveaway!');
if (!client.customMessages || !client.customMessages.giveawayMessages) client.customMessages = {
giveawayMessages: defaultGiveawayMessages
};
if (!prize) throw new Error('NuggiesError: prize wasnt provided while creating giveaway!');
if (typeof prize !== 'string') throw new TypeError('NuggiesError: prize should be a string');
if (!host) throw new Error('NuggiesError: host wasnt provided while creating giveaway');
Expand All @@ -52,12 +54,12 @@ class giveaways {
if (!endAfter) throw new Error('NuggiesError: time wasnt provided while creating giveaway');
if (typeof endAfter !== 'string') throw new TypeError('NuggiesError: endAfter should be a string');
if (!channel) throw new Error('NuggiesError: channel wasnt provided while creating giveaway');
const msg = await message.guild.channels.cache.get(channel).send(message.client.customMessages.giveawayMessages.giveaway, {
buttons: utils.getButtons(host), embed: await utils.giveawayEmbed(message.client, { host, prize, endAfter, winners, requirements }),
const msg = await channel.guild.channels.cache.get(channel).send(client.customMessages.giveawayMessages.giveaway, {
buttons: utils.getButtons(host), embed: await utils.giveawayEmbed(client, { host, prize, endAfter, winners, requirements }),
});
const data = await new schema({
messageID: msg.id,
channelID: channel,
channelID: channel.id,
guildID: msg.guild.id,
host: host,
winners: winners,
Expand Down Expand Up @@ -222,22 +224,27 @@ class giveaways {
}, 10000);
});
}
static async drop({ message, channel, prize, host }) {
static async drop(client, { channel, prize, host }) {
// eslint-disable-next-line no-unused-vars
let ended;
if(!message.client.customMessages.giveawayMessages) message.client.customMessages.giveawayMessages = defaultManagerOptions;
if (!channel) throw new Error('NuggiesError: channel ID not provided');
if (!host) throw new Error('NuggiesError: host not provided');
if (!client) throw new Error('NuggiesError: client not provided');
if (!client.customMessages || !client.customMessages.giveawayMessages) client.customMessages = {
giveawayMessages: defaultGiveawayMessages
};
if (!channel) throw new Error('NuggiesError: channel not provided');
if (!host) throw new Error('NuggiesError: host ID not provided');
if (!prize) throw new Error('NuggiesError: prize not provided');
if (!message) throw new Error('NuggiesError: message not provided');

const m = await message.client.channels.cache.get(channel).send({ embed: await utils.dropEmbed(message.client, { prize: prize, host: host }), component: await utils.dropButtons(prize) });
const filter = (button) => button.clicker.user.id === message.author.id;
const m = await client.channels.cache.get(channel).send({ embed: await utils.dropEmbed(client, { prize: prize, host: host }), component: await utils.dropButtons(prize) });
const filter = (button) => button.clicker.user.id === host;
const collector = await m.createButtonCollector(filter, { time: 90000, max: 1 });
collector.on('collect', async (b) => {
if (!b.client.customMessages || !b.client.customMessages.giveawayMessages) b.client.customMessages = {
giveawayMessages: defaultGiveawayMessages
};
b.reply.defer();
ended = true;
b.channel.send(message.client.customMessages.giveawayMessages.dropWin.replace(/{winner}/g, `<@${b.clicker.user.id}>`));
b.channel.send(b.client.customMessages.giveawayMessages.dropWin.replace(/{winner}/g, `<@${b.clicker.user.id}>`));
await utils.editDropButtons(m.client, b);
return collector.stop('end');
});
Expand Down
41 changes: 41 additions & 0 deletions src/classes/v12/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,34 @@ const mongoose = require('mongoose');
mongoose.set('useFindAndModify', false);
const handleButtons = require('./functions/handleButtons');
const handleMenus = require('./functions/handleMenus');
const merge = require('deepmerge');

const defaultGiveawayMessages = {
dmWinner: true,
giveaway: '🎉🎉 **GIVEAWAY MOMENT** 🎉🎉',
giveawayDescription: '🎁 Prize: **{prize}**\n🎊 Hosted by: {hostedBy}\n⏲️ Winner(s): `{winners}`\n\nRequirements: {requirements}',
endedGiveawayDescription: '🎁 Prize: **{prize}**\n🎊 Hosted by: {hostedBy}\n⏲️ Winner(s): {winners}',
giveawayFooterImage: 'https://cdn.discordapp.com/emojis/843076397345144863.png',
winMessage: '{winners} you won {prize} Congratulations! Hosted by {hostedBy}',
rerolledMessage: 'Rerolled! {winner} is the new winner of the giveaway!', // only {winner} placeholder
toParticipate: '**Click the Enter button to enter the giveaway!**',
newParticipant: 'You have successfully entered for this giveaway', // no placeholders | ephemeral
alreadyParticipated: 'you already entered this giveaway!', // no placeholders | ephemeral
noParticipants: 'There are not enough people in the giveaway!', // no placeholders
noRole: 'You do not have the required role(s)\n{requiredRoles}\n for the giveaway!', // only {requiredRoles} | ephemeral
dmMessage: 'You have won a giveaway in **{guildName}**!\nPrize: [{prize}]({giveawayURL})',
noWinner: 'Not enough people participated in this giveaway.', // no {winner} placerholder
alreadyEnded: 'The giveaway has already ended!', // no {winner} placeholder
dropWin: '{winner} Won The Drop!!', // only {winner} placeholder
};
const defaultButtonRolesMessages = {
addMessage: 'I have added the {role} role to you!',
removeMessage: 'I have removed the {role} role from you!',
};
const defaultDropdownRolesMessages = {
addMessage: 'I have added the {role} role to you!',
removeMessage: 'I have removed the {role} role from you!',
};

module.exports = {
/**
Expand All @@ -16,6 +44,19 @@ module.exports = {
useUnifiedTopology: true,
});
},
async Messages(client, {
giveawayOptions = {}, buttonRolesOptions = {}, dropdownRolesOptions = {}
}) {
if (!client) throw new TypeError('NuggiesError: You didn\'t provide a Client in Messages Function.');
if (typeof giveawayOptions !== 'object') throw new TypeError('NuggiesError: giveawaysOptions in Messages function is not an object.');
if (typeof buttonRolesOptions !== 'object') throw new TypeError('NuggiesError: buttonRolesOptions in Messages function is not an object.');
if (typeof dropdownRolesOptions !== 'object') throw new TypeError('NuggiesError: dropdownRolesOptions in Messages function is not an object.');
client.customMessages = {
giveawayMessages: merge(defaultGiveawayMessages, giveawayOptions),
buttonRolesMessages: merge(defaultButtonRolesMessages, buttonRolesOptions),
dropdownRolesMessages: merge(defaultDropdownRolesMessages, dropdownRolesOptions)
};
},
async handleInteractions(client) {
if (!client) throw new Error('NuggiesError: client not provided');
client.on('clickMenu', (menu) => handleMenus(client, menu));
Expand Down
17 changes: 6 additions & 11 deletions src/classes/v13/buttonroles.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
/* eslint-disable no-unused-vars */
const { MessageEmbed, Message, Client, MessageButton, MessageActionRow } = require('discord.js');
const merge = require('deepmerge');
const { MessageEmbed, Message, MessageButton, MessageActionRow } = require('discord.js');
const utils = require('../../functions/utils');
const defaultManagerOptions = {
addMessage: 'I have added the <@&{role}> role to you!',
removeMessage: 'I have removed the <@&{role}> role from you!',
};

class ButtonRoles {

constructor() {
Expand Down Expand Up @@ -47,9 +43,8 @@ class ButtonRoles {
* @param {String} channelID - the id of the channel you want to send the message to.
* @returns {Message} - The message sent
*/
static async create({ message, content, role, channelID }) {
if (!message) throw new TypeError('Provide the Discord Message');
if (!(message instanceof Message)) throw Error('Provide a valid message');
static async create(client, { content, role, channelID }) {
if (!client) throw new TypeError('Provide the Discord Client');
if (!content) throw new Error('Provide content!');
if (!(content instanceof MessageEmbed) || !typeof content == 'string') throw Error('Provide valid content');
if (!role) throw new Error('Role not provided!');
Expand Down Expand Up @@ -78,8 +73,8 @@ class ButtonRoles {
row.addComponents(buttons.slice(0 + (i * 5), 5 + (i * 5)));
});
return await (content instanceof MessageEmbed
? message.client.channels.cache.get(channelID).send({ embeds: [content], components: rows })
: message.client.channels.cache.get(channelID).send({ content, components: rows }));
? client.channels.cache.get(channelID).send({ embeds: [content], components: rows })
: client.channels.cache.get(channelID).send({ content, components: rows }));
}

/**
Expand Down
27 changes: 12 additions & 15 deletions src/classes/v13/dropdownroles.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
/* eslint-disable no-unused-vars */
const { MessageEmbed, Client, MessageActionRow, MessageSelectMenu } = require('discord.js');
const defaultManagerOptions = {
addMessage: 'I have added the <@&{role}> role to you!',
removeMessage: 'I have removed the <@&{role}> role from you!',
};
const merge = require('deepmerge');
const { MessageActionRow, MessageSelectMenu } = require('discord.js');
const { client } = require('./giveaways');
class DropdownRoles {
constructor() {
this.roles = [];
Expand Down Expand Up @@ -41,24 +37,25 @@ class DropdownRoles {
* @param {String} role - The role ID of the role
* @param {String} channelID - The channel ID that will be recieving the dropdown
*/
static async create({ message, content, role, channelID }) {
// if(!message.client.customMessages || !message.client.customMessages.dropdownrolesMessages) message.client.customMessages.dropdownrolesMessages = defaultManagerOptions;
if(!message) throw new TypeError('please provide the Discord Message');
static async create(client, { content, role, channelID }) {
if (!client) throw new TypeError('Provide the Discord Client');
if(!content) throw new Error('please provide content!');
if(!role) throw new Error('role not provided!');
if(!channelID) throw new Error('channelID not provided!');
if(!channelID) throw new Error('channel ID not provided!');
const dropdownsOptions = [];
// Promise.resolve(role).then(console.log);
// console.log(role);

for (const buttonObject of role.roles) {
dropdownsOptions.push({ emoji: buttonObject.emoji, label: buttonObject.label, value: buttonObject.role, description: `click this to get the ${message.guild.roles.cache.get(buttonObject.role).name} role!`.substr(0, 50) });
dropdownsOptions.push({ emoji: buttonObject.emoji, label: buttonObject.label, value: buttonObject.role, description: `click this to get the ${channel.guild.roles.cache.get(buttonObject.role).name} role!`.substr(0, 50) });
}

const dropdown = new MessageSelectMenu().setCustomId('dr');
dropdown.options = dropdownsOptions;
// console.log(dropdown);
const row = new MessageActionRow().addComponents([dropdown]);
content instanceof MessageEmbed ? message.client.channels.cache.get(channelID).send({ embeds: [content], components: [row] }) : message.client.channels.cache.get(channelID).send({ content, components: [row] });
if(typeof content === 'object') {
client.channels.cache.get(channelID).send({ embeds: [content], components: [row] })
} else {
client.channels.cache.get(channelID).send(content, { components: [row] })
}
}
}

Expand Down