-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
119 lines (115 loc) · 5.23 KB
/
server.js
File metadata and controls
119 lines (115 loc) · 5.23 KB
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
const discord = require("discord.js");
const client = new discord.Client();
const fs = require("fs");
const config = JSON.parse(fs.readFileSync("./config.json", {encoding: "utf-8"}));
const help = require("./help.js");
const fishEngine = require("./fish.js");
const gameEngine = require("./game.js");
const actionEngine = require("./actions.js");
client.on("ready", () => {
// initialise channels and server
// for ease of logging
global.server = client.guilds.get(config.server);
global.mLog = client.channels.get(config.channels.messageLog);
global.fLog = client.channels.get(config.channels.fishLog);
global.rLog = client.channels.get(config.channels.reasonLog);
global.gameLog = client.channels.get(config.channels.gameLog);
global.fishCategory = client.channels.get(config.channels.fishCategory);
global.turnTime = config.turnTime * 1000;
// log channel and server
console.log("Active on server " + server.name);
console.log("Logging messages to #" + mLog.name);
console.log("Logging fish data to #" + fLog.name);
console.log("Logging moderation data to #" + rLog.name);
});
client.on("message", (message) => {
let fishData = JSON.parse(fs.readFileSync("./fish.json", {encoding: "utf-8"}));
if (!message.author.bot) {
// log messages
if (message.channel.type != "dm") {
mLog.send(message.author.username + "#" + message.author.discriminator + ", in channel <#" + message.channel.id + "> said: \n```" + message.content + '```');
} else {
mLog.send(message.author.username + "#" + message.author.discriminator + ", in DMs said: \n```" + message.content + "```");
}
let ind = fishData.outstandingConfirmations.indexOf(message.author.id);
if (ind != -1) {
if (message.content == "Y" || message.content == "y") {
let params = fishData.confirmations[message.author.id].split(/\s+/g);
switch (params[0]) {
case "delete":
actionEngine.delete(client, message, params[1]);
break;
case "join":
actionEngine.join(client, message, params[1], params[2]);
break;
case "fish":
actionEngine.fish(client, message, params[1], params[2]);
break;
}
fishData = JSON.parse(fs.readFileSync("./fish.json", {encoding: "utf-8"}));
fishData.outstandingConfirmations.splice(ind, 1);
fishData.confirmations[message.author.id] = undefined;
fs.writeFileSync("./fish.json", JSON.stringify(fishData));
} else if (message.content == "N" || message.content == "n") {
let params = fishData.confirmations[message.author.id].split(/\s+/g);
switch (params[0]) {
case "delete":
actionEngine.noDelete(client, message, params[1]);
break;
case "join":
actionEngine.noJoin(client, message, params[1], params[2]);
break;
case "fish":
actionEngine.noFish(client, message, params[1], params[2]);
break;
}
fishData.outstandingConfirmations.splice(ind, 1);
fishData.confirmations[message.author.id] = undefined;
fs.writeFileSync("./fish.json", JSON.stringify(fishData));
}
} else {
if (message.content.startsWith("f!")) {
let command = message.content.substr(2).split(/\s+/g)[0];
switch (command) {
case "help":
help(client, message);
break;
case "init":
fishEngine.init(client, message);
break;
case "invite":
fishEngine.invite(client, message);
break;
case "status":
fishEngine.status(client, message);
break;
case "join":
fishEngine.join(client, message);
break;
case "leave":
fishEngine.leave(client, message);
break;
case "delete":
fishEngine.delete(client, message);
break;
case "alias":
actionEngine.alias(client, message);
break;
case "start":
gameEngine.start(client, message);
break;
case "ask":
gameEngine.ask(client, message);
break;
case "hand":
gameEngine.hand(client, message);
break;
case "list":
fishEngine.list(client, message);
break;
}
}
}
}
});
client.login(config.token);