-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
64 lines (57 loc) · 1.8 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
/**
* Written in 2021 by climbTheStairs <[email protected]>
*
* This file is part of LITERALLY 1984.
*
* To the extent possible under law,
* the author(s) have dedicated all copyright
* and related and neighboring rights to this software
* to the public domain worldwide.
* This software is distributed without any warranty.
*
* You should have received a copy
* of the CC0 Public Domain Dedication along with this software.
* If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
"use strict"
const fs = require("fs")
const { Client, Intents } = require("discord.js")
const conf = require("./etc/config.json")
const blacklistLoc = __dirname + "/etc/blacklist.txt"
const blacklist = fs.readFileSync(blacklistLoc, "utf-8").trim().split("\n")
const blacklistPat = new RegExp(blacklist.join("|"), "i")
// Init bot
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
]
})
client.once("ready", () => {
console.log(conf.info.ready)
client.user.setActivity(conf.activity)
client.user.setStatus(conf.status)
})
// Listen for new messages
client.on("messageCreate", (msg) => {
const { author, channel, content } = msg
if (author.bot)
return
if (isProfane(content)) {
warn(msg)
report(msg)
}
})
const isProfane = (content) => blacklistPat.test(content)
const warn = (msg) => msg.reply(conf.info.warning)
const report = ({ author, channel, content }) => {
const reportsChannel = client.channels.cache.get(conf.reportsChannelId)
const profanityReport = (
`<@${author.id}> wrote in <#${channel.id}>:\n` + content
)
reportsChannel.send(profanityReport)
}
// Log in
const tokenLoc = __dirname + "/etc/token"
const token = fs.readFileSync(tokenLoc, "utf-8").trim()
client.login(token)