· 5 years ago · Mar 06, 2020, 10:26 PM
1const prefix = "!"; //discord bot prefix
2const Discord = require("discord.js");
3const bot = new Discord.Client();
4const robloxranking = require("robloxrankingservice");
5const gamekey = "-CkfniAak-Ip-6FbK6G4eA";
6const express = require("express");
7const app = express();
8const apiKey = "85b9f5b7a718a8a13c4fcc7e7ad005bd";
9const oauthToken =
10 "167f004648ff9619ce3ec3072099c3f972ef138f929c57b3594b2d2bcd30c1b8";
11const request = require("request");
12const Trello = require("trello-node-api")(apiKey, oauthToken);
13const cooldowns = new Discord.Collection();
14
15app.get("/", (request, response) => {
16 response.sendStatus(200);
17});
18app.listen(process.env.PORT);
19
20const getId = function(username, cb) {
21 if (username) {
22 request(
23 "https://users.roblox.com/v1/usernames/users",
24 {
25 method: "POST",
26 headers: {
27 "Content-Type": "application/json"
28 }, //where???
29 body: `{
30 "usernames": [
31 "${username}"
32 ]
33 }`
34 },
35 function(err, res, data) {
36 try {
37 if (err) {
38 cb({
39 success: false
40 });
41 } else {
42 if (res.statusCode == 429) {
43 setTimeout(function() {
44 module.exports(username, cb);
45 }, 2000);
46 } else if (res.statusCode == 404) {
47 cb({
48 success: false
49 });
50 } else {
51 cb({
52 success: true,
53 data: JSON.parse(data)["data"][0]["id"]
54 });
55 }
56 }
57 } catch (err) {
58 cb({
59 success: false
60 });
61 }
62 }
63 );
64 } else {
65 cb({
66 success: false
67 });
68 }
69};
70
71bot.on("message", message => {
72 if (message.guild !== null && message.member !== null) {
73 if (message.content.startsWith(prefix + "session")) {
74 if (message.member.roles.find("name", "Sessions")) {
75 message.channel.send(
76 "Check your direct messages for more information."
77 );
78 var channel = null;
79 if (channel == null) {
80 message.author.createDM().then(chan => {
81 channel = chan;
82
83 const collector = new Discord.MessageCollector(
84 channel,
85 m => m.author.id == message.author.id,
86 { maxMatches: 1 }
87 );
88 message.author.send(
89 "What type of session are you hosting? Please reply with either **shift**, or **training**."
90 );
91 collector.on("collect", msg => {
92 if (msg.content.toLowerCase() === "cancel") {
93 message.author.send("Cancelled Prompt.");
94 } else {
95 let sessiontype = msg.content;
96 message.author.send(
97 "Alright! What time is the session starting at? Make sure you put the time in EST."
98 );
99 const collector1 = new Discord.MessageCollector(
100 channel,
101 m => m.author.id == message.author.id,
102 { maxMatches: 1 }
103 );
104
105 collector1.on("collect", msg1 => {
106 if (msg1.content.toLowerCase() === "cancel") {
107 message.author.send("Cancelled Prompt.");
108 } else {
109 let timestarting = msg1.content.toUpperCase();
110 message.author.send("Please send your Roblox username.");
111 const collector2 = new Discord.MessageCollector(
112 channel,
113 m => m.author.id == message.author.id,
114 { maxMatches: 1 }
115 );
116
117 collector2.on("collect", msg2 => {
118 if (msg1.content.toLowerCase() === "cancel") {
119 message.author.send("Cancelled Prompt.");
120 } else {
121 let channel = message.guild.channels.find(
122 c => c.name === "session-notifications"
123 );
124 let username = msg2.content;
125
126 message.author.send(
127 `Thanks! I'm now sending the notification on Discord and Roblox.`
128 );
129 robloxranking.shout(
130 gamekey,
131 4944028,
132 `A ${sessiontype} is currently being hosted by ${username} at ${timestarting} Eastern Standard Time. Why not come on down and attend?`
133 );
134 let embed = new Discord.RichEmbed()
135 .setTitle("Session Scheduled")
136 .addField("Session Type:", sessiontype)
137 .addField("Session Host:", username)
138 .addField("Starting At:", timestarting)
139 .addField(
140 "Link:",
141 "[Group Page](https://www.roblox.com/groups/4944028/Atlanta-Hotels#!/about)"
142 )
143 .setColor(0x59e68e)
144 .setThumbnail(bot.user.avatarURL);
145
146 channel.send("<@&659625628345171970>");
147 channel.send(embed);
148 }
149 });
150 }
151 });
152 }
153 });
154 });
155 }
156 }
157 }
158 }
159});
160
161bot.on("message", message => {
162 if (message.guild !== null && message.member !== null) {
163 let role = message.guild.roles.find(
164 r => r.name === "Session Notifications"
165 );
166 const msg = message.content.toLowerCase();
167 if (message.author.bot) return;
168 const mention = message.mentions.users.first();
169 if (msg.startsWith(prefix + "optin")) {
170 message.member.addRole(role);
171 let embed = new Discord.RichEmbed()
172 .setTitle("Session Ping On")
173 .addField(
174 "You will now be pinged when sessions are hosted.",
175 "To disable being pinged for sessions, simply say !optout."
176 )
177 .setColor("#5b9cc2");
178 message.channel.send(embed);
179 }
180 }
181});
182
183bot.on("message", message => {
184 if (message.guild !== null && message.member !== null) {
185 let role = message.guild.roles.find(
186 r => r.name === "Session Notifications"
187 );
188 const msg = message.content.toLowerCase();
189 if (message.author.bot) return;
190 if (msg.startsWith(prefix + "optout")) {
191 message.member.removeRole(role);
192 let embed = new Discord.RichEmbed()
193 .setTitle("Session Ping Off")
194 .addField(
195 "You will no longer be pinged when sessions are hosted.",
196 "To enable the session ping again, simply say !optin."
197 )
198 .setColor("#5b9cc2");
199 message.channel.send(embed);
200 }
201 }
202});
203
204bot.on("message", message => {
205 const msg = message.content.toLowerCase();
206
207 let messageArray = message.content.split(" ");
208 let args = messageArray.slice(1);
209 if (msg.startsWith(prefix + "blacklist")) {
210 let reason = args.slice(1).join(" ");
211 let username = args[0];
212 if (message.member.roles.find(r => r.name === "Atlanta SHR ?")) {
213 getId(`${username}`, data => {
214 console.log(data);
215
216 var cardRequest = function(data) {
217 var data = {
218 name: `${username} | ${data.data}`,
219 desc: `N/A`,
220 pos: "top",
221 idList: "5dcb1b8a58b5d75dfe0d6399" //REQUIRED
222 };
223 Trello.card
224 .create(data)
225 .then(function(response) {
226 console.log("response ", response);
227 })
228 .catch(function(error) {
229 console.log("error", error);
230 });
231 };
232
233 cardRequest(data);
234
235 const embed = new Discord.RichEmbed()
236 .setTitle("User Blacklisted!")
237 .addField(
238 "The selected user was banned from all groups.",
239 "They will now be prevented from joining any game associated with 4PF."
240 )
241 .addField("Username", `${username}`)
242 .addField("UserId", `${data.data}`)
243 .setColor(0x59e68e);
244 message.channel.send(embed);
245 });
246 }
247 }
248});
249
250bot.on("ready", () => {
251 console.log("Bot Enabled");
252 bot.user.setActivity("Atlanta Hotels");
253});
254
255bot.login(process.env.DISCORD_TOKEN);