-
Notifications
You must be signed in to change notification settings - Fork 7
/
server.js
137 lines (117 loc) · 3.76 KB
/
server.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
const http = require("http");
const express = require("express");
const app = express();
app.get("/", (request, response) => {
console.log(Date.now() + " Ping Received");
response.sendStatus(200);
});
app.listen(process.env.PORT);
setInterval(() => {
http.get(`http://${process.env.PROJECT_DOMAIN}.glitch.me/`);
}, 280000);
const Discord = require("discord.js");
const client = new Discord.Client();
const botconfig = require("./config/botconfig.json");
const fs = require("fs");
const moment = require("moment");
client.commands = new Discord.Collection();
fs.readdir("./commands/", (err, files) => {
if (err) console.log(err);
let jsfile = files.filter(f => f.split(".").pop() === "js");
if (jsfile.length <= 0) {
console.log("Couldn't find commands.");
return;
}
jsfile.forEach((f, i) => {
let props = require(`./commands/${f}`);
console.log(`${f} is succesfully loaded.`);
client.commands.set(props.help.name, props);
});
});
client.on("ready", async => {
console.log(`The bot ${client.user.tag} is up and running!`);
client.user.setStatus("online");
client.user.setActivity(`Moderating ${client.guilds.size} server(s)!`, {
type: "PLAYING"
});
});
client.on("guildCreate", async guild => {
client.guilds.map(g => g.owner.user.tag | guild.name | guild.invite);
let owner = guild.owner;
let ownerembed = new Discord.RichEmbed()
.setTitle(`**Thank you**`)
.setDescription(`Thank you for using our bot.`)
.setColor("GREEN")
.addField(
`Channels needed:\n`,
`>bot-logs\n>punishments\n>appeals\n>suggestions\n>reports`
);
owner.send(ownerembed);
});
client.on("guildBanAdd", async (guild, user) => {
let logs = guild.channels.find(`name`, "bot-logs");
let embed = new Discord.RichEmbed()
.setTitle(`**Guild ban add**`)
.setDescription(
`The user: ${user.member} has been banned from ${guild.name}.`
)
.setColor("RED")
.setFooter(
`At: ${moment().format("dddd, MMMM Do YYYY, h:mm A", Date.now())}`
);
logs.send(embed);
});
client.on("guildBanRemove", async (guild, user) => {
let logs = guild.channels.find(`name`, "bot-logs");
let embed = new Discord.RichEmbed()
.setTitle(`**Guild ban Remove**`)
.setDescription(
`The user: ${user.id} has been unbanned from ${guild.name}.`
)
.setColor("GREEN")
.setFooter(
`At: ${moment().format("dddd, MMMM Do YYYY, h:mm A", Date.now)}`
);
logs.send(embed);
});
client.on("roleCreate", async role => {
let guild = role.guild;
let logs = role.guild.channels.find(`name`, "bot-logs");
let embed = new Discord.RichEmbed()
.setTitle(`**ROLE**`)
.setDescription(`The role: ${role.name} has been created.`)
.setFooter(`At: ${moment().format("dddd, MMMM Do YYYY, h:mm A", Date.now)}`)
.setColor("GREEN");
logs.send(embed);
});
client.on("message", async message => {
if (message.author.bot) return;
if (message.channel.type === "dm") return;
if (message.content.indexOf(botconfig.prefix) !== 0) return;
//Defining the args and all
let messageArray = message.content.split(" ");
let cmd = messageArray[0].toLowerCase();
let args = messageArray.slice(1);
//Trying the command handler to run.
let prefix = botconfig.prefix;
try {
let commandfile = client.commands.get(cmd.slice(prefix.length));
if (commandfile) commandfile.run(client, message, args);
} catch (e) {
console.log(e.message);
} finally {
console.log(`${message.author.tag} has run the command ${cmd}`);
}
});
client.on("message", async message => {
//antiswear
if (
botconfig.swearwords.some(word =>
message.content.toLowerCase().includes(word)
)
) {
message.delete();
message.channel.send(`You aren't allowed to use any swearwords!`);
}
});
client.login(botconfig.token);