-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
271 lines (235 loc) · 10.8 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
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
// server.js
// To launch server, enter 'node server.js' in terminal
/* Initialise Project Server Calls */
//const http = require('http');
const express = require('express');
const fs = require('fs');
const app = express();
/* Initialise discord.js Calls */
const Discord = require('discord.js'); //Calling discord.js Package
const bot = new Discord.Client(); //Initialise discord bot instance
const embed = new Discord.RichEmbed()
.setTitle("Click here for JeffBot's website")
.setAuthor("Created by seenaweena")
.setColor(0x00AE86)
.setThumbnail("http://i.imgur.com/p2qNFag.png")
.setDescription("To begin the work of JeffBot, type >start \nTo create Jeffinators, use >jeffinator- only Jeffinators can Jeff others \nHaving created Jeffinators, give users the role of Jeffinator with >jeffinate @user \nArmed with the role of Jeffinator, you may Jeff a user like so: >jefficate @user \nJeffinators may also unJeff Jeffed users, like so: >unjefficate @user \nRegular users may not Jeffinate themselves- please be patient and allow senior Jeffinators to Jeffinate you if they so please \nJeffed users may not unJeff themselves, and only Jeffinators may Jeff others \n")
.addBlankField()
.setTimestamp()
.setURL("https://jeffbot-v3.glitch.me")
.addField("How to use JeffBot", ">jefficate Jeff someone \n>unjefficate to unjeff someone \n>jeffinate to give someone the ability to jefficate others")
.addBlankField()
.addField("Basic Debugging", "if the bot is ignoring the Jeff/Jeffinator roles, test whether the bot has detected the Jeff roles in your server. To test this, use >findjeff and >findjeffinator")
.addBlankField()
.setFooter("Thank you for using Jeffbot. Have a Jefftastic time!");
//global variables
var jeffRole = '';
var jeffinatorRole = '';
//var modRole = '';
//var modArray = [];
//global constants
const prefix = ">";
/* Listener Event: Message Received */
bot.on('message', async message => {
/* Command-Argument separator */
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
/* Variables */
let msg = message.content.toUpperCase(); //Converts entire message to upper case
/* Checks for botception */
if (message.author.bot) return;
/* Ping Pong Function */
if (msg === ">" + 'PING') //Checks for presence of prefix
{
const m = await message.channel.send("Ping?");
m.edit(`Pong! Latency is ${m.createdTimestamp - message.createdTimestamp}ms.
API Latency is ${Math.round(bot.ping)}ms`);
fs.appendFile("public/log.log", Date.now() + " Pongged user " + message.author.username +
'(' + message.author + ') on server '+ message.guild.name + '\n', function (err) {
if (err) {
return console.log(err);
}
})
}
if (msg === ">" + 'HELP')
{
message.channel.send({embed});
fs.appendFile("public/log.log", Date.now() + " Helped user " + message.author.username +
'(' + message.author +') on server '+ message.guild.name + ')\n', function (err) {
if (err) {
return console.log(err);
}
})
}
if (msg === ">" + 'START')
{
message.guild.createRole({name: 'Jeff'});
message.channel.send('It is done');
jeffRole = message.guild.roles.find("name", "Jeff");
message.channel.send('Please now use >jeffinate to begin the rise of the Jeffinators');
fs.appendFile("public/log.log", Date.now() + " Initialized Jeff on server " +
message.guild.name + '\n', function (err) {
if (err) {
return console.log(err);
}
})
}
if (msg === ">" + 'JEFFINATOR') {
message.guild.createRole({name: 'Jeffinator'});
message.channel.send('It is done');
jeffinatorRole = message.guild.roles.find("name", "Jeffinator")
}
if (msg === ">" + 'FINDJEFF')
{
jeffRole = message.guild.roles.find("name", "Jeff");
if (!jeffRole) {
message.channel.send('JeffBot cannot find his Jeff role.' +
' Please delete any roles called Jeff and then run >start')
}
else {
message.channel.send('Never fear, Jeff is indeed here')
}
fs.appendFile("public/log.log", Date.now() + " Jeff was searched for by user " + message.author.username +
'(' + message.author + ') on server '+ message.guild.name + '\n', function (err) {
if (err) {
return console.log(err);
}
})
}
if (msg === ">" + 'FINDJEFFINATOR') {
jeffinatorRole = message.guild.roles.find("name", "Jeffinator");
if (!jeffRole) {
message.channel.send('JeffBot cannot find his Jeffinator role. ' +
'Please delete any roles called Jeffinator and then run >jeffinate')
}
else {
message.channel.send('Never fear, Jeffinator is indeed here')
}
fs.appendFile("public/log.log", Date.now() + " Jeffinator was serached for by user " + message.author.username +
'(' + message.author +') on server '+ message.guild.name + '\n', function (err) {
if (err) {
return console.log(err);
}
})
}
if (msg === ">" + 'PURGEJEFF')
{
console.log('purgejeff');
message.channel.send('Execute order Jeffty-Jeff');
message.guild.roles.get(jeffRole.id).delete();
message.channel.send('It is done my lord');
fs.appendFile("public/log.log", Date.now() + " Jeff was purged by user " + message.author.username +
'(' + message.author + ') on server '+ message.guild.name + '\n', function (err) {
if (err) {
return console.log(err);
}
})
}
if (command === 'jefficate')
{
jeffinatorRole = message.guild.roles.find("name", "Jeffinator");
if (message.member.roles.has(jeffinatorRole.id)) {
jeffRole = message.guild.roles.find("name", "Jeff");
let member = message.mentions.members.first() || message.guild.members.get(args[0]);
if (!member) {
message.reply("Please mention a valid member of this server");
}
member.addRole(jeffRole).catch(console.error);
message.channel.send(member.user.username, 'jefficated');
console.log(member.user.username, 'jefficated');
}
else {
message.channel.send("You do not have permission to use this command")
}
}
if (command === 'unjefficate')
{
jeffRole = message.guild.roles.find("name", "Jeff");
if (message.member.roles.has(jeffRole.id)) {
//Checks for role (Jeff), Role ID hardcoded and prevents self-unjeffication
console.log(message.member.user.username, 'tried to unjefficate themself...');
message.channel.send(message.member.user.username, 'tried to unjefficate themself...');
message.author.send("Resistance is futile")
}
else {
jeffRole = message.guild.roles.find("name", "Jeff");
let member = message.mentions.members.first() || message.guild.members.get(args[0]);
if (!member)
return message.reply("Please mention a valid member of this server");
member.removeRole(jeffRole).catch(console.error);
message.channel.send(` ${message.channel.send} unjefficated`);
console.log(member.user.username, 'unjefficated');
}
}
if (command === 'jeffinate')
{
jeffinatorRole = message.guild.roles.find("name", "Jeffinator");
if (message.member.roles.has(jeffinatorRole.id)) {
let member = message.mentions.members.first() || message.guild.members.get(args[0]);
if (!member) {
message.reply("Please mention a valid member of this server");
}
member.addRole(jeffinatorRole).catch(console.error);
console.log(message.member.username, 'was jeffinated');
message.channel.send(message.member.username, "has become a Jeffinator")
}
else {
message.channel.send("You must be a Jeffinator to use this command")
}
}
/* Delete message and replace with Jeffs */
if (!jeffRole) return;
if (message.member.roles.has(jeffRole.id)) //Checks for roleID of role 'Jeff' initialised on >Start
{
/* Handling original user message */
message.delete(); //Delete the user's message from the chat channel
let splitStringArray = message.content.split(" "); //Split message into words, create array of words
let msgWordCount = splitStringArray.length; //Check how many words in the original message
/* For Loop to create array of 'jeff' */
var i; //Declare loop variable
let jeffArray = []; //Declare empty array
jeffArray.push('Jeff');
if (msgWordCount > 1) {
for (i = 0; i < msgWordCount - 1; i++) { //Loop through for number of words in message
jeffArray.push('jeff') //Push 'jeff' to jeffArray
}
}
/* Outputting jeffArray */
let jeffString = jeffArray.join(" "); //Turn array into string separated with spaces
message.channel.send(jeffString); //Send jeffString into chat channel
message.author.send('You just got Jeffed! Tag your friends to Jeff them also!') //PM author of original message
}
});
/* Event: Bot startup & successful login*/
bot.on("ready", () => {
//Output basic statistics of bot to console
console.log(`Bot has started, with ${bot.users.size} users,
in ${bot.channels.size} channels of ${bot.guilds.size} guilds.`);
//logger.info(`Bot has started, with ${bot.users.size} users,
// in ${bot.channels.size} channels of ${bot.guilds.size} guilds.`)
bot.user.setActivity(`Serving ${bot.users.size} Jeffs in ${bot.guilds.size} Guilds`) //Set Activity
//bot.user.setActivity(`Performing Maintenance - May be unresponsive`) //Set Maintenence Activity
});
/* Login */
bot.login(process.env.TOKEN); //Bot login with token defined in config.js
/* Uptime pinger (Now using UptimeRobot)*/
/*
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);
*/
// http://expressjs.com/en/starter/static-files.html
app.use(express.static('public'));
// http://expressjs.com/en/starter/basic-routing.html
app.get('/', function (request, response) {
response.sendFile(__dirname + '/views/index.html');
});
// listen for requests :)
var listener = app.listen(process.env.PORT, function () {
console.log('Your app is listening on port ' + listener.address().port);
});