This repository has been archived by the owner on Feb 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathMain.js
323 lines (291 loc) · 15.1 KB
/
Main.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
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
const Discord = require("discord.js");
const client = new Discord.Client({
disabledEvents: ["RELATIONSHIP_ADD", "RELATIONSHIP_REMOVE", "TYPING_START"],
disableEveryone: true,
messageCacheMaxSize: 150,
messageCacheLifetime: 240,
messageSweepInterval: 300,
});
const fs = require("fs");
const sql = require("sqlite");
sql.open("./assets/guildsettings.sqlite");
const invitecheck = ["discord.gg", "discord.me", "discord.io/", "discordapp.com/invite"]
const weblinkcheck = ["http", "www.", ".com", ".net", ".org", ".ca", ".co.uk"]
const config = require("./assets/jsons/config.json");
client.on('warn', err => console.warn('[WARNING]', err));
client.on('error', err => console.error('[ERROR]', err));
client.on('uncaughtException', (err) => {
console.log("Uncaught Exception: " + err)
process.exit(1)
});
process.on('unhandledRejection', (reason, promise) => {
console.log('[FATAL] Possibly Unhandled Rejection at: Promise ', promise, ' reason: ', reason.message);
});
client.on('disconnect', () => {
console.warn('Disconnected!')
process.exit(0);
})
client.on('reconnecting', () => console.warn('Reconnecting...'))
const talkedRecently = new Set();
const talkedRecently2 = new Set();
var cooldownUsers = [];
const checkCooldown = ((userId) => {
if(cooldownUsers.indexOf(userId) > -1) {
return true;
} else {
return false;
}
});
const removeCooldown = ((userId, timeInSeconds) => {
let index = cooldownUsers.indexOf(userId);
if(index > -1) {
setTimeout(() => {
cooldownUsers = cooldownUsers.splice(index, 0);
}, timeInSeconds * 1000)
}
});
fs.readdir('./events/', (err, files) => {
files = files.filter(f => f.endsWith('.js'));
files.forEach(f => {
const event = require(`./events/${f}`);
client.on(f.split('.')[0], event.bind(null, client));
delete require.cache[require.resolve(`./events/${f}`)];
});
});
client.on("guildCreate", async (guild) => {
try {
console.log(`Someone added Orcinus to their discord! ${guild.name} Member count: ${guild.memberCount} owned by: ${guild.owner.user.username}!`)
const owner = guild.owner.user
var guildMsg = [
"Thanks for adding me to your server. Just a few tips to get you started..",
"```**1.** Orcinus default prefix is `>`.",
"**2.** Commands will not work in direct messages.",
"**3.** Set welcome leave messages with >welcomeleave.",
"**4.** Set logs channel with >logs [channel name].",
"**5.** Set autorole with >autorole [role name].",
"**6.** Prefix can be changed with >prefix [new prefix].",
"**7.** Profile System can be enabled with >profilesystem.",
"**8.** Automod can be enabled with >automod enable all```"
]
owner.send(guildMsg)
} catch (err) {
return;
}
});
client.on('guildDelete', (guild) => {
console.log(`Someone removed Orcinus from their discord! ${guild.name} Member count: ${guild.memberCount} owned by: ${guild.owner.user.username}!`)
sql.run(`DELETE FROM scores WHERE guildId = ${guild.id}`)
});
client.on("guildMemberAdd", (member) => {
if (!member.guild.member(client.user).hasPermission('SEND_MESSAGES')) return;
if (!member.guild.member(client.user).hasPermission('VIEW_CHANNEL')) return;
if (!member.guild.member(client.user).hasPermission('READ_MESSAGE_HISTORY')) return;
sql.get(`SELECT * FROM scores WHERE guildId ="${member.guild.id}"`).then(row => {
if (row.antijoin === "enabled") {
member.user.send("Anti-join has been enabled in " + member.guild.name + " you have been kicked automatically.")
member.guild.member(member.user.id).kick().catch(console.error);
} else {
if (!member.guild.member(client.user).hasPermission('MANAGE_ROLES')) return;
let autoRole = client.guilds.get(member.guild.id).roles.find(r => r.name == row.roletogive);
if (!autoRole) return
member.guild.member(member.user.id).addRole(autoRole).catch(console.error);
}
})
});
client.on('messageReactionAdd', (reaction, user) => {
if (reaction.emoji.name === '⭐') {
let message = reaction.message
if (message.author.bot) return;
if (message.channel.type === 'dm') return;
if (!message.guild.member(client.user).hasPermission('SEND_MESSAGES')) return;
if (!message.guild.member(client.user).hasPermission('VIEW_CHANNEL')) return;
if (!message.guild.member(client.user).hasPermission('READ_MESSAGE_HISTORY')) return;
if (message <= 1) return;
if (message.guild.id === "110373943822540800") return;
if (message.guild.id === "264445053596991498") return;
const embed = new Discord.RichEmbed()
.setAuthor(message.author.username, message.author.avatarURL)
.setColor(0x00A2E8)
.setTitle(`⭐ ${client.user.username} Starboard ⭐`)
.addField('Starred By', `${user.username}`, true)
.addField('Channel', `${message.channel}`, true)
.addField('Message', `${message.content}`, false)
.setTimestamp()
let modlog = message.guild.channels.find(channel => channel.name == 'starboard');
if (!modlog) return
if (user.id === message.author.id) return message.channel.send(`${message.author}, You can't star your own messages!`)
reacts = message.reactions.filter(function (reacts) {
return reacts.emoji.name === '⭐'
})
if (reacts.length > 1) return;
client.channels.get(modlog.id).send({embed}).catch(console.error);
}
});
client.on("message", async (message) => {
if (message.author.bot) return;
if (message.channel.type === 'dm') return;
if (!message.guild.member(client.user).hasPermission('SEND_MESSAGES')) return;
if (!message.guild.member(client.user).hasPermission('MANAGE_MESSAGES')) return;
if (!message.guild.member(client.user).hasPermission('EMBED_LINKS')) return;
if (!message.guild.member(client.user).hasPermission('VIEW_CHANNEL')) return;
if (!message.guild.member(client.user).hasPermission('READ_MESSAGE_HISTORY')) return;
sql.get(`SELECT * FROM scores WHERE guildId ="${message.guild.id}"`).then(row => {
if (!row) return;
const prefix = row.prefix
const args = message.content.slice(prefix.length).trim().split(/ +/g);
if (message.content.startsWith("<@" + client.user.id +">") || message.content.startsWith("<@!" + client.user.id +">")) {
message.reply("current guild prefix is `" + row.prefix + "`.")
}
if (invitecheck.some(word => message.content.toLowerCase().includes(word))) {
if (message.content.includes(row.prefix)) return
if (row.automoderation === "disabled") return;
if (row.invitelinkprotection === "disabled") return;
if (message.member.hasPermission("KICK_MEMBERS")) return;
message.delete()
let modlog = message.guild.channels.find(channel => channel.name == row.logschannel);
const embed = new Discord.RichEmbed()
.setColor(0x00A2E8)
.setTitle("Action: Auto Moderation")
.addField("Moderator", client.user.username + " (ID: " + client.user.id + ")")
.addField("User", message.author.username + " (ID: " + message.author.id + ")")
.addField("In channel", message.channel.name, true)
.addField("Reason", "Invite Link", true)
.addField("Invite link", message.cleanContent)
.setFooter("Time used: " + message.createdAt.toDateString())
if (!modlog) return;
if (row.logsenabled === "disabled") return;
client.channels.get(modlog.id).send({embed});
message.reply(" not allowed to post invite links.").then((response) => {
response.delete(6000);
});
}
if (weblinkcheck.some(word2 => message.content.toLowerCase().includes(word2))) {
if (message.content.includes(row.prefix)) return
if (row.automoderation === "disabled") return;
if (row.websitelinkprotection === "disabled") return;
if (message.member.hasPermission("KICK_MEMBERS")) return;
message.delete()
let modlog = message.guild.channels.find(channel => channel.name == row.logschannel);
const embed = new Discord.RichEmbed()
.setColor(0x00A2E8)
.setTitle("Action: Auto Moderation")
.addField("Moderator", client.user.username + " (ID: " + client.user.id + ")")
.addField("User", message.author.username + " (ID: " + message.author.id + ")")
.addField("In channel", message.channel.name, true)
.addField("Reason", "Website Link", true)
.addField("Website link", message.cleanContent)
.setFooter("Time used: " + message.createdAt.toDateString())
if (!modlog) return;
if (row.logsenabled === "disabled") return;
client.channels.get(modlog.id).send({embed});
message.reply(" not allowed to post website links.").then((response) => {
response.delete(6000);
});
}
if (message.content.includes('')) {
if (message.content.includes(row.prefix)) return
if (row.automoderation === "disabled") return;
if (row.dupcharactersprotection === "disabled") return;
if (message.member.hasPermission("KICK_MEMBERS")) return;
const check1 = args.join(" ")
if (check1.includes('.')) return;
var hasDuplicates = /([a-zA-Z])\1+$/;
const result = hasDuplicates.test(check1)
if (result === true) {
message.delete()
let modlog = message.guild.channels.find(channel => channel.name == row.logschannel);
const embed = new Discord.RichEmbed()
.setColor(0x00A2E8)
.setTitle("Action: Auto Moderation")
.addField("Moderator", client.user.username + " (ID: " + client.user.id + ")")
.addField("User", message.author.username + " (ID: " + message.author.id + ")")
.addField("In channel", message.channel.name, true)
.addField("Reason", "Duplicated Characters", true)
.addField("Message Content", message.cleanContent)
.setFooter("Time used: " + message.createdAt.toDateString())
if (!modlog) return;
if (row.logsenabled === "disabled") return;
client.channels.get(modlog.id).send({embed});
let user = message.guild.member(message.mentions.users.first())
message.reply(" message contains duplicated characters.").then((response) => {
response.delete(6000);
});
}
}
if (message.content.includes('')) {
if (message.member.hasPermission("KICK_MEMBERS")) return;
if (row.slowmode === "disabled") return;
if (row.slowmode === "enabled") {
if(checkCooldown(message.author.id)) {
message.delete();
}
cooldownUsers.push(message.author.id);
removeCooldown(message.author.id, row.slowmodetime);
}
}
})
if (message.content.startsWith("")) {
sql.get(`SELECT * FROM scores WHERE guildId ="${message.guild.id}"`).then(row2 => {
if (!row2) return;
if (row2.levelsystem === "disabled") return;
sql.get(`SELECT * FROM profiles WHERE guildId ="${message.guild.id}" AND userId ="${message.author.id}"`).then(row => {
if (!row) return;
if (row.level === 25) {
if (row.awards.includes("None")) return sql.run(`UPDATE profiles SET awards = "" WHERE guildId ="${message.guild.id}" AND userId = ${message.author.id}`);
if (row.awards.includes(":tada:")) return;
sql.run(`UPDATE profiles SET awards = "${row.rewards + ":tada:"}" WHERE guildId ="${message.guild.id}" AND userId = ${message.author.id}`);
} else if (row.level === 50) {
if (row.awards.includes("None")) return sql.run(`UPDATE profiles SET awards = "" WHERE guildId ="${message.guild.id}" AND userId = ${message.author.id}`);
if (row.awards.includes(":medal:")) return;
sql.run(`UPDATE profiles SET awards = "${row.awards + " :medal:"}" WHERE guildId ="${message.guild.id}" AND userId = ${message.author.id}`);
} else if (row.level === 100) {
if (row.awards.includes("None")) return sql.run(`UPDATE profiles SET awards = "" WHERE guildId ="${message.guild.id}" AND userId = ${message.author.id}`);
if (row.awards.includes(":trophy:")) return;
sql.run(`UPDATE profiles SET awards = "${row.awards + " :trophy:"}" WHERE guildId ="${message.guild.id}" AND userId = ${message.author.id}`);
} else if (row.cash >= 10000) {
if (row.awards.includes("None")) return sql.run(`UPDATE profiles SET awards = "" WHERE guildId ="${message.guild.id}" AND userId = ${message.author.id}`);
if (row.awards.includes(":moneybag:")) return;
sql.run(`UPDATE profiles SET awards = "${row.awards + " :moneybag:"}" WHERE guildId ="${message.guild.id}" AND userId = ${message.author.id}`);
} else if (row.cash >= 100000) {
if (row.awards.includes("None")) return sql.run(`UPDATE profiles SET awards = "" WHERE guildId ="${message.guild.id}" AND userId = ${message.author.id}`);
if (row.awards.includes(":credit_card:")) return;
sql.run(`UPDATE profiles SET awards = "${row.awards + " :credit_card:"}" WHERE guildId ="${message.guild.id}" AND userId = ${message.author.id}`);
} else {
return;
}
});
});
}
if (message.content.startsWith("")) {
sql.get(`SELECT * FROM scores WHERE guildId ="${message.guild.id}"`).then(row2 => {
if (!row2) return;
if (row2.levelsystem === "disabled") return;
if (talkedRecently.has(message.author.id)) return;
const xpgained = Math.floor(Math.random() * 15) + 1;
sql.get(`SELECT * FROM profiles WHERE guildId ="${message.guild.id}" AND userId ="${message.author.id}"`).then(row => {
if (!row) {
sql.run("INSERT INTO profiles (guildId, userId, xp, level, bank, cash, awards, rep, username, winningchance) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", [message.guild.id, message.author.id, 0, 1, 0, 100, "None", 0, message.author.username, 0]);
} else {
let curLevel = Math.floor(0.1 * Math.sqrt(row.xp + 1));
if (curLevel > row.level) {
row.level = curLevel;
if (row.level >= 300) return;
sql.run(`UPDATE profiles SET xp = ${row.xp + xpgained}, level = ${row.level} WHERE guildId ="${message.guild.id}" AND userId = ${message.author.id}`);
}
if (row.xp >= 9999999) return;
sql.run(`UPDATE profiles SET xp = ${row.xp + xpgained}, cash = ${row.cash + 10}, username = "${message.author.username}" WHERE guildId ="${message.guild.id}" AND userId = ${message.author.id}`);
}
}).catch(() => {
console.error;
sql.run("CREATE TABLE IF NOT EXISTS profiles (guildId TEXT, userId TEXT, xp INTEGER, level INTEGER, bank INTEGER, cash INTEGER, awards TEXT, rep INTEGER, username TEXT, winningchance INTEGER)").then(() => {
sql.run("INSERT INTO profiles (guildId, userId, xp, level, bank, cash, awards, rep, username, winningchance) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", [message.guild.id, message.author.id, 0, 1, 0, 100, "None", 0, message.author.username, 0]);
})
})
talkedRecently.add(message.author.id);
setTimeout(() => {
talkedRecently.delete(message.author.id);
}, 60000);
})
}
});
client.login(config.token);