This repository has been archived by the owner on Feb 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
98 lines (86 loc) · 2.9 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
// Programmers : Andrew Robinson & Jonas Smith
// Date start : 3/11/2018
// Purpose : We are all drunk
//
var Discord = require('discord.js');
var winston = require('winston');
var auth = require('./auth.json');
var userDict = { };
const bot = new Discord.Client();
const logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
transports: [
// - Write to all logs with level `info` and below to `combined.log`
// - Write all logs error (and below) to `error.log`.
//
new winston.transports.File({ filename: 'error.log', level: 'error' }),
new winston.transports.File({ filename: 'combined.log' })
]
});
// Called when bot get created.
bot.on("ready", () => {
logger.info("Starting server. Bot was ready at: " + bot.readyAt)
console.log("Server created and ready! Time when ready: " + bot.readyAt)
});
// Checking message for drunk status and !set cmd
//
bot.on("message", (message) => {
// get current sender of message
//
var sender = message.author.username;
// react with 🍺 if drunk = true
//
if (userDict[sender] == true && !message.content.startsWith("!set")){
message.react("🍺")
}
// command to add/remove drunk status from dict. & display discord bot message.
//
if (message.content.startsWith("!set") && (sender == "SirArkimedes" || sender == "VOXEL")) {
var cmdArray = message.content.split(" ");
// Toggles user status of drunk. allows for a simpler command of !set [USERNAME]
// instead of !set [USERNAME] [BOOL].
//
if(userDict[cmdArray[1]] == true) {
userDict[cmdArray[1]] = false; }
else {
userDict[cmdArray[1]] = true; }
// Message is displayed when user is "LIT".
//
if (userDict[cmdArray[1]] == true){
message.channel.send(cmdArray[1] + " is DRUNK! 🍺🍺🍺🍺");
}
// Get all current "drunk" users for Game status.
//
var status = "";
for (key in userDict) {
if (userDict[key] == true) {
status = status + key + ", ";
}
}
// Display game status.
//
if (status == "") {
status = "no one";
bot.user.setPresence( { game: { name: "" }, status: "online" } )
.then(function(user) {
logger.info("User status set to: " + user.presence.game.name);
})
.catch(function(error) {
logger.error(error.toString());
});
} else {
status = status.substring(0, status.length - 2);
bot.user.setPresence( { game: { name: "drunk with " + status + "!"}, status: "online" } )
.then(function(user) {
logger.info("User status set to: " + user.presence.game.name);
})
.catch(function(error) {
logger.error(error.toString());
});
}
}
});
// Logs in the bot with the auth.token
//
bot.login(auth.token);