-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
118 lines (100 loc) · 3.47 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
const Discord = require("discord.js");
const DAttachment = require('discord.js').Attachment;
const config = require('./data/config.json')
const package = require('./package.json')
const fs = require('fs')
const fse = require('fs-extra')
var request = require('request')
const DBLToken = config.dbltoken
const DBL = require('dblapi.js')
const dbl = new DBL(DBLToken)
const client = new Discord.Client({
autoReconnect: true
});
const color = config.color
var prefix = config.prefix
client.on("message", (message) => {
const args = message.content.split(" ");
const command = message.content.split(" ")[0]
if(message.author.bot || !command.startsWith(prefix) || message.channel.type === "dm") return;
const cmd = client.commands.get(command.slice(prefix.length))
if(cmd)
cmd.run(client, message, args, config, color)
})
client.on("ready", () => {
fs.readFile(`./data/src/utils/filePath.json`, "utf8", function(err, fp) {
fp = JSON.parse(fp)
console.log("[LOGGED ON] " +client.user.tag + " | " + client.user.id)
function activityUpdate() {
dbl.postStats(client.guilds.size)
client.user.setActivity('on ' + client.guilds.size + ' servers', {
type: 'WATCHING'
})
return console.log('[STATS] Stats Updated')
}
activityUpdate()
setInterval(activityUpdate, 120000)
if(fs.existsSync(fp.temp.path)) {
fse.remove(fp.temp.path)
}
console.log(Date.now())
if(!fs.existsSync(fp.temp.path)) {
fs.mkdirSync(fp.temp.path)
}
if(!fs.existsSync(fp.temp.userdata)) {
fs.mkdirSync(fp.temp.userdata)
}
if(!fs.existsSync(fp.data.serverdata)) {
fs.mkdirSync(fp.data.serverdata)
}
if(!fs.existsSync(fp.persistent.path)) {
fs.mkdirSync(fp.persistent.path)
}
});
})
client.commands = new Discord.Collection();
fs.readdir("./data/commands", (err, files) => {
if(err) console.error(err)
const jsFiles = files.filter(f => f.split(".").pop() === "js")
if(jsFiles.length <= 0) {
console.log("No commands loaded")
return;
}
console.log('[Commands Loaded] ' + jsFiles.length)
jsFiles.forEach((f, i) => {
const props = require("./data/commands/" + f)
client.commands.set(props.help.name, props)
})
})
client.on("message", (message) => {
fs.readFile(`./data/src/utils/filePath.json`, "utf8", function(err, fp) {
fp = JSON.parse(fp)
if(!fs.existsSync(`${fp.temp.path}`)) {
fs.mkdirSync(`${fp.temp.path}`)
}
if(!fs.existsSync(`${fp.data.serverdata}`)) {
fs.mkdirSync(`${fp.data.serverdata}`)
}
if(!fs.existsSync(`${fp.data.serverdata}/${message.guild.id}`)) {
fs.mkdirSync(`${fp.data.serverdata}/${message.guild.id}`)
}
if(message.channel.type == 'text') {
if(!fs.existsSync(`${fp.temp.path}/${message.guild.id}`)) {
fs.mkdirSync(`${fp.temp.path}/${message.guild.id}`)
}
}
});
})
client.on("message", (message) => {
const triggerMention = new RegExp(`^<@!?${client.user.id}>`);
const trigger = message.content.match(triggerMention) ? message.content.match(triggerMention)[0] : config.testString;
if(message.content.startsWith(`${trigger}`)) {
var m = new Discord.RichEmbed()
.setColor(color)
.setTitle(client.user.username)
.setAuthor(client.user.tag, client.user.displayAvatarURL)
.setDescription("```" + prefix + "```")
return message.channel.send(m)
}
})
client.login(config.token)