-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
261 lines (234 loc) · 10.6 KB
/
index.js
File metadata and controls
261 lines (234 loc) · 10.6 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
const Discord = require('discord.js');
const asyncpkg = require("async")
global.ready = false
global.bot = new Discord.Client();
global.botOnline = true
global.fs = require('fs')
global.functions = require(`./Utils/functions.js`)
global.display = require(`./Utils/display.js`)
var commands = {}
var commandlist = {}
fs.readdir("./Commands/", (err, files) => {
if (err) return console.error(err);
console.log("Ran")
files.forEach(file => {
//console.log(file)
// If the file is not a JS file, ignore it (thanks, Apple)
if (!file.endsWith(".js")) { return };
// Load the event file itself
let commandname = file.split(".")[0];
//console.log(commandname)
commands[commandname] = require(`./Commands/${file}`);
commandlist[commandname] = "exists"
// Get just the event name from the file name
delete require.cache[require.resolve(`./Commands/${file}`)];
});
//console.log(commandlist)
});
let config = require('./config.json')
global.talkedRecently = new Set();
const TOKEN = config.token;
global.devData = JSON.parse(fs.readFileSync('Storage/devData.json', 'utf8'));
global.admins = devData.admins
global.devs = devData.devs
global.debugGuildId = devData.debugGuildId
global.debugChannelId = devData.debugChannelId
global.defaultPrefix = devData.defaultPrefix
global.moment = require('moment'); //moment package, lets you view date and time nicely
global.devData = JSON.parse(fs.readFileSync('Storage/devData.json', 'utf8'));
global.serverData = JSON.parse(fs.readFileSync('Storage/serverData.json', 'utf8'));
global.gameData = JSON.parse(fs.readFileSync('Storage/gameData.json', 'utf8'));
global.userData = JSON.parse(fs.readFileSync('Storage/userData.json', 'utf8'));
function addServer(guild) {
if (serverData[guild.id] == undefined) { serverData[guild.id] = {} }
serverData[guild.id].prefix = defaultPrefix
serverData[guild.id].disabledChannels = []
}
//console.log("Hello")
function evaluateMessage(message) {
if (ready == false) { return }
if (bot.user.id === message.author.id) { return }
if (!devData.enable && devs.indexOf(message.author.id) == -1) {
return;
}
//console.time("actual ping")
//sendMessage(message.channel, "actual ping")
/*if (banlist.indexOf(message.author.id) != -1){
return;
}*/
if (message.channel.type != "dm" && serverData[message.guild.id] == undefined) {
addServer(message.guild)
}
message.content = message.content.trim().split(/\s+/).join(" ")
let prefix = (message.channel.type == "dm") ? defaultPrefix : serverData[message.guild.id].prefix;
if (message.content.startsWith("<@579335308638945304>")) prefix = "<@579335308638945304>"
if (message.content.startsWith("<@!579335308638945304>")) prefix = "<@!579335308638945304>"
if (message.content.startsWith("<@579335308638945304> ")) {
let words = message.content.trim().split(/\s+/)
words.splice(0, 1)
message.content = prefix + words.join(" ")
}
if (message.content.startsWith("<@!579335308638945304> ")) {
let words = message.content.trim().split(/\s+/)
words.splice(0, 1)
message.content = prefix + words.join(" ")
}
if (message.author.bot == true) {
return
}
if ((message.content.startsWith(prefix + "setcommandtimer") || message.content.startsWith(prefix + "sct")) && devs.indexOf(message.author.id) != -1) {
let words = message.content.trim().split(/\s+/)
let time = 0
let ts = message.createdTimestamp;
let regexp = /\b([0-9]+h)?([0-9]+m)?([0-9]+s)?\b/
if (words[1] != undefined && regexp.test(words[1])) {
let saveindex = 0
const timevalues = { "h": 3600000, "m": 60000, "s": 1000 }
for (var i = 0; i < words[1].length; i++) {
if (timevalues[words[1].slice(i, i + 1)] != undefined) {
if (isNaN(parseInt(words[1].slice(saveindex, i)))) { return functions.replyMessage(message, "Something happened. The regex broke.") }
time += parseInt(words[1].slice(saveindex, i)) * timevalues[words[1].slice(i, i + 1)]
saveindex = i + 1
}
}
} else {
return functions.replyMessage(message, "Please specify a valid time. Ex. 1h2m3s")
}
words.splice(0, 2)
message.content = prefix + words.join(" ")
message.createdTimestamp += time
functions.replyMessage(message, "The command `" + prefix + words.join(" ") + "`" + " will be executed in " + functions.displayTime(ts + time, ts))
bot.setTimeout(function () {
evaluateMessage(message)
}, time)
return
}
let id = message.author.id;
if (message.content.startsWith(prefix + "runas") && devs.indexOf(message.author.id) != -1) {
let words = message.content.trim().split(/\s+/)
if (words.length < 3) {
return functions.replyMessage(message, "Please specify a user and a command.")
}
words.splice(0, 1)
if (words[0].startsWith("<@") && words[0].endsWith(">")) {
words[0] = words[0].slice(2, -1)
}
if (words[0].startsWith("!")) {
words[0] = words[0].slice(1)
}
if (userData[words[0]] == undefined || !bot.users.has(words[0])) {
return functions.replyMessage(message, "That is an invalid user.")
}
message.author = bot.users.get(words[0])
words.splice(0, 1)
message.content = words.join(" ")
}
message.author.original = id
functions.respond(message)
if (!message.content.startsWith(prefix)) {
return;
}
id = message.author.id;
let ts = message.createdTimestamp;
let words = message.content.trim().split(/\s+/)
//here
let command = words[0].toLowerCase()
if (command.length <= prefix.length) { return }
command = command.slice(prefix.length)
//-----------------------------
functions.checkStuff(message)
if (command == 'reload' && devs.indexOf(message.author.id) != -1) {
//if (words.length <= 1) return functions.replyMessage(message, "Must provide a command name to reload.");
let commandName = words[1];
// Check if the command exists and is valid
if (commandName == "all" || 1 == 1) { commandName = "Utils" }
if (commandName == "Utils") {
fs.readdir("./Utils/", (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
//console.log(file)
// If the file is not a JS file, ignore it (thanks, Apple)
if (!file.endsWith(".js")) { return };
// Load the event file itself
let commandname = file.split(".")[0];
//console.log(commandname)
delete require.cache[require.resolve(`./Utils/${file}`)];
// Get just the event name from the file name
});
})
functions.replyMessage(message, "You have successfully reloaded all Utils!")
commandName = "functions"
}
if (commandName == "functions") {
delete require.cache[require.resolve(`./Utils/functions.js`)];
functions.replyMessage(message, "You have successfully reloaded all functions.")
commandName = "displays"
}
if (commandName == "displays") {
delete require.cache[require.resolve(`./Utils/display.js`)];
//delete require.cache[require.resolve(`./index.js`)]
commandName = "Commands"
functions.replyMessage(message, "You have successfully reloaded all displays.")
}
if (commandName == "Commands") {
fs.readdir("./Commands/", (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
//console.log(file)
// If the file is not a JS file, ignore it (thanks, Apple)
if (!file.endsWith(".js")) { return };
// Load the event file itself
let commandname = file.split(".")[0];
//console.log(commandname)
delete require.cache[require.resolve(`./Commands/${file}`)];
commands[commandname] = require(`./Commands/${file}`);
commandlist[commandname] = "exists"
// Get just the event name from the file name
delete require.cache[require.resolve(`./Commands/${file}`)];
});
console.log(commandlist)
});
functions.replyMessage(message, "All commands have been reloaded!")
} else {
if (!commandName.endsWith(".js")) { return functions.replyMessage(message, "The file needs to end with .js (e.g. attack.js)") }
if (commands[commandName.split(".")[0]] == undefined) {
return functions.replyMessage(message, "That command does not exist");
}
// the path is relative to the *current folder*, so just ./filename.js
delete require.cache[require.resolve(`./Commands/${commandName}`)];
delete commands[commandName.split(".")[0]];
commands[commandName.split(".")[0]] = require(`./Commands/${commandName}`);
functions.replyMessage(message, `The command ${commandName} has been reloaded!`);
}
}
//do command stuff here
if (commandlist[command] == undefined) { return }
console.log(message.author.id + "|" + message.content + "|" + ts)
commands[command](message)
functions.checkStuff(message)
}
bot.on("message", message => {
evaluateMessage(message)
});
bot.on('ready', function () {
console.log("Ascella Activated!");
ready = true
bot.user.setActivity('with the lives of mortals', { type: 'PLAYING' });
})
bot.on("guildCreate", guild => {
console.log("Joined a new guild: " + guild.name);
addServer(guild)
var allowedchannels = guild.channels.filter(channel => channel.type == "text" && channel.memberPermissions(bot.user).has("SEND_MESSAGES"))
if (allowedchannels.size == 0) { return }
var channel = allowedchannels.find(channel => channel.name == "botspam" || channel.name == "general")
if (channel == undefined) { channel = allowedchannels.first() }
})
bot.on("disconnect", event => {
console.log("Bot disconnected");
})
bot.on("error", error => {
console.log(error.message + "\nFile name:" + error.fileName + "\nLine number:" + error.lineNumber);
})
bot.on("debug", debug => {
})
bot.login(TOKEN);