-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
215 lines (176 loc) · 5.57 KB
/
index.js
File metadata and controls
215 lines (176 loc) · 5.57 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
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
require("dotenv").config();
const Discord = require("discord.js");
const bot = new Discord.Client({
partials: ["USER", "REACTION", "GUILD_MEMBER"],
});
bot.commands = new Discord.Collection();
const botCommands = require("./commands/");
const TOKEN = process.env.TOKEN;
Object.keys(botCommands).map((key) => {
bot.commands.set(botCommands[key].name, botCommands[key]);
});
bot.login(TOKEN);
bot.on("ready", () => {
console.info(`Logged in as ${bot.user.tag}!`);
});
bot.on("message", (msg) => {
if (msg.author.bot) {
return;
}
let args;
let command;
if (!msg.content.startsWith("!")) {
return;
}
if (msg.content.startsWith("!")) {
args = msg.content.split(" ");
command = args[0].toLowerCase().toString().slice(1, args[0].length);
}
if (!bot.commands.has(command)) {
return;
}
try {
bot.commands.get(command).execute(msg, args);
} catch (error) {
console.error(error);
}
});
bot.on("messageReactionAdd", (reaction, user) => {
// let time = reaction.message.createdTimestamp;
// let currentTime = new Date().getTime();
// console.log(time - currentTime);
// function findTime() {}
if (
reaction.message.reactions.cache.size > 1 &&
reaction.message.author.id == "773710233977618464"
) {
reaction.remove();
}
function getNickname(array) {
for (let i = 0; i < array.length; i++) {
if (array[i].id === user.id) {
let nickname = array[i].nickname;
return nickname;
}
}
}
if (
reaction.emoji.name === "🕵️♂️" &&
reaction.message.author.id !== "773710233977618464"
) {
return;
}
if (
reaction.emoji.name === "🕵️♂️" &&
reaction.message.author.bot &&
user.id !== "773710233977618464"
) {
if (reaction.message.embeds.length < 1 && reaction.message.author.bot) {
return;
}
const spotsLeft = reaction.message.embeds[0].fields[1].value;
if (spotsLeft == 0) {
return reaction.users.remove(user.id);
}
let newEmbed = reaction.message.embeds[0];
let guildMembers = reaction.message.guild.members.cache.map((member, i) => {
let rMember = {};
rMember.nickname = member.nickname;
rMember.id = i;
return rMember;
});
let newParticipant = getNickname(guildMembers) || user.tag;
if (newEmbed.fields[2].value[0] == "0") {
newEmbed.fields[2].value = [
`${newEmbed.fields[2].value.length}. ${newParticipant}`,
];
} else {
let participants = newEmbed.fields[2].value;
let num =
typeof participants === "string" ? participants.split("\n").length : 0;
let newEntry = `\n${num + 1}. ${newParticipant}`;
participants += newEntry;
newEmbed.fields[2] = { name: "Participants", value: participants };
}
newEmbed.fields[1] = {
name: "Spots Left",
value: newEmbed.fields[1].value - 1,
};
let newEmbedObj = new Discord.MessageEmbed(newEmbed);
if (newEmbed.fields[1].value == 0) {
let hostValue = newEmbed.fields[0].value;
let hostSplit = hostValue.slice(0, -15);
const guildMap = reaction.message.guild.members.cache.map((m) => {
return m;
});
let host = guildMap.find((user) => user.nickname == hostSplit) || null;
if (host) {
let searchableListValue = newEmbed.fields[2].value;
let searchableListSplit = searchableListValue.split(/[\n.]/) || null;
if (searchableListSplit) {
let searchableListFilter = searchableListSplit.filter((item) =>
isNaN(parseInt(item))
);
let searchableList = searchableListFilter.join();
host.send(searchableList);
}
}
}
return reaction.message.edit(newEmbedObj);
}
});
bot.on("messageReactionRemove", (reaction, user) => {
const spotsLeft = reaction.message.embeds[0].fields[1].value;
const userLength = reaction.message.embeds[0].fields[2].value.split("\n");
const checkNum = userLength.length + 1;
if (spotsLeft == 0 && reaction.count == checkNum) {
return;
}
function getNickname(array) {
for (let i = 0; i < array.length; i++) {
if (array[i].id === user.id) {
let nickname = array[i].nickname;
return nickname;
}
}
}
function newArray(array) {
let newUserListArray = [];
for (let i = 0; i < array.length; i++) {
let newEntry = `${i + 1}. ${array[i]}`;
newUserListArray.push(newEntry);
}
return newUserListArray;
}
if (
reaction.emoji.name === "🕵️♂️" &&
reaction.message.author.bot &&
user.id !== "773710233977618464"
) {
let newEmbed = reaction.message.embeds[0];
let guildMembers = reaction.message.guild.members.cache.map((member, i) => {
let rMember = {};
rMember.nickname = member.nickname;
rMember.id = i;
return rMember;
});
let oldParticipant = getNickname(guildMembers) || user.tag;
const userList = newEmbed.fields[2].value.split("\n");
const newUserList = userList.filter(
(participant) => !participant.includes(oldParticipant)
);
const newUserListUnnumber = newUserList.map((participant) => {
const rParticipant = participant.substring(3);
return rParticipant;
});
const newUserListArray = newArray(newUserListUnnumber);
const newUserListJoined = newUserListArray.join("\n");
newEmbed.fields[2].value = newUserListJoined || 0;
newEmbed.fields[1] = {
name: "Spots Left",
value: parseInt(newEmbed.fields[1].value) + 1,
};
let newEmbedObj = new Discord.MessageEmbed(newEmbed);
return reaction.message.edit(newEmbedObj);
}
});