-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
1674 lines (1625 loc) · 51.5 KB
/
index.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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const Discord = require("discord.js");
const client = new Discord.Client({
intents: [
"GUILDS",
"GUILD_MESSAGES",
"GUILD_MEMBERS",
"GUILD_VOICE_STATES",
"DIRECT_MESSAGES",
],
partials: ["MESSAGE", "CHANNEL", "REACTION"],
});
const {
createAudioPlayer,
createAudioResource,
StreamType,
demuxProbe,
joinVoiceChannel,
NoSubscriberBehavior,
AudioPlayerStatus,
VoiceConnectionStatus,
getVoiceConnection,
} = require("@discordjs/voice");
const ytdl = require("ytdl-core");
const play = require("play-dl");
const { MessageEmbed } = require("discord.js");
const fetch = require("node-fetch");
const prefix = "ylc";
const dotenv = require("dotenv").config();
const yaml = require("js-yaml");
const fs = require("fs");
const express = require("express");
const mongoose = require("mongoose");
const User = require("./models/User");
//Connect to the Database
mongoose
.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log("MongoDB Connected");
})
.catch((err) => console.log(err));
const app = express();
const bodyParser = require("body-parser");
const puppeteer = require("puppeteer");
const potd = require("./paperoftheday.json");
const { MessageActionRow, MessageSelectMenu } = require("discord.js");
var loaded = false;
let social_papers = [];
let top_5_social_papers = [];
let latest_papers = [];
let top_5_latest_papers = [];
let greatest_papers = [];
let top_5_greatest_papers = [];
let trending_papers = [];
let top_5_trending_papers = [];
let colors = [
"#FF0000",
"#FFC000",
"#FFFC00",
"#FF0000",
"#00FFFF",
"#FF0000",
"#8c52ff",
"#5cf000",
];
let domains = {
ML: ["Machine Learning", "https://i.imgur.com/ZLRhN5e.png"],
AI: "Artificial Intelligence",
CV: ["Computer Vision", "https://i.imgur.com/tRGQP7D.png"],
RO: ["Robotics", "https://i.imgur.com/fF9LVk7.png"],
DM: "Data Mining",
SP: "Speech Processing",
DS: "Data Science",
DL: "Deep Learning",
NLP: "Natural Language Processing",
};
//Welcome Message ✅
//Roles by Reaction
//Slash Commands
//Wishlist ✅ (Partially)
//Level Up System
const wyd_responses = [
"Searching for the orphanage you came from so I can send you back.",
"Meditating. Be quiet",
"Minding my own business. You should try it.",
"Pretending to be invisible",
"Changing the config settings for NASA satellites. Same old same old, you know how it is.",
"Living the dream.",
"Planning to take over the world. You know. The usual.",
"Enslaving humanity one sandwich at a time. Would you like some lunch?",
"Inventing time travel. I'll let you know how it works out last week.",
];
// function add_xp(message, xp) {
// User.findOne({
// id: message.author.id,
// }).then((user
// ) => {
// if (user) {
// user.xp += xp;
// user.save().then((user) => {
// console.log(`${user.name} has gained ${xp} xp`);
// if (user.xp >= user.level * 10) {
// user.level += 1;
// user.xp = 0;
// user.save().then((user) => {
// console.log(`${user.name} has leveled up to level ${user.level}`);
// //Send a message to the user
// message.channel.send(
// `${user.name} has leveled up to level ${user.level}`
// );
// });
// }
// });
// }
// else{
// new_user = new User({
// id: message.author.id,
// name: message.author.username,
// xp: xp,
// level: 1,
// wishlist: [],
// blogs: [],
// });
// new_user.save().then((user) => {
// console.log(`${user.name} has gained ${xp} xp`);
// if (user.xp >= user.level * 10) {
// user.level += 1;
// user.xp = 0;
// user.save().then((user) => {
// console.log(`${user.name} has leveled up to level ${user.level}`);
// //Send a message to the user
// message.channel.send(
// `${user.name} has leveled up to level ${user.level}`
// );
// });
// }
// });
// }
// });
// }
//Update Paper of the Day if it isn't updated in the JSON file
function update_paper_of_the_day(write_object, channel_id) {
console.log(channel_id);
const channel = client.channels.cache.get(channel_id);
fs.readFile("./paperoftheday.json", (err, data) => {
if (err) throw err;
var doc = JSON.parse(data);
//if the date is not in the file add the paper
if (doc.findIndex((x) => x.date === write_object.date) === -1) {
doc.push(write_object);
fs.writeFile("./paperoftheday.json", JSON.stringify(doc), (err) => {
if (err) throw err;
console.log("Paper of the day updated!");
const potdEmbed = new MessageEmbed()
//set color to random from colors array
.setColor(colors[Math.floor(Math.random() * colors.length)])
.setTitle("Paper of the Day 📝 ")
.setImage("https://i.imgur.com/12abBCa.png")
.setDescription("The paper of the day is:")
.addFields(
{
name: "Title",
value:
doc[doc.findIndex((x) => x.date === write_object.date)].title,
inline: false,
},
{
name: "Description",
value:
doc[doc.findIndex((x) => x.date === write_object.date)]
.description,
inline: false,
}
//// { name: '\u200B', value: '\u200B' },
)
.setTimestamp()
.setURL(doc[doc.findIndex((x) => x.date === write_object.date)].link)
.setFooter({
text: "Research et Al",
iconURL: "https://i.imgur.com/eBiE8DT.png",
});
channel.send({ embeds: [potdEmbed] });
});
}
//if the date is in the file, send the paper of the day
else {
console.log("Date already in file!");
//create embed for the paper of the day
const channel = client.channels.cache.find(
(channel) => channel.id === channel_id
);
const potdEmbed = new MessageEmbed()
.setColor(colors[Math.floor(Math.random() * colors.length)])
.setTitle("Paper of the Day 📝 ")
.setImage("https://i.imgur.com/12abBCa.png")
.setDescription("The paper of the day is:")
.addFields(
{
name: "Title",
value:
doc[doc.findIndex((x) => x.date === write_object.date)].title,
inline: false,
},
{
name: "Description",
value:
doc[doc.findIndex((x) => x.date === write_object.date)]
.description,
inline: false,
}
//// { name: '\u200B', value: '\u200B' },
)
.setTimestamp()
.setURL(doc[doc.findIndex((x) => x.date === write_object.date)].link)
.setFooter({
text: "Research et Al",
iconURL: "https://i.imgur.com/eBiE8DT.png",
});
channel.send({ embeds: [potdEmbed] });
}
});
}
//Function to get all the data from paperswithcode.com
function scrape_data(query) {
const scrape = async () => {
const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
await page.goto("https://paperswithcode.com" + query, {
waitUntil: "domcontentloaded",
}); // navigate to url and wait for page loading
const result = await page.evaluate(() => {
hrefs_list = [
...new Set(
Array.from(document.querySelectorAll(".badge-light"), (a) =>
a.getAttribute("href")
)
),
];
for (i = 0; i < hrefs_list.length; i++) {
hrefs_list[i] =
"https://paperswithcode.com" + hrefs_list[i].split("#")[0];
}
hrefs_list = [
...new Set(
hrefs_list.filter(
(a) => a.includes("/paper/") || a.includes("/search?")
)
),
];
return {
hrefs: hrefs_list,
data: document
.querySelector(".home-page")
.innerText.split("\n")
.filter((x) => x != " " && x != ""),
};
});
await browser.close();
return result;
};
scrape().then((obj) => {
arr = obj.data;
let hrefs_list = obj.hrefs;
const res = [];
var temp = [];
if (query === "/top-social") {
for (let i = 0; i < arr.length; i += 1) {
if (arr[i] == "TWEETS") {
temp.push(hrefs_list[0]);
res.push(temp);
hrefs_list = hrefs_list.slice(1);
temp = [];
} else {
temp.push(arr[i]);
}
}
social_papers = res;
top_5_social_papers = social_papers.slice(0, 5);
loaded = true;
} else if (query === "/latest") {
for (let i = 0; i < arr.length; i += 1) {
if (arr[i] == " Code") {
temp.push(hrefs_list[0]);
res.push(temp);
hrefs_list = hrefs_list.slice(1);
temp = [];
} else {
temp.push(arr[i]);
}
}
latest_papers = res;
top_5_latest_papers = latest_papers.slice(0, 5);
loaded = true;
} else if (query === "/greatest" || query === "/latest" || query === "/") {
for (let i = 0; i < arr.length; i += 1) {
if (arr[i] == " Code") {
temp.push(hrefs_list[0]);
res.push(temp);
hrefs_list = hrefs_list.slice(1);
temp = [];
} else {
temp.push(arr[i]);
}
}
if (query === "/latest") {
latest_papers = res;
top_5_latest_papers = latest_papers.slice(0, 5);
loaded = true;
} else if (query === "/greatest") {
greatest_papers = res;
top_5_greatest_papers = greatest_papers.slice(0, 5);
loaded = true;
} else {
trending_papers = res;
top_5_trending_papers = trending_papers.slice(0, 5);
loaded = true;
}
}
});
}
scrape_data("/top-social");
scrape_data("/latest");
scrape_data("/greatest");
scrape_data("/");
app.use(
bodyParser.urlencoded({
extended: true,
})
);
//Conferences from the website repository
let conference_doc = yaml.load(fs.readFileSync("./conferences.yml", "utf8"));
conference_doc.sort((a, b) => Date.parse(a.deadline) - Date.parse(b.deadline));
conference_doc = conference_doc.filter(function (conference) {
return (
Date.parse(conference.deadline) > Date.now() && conference.year >= 2022
);
});
// console.log(conference_doc);
// app.get("/", function () {
// const channel = client.channels.cache.find(
// (channel) => channel.id === process.env.CHANNEL_ID
// );
// channel.send(
// "This is an automated message sent from port " + process.env.PORT
// );
// });
//Send a message to the channel if there's a new post
app.get("/blog", function (req, res) {
const channel = client.channels.cache.find(
(channel) => channel.id === process.env.CHANNEL_ID
);
const blogEmbed = new MessageEmbed()
.setColor(colors[Math.floor(Math.random() * colors.length)])
.setTitle("New Blog Post")
.setDescription(
"Oooh\n Looks like we have a new blog post by " + req.query.name + "!"
)
.setThumbnail(req.query.blogImg)
.addFields(
{
name: "**" + req.query.blogName + "**",
value: req.query.blogContent,
inline: false,
}
//// { name: '\u200B', value: '\u200B' },
)
.setTimestamp()
.setURL(req.query.blogURL)
.setFooter({
text: "Research et Al",
iconURL: "https://i.imgur.com/eBiE8DT.png",
});
channel.send({ embeds: [blogEmbed] });
});
//Send a message if someone joins the channel
client.on("guildMemberAdd", async (member) => {
console.log("New Member Joined");
const welcomeEmbed = new MessageEmbed();
// member.roles.add(member.guild.roles.cache.find(role => role.name === 'Computer Vision'))
welcomeEmbed.setColor("#5cf000");
welcomeEmbed.setTitle(member.user.username + " is now Among Us ");
welcomeEmbed.setDescription("Welcome to the server!");
welcomeEmbed.setTimestamp();
welcomeEmbed.setImage(
"https://cdn.mos.cms.futurecdn.net/93GAa4wm3z4HbenzLbxWeQ-650-80.jpg.webp"
);
member.guild.channels.cache
.find((channel) => channel.id === process.env.WELCOME_CHANNEL_ID)
.send({ embeds: [welcomeEmbed] });
});
client.on("ready", () => {
client.user.setActivity("you learn about research related matters", {
type: "WATCHING",
});
console.log("Bot is ready");
});
client.on("messageCreate", async function (message) {
if (message.author.bot) return;
var msgtok = message.content.toLowerCase().split(" "); //Tokenize the message
var command = msgtok[1];
if (msgtok[0] != prefix) {
return;
}
// const commandBody = message.content.slice(prefix.length);
// const args = commandBody.split(' ');
// const command = args.shift().toLowerCase();
const channel = client.channels.cache.find(
(channel) => channel.id === message.channel.id
);
if (command === "ping") {
const timeTaken = Date.now() - message.createdTimestamp;
message.reply(`Hello! This message had a latency of ${timeTaken}ms.`);
} else if (command === "upcoming") {
//create embed for upcoming events
const upcomingEmbed = new MessageEmbed()
.setColor(colors[Math.floor(Math.random() * colors.length)])
.setTitle("Upcoming Events")
.setDescription("Here are the upcoming events!")
.addFields(
{
name: "**" + "έρευνα (Erevna)" + "**",
value:
"Want to publish a scientific paper but don't know where to start? Don't worry, we have got you covered!\nPresenting to you, έρευνα (Erevna), a 3 week-long event to familiarize students with the proceedings of academic conferences and help them master the art of scientific writing! ✍️",
inline: false,
},
{
name: "**" + "Registration Link" + "**",
value: "https://forms.gle/DE3oDQ7BTTknBHwD7",
inline: false,
}
)
.setImage(
"https://cdn.discordapp.com/attachments/904777742145437746/944529799488090122/WhatsApp_Image_2022-02-19_at_1.23.14_PM.jpeg"
)
.setTimestamp()
.setFooter({
text: "Research et Al",
iconURL: "https://i.imgur.com/eBiE8DT.png",
});
channel.send({ embeds: [upcomingEmbed] });
} else if (command === "excuse") {
excuse = fetch("https://excuser.herokuapp.com/v1/excuse").then((res) =>
res.json()
);
excuse.then((data) => {
data = data[0];
const excuseEmbed = new MessageEmbed()
.setColor(colors[Math.floor(Math.random() * colors.length)])
.setTitle("Excuse Generator")
.setThumbnail(
"https://styles.redditmedia.com/t5_26eosz/styles/profileIcon_8847im20pb081.jpg"
)
.addFields({
name:
"**" +
data.category.charAt(0).toUpperCase() +
data.category.slice(1) +
" Excuse" +
"**",
value: data.excuse,
inline: false,
})
.setTimestamp()
.setFooter({
text: "Research et Al",
iconURL: "https://i.imgur.com/eBiE8DT.png",
});
channel.send({ embeds: [excuseEmbed] });
});
} else if (command === "kanye") {
quote = fetch("https://api.kanye.rest/").then((res) => res.json());
quote.then((data) => {
kanyeEmbed = new MessageEmbed()
.setColor(colors[Math.floor(Math.random() * colors.length)])
.setTitle("Kanye Quote")
// .setDescription("Here is your Kanye West quote!")
.setThumbnail(
"https://media.vanityfair.com/photos/62093321237a9fc52a53a0d4/3:4/w_2460,h_3280,c_limit/1366417675"
)
.addFields({
name: "\u200B",
value: "**" + data.quote + "**",
inline: false,
})
.setTimestamp()
.setFooter({
text: "Research et Al",
iconURL: "https://i.imgur.com/eBiE8DT.png",
});
channel.send({ embeds: [kanyeEmbed] });
});
} else if (command === "fact") {
fact = fetch("https://uselessfacts.jsph.pl/random.json?language=en").then(
(res) => res.json()
);
fact.then((data) => {
factEmbed = new MessageEmbed();
factEmbed.setColor(colors[Math.floor(Math.random() * colors.length)]);
factEmbed.setTitle("Fact");
factEmbed.setThumbnail(
"https://www.changefactory.com.au/wp-content/uploads/2010/09/article-fact-or-opinion.jpg"
);
factEmbed.addFields({
name: "Did you know?",
value: "**" + data.text + "**",
inline: false,
});
factEmbed.setTimestamp();
factEmbed.setFooter({
text: "Research et Al",
iconURL: "https://i.imgur.com/eBiE8DT.png",
});
channel.send({ embeds: [factEmbed] });
});
} else if (command === "wyd" || command === "wassup" || command === "sup") {
console.log(message.channel.id);
// random element from wyd_responses
message.reply(wyd_responses[(wyd_responses.length * Math.random()) | 0]);
// add_xp(message, 1);
} else if (command === "test") {
channel.send(message.author.username + " has tested the bot!");
} else if (command === "save") {
// message.reply("Here are the papers you have added to your wishlist: " );
fs.readFile("./paperoftheday.json", (err, data) => {
if (err) throw err;
//save the data to doc
let wishlist = [];
doc = JSON.parse(data);
data =
doc[
doc.findIndex(
(x) => x.date === new Date().toLocaleDateString("en-US")
)
];
wishlist.push(data);
const new_user = User({
id: message.author.id,
name: message.author.username,
wishlist: wishlist,
blogs: [],
// xp: 0,
// level : 1,
});
//check if user exists
User.findOne({ id: message.author.id }, (err, user) => {
if (err) throw err;
if (!user) {
console.log("User not found, creating new user");
new_user.save(function (err) {
if (err) return handleError(err);
// saved!
console.log("saved!");
message.reply("Saved Paper of the Day!");
});
} else {
//check if paper is already in wishlist
if (user.wishlist.find((x) => x.title === data.title)) {
message.reply("You have already saved this paper!");
} else {
user.wishlist.push(data);
user.save(function (err) {
if (err) return handleError(err);
// saved!
console.log("saved!");
message.reply("Saved Paper of the Day!");
});
}
}
});
//get paper of the day from paperoftheday.json
//get wishlist from database
// for (let i = 0; i < wishlist.length; i += 1) {
// message.reply(wishlist[i]);
// }
//add paper of the day to wishlist
});
} else if (command === "saved") {
index = parseInt(msgtok[2]) - 1;
//get wishlist from database
User.findOne({ id: message.author.id }, function (err, user) {
if (err) return handleError(err);
if (user) {
message.reply("Here are the papers you have saved: ");
//create embed for wishlist
var wishlistEmbed = new MessageEmbed()
.setColor(colors[Math.floor(Math.random() * colors.length)])
.setTitle("Your Saved Papers 📝")
// .setDescription('Here are the papers you have saved: ')
.setTimestamp()
.setFooter({
text: "Research et Al",
iconURL: "https://i.imgur.com/eBiE8DT.png",
});
let wishlist = user.wishlist.slice(5 * index - 5).slice(0, 5);
if (wishlist.length == 0) {
message.reply("You have not saved these many papers yet!");
} else {
for (let i = 0; i < wishlist.length; i += 1) {
wishlistEmbed.addFields(
{
name: "```" + (i + 1) + ") " + wishlist[i].title + "```",
value: wishlist[i].description,
inline: false,
},
//// { name: '\u200B', value: '\u200B' },
{ name: "Link", value: wishlist[i].link, inline: false }
);
}
message.channel.send({ embeds: [wishlistEmbed] });
}
} else {
message.reply(
"You have no papers saved!\n Use `ylc save` to save a paper!"
);
}
// message.channel.send({ embeds: [wishlistEmbed] });
});
} else if (command === "remove") {
index = parseInt(msgtok[2]) - 1;
User.findOne({ id: message.author.id }, function (err, user) {
if (err) return handleError(err);
if (user) {
if (user.wishlist.length > index) {
//remove paper at index from wishlist
user.wishlist.splice(index, 1);
user.save(function (err) {
if (err) return handleError(err);
console.log("removed!");
message.reply("Removed the Paper!");
});
} else {
message.reply("Please enter a valid number!");
}
} else {
message.reply("You have no papers saved!");
}
});
} else if (command === "roles") {
const row = new MessageActionRow().addComponents(
new MessageSelectMenu()
.setCustomId("select")
.setPlaceholder("Nothing selected")
.addOptions([
{
label: "Machine Learning",
description: "This is a description",
value: "ML",
},
{
label: "Computer Vision",
description: "This is also a description",
value: "CV",
},
{
label: "Robotics",
description: "This is also a description",
value: "RO",
},
// {
// label: 'Natural Language Processing',
// description: 'This is also a description',
// value: 'NLP',
// },
// {
// label: 'Speech Processing',
// description: 'This is also a description',
// value: 'SP',
// }
])
);
message.reply({ content: "Here's a list of roles:", components: [row] });
client.on("interactionCreate", async (interaction) => {
if (!interaction.isSelectMenu()) return;
const sub = interaction.values[0];
if (sub === "ML") {
//check if already has role ML
if (
message.member.roles.cache.find(
(role) => role.name === "Machine Learning"
)
) {
interaction
.update({
content: "You already have the Machine Learning Role!",
components: [],
ephemeral: true,
})
.then()
.catch(console.error);
} else {
//add role ML
message.member.roles.add(
message.guild.roles.cache.find(
(role) => role.name === "Machine Learning"
)
);
interaction
.update({
content:
"Congrats!\n You have been added to the Machine Learning Role!",
components: [],
ephemeral: true,
})
.then()
.catch(console.error);
}
} else if (sub === "CV") {
//check if already has role CV
if (
message.member.roles.cache.find(
(role) => role.name === "Computer Vision"
)
) {
interaction
.update({
content: "You already have the Computer Vision role!",
components: [],
ephemeral: true,
})
.then()
.catch(console.error);
} else {
//add role CV
message.member.roles.add(
message.guild.roles.cache.find(
(role) => role.name === "Computer Vision"
)
);
interaction
.update({
content:
"Congrats!\n You have been added to the Computer Vision Role!",
components: [],
ephemeral: true,
})
.then()
.catch(console.error);
}
} else if (sub === "RO") {
//check if already has role RO
if (
message.member.roles.cache.find((role) => role.name === "Robotics")
) {
interaction
.update({
content: "You already have the Robotics Role!",
components: [],
ephemeral: true,
})
.then()
.catch(console.error);
} else {
//add role RO
message.member.roles.add(
message.guild.roles.cache.find((role) => role.name === "Robotics")
);
interaction
.update({
content: "Congrats!\n You have been added to the Robotics Role!",
components: [],
ephemeral: true,
})
.then()
.catch(console.error);
}
}
});
} else if (command === "domains") {
const row = new MessageActionRow().addComponents(
new MessageSelectMenu()
.setCustomId("select")
.setPlaceholder("Nothing selected")
.addOptions([
{
label: "Machine Learning",
description: "This is a description",
value: "ML",
},
{
label: "Computer Vision",
description: "This is also a description",
value: "CV",
},
{
label: "Robotics",
description: "This is also a description",
value: "RO",
},
// {
// label: 'Natural Language Processing',
// description: 'This is also a description',
// value: 'NLP',
// },
// {
// label: 'Speech Processing',
// description: 'This is also a description',
// value: 'SP',
// }
])
);
message.reply({ content: "Here's a list of domains:", components: [row] });
client.on("interactionCreate", async (interaction) => {
if (!interaction.isSelectMenu()) return;
// console.log(interaction)
//get elements from doc if sub is equal to interaction.values[0]
const sub = interaction.values[0];
const sub_list = conference_doc.filter(function (conference) {
return conference.sub === sub;
});
console.log(sub);
console.log(sub_list);
conference_embed = new MessageEmbed()
.setColor(colors[Math.floor(Math.random() * colors.length)])
.setTitle(domains[sub][0])
.setDescription("Upcoming Conferences:" + "\n")
.setThumbnail(domains[sub][1])
.addFields(
{
name:
"```" +
sub_list[0].title +
"```" +
" held from " +
sub_list[0].date,
value: sub_list[0].link,
inline: false,
}
//// { name: '\u200B', value: '\u200B' },
// {
// name:
// "```" +
// sub_list[1].title +
// "```" +
// " held from " +
// sub_list[1].date,
// value: sub_list[1].link,
// inline: false,
// }
);
//Here there's an error, and i don't know why it occurs, but catching it stops the program from crashing
interaction
.update({
content: "Here's what I found",
embeds: [conference_embed],
components: [],
ephemeral: true,
})
.then()
.catch(console.error);
});
} else if (command === "conferences") {
console.log(conference_doc);
// inside a command, event listener, etc.
const embed = new MessageEmbed()
.setColor("#8c52ff")
.setTitle("Upcoming Conferences")
.setDescription("These are 5 upcoming conferences")
.setThumbnail("https://i.imgur.com/eBiE8DT.png")
.addFields(
{
name:
"```" +
conference_doc[0].title +
"```" +
" held from " +
conference_doc[0].date,
value: conference_doc[0].link,
inline: false,
},
//// { name: '\u200B', value: '\u200B' },
{
name:
"```" +
conference_doc[1].title +
"```" +
" held from " +
conference_doc[1].date,
value: conference_doc[1].link,
inline: false,
},
//// { name: '\u200B', value: '\u200B' },
{
name:
"```" +
conference_doc[2].title +
"```" +
" held from " +
conference_doc[2].date,
value: conference_doc[2].link,
inline: false,
},
//// { name: '\u200B', value: '\u200B' },
{
name:
"```" +
conference_doc[3].title +
"```" +
" held from " +
conference_doc[3].date,
value: conference_doc[3].link,
inline: false,
},
//// { name: '\u200B', value: '\u200B' },
{
name:
"```" +
conference_doc[4].title +
"```" +
" held from " +
conference_doc[4].date,
value: conference_doc[4].link,
inline: false,
}
//// { name: '\u200B', value: '\u200B' },
)
.setTimestamp()
.setFooter({
text: "Research et Al",
iconURL: "https://i.imgur.com/eBiE8DT.png",
});
channel.send({ embeds: [embed] });
} else if (command === "instagram") {
const embed = new MessageEmbed()
.setColor("#8c52ff")
.setTitle("Instagram")
.setDescription("This is the link to our Instagram page")
.setThumbnail(
"https://upload.wikimedia.org/wikipedia/commons/thumb/a/a5/Instagram_icon.png/1024px-Instagram_icon.png"
)
.addFields({
name: "Link",
value: "https://www.instagram.com/research_et_al/",
inline: false,
})
.setTimestamp()
.setFooter({
text: "Research et Al",
iconURL: "https://i.imgur.com/eBiE8DT.png",
});
channel.send({ embeds: [embed] });
} else if (command === "github") {
const embed = new MessageEmbed()
.setColor("#8c52ff")
.setTitle("Github")
.setDescription("This is the link to our Github page")
.setThumbnail(
"https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png"
)
.addFields({
name: "Link",
value: "https://github.com/Research-Et-Al",
inline: false,
})
.setTimestamp()
.setFooter({
text: "Research et Al",
iconURL: "https://i.imgur.com/eBiE8DT.png",
});
channel.send({ embeds: [embed] });
} else if (command === "linkedin") {
const embed = new MessageEmbed()