diff --git a/README.md b/README.md
index 6197d4f..f891a5e 100644
--- a/README.md
+++ b/README.md
@@ -29,8 +29,9 @@ If you need help with the bot, feel free to [join our support server](https://di
**Other Information**
Invite Manager requires Node.js v12 or higher.
-[License](https://github.com/TheShadowGamer/invite-manager/blob/master/LICENSE)
-[Acknowledgements](https://github.com/TheShadowGamer/invite-manager/blob/master/acknowledgements.md)
+[License](https://github.com/TheShadowGamer/invite-manager/blob/master/LICENSE)
+[Acknowledgements](https://github.com/TheShadowGamer/invite-manager/blob/master/acknowledgements.md)
+[Plugins](https://github.com/TheShadowGamer/invite-manager-plugins)
Please note we are not responsible for if anything happens to your bot account. It is your responsibility to keep the token away from anyone you don't trust. The bot uses discord.js to interact with the Discord API with your bot token. Do not share your .env file with anyone once filled out.
diff --git a/commands/invites/invites.js b/commands/invites/invites.js
index 2c21b8e..442afc5 100644
--- a/commands/invites/invites.js
+++ b/commands/invites/invites.js
@@ -34,7 +34,7 @@ module.exports.slashCommand = async (client, interaction, args, respond) => {
const member = await interaction.guild.members.fetch(args[0].value);
const amount = args[1].value;
interaction.member = await interaction.guild.members.fetch(interaction.member.user.id);
- if(!interaction.member.roles.cache.some(role => role.name === 'Manage Invites') && !message.member.permissions.has(['BAN_MEMBERS', 'KICK_MEMBERS', 'MANAGE_GUILD', 'MANAGE_CHANNELS'])) client.handler.emit('missingPermissions', respond, client.handler.findCommand('invites'), 'user', 'Manage Invites');
+ if(!interaction.member.roles.cache.some(role => role.name === 'Manage Invites') && !interaction.member.permissions.has(['BAN_MEMBERS', 'KICK_MEMBERS', 'MANAGE_GUILD', 'MANAGE_CHANNELS'])) client.handler.emit('missingPermissions', respond, client.handler.findCommand('invites'), 'user', 'Manage Invites');
let entry = await invites.findOrCreate({where: {discordUser: member.id, guildID: interaction.guild.id}, defaults: {discordUser: member.id, invites: 0, guildID: interaction.guild.id}});
await entry[0].increment('invites', {by: amount});
let embed = new MessageEmbed()
@@ -64,7 +64,7 @@ module.exports.slashCommand = async (client, interaction, args, respond) => {
const member = await interaction.guild.members.fetch(args[0].value);
const amount = args[1].value;
interaction.member = await interaction.guild.members.fetch(interaction.member.user.id);
- if(!interaction.member.roles.cache.some(role => role.name === 'Manage Invites') && !message.member.permissions.has(['BAN_MEMBERS', 'KICK_MEMBERS', 'MANAGE_GUILD', 'MANAGE_CHANNELS'])) client.handler.emit('missingPermissions', respond, client.handler.findCommand('invites'), 'user', 'Manage Invites');
+ if(!interaction.member.roles.cache.some(role => role.name === 'Manage Invites') && !interaction.member.permissions.has(['BAN_MEMBERS', 'KICK_MEMBERS', 'MANAGE_GUILD', 'MANAGE_CHANNELS'])) client.handler.emit('missingPermissions', respond, client.handler.findCommand('invites'), 'user', 'Manage Invites');
let embed = new MessageEmbed()
.setColor(client.config.colors.main)
.setFooter(client.user.username, client.user.displayAvatarURL({dynamic: true}))
diff --git a/commands/invites/removeinvites.js b/commands/invites/removeinvites.js
index 18430ee..259c4e3 100644
--- a/commands/invites/removeinvites.js
+++ b/commands/invites/removeinvites.js
@@ -48,7 +48,7 @@ module.exports = class RemoveInvitesCommand extends Command {
return message.channel.send(embed);
};
await entry[0].decrement('invites', {by: amount});
- embed.setDescription(`Added ${amount} invites to ${member.toString()}! They now have ${entry[0].invites - amount} invites!`);
+ embed.setDescription(`Removed ${amount} invites from ${member.toString()}! They now have ${entry[0].invites - amount} invites!`);
return message.channel.send(embed);
};
};
diff --git a/functions/index.js b/functions/index.js
new file mode 100644
index 0000000..c88da09
--- /dev/null
+++ b/functions/index.js
@@ -0,0 +1,7 @@
+require('fs')
+ .readdirSync(__dirname)
+ .filter(file => file !== 'index.js')
+ .forEach(filename => {
+ const moduleName = filename.split('.')[0];
+ exports[moduleName] = require(`${__dirname}/${filename}`);
+ });
\ No newline at end of file
diff --git a/index.js b/index.js
index a130d43..5d6bf8e 100644
--- a/index.js
+++ b/index.js
@@ -1,15 +1,16 @@
const { AkairoClient, CommandHandler, ListenerHandler } = require('discord-akairo');
-const { Team } = require('discord.js');
+const { readdir, stat } = require('fs');
const { prefix } = require('./config');
+const { Team } = require('discord.js');
+const { join } = require('path');
const Sequelize = require('sequelize');
-const path = require('path');
-const fs = require('fs');
const app = require('express')()
require('dotenv').config();
app.get("/", (req, res) => res.sendStatus(200))
let listener = app.listen(process.env.PORT, () => console.log('Your app is currently listening on port: ' + listener.address().port));
let client = new AkairoClient({partials: ['GUILD_MEMBER']});
client.config = require('./config')
+client.tools = require('./functions')
const sequelize = new Sequelize({
dialect: 'sqlite',
storage: '.data/db.sqlite',
@@ -25,6 +26,7 @@ invites.sync();
client.invites = invites;
const guildInvites = new Map();
client.guildInvites = guildInvites;
+client.sequelize = sequelize
const slashCommandList = [];
client.slashCommandList = slashCommandList;
let commandHandler = new CommandHandler(client, {
@@ -42,13 +44,13 @@ let commandHandler = new CommandHandler(client, {
},
commandUtil: true
});
-commandHandler.resolver.addType("custom-MEMBER", async (message, phrase) => {
- if(!phrase) return null;
- let member;
- try {member = await message.guild.members.fetch(phrase)} catch (error) {};
- if(!member) member = client.util.resolveMember(phrase, message.guild.members.cache);
- if(!member) member = (await (message.guild.members.fetch({query: phrase}))).first();
- return member || null;
+readdir(join(__dirname, './types/'), async (err, files) => {
+ if(err) return console.log(chalk.red('An error occured when checking the types folder for types to load: ' + err));
+ files.forEach(async (file) => {
+ if(!file.endsWith('.js')) return;
+ let typeFile = require(join(__dirname, 'types', file));
+ commandHandler.resolver.addType(file.split('.')[0], async (message, phrase) => typeFile(message, phrase, client))
+ });
});
client.handler = commandHandler;
let listenerHandler = new ListenerHandler(client, {
@@ -61,19 +63,19 @@ listenerHandler.setEmitters({
});
listenerHandler.loadAll();
commandHandler.loadAll();
-async function registerSlashCommands(dir) {;
- fs.readdir(path.join(__dirname, dir), async (err, files) => {
+async function registerSlashCommands(dir) {
+ readdir(join(__dirname, dir), async (err, files) => {
if(err){
return console.log(chalk.red('An error occured when checking the commands folder for commands to load: ' + err));
};
files.forEach(async (file) => {
- fs.stat(path.join(__dirname, dir, file), (err, stat) => {
+ stat(join(__dirname, dir, file), (err, stat) => {
if(err) return console.log(chalk.red('An error occured when checking the commands folder for commands to load: ' + err));
if(stat.isDirectory()) {
- registerSlashCommands(path.join(dir, file));
+ registerSlashCommands(join(dir, file));
} else {
if(!file.endsWith('.js')) return;
- let commandFile = require(path.join(__dirname, dir, file));
+ let commandFile = require(join(__dirname, dir, file));
slashCommandList.push({
run: commandFile.slashCommand,
name: file.split('.')[0]
diff --git a/package-lock.json b/package-lock.json
index 256d673..e77d44d 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "invite-manager",
- "version": "2.0.6",
+ "version": "2.1.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -328,9 +328,9 @@
"integrity": "sha512-INWYmHo6NgyYx1ZKGSCmgznVfvkXpWGj4fGCGjO8IPkZ06Bidb9YKr4rXy2lwG0kprCjvqY0qbbhcw6N050abQ=="
},
"discord.js": {
- "version": "12.5.2",
- "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-12.5.2.tgz",
- "integrity": "sha512-PAJv2azCHZNz5VlSOcEYS3SPBmYvka0WHlWhTlHgorfJVRcm1xPwYFqPeU+8+YsWlUxkfgGUD2bnNkVx6vIqPw==",
+ "version": "12.5.3",
+ "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-12.5.3.tgz",
+ "integrity": "sha512-D3nkOa/pCkNyn6jLZnAiJApw2N9XrIsXUAdThf01i7yrEuqUmDGc7/CexVWwEcgbQR97XQ+mcnqJpmJ/92B4Aw==",
"requires": {
"@discordjs/collection": "^0.1.6",
"@discordjs/form-data": "^3.0.1",
@@ -1568,9 +1568,9 @@
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
},
"ws": {
- "version": "7.4.4",
- "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.4.tgz",
- "integrity": "sha512-Qm8k8ojNQIMx7S+Zp8u/uHOx7Qazv3Yv4q68MiWWWOJhiwG5W3x7iqmRtJo8xxrciZUY4vRxUTJCKuRnF28ZZw=="
+ "version": "7.4.5",
+ "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.5.tgz",
+ "integrity": "sha512-xzyu3hFvomRfXKH8vOFMU3OguG6oOvhXMo3xsGy3xWExqaM2dxBbVxuD99O7m3ZUFMvvscsZDqxfgMaRr/Nr1g=="
},
"yallist": {
"version": "4.0.0",
diff --git a/package.json b/package.json
index 898843f..5de656a 100644
--- a/package.json
+++ b/package.json
@@ -1,12 +1,12 @@
{
"name": "invite-manager",
- "version": "2.0.6",
+ "version": "2.1.0",
"description": "Invite manager is an open source bot that allows you to track people's invites. You can join the support server here if you need help with anything: https://discord.gg/xNks8jb",
"main": "index.js",
"dependencies": {
"chalk": "^4.1.0",
"discord-akairo": "^8.1.0",
- "discord.js": "^12.5.2",
+ "discord.js": "^12.5.3",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"figlet": "^1.4.0",
diff --git a/slash-commands/mainBot.js b/slash-commands/mainBot.js
new file mode 100644
index 0000000..a0d5646
--- /dev/null
+++ b/slash-commands/mainBot.js
@@ -0,0 +1,92 @@
+module.exports = [
+ {
+ name: 'uptime',
+ description: 'Tells you how long the bot has been up.'
+ },
+ {
+ name: 'invites',
+ description: 'Add, remove, reset, or view invites.',
+ options: [
+ {
+ name: 'show',
+ description: 'Shows you the amount of invites someone has.',
+ type: 1,
+ options: [
+ {
+ name: 'member',
+ description: 'The member to see the invites of. If none is provided, shows your invites.',
+ type: 6,
+ required: false
+ }
+ ]
+ },
+ {
+ name: 'add',
+ description: 'Add invites to a member.',
+ type: 1,
+ options: [
+ {
+ name: 'member',
+ description: 'The member to add invites from.',
+ type: 6,
+ required: true
+ },
+ {
+ name: 'amount',
+ description: 'The amount of invites to add.',
+ type: 4,
+ required: true
+ }
+ ]
+ },
+ {
+ name: 'remove',
+ description: 'Remove invites from a member.',
+ type: 1,
+ options: [
+ {
+ name: 'member',
+ description: 'The member to remove invites from.',
+ type: 6,
+ required: true
+ },
+ {
+ name: 'amount',
+ description: 'The amount of invites to remove.',
+ type: 4,
+ required: true
+ }
+ ]
+ },
+ {
+ name: 'reset',
+ description: 'Remove all invites from the mentioned member.',
+ type: 1,
+ options: [
+ {
+ name: 'member',
+ description: 'The member to reset the invites of.',
+ type: 6,
+ required: true
+ }
+ ]
+ },
+ ]
+ },
+ {
+ name: 'help',
+ description: 'Displays a list of available command, or detailed information for a specific command.',
+ options: [
+ {
+ name: 'command',
+ description: 'A command to get more information about.',
+ type: 3,
+ required: false
+ }
+ ]
+ },
+ {
+ name: 'leaderboard',
+ description: 'Sends a list of the top ten inviters.'
+ }
+]
\ No newline at end of file
diff --git a/slash-setup.js b/slash-setup.js
index b4aad4d..8217870 100644
--- a/slash-setup.js
+++ b/slash-setup.js
@@ -1,101 +1,16 @@
-let commands = [
- {
- name: 'uptime',
- description: 'Tells you how long the bot has been up.'
- },
- {
- name: 'invites',
- description: 'Add, remove, reset, or view invites.',
- options: [
- {
- name: 'show',
- description: 'Shows you the amount of invites someone has.',
- type: 1,
- options: [
- {
- name: 'member',
- description: 'The member to see the invites of. If none is provided, shows your invites.',
- type: 6,
- required: false
- }
- ]
- },
- {
- name: 'add',
- description: 'Add invites to a member.',
- type: 1,
- options: [
- {
- name: 'member',
- description: 'The member to add invites from.',
- type: 6,
- required: true
- },
- {
- name: 'amount',
- description: 'The amount of invites to add.',
- type: 4,
- required: true
- }
- ]
- },
- {
- name: 'remove',
- description: 'Remove invites from a member.',
- type: 1,
- options: [
- {
- name: 'member',
- description: 'The member to remove invites from.',
- type: 6,
- required: true
- },
- {
- name: 'amount',
- description: 'The amount of invites to remove.',
- type: 4,
- required: true
- }
- ]
- },
- {
- name: 'reset',
- description: 'Remove all invites from the mentioned member.',
- type: 1,
- options: [
- {
- name: 'member',
- description: 'The member to reset the invites of.',
- type: 6,
- required: true
- }
- ]
- },
- ]
- },
- {
- name: 'help',
- description: 'Displays a list of available command, or detailed information for a specific command.',
- options: [
- {
- name: 'command',
- description: 'A command to get more information about.',
- type: 3,
- required: false
- }
- ]
- },
- {
- name: 'leaderboard',
- description: 'Sends a list of the top ten inviters.'
- }
-]
-const { Client } = require('discord.js')
+const { readdir } = require('fs')
+const { red } = require('chalk')
+
+let commands = []
+
+readdir('./slash-commands/', (err, files) => {
+ if(err) return console.log(red('An error occured when checking the slash commands folder for slash commands to load: ' + err));
+ files.forEach(file => {
+ let commandFile = require(`./slash-commands/${file}`)
+ commandFile.forEach(command => commands.push(command))
+ })
+})
-/**
- * Adds all slash commands to the passed client
- * @param {Client} client - The client to add slash commands to
- */
module.exports.registerCommands = async (client) => {
let application = await client.fetchApplication();
for (let i = 0; i < commands.length; i++) {
@@ -107,10 +22,6 @@ module.exports.registerCommands = async (client) => {
}
}
-/**
- * Deletes all slash commands from the passed client
- * @param {Client} client - The client to remove slash commands from
- */
module.exports.deleteCommands = async (client) => {
let application = await client.fetchApplication()
let commands = await client.api.applications(application.id).commands.get()
diff --git a/types/custom-MEMBER.js b/types/custom-MEMBER.js
new file mode 100644
index 0000000..7988227
--- /dev/null
+++ b/types/custom-MEMBER.js
@@ -0,0 +1,8 @@
+module.exports = async (message, phrase, client) => {
+ if(!phrase) return null;
+ let member;
+ try {member = await message.guild.members.fetch(phrase)} catch (error) {};
+ if(!member) member = client.util.resolveMember(phrase, message.guild.members.cache);
+ if(!member) member = (await (message.guild.members.fetch({query: phrase}))).first();
+ return member || null;
+}
\ No newline at end of file