-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
223 lines (184 loc) · 6.11 KB
/
bot.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
require('dotenv').config();
const Discord = require('discord.js');
const fs = require("fs");
var moment = require('moment')
require("moment-duration-format");
const client = new Discord.Client();
const disbut = require('discord-buttons');
client.commands = new Discord.Collection();
const TOKEN = process.env.TOKEN;
// utils init
const SingleMessageResponse = require('./utils/sResponse.js')
// commands init
fs.readdir("./commands/", (err, files) => {
if(err) console.log(err);
let jsfile = files.filter(f => f.split(".").pop() === "js");
if(jsfile.length <= 0){
throw new Error("Couldn't find commands.");
}
jsfile.forEach((f, i) =>{
let props = require(`./commands/${f}`);
console.info(`${f} loaded!`);
client.commands.set(props.help.name, props);
});
});
client.on('ready', () => {
console.info(`\nLogged in as ${client.user.tag}!\n`);
client.user.setPresence({ activity: { name: 'Brain Games' }, status: 'online' })
//.then(console.info)
.catch(console.error);
});
const talkedRecently = new Set();
let commandsRun = 0;
let prefix = ">";
client.on('message', message => {
// General checks:
if(message.author.bot || message.channel.type === 'dm') return;
SingleMessageResponse.run(message);
if (talkedRecently.has(message.author.id) && message.content.substring(0,1) == prefix) {
//bot is on cooldown
console.warn("Bot is on cooldown.")
let cooldownEmbed = new Discord.MessageEmbed()
.setColor('#8f0707')
.setTitle('Cooldown')
.setDescription('You are still on 2 second cooldown!\nStop spamming, 🆔!')
return message.channel.send(cooldownEmbed)
} else {
// bot is not on cooldown, continue
// Common vars
let content = message.cleanContent.split(/\s+/);
let command = content[0].toLowerCase();
//console.log(`running command ${command}`)
let args = content.slice(1);
if (command.substring(0,1) != prefix) return;
// Checks if message contains a command and runs it
let commandfile = client.commands.get(command.slice(prefix.length));
if(commandfile) {
commandsRun++;
commandfile.run(client,disbut,message,args);
cooldown(message.author.id);
} else {
if (command.slice(prefix.length) == "botstats") {
commandsRun++;
botstats(message);
cooldown(message.author.id);
return;
}
console.warn(`Command ${command.slice(prefix.length)} does not exist.`)
}
}
});
//////////////////////////////////////////////BOTSTATS//////////////////////////////////////////////
function botstats(message) {
const botstats = new Discord.MessageEmbed()
.setColor('#ba365b')
.setTitle('Bot Statistics')
.addFields(
{
name: "Commands Run",
value: commandsRun
},
{
name: "Current Command Count",
value: client.commands.array().length + 1
},
{
name: "Uptime",
value: moment.duration(client.uptime).format(" D [days], H [hrs], m [mins], s [secs]")
}
)
.setTimestamp()
.setFooter('BrainBot', 'https://i.imgur.com/AkAd7Qo.png');
return message.channel.send(botstats);
}
////////////////////////////////////////////////LOGS////////////////////////////////////////////////
client.on("messageDelete", function(messageDelete){
if (messageDelete.bot || messageDelete.author.tag === "GitHub#0000" || messageDelete.author.tag === "Rythm#3722") return;
var messageText;
if (messageDelete.content.length > 800) {
messageText = `${messageDelete.content.substring(0, 800)}...`;
} else {
messageText = messageDelete.content;
}
let deleteEmbed = new Discord.MessageEmbed()
.setColor('#ba365b')
.setTitle('Message Deleted')
.setTimestamp()
.setFooter('BrainBot', 'https://i.imgur.com/AkAd7Qo.png')
.addFields(
{
name: 'Channel:',
value: `${messageDelete.guild.channels.cache.get(`${messageDelete.channel.id}`).toString()}`
},
{
name: 'User:',
value: `${messageDelete.author.tag} [${messageDelete.author.id}]`
},
{
name: 'Message:',
value: `\`\`\`\n${messageText}\n\`\`\``
}
);
client.channels.cache
.get("789829927515062282")
.send(deleteEmbed);
});
client.on('messageUpdate', function(oldMessage, newMessage){
if (newMessage.bot || newMessage.author.tag === "GitHub#0000" || newMessage.author.tag === "Rythm#3722") return;
var oldMessageText;
if (oldMessage.content.length > 475) {
oldMessageText = `${oldMessage.content.substring(0, 475)}...`;
} else {
oldMessageText = oldMessage.content;
}
var newMessageText;
if (newMessage.content.length > 475) {
newMessageText = `${newMessage.content.substring(0, 475)}...`;
} else {
newMessageText = newMessage.content;
}
let editEmbed = new Discord.MessageEmbed()
.setColor('#ba365b')
.setTitle('Message Edited')
.setURL(`${newMessage.url}`)
.setTimestamp()
.setFooter('BrainBot', 'https://i.imgur.com/AkAd7Qo.png')
.addFields(
{
name: 'Channel:',
value: `${newMessage.guild.channels.cache.get(`${newMessage.channel.id}`).toString()}`
},
{
name: 'User:',
value: `${newMessage.author.tag} [${newMessage.author.id}]`
},
{
name: 'Old Message:',
value: `\`\`\`\n${oldMessageText}\n\`\`\``
},
{
name: 'New Message:',
value: `\`\`\`\n${newMessageText}\n\`\`\``
}
);
client.channels.cache
.get("789829927515062282")
.send(editEmbed);
});
/*client.on("guildMemberAdd", function(member){
console.info(`New member: ${member.tag}`);
var joinMessages = []
client.channels.cache
.get("789829927515062282")
.send(joinMessages[Math.floor(Math.random() * joinMessages.length)]);
});*/
//////////////////////////////////////////////COOLDOWN//////////////////////////////////////////////
function cooldown(user) {
talkedRecently.add(user);
setTimeout(() => {
// Removes the user from the set after 2 seconds
talkedRecently.delete(user);
}, 2000);
}
client.login(TOKEN);
disbut(client);