-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
94 lines (94 loc) · 3.56 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const { AkairoClient, CommandHandler, ListenerHandler } = require('discord-akairo');
const { readdir, stat } = require('fs');
const { prefix } = require('./config');
const { Team } = require('discord.js');
const { join } = require('path');
const Sequelize = require('sequelize');
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',
logging: false
});
const invites = sequelize.define('invite', {
discordUser: Sequelize.STRING,
inviter: Sequelize.STRING,
invites: Sequelize.NUMBER,
guildID: Sequelize.STRING
});
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, {
directory: './commands/',
allowMention: true,
prefix: prefix,
argumentDefaults: {
prompt: {
timeout: 'Time ran out, command has been cancelled.',
ended: 'Too many retries, command has been cancelled.',
cancel: 'Command has been cancelled.',
retries: 1,
time: 30000
}
},
commandUtil: true
});
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, {
directory: './listeners/'
});
commandHandler.useListenerHandler(listenerHandler);
listenerHandler.setEmitters({
commandHandler: commandHandler,
ws: client.ws
});
listenerHandler.loadAll();
commandHandler.loadAll();
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) => {
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(join(dir, file));
} else {
if(!file.endsWith('.js')) return;
let commandFile = require(join(__dirname, dir, file));
slashCommandList.push({
run: commandFile.slashCommand,
name: file.split('.')[0]
});
};
});
});
});
};
registerSlashCommands('./commands/');
client.login(process.env.token);
client.fetchApplication().then((application) => {
let owners = application.owner;
if(owners instanceof Team) {owners = owners.members.map(user => user.id)} else {owners = owners.id};
client.ownerID = owners;
});