-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
92 lines (78 loc) · 2.46 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
require('dotenv').config()
const url = "mongodb://Warns:warn@192.168.1.134:27017/Warns"
const mongoose = require('mongoose');
mongoose.connect(url, {
useNewUrlParser: true,
useUnifiedTopology: true
})
// Util
const ora = require('ora')
const config = require('./config')
const fs = require('fs')
// Express
const express = require('express');
const app = express();
// Slash Commands
const { Collection } = require('discord.js')
const discord = require('discord.js')
const slash = require('./src/util/slash')
const { builtinModules } = require('module')
// CLI
const intentsLoader = ora('Registering Intents').start()
// Checks
let finalIntents = []
if (!Array.isArray(config.bot.intents)) {
intentsLoader.warn(
'Intents in config file must be in an array, default intents will be used'
)
} else {
finalIntents = config.bot.intents
intentsLoader.succeed('Loaded intents successfully from the config file')
}
const Client = new discord.Client({ intents: finalIntents })
// Commands
Client.commands = new Collection()
const events = fs
.readdirSync('./src/events')
.filter(file => file.endsWith('.js'))
events.forEach(event => {
const eventFile = require(`./src/events/${event}`)
if (eventFile.oneTime) {
Client.once(eventFile.event, (...args) => eventFile.run(...args))
} else {
Client.on(eventFile.event, (...args) => eventFile.run(...args))
}
})
Client.login(config.bot.token)
const expresscli = ora('Registering Express').start()
const files = fs.readdirSync('./src/express/requests').filter(f => f .endsWith('.js'))
files.forEach(f => {
const file = require(`./src/express/requests/${f}`)
if(file && file.name) {
try {
app.get(file.name, file.run)
expresscli.succeed(`Successfully Loaded Express System`)
} catch(err) {
expresscli.warn(`[ERROR] ${err}`)
}
}
})
const array = []
const info = []
app.get('/', (req, res) => {
let commands = fs.readdirSync(`./src/commands/`).filter(f => f.endsWith('.js')).forEach((cmd) => {
let prop = require(`./src/commands/${cmd}`)
array.push(prop.name)
info.push(prop.info)
})
const infomation = info.join("<br>")
const cmds = array.join("<br>")
let file = fs.readFileSync('./src/express/html/index.html', { encoding: 'utf8'})
file = file.replace('$$cmds$$', cmds)
res.send(file)
})
app.use('/css', express.static('./src/express/css'))
app.use('/bootstrap', express.static('./node_modules/bootstrap'))
app.listen(3000)
module.exports.Client = Client;
module.exports = Client;