-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
107 lines (84 loc) · 3.29 KB
/
app.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
const Discord = require('discord.js')
const client = new Discord.Client()
const { prefix, swears, logChannel, staffRole, adminRole, deletedLog } = require('./config.json')
const { token } = require('./auth.json')
const commands = require('./commands.js')
const mongo = require('./libraries/mongo')
const loggg = require('./send-log')
const embeds = require('./libraries/embeds')
const eventHandler = require('./event-handler')
const NodeChache = require('node-cache')
const myCache = new NodeChache( { stdTTL: 0, checkperiod: 0 } )
//connect
client.on('ready', async () => {
console.log("connected as " + client.user.tag);
client.user.setActivity("Alan", {type: 'WATCHING'})
const size = client.guilds.cache.size
console.log("active in ",size," servers");
await mongo().then((mongoose) => {
try{
console.log('Connected to mongo')
}finally{
mongoose.connection.close()
}
})
})
client.login(token)
//message listener
client.on('message', (recievedMessage) => {
//ignores messages from dm's
if (recievedMessage.channel.type == "dm"){
return
}
//checks if message author is bot
if (recievedMessage.author == client.user) {
return
}
//logs recieved message
console.log(`Mesaage recieved: "${recievedMessage.content}" from: ${recievedMessage.author.tag}`);
//checks if message contains the prefix
if (recievedMessage.content.startsWith(prefix)){
processCommand(recievedMessage)
}
//slur filter
//checks if any message contains any word from the swear array in config.json
//makes the input lowercase (.lowercase())
//also removes all spaces with (.replace(/\s+/g)) to detect slurs written like this: S L U R
//\s+ is all whitespaces, /g is global. so it replaces all whitespace in global with '', in other words nothing
if(swears.some(word => recievedMessage.content.toLowerCase().replace(/\s+/g, '').includes(word))){
eventHandler('slur', recievedMessage)
}
});
//Logs all deleted messages
client.on("messageDelete", (messageDelete) => {
//ignore messages from the bot
if (messageDelete.author == client.user){
return
}
if (messageDelete.channel.type == "dm"){
return
}
eventHandler('delete', messageDelete)
});
client.on('guildCreate', (newGuild) => {
const { systemChannel } = newGuild
embeds.onJoin(systemChannel)
if(!newGuild.roles.cache.find(r => r.name === "Muted")){
newGuild.roles.create({
data: {
name: 'Muted',
},
reason: 'muted role for members that are muted, You will have to configure permissions yourself!'
})
}
})
//processes the promted command, and checks if its valid
function processCommand(recievedMessage){
let fullCommand = recievedMessage.content.substr(1)
let splitCommand = fullCommand.split(" ")
let primaryCommand = splitCommand[0]
let arguments = splitCommand.slice(1)
console.log(`primary command: "${primaryCommand}" from ${recievedMessage.author.username}`);
//hands off user input the the command.js
commands.command(recievedMessage, primaryCommand, arguments)
}