Skip to content
This repository was archived by the owner on Jul 9, 2024. It is now read-only.

Commit 62198d0

Browse files
v2.1.0 - Plugin Support (#10)
1 parent 573cdf2 commit 62198d0

File tree

10 files changed

+151
-130
lines changed

10 files changed

+151
-130
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ If you need help with the bot, feel free to [join our support server](https://di
2929
**Other Information**
3030
Invite Manager requires Node.js v12 or higher.
3131

32-
[License](https://github.com/TheShadowGamer/invite-manager/blob/master/LICENSE)
33-
[Acknowledgements](https://github.com/TheShadowGamer/invite-manager/blob/master/acknowledgements.md)
32+
[License](https://github.com/TheShadowGamer/invite-manager/blob/master/LICENSE) <br>
33+
[Acknowledgements](https://github.com/TheShadowGamer/invite-manager/blob/master/acknowledgements.md) <br>
34+
[Plugins](https://github.com/TheShadowGamer/invite-manager-plugins)
3435

3536
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.
3637

commands/invites/invites.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports.slashCommand = async (client, interaction, args, respond) => {
3434
const member = await interaction.guild.members.fetch(args[0].value);
3535
const amount = args[1].value;
3636
interaction.member = await interaction.guild.members.fetch(interaction.member.user.id);
37-
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');
37+
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');
3838
let entry = await invites.findOrCreate({where: {discordUser: member.id, guildID: interaction.guild.id}, defaults: {discordUser: member.id, invites: 0, guildID: interaction.guild.id}});
3939
await entry[0].increment('invites', {by: amount});
4040
let embed = new MessageEmbed()
@@ -64,7 +64,7 @@ module.exports.slashCommand = async (client, interaction, args, respond) => {
6464
const member = await interaction.guild.members.fetch(args[0].value);
6565
const amount = args[1].value;
6666
interaction.member = await interaction.guild.members.fetch(interaction.member.user.id);
67-
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');
67+
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');
6868
let embed = new MessageEmbed()
6969
.setColor(client.config.colors.main)
7070
.setFooter(client.user.username, client.user.displayAvatarURL({dynamic: true}))

commands/invites/removeinvites.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module.exports = class RemoveInvitesCommand extends Command {
4848
return message.channel.send(embed);
4949
};
5050
await entry[0].decrement('invites', {by: amount});
51-
embed.setDescription(`Added ${amount} invites to ${member.toString()}! They now have ${entry[0].invites - amount} invites!`);
51+
embed.setDescription(`Removed ${amount} invites from ${member.toString()}! They now have ${entry[0].invites - amount} invites!`);
5252
return message.channel.send(embed);
5353
};
5454
};

functions/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require('fs')
2+
.readdirSync(__dirname)
3+
.filter(file => file !== 'index.js')
4+
.forEach(filename => {
5+
const moduleName = filename.split('.')[0];
6+
exports[moduleName] = require(`${__dirname}/${filename}`);
7+
});

index.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
const { AkairoClient, CommandHandler, ListenerHandler } = require('discord-akairo');
2-
const { Team } = require('discord.js');
2+
const { readdir, stat } = require('fs');
33
const { prefix } = require('./config');
4+
const { Team } = require('discord.js');
5+
const { join } = require('path');
46
const Sequelize = require('sequelize');
5-
const path = require('path');
6-
const fs = require('fs');
77
const app = require('express')()
88
require('dotenv').config();
99
app.get("/", (req, res) => res.sendStatus(200))
1010
let listener = app.listen(process.env.PORT, () => console.log('Your app is currently listening on port: ' + listener.address().port));
1111
let client = new AkairoClient({partials: ['GUILD_MEMBER']});
1212
client.config = require('./config')
13+
client.tools = require('./functions')
1314
const sequelize = new Sequelize({
1415
dialect: 'sqlite',
1516
storage: '.data/db.sqlite',
@@ -25,6 +26,7 @@ invites.sync();
2526
client.invites = invites;
2627
const guildInvites = new Map();
2728
client.guildInvites = guildInvites;
29+
client.sequelize = sequelize
2830
const slashCommandList = [];
2931
client.slashCommandList = slashCommandList;
3032
let commandHandler = new CommandHandler(client, {
@@ -42,13 +44,13 @@ let commandHandler = new CommandHandler(client, {
4244
},
4345
commandUtil: true
4446
});
45-
commandHandler.resolver.addType("custom-MEMBER", async (message, phrase) => {
46-
if(!phrase) return null;
47-
let member;
48-
try {member = await message.guild.members.fetch(phrase)} catch (error) {};
49-
if(!member) member = client.util.resolveMember(phrase, message.guild.members.cache);
50-
if(!member) member = (await (message.guild.members.fetch({query: phrase}))).first();
51-
return member || null;
47+
readdir(join(__dirname, './types/'), async (err, files) => {
48+
if(err) return console.log(chalk.red('An error occured when checking the types folder for types to load: ' + err));
49+
files.forEach(async (file) => {
50+
if(!file.endsWith('.js')) return;
51+
let typeFile = require(join(__dirname, 'types', file));
52+
commandHandler.resolver.addType(file.split('.')[0], async (message, phrase) => typeFile(message, phrase, client))
53+
});
5254
});
5355
client.handler = commandHandler;
5456
let listenerHandler = new ListenerHandler(client, {
@@ -61,19 +63,19 @@ listenerHandler.setEmitters({
6163
});
6264
listenerHandler.loadAll();
6365
commandHandler.loadAll();
64-
async function registerSlashCommands(dir) {;
65-
fs.readdir(path.join(__dirname, dir), async (err, files) => {
66+
async function registerSlashCommands(dir) {
67+
readdir(join(__dirname, dir), async (err, files) => {
6668
if(err){
6769
return console.log(chalk.red('An error occured when checking the commands folder for commands to load: ' + err));
6870
};
6971
files.forEach(async (file) => {
70-
fs.stat(path.join(__dirname, dir, file), (err, stat) => {
72+
stat(join(__dirname, dir, file), (err, stat) => {
7173
if(err) return console.log(chalk.red('An error occured when checking the commands folder for commands to load: ' + err));
7274
if(stat.isDirectory()) {
73-
registerSlashCommands(path.join(dir, file));
75+
registerSlashCommands(join(dir, file));
7476
} else {
7577
if(!file.endsWith('.js')) return;
76-
let commandFile = require(path.join(__dirname, dir, file));
78+
let commandFile = require(join(__dirname, dir, file));
7779
slashCommandList.push({
7880
run: commandFile.slashCommand,
7981
name: file.split('.')[0]

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "invite-manager",
3-
"version": "2.0.6",
3+
"version": "2.1.0",
44
"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",
55
"main": "index.js",
66
"dependencies": {
77
"chalk": "^4.1.0",
88
"discord-akairo": "^8.1.0",
9-
"discord.js": "^12.5.2",
9+
"discord.js": "^12.5.3",
1010
"dotenv": "^8.2.0",
1111
"express": "^4.17.1",
1212
"figlet": "^1.4.0",

slash-commands/mainBot.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
module.exports = [
2+
{
3+
name: 'uptime',
4+
description: 'Tells you how long the bot has been up.'
5+
},
6+
{
7+
name: 'invites',
8+
description: 'Add, remove, reset, or view invites.',
9+
options: [
10+
{
11+
name: 'show',
12+
description: 'Shows you the amount of invites someone has.',
13+
type: 1,
14+
options: [
15+
{
16+
name: 'member',
17+
description: 'The member to see the invites of. If none is provided, shows your invites.',
18+
type: 6,
19+
required: false
20+
}
21+
]
22+
},
23+
{
24+
name: 'add',
25+
description: 'Add invites to a member.',
26+
type: 1,
27+
options: [
28+
{
29+
name: 'member',
30+
description: 'The member to add invites from.',
31+
type: 6,
32+
required: true
33+
},
34+
{
35+
name: 'amount',
36+
description: 'The amount of invites to add.',
37+
type: 4,
38+
required: true
39+
}
40+
]
41+
},
42+
{
43+
name: 'remove',
44+
description: 'Remove invites from a member.',
45+
type: 1,
46+
options: [
47+
{
48+
name: 'member',
49+
description: 'The member to remove invites from.',
50+
type: 6,
51+
required: true
52+
},
53+
{
54+
name: 'amount',
55+
description: 'The amount of invites to remove.',
56+
type: 4,
57+
required: true
58+
}
59+
]
60+
},
61+
{
62+
name: 'reset',
63+
description: 'Remove all invites from the mentioned member.',
64+
type: 1,
65+
options: [
66+
{
67+
name: 'member',
68+
description: 'The member to reset the invites of.',
69+
type: 6,
70+
required: true
71+
}
72+
]
73+
},
74+
]
75+
},
76+
{
77+
name: 'help',
78+
description: 'Displays a list of available command, or detailed information for a specific command.',
79+
options: [
80+
{
81+
name: 'command',
82+
description: 'A command to get more information about.',
83+
type: 3,
84+
required: false
85+
}
86+
]
87+
},
88+
{
89+
name: 'leaderboard',
90+
description: 'Sends a list of the top ten inviters.'
91+
}
92+
]

slash-setup.js

Lines changed: 12 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,16 @@
1-
let commands = [
2-
{
3-
name: 'uptime',
4-
description: 'Tells you how long the bot has been up.'
5-
},
6-
{
7-
name: 'invites',
8-
description: 'Add, remove, reset, or view invites.',
9-
options: [
10-
{
11-
name: 'show',
12-
description: 'Shows you the amount of invites someone has.',
13-
type: 1,
14-
options: [
15-
{
16-
name: 'member',
17-
description: 'The member to see the invites of. If none is provided, shows your invites.',
18-
type: 6,
19-
required: false
20-
}
21-
]
22-
},
23-
{
24-
name: 'add',
25-
description: 'Add invites to a member.',
26-
type: 1,
27-
options: [
28-
{
29-
name: 'member',
30-
description: 'The member to add invites from.',
31-
type: 6,
32-
required: true
33-
},
34-
{
35-
name: 'amount',
36-
description: 'The amount of invites to add.',
37-
type: 4,
38-
required: true
39-
}
40-
]
41-
},
42-
{
43-
name: 'remove',
44-
description: 'Remove invites from a member.',
45-
type: 1,
46-
options: [
47-
{
48-
name: 'member',
49-
description: 'The member to remove invites from.',
50-
type: 6,
51-
required: true
52-
},
53-
{
54-
name: 'amount',
55-
description: 'The amount of invites to remove.',
56-
type: 4,
57-
required: true
58-
}
59-
]
60-
},
61-
{
62-
name: 'reset',
63-
description: 'Remove all invites from the mentioned member.',
64-
type: 1,
65-
options: [
66-
{
67-
name: 'member',
68-
description: 'The member to reset the invites of.',
69-
type: 6,
70-
required: true
71-
}
72-
]
73-
},
74-
]
75-
},
76-
{
77-
name: 'help',
78-
description: 'Displays a list of available command, or detailed information for a specific command.',
79-
options: [
80-
{
81-
name: 'command',
82-
description: 'A command to get more information about.',
83-
type: 3,
84-
required: false
85-
}
86-
]
87-
},
88-
{
89-
name: 'leaderboard',
90-
description: 'Sends a list of the top ten inviters.'
91-
}
92-
]
93-
const { Client } = require('discord.js')
1+
const { readdir } = require('fs')
2+
const { red } = require('chalk')
3+
4+
let commands = []
5+
6+
readdir('./slash-commands/', (err, files) => {
7+
if(err) return console.log(red('An error occured when checking the slash commands folder for slash commands to load: ' + err));
8+
files.forEach(file => {
9+
let commandFile = require(`./slash-commands/${file}`)
10+
commandFile.forEach(command => commands.push(command))
11+
})
12+
})
9413

95-
/**
96-
* Adds all slash commands to the passed client
97-
* @param {Client} client - The client to add slash commands to
98-
*/
9914
module.exports.registerCommands = async (client) => {
10015
let application = await client.fetchApplication();
10116
for (let i = 0; i < commands.length; i++) {
@@ -107,10 +22,6 @@ module.exports.registerCommands = async (client) => {
10722
}
10823
}
10924

110-
/**
111-
* Deletes all slash commands from the passed client
112-
* @param {Client} client - The client to remove slash commands from
113-
*/
11425
module.exports.deleteCommands = async (client) => {
11526
let application = await client.fetchApplication()
11627
let commands = await client.api.applications(application.id).commands.get()

types/custom-MEMBER.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = async (message, phrase, client) => {
2+
if(!phrase) return null;
3+
let member;
4+
try {member = await message.guild.members.fetch(phrase)} catch (error) {};
5+
if(!member) member = client.util.resolveMember(phrase, message.guild.members.cache);
6+
if(!member) member = (await (message.guild.members.fetch({query: phrase}))).first();
7+
return member || null;
8+
}

0 commit comments

Comments
 (0)