· 6 years ago · Mar 21, 2020, 08:06 PM
1// Global Definitions
2
3const Util = require("discord.js");
4const Discord = require("discord.js");
5const client = new Discord.Client();
6const ytdl = require("ytdl-core");
7const YouTube = require("simple-youtube-api");
8const randomPuppy = require("random-puppy");
9const urban = require("urban");
10const { stripIndents } = require("common-tags");
11const weather = require("weather-js");
12const DBL = require("dblapi.js");
13const dbl = new DBL(process.env.DBTOKEN, client);
14const fetch = require("node-fetch");
15const queue = new Map();
16const youtube = new YouTube(process.env.GOOGLEAPI);
17const emojiNext = "➡"; // Unicodes are auto identified in Discord, so it's fine!
18const emojiPrevious = "⬅";
19const reactionArrow = [emojiPrevious, emojiNext];
20const time = 600000; // Menu Timeout: 10 Minutes
21const http = require("http");
22const express = require("express");
23`1`;
24const app = express();
25app.get("/", (request, response) => {
26 console.log(Date.now() + " Ping Received");
27 response.sendStatus(200);
28});
29app.listen(process.env.PORT);
30const opts = {
31 maxResults: 25,
32 key: process.env.YOUTUBE,
33 type: "video"
34};
35const prefix = "rh!";
36const owner = "Raymond#9533";
37let cooldown = new Set();
38// Console Logging
39
40client.once("ready", () => {
41 console.log("Ready!");
42 console.log(
43 `The bot is currently serviing ${client.users.size} users, in ${client.guilds.size} servers.`
44 );
45 client.user.setPresence({ activity: { name: "rh!help | hackerman14.tk" }, status: "dnd" })
46 .then(console.log)
47 .catch(console.error);
48});
49client.once("reconnecting", () => {
50 console.log("Reconnecting!");
51});
52client.once("disconnect", () => {
53 console.log("Disconnect!");
54});
55client.on("warn", console.warn);
56client.on("error", console.error);
57client.on("uncaughtException", err => {
58 console.log(err);
59 process.exit(1);
60});
61dbl.on("posted", () => {
62 console.log("Server count is posted on TOP.gg!");
63});
64dbl.on("error", e => {
65 console.log(`An error occurred to TOP.gg! ${e}`);
66});
67
68// Client Codes
69
70client.on("message", async message => {
71 // Client Rules
72
73 let msg = message.content.toLowerCase();
74 if (message.author.bot) return;
75 if (!message.guild) return;
76 if (!message.content.startsWith(prefix)) return;
77 var args = message.content.split(" ").slice(1);
78 const channel = message.channel;
79 const args1 = message.content.split(" ");
80 const searchString = args1.slice(1).join(" ");
81 const url = args1[1] ? args1[1].replace(/<(.+)>/g, "$1") : "";
82 const serverQueue = queue.get(message.guild.id);
83
84 // Commands Cooldown & All Commands
85
86 if (cooldown.has(message.author.id)) {
87 message.channel.send({
88 embed: {
89 color: Math.floor(Math.random() * 16777214) + 1,
90 title: "**Command Cooldown**",
91 description:
92 "Dude you have to wait 1 seconds before you can do another command!",
93 timestamp: new Date(),
94 footer: {
95 text: "Made with ❤️ created by " + owner
96 }
97 }
98 });
99 } else {
100 // Every commands goes here!
101
102 // DM
103
104 if (message.channel.type == "dm") {
105 message.author.send({
106 embed: {
107 color: Math.floor(Math.random() * 16777214) + 1,
108 title: "**OK Boomer**",
109 description: "You realise that I don't work in DMs...",
110 timestamp: new Date(),
111 footer: {
112 text: "Made with ❤️ created by" + owner
113 }
114 }
115 });
116 }
117
118 // Commands
119
120 if (msg.startsWith(`${prefix}help`)) {
121 sendList(channel, getList);
122 return;
123 }
124
125 if (msg.startsWith(`${prefix}about`)) {
126 message.channel.send({
127 embed: {
128 color: Math.floor(Math.random() * 16777214) + 1,
129 title: "**About This Bot**",
130 description: "The information about this bot!",
131 thumbnail: {
132 url: client.user.displayAvatarURL
133 },
134 fields: [
135 {
136 name: "Bot Name",
137 value: "hackerman14"
138 },
139 {
140 name: "Bot Since",
141 value: "September 7, 2019 at 3:22:08 AM"
142 },
143 {
144 name: "Creator",
145 value: "[" + owner + "](https://raymond-1227.github.io)"
146 },
147 {
148 name: "Host",
149 value: "[Glitch.com](https://glitch.com)"
150 },
151 {
152 name: "Always Online",
153 value: "[UptimeRobot](https://uptimerobot.com)"
154 },
155 {
156 name: "Code Sources",
157 value:
158 "[GitHub/raymond-1227/hackerman14-bot](https://github.com/raymond-1227/hackerman14-bot)"
159 },
160 {
161 name: "Library",
162 value: "[Discord.js](https://discord.js.org)"
163 }
164 ],
165 timestamp: new Date(),
166 footer: {
167 text: "Made with ❤️ created by " + owner
168 }
169 }
170 });
171 }
172
173 if (msg.startsWith(`${prefix}facts`)) {
174 fetch("https://useless-facts.sameerkumar.website/api")
175 .then(res => res.json())
176 .then(body => {
177 message.channel.send({
178 embed: {
179 color: Math.floor(Math.random() * 16777214) + 1,
180 title: "**Boring Facts**",
181 description: body.data,
182 timestamp: new Date(),
183 footer: {
184 text: "Made with ❤️ created by " + owner
185 }
186 }
187 });
188 });
189 }
190
191 if (msg.startsWith(`${prefix}skeppy`)) {
192 var answers = [
193 "flip flop",
194 "14",
195 "ping spoofing",
196 "turtle",
197 "daddy",
198 "BadBoyHalo",
199 "BadBoyHalo is a potato",
200 "Jif",
201 "I was testing",
202 "cheesy fries",
203 "slash slash undo",
204 "idot",
205 "sotp",
206 "pine cone",
207 "thin crust pizza",
208 "ding",
209 "oh my godness",
210 "candad",
211 "muffintop",
212 "muffin",
213 "bisector",
214 "photosynthesis",
215 "slash slash sudo",
216 "CryBoyHalo",
217 "muffin time",
218 "uh oh spaghettios",
219 "japenese symbol for beginner",
220 "diameter",
221 "perpendicularity",
222 "hi im the real skeppy",
223 "like or die tmr",
224 "heal pool",
225 "bald",
226 "fish in a bucket",
227 "golden helmet",
228 "a6d's little brother",
229 "BaldBoyHalo",
230 "magnifying glass tilted left",
231 "magnifying glass tilted right",
232 "f",
233 "japanese symbol for beginner",
234 "DrunkBoyHalo",
235 "oh neat, hieroglyphs",
236 "a apollonian gasket",
237 "Rhobicosidodecahedron",
238 "minecraft but",
239 "do not do that"
240 ];
241 var randomAnswer = answers[Math.floor(Math.random() * answers.length)];
242 message.channel.send({
243 embed: {
244 color: Math.floor(Math.random() * 16777214) + 1,
245 title: "**Skeppy Memes**",
246 description: randomAnswer,
247 timestamp: new Date(),
248 footer: {
249 text: "Made with ❤️ created by " + owner
250 }
251 }
252 });
253 }
254
255 if (msg.startsWith(`${prefix}ping`)) {
256 let m = await message.channel.send({
257 embed: {
258 color: Math.floor(Math.random() * 16777214) + 1,
259 title: "**Lag Machine**",
260 description: "Ping?",
261 timestamp: new Date(),
262 footer: {
263 text: "Made with ❤️ created by " + owner
264 }
265 }
266 });
267 m.edit({
268 embed: {
269 color: Math.floor(Math.random() * 16777214) + 1,
270 title: "**Lag Machine**",
271 description: "Pong!",
272 fields: [
273 {
274 name: "Latency",
275 value: `${m.createdTimestamp - message.createdTimestamp}ms`
276 },
277 {
278 name: "API Latency",
279 value: `${Math.round(client.ws.ping)}ms`
280 }
281 ],
282 timestamp: new Date(),
283 footer: {
284 text: "Made with ❤️ created by " + owner
285 }
286 }
287 });
288 }
289
290 if (msg.startsWith(`${prefix}8`)) {
291 const sayMessage = args.join(" ");
292 var answers = [
293 "It is certain.",
294 "It is decidedly so.",
295 "Without a doubt.",
296 "Yes - definitely.",
297 "You may rely on it.",
298 "As I see it, yes.",
299 "Most likely.",
300 "Outlook good.",
301 "Yes",
302 "Signs point to yes.",
303 "Reply hazy, try again.",
304 "Ask again later.",
305 "Better not tell you now.",
306 "Cannot predict now.",
307 "Concentrate and ask again.",
308 "Don't count on it.",
309 "My reply is no.",
310 "My sources say no.",
311 "Outlook not so good.",
312 "Very doubtful."
313 ];
314 var randomAnswer = answers[Math.floor(Math.random() * answers.length)];
315
316 if (!args[0])
317 return message.channel.send({
318 embed: {
319 color: Math.floor(Math.random() * 16777214) + 1,
320 title: "**The Legendary 8 Ball**",
321 description: "You need to say something for the bot to response!",
322 timestamp: new Date(),
323 footer: {
324 text: "Made with ❤️ created by " + owner
325 }
326 }
327 });
328
329 message.channel.send({
330 embed: {
331 color: Math.floor(Math.random() * 16777214) + 1,
332 title: "**The Legendary 8 Ball**",
333 description: "This smart ball has something to tell you.",
334 fields: [
335 {
336 name: "Your Question",
337 value: sayMessage
338 },
339 {
340 name: "The 8 Ball's Big Words",
341 value: randomAnswer
342 }
343 ],
344 timestamp: new Date(),
345 footer: {
346 text: "Made with ❤️ created by " + owner
347 }
348 }
349 });
350 }
351
352 if (msg.startsWith(`${prefix}gif`)) {
353 fetch(process.env.GIPHY)
354 .then(res => res.json())
355 .then(body => {
356 message.channel.send({
357 embed: {
358 color: Math.floor(Math.random() * 16777214) + 1,
359 title: "**Random GIF**",
360 description: "Here's your GIF!",
361 timestamp: new Date(),
362 image: {
363 url: body.data.image_original_url
364 },
365 footer: {
366 text: "Made with ❤️ created by " + owner
367 }
368 }
369 });
370 });
371 }
372
373 if (msg.startsWith(`${prefix}sembed`)) {
374 const exampleEmbed = {
375 color: 0x0099ff,
376 title: "Some title",
377 url: "https://discord.js.org",
378 author: {
379 name: "Some name",
380 icon_url: "https://i.imgur.com/wSTFkRM.png",
381 url: "https://discord.js.org"
382 },
383 description: "Some description here",
384 thumbnail: {
385 url: "https://i.imgur.com/wSTFkRM.png"
386 },
387 fields: [
388 {
389 name: "Regular field title",
390 value: "Some value here"
391 },
392 {
393 name: "\u200b",
394 value: "\u200b"
395 },
396 {
397 name: "Inline field title",
398 value: "Some value here",
399 inline: true
400 },
401 {
402 name: "Inline field title",
403 value: "Some value here",
404 inline: true
405 },
406 {
407 name: "Inline field title",
408 value: "Some value here",
409 inline: true
410 }
411 ],
412 image: {
413 url: "https://i.imgur.com/wSTFkRM.png"
414 },
415 timestamp: new Date(),
416 footer: {
417 text: "Some footer text here",
418 icon_url: "https://i.imgur.com/wSTFkRM.png"
419 }
420 };
421
422 message.channel.send({ embed: exampleEmbed });
423 }
424
425 if (msg.startsWith(`${prefix}user`)) {
426 var member = message.mentions.users.first() || message.author;
427 var userCreated = member.createdAt.toString().split(" ");
428 message.channel.send({
429 embed: {
430 color: Math.floor(Math.random() * 16777214) + 1,
431 title: "**User Information**",
432 description: "Here's the user information!",
433 thumbnail: {
434 url: member.avatarURL
435 },
436 fields: [
437 {
438 name: "Username + Tag",
439 value: member.tag
440 },
441 {
442 name: "User ID",
443 value: member.id
444 },
445 {
446 name: "Account Since",
447 value:
448 userCreated[1] + " " + userCreated[2] + ", " + userCreated[3]
449 },
450 {
451 name: "Game Presence",
452 value: member.presence.game ? member.presence.game.name : "none"
453 }
454 ],
455 timestamp: new Date(),
456 footer: {
457 text: "Made with ❤️ created by " + owner
458 }
459 }
460 });
461 }
462
463 if (msg.startsWith(`${prefix}server`)) {
464 var serverCreated = message.guild.createdAt.toString().split(" ");
465 let region = {
466 brazil: ":flag_br: Brazil",
467 "eu-central": ":flag_eu: Central Europe",
468 singapore: ":flag_sg: Singapore",
469 "us-central": ":flag_us: U.S. Central",
470 sydney: ":flag_au: Sydney",
471 "us-east": ":flag_us: U.S. East",
472 "us-south": ":flag_us: U.S. South",
473 "us-west": ":flag_us: U.S. West",
474 "eu-west": ":flag_eu: Western Europe",
475 "vip-us-east": ":flag_us: VIP U.S. East",
476 london: ":flag_gb: London",
477 amsterdam: ":flag_nl: Amsterdam",
478 hongkong: ":flag_hk: Hong Kong",
479 russia: ":flag_ru: Russia",
480 southafrica: ":flag_za: South Africa"
481 };
482 message.channel.send({
483 embed: {
484 color: Math.floor(Math.random() * 16777214) + 1,
485 title: "**Server Information**",
486 description: "Here's the server information!",
487 fields: [
488 {
489 name: "Server Name",
490 value: message.guild.name
491 },
492 {
493 name: "Server ID",
494 value: message.guild.id
495 },
496 {
497 name: "Server Since",
498 value:
499 serverCreated[1] +
500 " " +
501 serverCreated[2] +
502 ", " +
503 serverCreated[3]
504 },
505 {
506 name: "Server Owner",
507 value: message.guild.owner.user
508 },
509 {
510 name: "Server Owner's User ID",
511 value: message.guild.owner.id
512 },
513 {
514 name: "Server Region",
515 value: region[message.guild.region]
516 },
517 {
518 name: "Total Members",
519 value: message.guild.memberCount
520 },
521 {
522 name: "Total Channels",
523 value: message.guild.channels.cache.size
524 },
525 {
526 name: "Total Roles",
527 value: message.guild.roles.cache.size
528 },
529 {
530 name: "AFK Channel",
531 value: message.guild.afkChannel
532 }
533 ],
534 timestamp: new Date(),
535 footer: {
536 text: "Made with ❤️ created by " + owner
537 }
538 }
539 });
540 }
541
542 if (msg.startsWith(`${prefix}say`)) {
543 const sayMessage = args.join(" ");
544 if (!args[0])
545 return message.channel
546 .send({
547 embed: {
548 color: Math.floor(Math.random() * 16777214) + 1,
549 title: "**Action Copy Cat**",
550 description: "You need to say something for the bot to say!",
551 timestamp: new Date(),
552 footer: {
553 text: "Made with ❤️ created by " + owner
554 }
555 }
556 })
557 .then(msg => {
558 msg.delete(10000);
559 });
560 message.delete().catch(O_o => {});
561 message.channel.send(sayMessage);
562 }
563
564 if (msg.startsWith(`${prefix}meme`)) {
565 const subReddits = [
566 "dankmeme",
567 "memes",
568 "me_irl",
569 "AdviceAnimals",
570 "MemeEconomy",
571 "ComedyCemetery",
572 "PrequelMemes",
573 "terriblefacebookmemes",
574 "PewdiepieSubmissions",
575 "funny",
576 "teenagers"
577 ];
578 const random = subReddits[Math.floor(Math.random() * subReddits.length)];
579 const meme = await randomPuppy(random);
580 message.channel.send({
581 embed: {
582 color: Math.floor(Math.random() * 16777214) + 1,
583 title: "**Reddit Memes**",
584 description: `A meme from /r/${random}`,
585 timestamp: new Date(),
586 image: {
587 url: meme
588 },
589 footer: {
590 text: "Made with ❤️ created by " + owner
591 }
592 }
593 });
594 }
595
596 if (msg.startsWith(`${prefix}weather`)) {
597 weather.find({ search: args.join(" "), degreeType: "F" }),
598 function(err, result) {
599 if (err) console.log(err);
600 if (!args[0]) return;
601 console.log(JSON.stringify(result, null, 2));
602
603 var location = result[0].location;
604 var current = result[0].current;
605
606 message.channel.send({
607 embed: {
608 color: Math.floor(Math.random() * 16777214) + 1,
609 title: "**Weather Forecast**",
610 description: `${current.skytext}`,
611 author: { name: `Weather for ${current.observationpoint}` },
612 thumbnail: current.imageUrl,
613 fields: [
614 {
615 name: "Timezone",
616 value: `UTC${current.timezone}`,
617 inline: true
618 },
619 {
620 name: "Degree Type",
621 value: location.degreeType,
622 inline: true
623 },
624 {
625 name: "Temperature",
626 value: `${current.temperature} Degrees`,
627 inline: true
628 },
629 {
630 name: "Feels Like",
631 value: `${current.feelslike} Degrees`,
632 inline: true
633 },
634 {
635 name: "Winds",
636 value: current.winddisplay,
637 inline: true
638 },
639 {
640 name: "Humidity",
641 value: `${current.humidity}%`,
642 inline: true
643 }
644 ],
645 timestamp: new Date(),
646 footer: {
647 text: "Made with ❤️ created by " + owner
648 }
649 }
650 });
651 };
652 }
653
654 if (msg.startsWith(`${prefix}uptime`)) {
655 let totalSeconds = client.uptime / 1000;
656 let days = Math.floor(totalSeconds / 86400);
657 let hours = Math.floor(totalSeconds / 3600);
658 totalSeconds %= 3600;
659 let minutes = Math.floor(totalSeconds / 60);
660 let seconds = totalSeconds % 60;
661 let roundedSeconds = Math.round(seconds);
662 let uptime = `${days} days, ${hours} hours, ${minutes} minutes and ${seconds} seconds`;
663 message.channel.send({
664 embed: {
665 color: Math.floor(Math.random() * 16777214) + 1,
666 title: "**Time Tracker**",
667 description: `The bot has stayed on for ${uptime}!`,
668 timestamp: new Date(),
669 footer: {
670 text: "Made with ❤️ created by " + owner
671 }
672 }
673 });
674 }
675
676 if (msg.startsWith(`${prefix}joke`)) {
677 fetch("https://api.icndb.com/jokes/random")
678 .then(res => res.json())
679 .then(body => {
680 message.channel.send({
681 embed: {
682 color: Math.floor(Math.random() * 16777214) + 1,
683 title: "**Dumb Jokes**",
684 description: body.data,
685 timestamp: new Date(),
686 footer: {
687 text: "Made with ❤️ created by " + owner
688 }
689 }
690 });
691 });
692 }
693
694 if (msg.startsWith(`${prefix}urban`)) {
695 if (!message.channel.nsfw)
696 return message.channel.send({
697 embed: {
698 color: Math.floor(Math.random() * 16777214) + 1,
699 title: "**Urban Dictionary**",
700 description:
701 "Due to some NSFW words definition, so please run this in a NSFW channel!",
702 timestamp: new Date(),
703 footer: {
704 text: "Made with ❤️ created by " + owner
705 }
706 }
707 });
708
709 if (args < 1 || !["random", "search"].includes(args[0]))
710 return message.channel.send({
711 embed: {
712 color: Math.floor(Math.random() * 16777214) + 1,
713 title: "**Urban Dictionary**",
714 description: "Please enter something in order to search!",
715 timestamp: new Date(),
716 footer: {
717 text: "Made with ❤️ created by " + owner
718 }
719 }
720 });
721
722 let search = args[1] ? urban(args.slice(1).join(" ")) : urban.random();
723 try {
724 search.first(res => {
725 if (!res)
726 return message.channel.send({
727 embed: {
728 color: Math.floor(Math.random() * 16777214) + 1,
729 title: "**Urban Dictionary**",
730 description: "No results found for this topic!",
731 timestamp: new Date(),
732 footer: {
733 text: "Made with ❤️ created by " + owner
734 }
735 }
736 });
737
738 let {
739 word,
740 definition,
741 example,
742 thumbs_up,
743 thumbs_down,
744 permalink,
745 author
746 } = res;
747
748 let urbanEmbed = new Discord.MessageEmbed({
749 color: Math.floor(Math.random() * 16777214) + 1,
750 title: "**Urban Dictionary**",
751 description: "Here's the definition!",
752 thumbnail: {
753 url: "https://file.coffee/u/Q39Od2R9wwf.png"
754 },
755 fields: [
756 {
757 name: "Word",
758 value: word
759 },
760 {
761 name: "Definition",
762 value: definition || "No definition given"
763 },
764 {
765 name: "Word Example",
766 value: example || "No example given"
767 },
768 {
769 name: "Upvotes",
770 value: thumbs_up || 0
771 },
772 {
773 name: "Downvotes",
774 value: thumbs_down || 0
775 },
776 {
777 name: "Link to the word",
778 value: `[${word}](${permalink ||
779 "https://urbandictionary.com"})`
780 },
781 {
782 name: "Author",
783 value: author || "Unknown"
784 }
785 ],
786 timestamp: new Date(),
787 footer: {
788 text: "Made with ❤️ created by " + owner
789 }
790 });
791 message.channel.send(urbanEmbed);
792 });
793 } catch (e) {
794 console.log(e);
795 return message.channel.send({
796 embed: {
797 color: Math.floor(Math.random() * 16777214) + 1,
798 title: "**Urban Dictionary**",
799 description: "An error occured, please try again!",
800 timestamp: new Date(),
801 footer: {
802 text: "Made with ❤️ created by " + owner
803 }
804 }
805 });
806 }
807 }
808
809 // Music Commands
810
811 if (msg.startsWith(`${prefix}play`)) {
812 const voiceChannel = message.member.voice.channel;
813 if (!voiceChannel)
814 return message.channel.send({
815 embed: {
816 color: Math.floor(Math.random() * 16777214) + 1,
817 title: "**Windows Media Player**",
818 description:
819 "I'm sorry but you need to be in a voice channel to play music!",
820 timestamp: new Date(),
821 footer: {
822 text: "Made with ❤️ created by " + owner
823 }
824 }
825 });
826 const permissions = voiceChannel.permissionsFor(message.client.user);
827 if (!permissions.has("CONNECT")) {
828 return message.channel.send({
829 embed: {
830 color: Math.floor(Math.random() * 16777214) + 1,
831 title: "**Windows Media Player**",
832 description:
833 "I cannot connect to your voice channel, make sure I have the proper permissions!",
834 timestamp: new Date(),
835 footer: {
836 text: "Made with ❤️ created by " + owner
837 }
838 }
839 });
840 }
841 if (!permissions.has("SPEAK")) {
842 return message.channel.send({
843 embed: {
844 color: Math.floor(Math.random() * 16777214) + 1,
845 title: "**Windows Media Player**",
846 description:
847 "I cannot speak in this voice channel, make sure I have the proper permissions!",
848 timestamp: new Date(),
849 footer: {
850 text: "Made with ❤️ created by " + owner
851 }
852 }
853 });
854 }
855
856 if (
857 url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)
858 ) {
859 const playlist = await youtube.getPlaylist(url);
860 const videos = await playlist.getVideos();
861 for (const video of Object.values(videos)) {
862 const video2 = await youtube.getVideoByID(video.id); // eslint-disable-line no-await-in-loop
863 await handleVideo(video2, message, voiceChannel, true); // eslint-disable-line no-await-in-loop
864 }
865 return message.channel.send({
866 embed: {
867 color: Math.floor(Math.random() * 16777214) + 1,
868 title: "**Windows Media Player**",
869 description: `✅ Playlist: **${playlist.title}** has been added to the queue!`,
870 timestamp: new Date(),
871 footer: {
872 text: "Made with ❤️ created by " + owner
873 }
874 }
875 });
876 } else {
877 try {
878 var video = await youtube.getVideo(url);
879 } catch (error) {
880 try {
881 var videos = await youtube.searchVideos(searchString, 10);
882 let index = 0;
883 message.channel.send({
884 embed: {
885 color: Math.floor(Math.random() * 16777214) + 1,
886 title: "**Windows Media Player**",
887 description:
888 "Please provide a value to select one of the search results ranging from 1-10!",
889 fields: [
890 {
891 name: "Song Selection",
892 value: `${videos
893 .map(video2 => `**${++index} -** ${video2.title}`)
894 .join("\n")}`
895 }
896 ],
897 timestamp: new Date(),
898 footer: {
899 text: "Made with ❤️ created by " + owner
900 }
901 }
902 });
903 // eslint-disable-next-line max-depth
904 try {
905 var response = await message.channel.awaitMessages(
906 msg2 => msg2.content > 0 && msg2.content < 11,
907 {
908 max: 1,
909 time: 10000,
910 errors: ["time"]
911 }
912 );
913 } catch (err) {
914 console.error(err);
915 return message.channel.send({
916 embed: {
917 color: Math.floor(Math.random() * 16777214) + 1,
918 title: "**Windows Media Player**",
919 description:
920 "No or invalid value entered, cancelling video selection!",
921 timestamp: new Date(),
922 footer: {
923 text: "Made with ❤️ created by " + owner
924 }
925 }
926 });
927 }
928 const videoIndex = parseInt(response.first().content);
929 var video = await youtube.getVideoByID(videos[videoIndex - 1].id);
930 } catch (err) {
931 console.error(err);
932 return message.channel.send({
933 embed: {
934 color: Math.floor(Math.random() * 16777214) + 1,
935 title: "**Windows Media Player**",
936 description: "I could not obtain any search results!",
937 timestamp: new Date(),
938 footer: {
939 text: "Made with ❤️ created by " + owner
940 }
941 }
942 });
943 }
944 }
945 return handleVideo(video, message, voiceChannel);
946 }
947 } else if (msg.startsWith(`${prefix}skip`)) {
948 if (!message.member.voiceChannel)
949 return message.channel.send({
950 embed: {
951 color: Math.floor(Math.random() * 16777214) + 1,
952 title: "**Windows Media Player**",
953 description: "You are not in a voice channel!",
954 timestamp: new Date(),
955 footer: {
956 text: "Made with ❤️ created by " + owner
957 }
958 }
959 });
960 if (!serverQueue)
961 return message.channel.send({
962 embed: {
963 color: Math.floor(Math.random() * 16777214) + 1,
964 title: "**Windows Media Player**",
965 description: "There is nothing playing that I can skip for you!",
966 timestamp: new Date(),
967 footer: {
968 text: "Made with ❤️ created by " + owner
969 }
970 }
971 });
972 serverQueue.connection.dispatcher.end("Skip command has been used!");
973 return undefined;
974 } else if (msg.startsWith(`${prefix}stop`)) {
975 if (!message.member.voiceChannel)
976 return message.channel.send({
977 embed: {
978 color: Math.floor(Math.random() * 16777214) + 1,
979 title: "**Windows Media Player**",
980 description: "You are not in a voice channel!",
981 timestamp: new Date(),
982 footer: {
983 text: "Made with ❤️ created by " + owner
984 }
985 }
986 });
987 if (!serverQueue)
988 return message.channel.send({
989 embed: {
990 color: Math.floor(Math.random() * 16777214) + 1,
991 title: "**Windows Media Player**",
992 description: "There is nothing playing that I can stop for you!",
993 timestamp: new Date(),
994 footer: {
995 text: "Made with ❤️ created by " + owner
996 }
997 }
998 });
999 serverQueue.songs = [];
1000 serverQueue.connection.dispatcher.end("Stop command has been used!");
1001 return undefined;
1002 } else if (msg.startsWith(`${prefix}volume`)) {
1003 if (!message.member.voiceChannel)
1004 return message.channel.send({
1005 embed: {
1006 color: Math.floor(Math.random() * 16777214) + 1,
1007 title: "**Windows Media Player**",
1008 description: "You are not in a voice channel!",
1009 timestamp: new Date(),
1010 footer: {
1011 text: "Made with ❤️ created by " + owner
1012 }
1013 }
1014 });
1015 if (!serverQueue)
1016 return message.channel.send({
1017 embed: {
1018 color: Math.floor(Math.random() * 16777214) + 1,
1019 title: "**Windows Media Player**",
1020 description: "There is nothing playing!",
1021 timestamp: new Date(),
1022 footer: {
1023 text: "Made with ❤️ created by " + owner
1024 }
1025 }
1026 });
1027 if (!args1[1])
1028 return message.channel.send({
1029 embed: {
1030 color: Math.floor(Math.random() * 16777214) + 1,
1031 title: "**Windows Media Player**",
1032 description: `The current volume is **${serverQueue.volume}**!`,
1033 timestamp: new Date(),
1034 footer: {
1035 text: "Made with ❤️ created by " + owner
1036 }
1037 }
1038 });
1039 serverQueue.volume = args1[1];
1040 serverQueue.connection.dispatcher.setVolumeLogarithmic(args1[1] / 5);
1041 return message.channel.send({
1042 embed: {
1043 color: Math.floor(Math.random() * 16777214) + 1,
1044 title: "**Windows Media Player**",
1045 description: `I set the volume to **${args1[1]}**`,
1046 timestamp: new Date(),
1047 footer: {
1048 text: "Made with ❤️ created by " + owner
1049 }
1050 }
1051 });
1052 } else if (msg.startsWith(`${prefix}nowplaying`)) {
1053 if (!serverQueue)
1054 return message.channel.send({
1055 embed: {
1056 color: Math.floor(Math.random() * 16777214) + 1,
1057 title: "**Windows Media Player**",
1058 description: "There is nothing playing!",
1059 timestamp: new Date(),
1060 footer: {
1061 text: "Made with ❤️ created by " + owner
1062 }
1063 }
1064 });
1065 return message.channel.send({
1066 embed: {
1067 color: Math.floor(Math.random() * 16777214) + 1,
1068 title: "**Windows Media Player**",
1069 description: `Now playing: **${serverQueue.songs[0].title}**!`,
1070 timestamp: new Date(),
1071 footer: {
1072 text: "Made with ❤️ created by " + owner
1073 }
1074 }
1075 });
1076 } else if (msg.startsWith(`${prefix}queue`)) {
1077 if (!serverQueue)
1078 return message.channel.send({
1079 embed: {
1080 color: Math.floor(Math.random() * 16777214) + 1,
1081 title: "**Windows Media Player**",
1082 description: "There is nothing playing!",
1083 timestamp: new Date(),
1084 footer: {
1085 text: "Made with ❤️ created by " + owner
1086 }
1087 }
1088 });
1089 return message.channel.send({
1090 embed: {
1091 color: Math.floor(Math.random() * 16777214) + 1,
1092 title: "**Windows Media Player**",
1093 description: `Now playing: ${serverQueue.songs[0].title}`,
1094 fields: [
1095 {
1096 name: "Song Queue",
1097 value: `${serverQueue.songs
1098 .map(song => `**-** ${song.title}`)
1099 .join("\n")}`
1100 }
1101 ],
1102 timestamp: new Date(),
1103 footer: {
1104 text: "Made with ❤️ created by " + owner
1105 }
1106 }
1107 });
1108 } else if (msg.startsWith(`${prefix}pause`)) {
1109 if (serverQueue && serverQueue.playing) {
1110 serverQueue.playing = false;
1111 serverQueue.connection.dispatcher.pause();
1112 return message.channel.send({
1113 embed: {
1114 color: Math.floor(Math.random() * 16777214) + 1,
1115 title: "**Windows Media Player**",
1116 description: "Paused the music for you!",
1117 timestamp: new Date(),
1118 footer: {
1119 text: "Made with ❤️ created by " + owner
1120 }
1121 }
1122 });
1123 }
1124 return message.channel.send({
1125 embed: {
1126 color: Math.floor(Math.random() * 16777214) + 1,
1127 title: "**Windows Media Player**",
1128 description: "There is nothing playing!",
1129 timestamp: new Date(),
1130 footer: {
1131 text: "Made with ❤️ created by " + owner
1132 }
1133 }
1134 });
1135 } else if (msg.startsWith(`${prefix}resume`)) {
1136 if (serverQueue && !serverQueue.playing) {
1137 serverQueue.playing = true;
1138 serverQueue.connection.dispatcher.resume();
1139 return message.channel.send({
1140 embed: {
1141 color: Math.floor(Math.random() * 16777214) + 1,
1142 title: "**Windows Media Player**",
1143 description: "▶ Resumed the music for you!",
1144 timestamp: new Date(),
1145 footer: {
1146 text: "Made with ❤️ created by " + owner
1147 }
1148 }
1149 });
1150 }
1151 return message.channel.send({
1152 embed: {
1153 color: Math.floor(Math.random() * 16777214) + 1,
1154 title: "**Windows Media Player**",
1155 description: "There is nothing playing!",
1156 timestamp: new Date(),
1157 footer: {
1158 text: "Made with ❤️ created by " + owner
1159 }
1160 }
1161 });
1162 }
1163
1164 return undefined;
1165
1166 // Adds the user to the set so that they can't talk for a minute
1167 cooldown.add(message.author.id);
1168 setTimeout(() => {
1169 // Removes the user from the set after a minute
1170 cooldown.delete(message.author.id);
1171 }, 1000);
1172 }
1173});
1174
1175// Functions
1176
1177async function handleVideo(video, message, voiceChannel, playlist = false) {
1178 const serverQueue = queue.get(message.guild.id);
1179 console.log(video);
1180 const song = {
1181 id: video.id,
1182 title: Util.escapeMarkdown(video.title),
1183 url: `https://www.youtube.com/watch?v=${video.id}`
1184 };
1185 if (!serverQueue) {
1186 const queueConstruct = {
1187 textChannel: message.channel,
1188 voiceChannel: voiceChannel,
1189 connection: null,
1190 songs: [],
1191 volume: 5,
1192 playing: true
1193 };
1194 queue.set(message.guild.id, queueConstruct);
1195
1196 queueConstruct.songs.push(song);
1197
1198 try {
1199 var connection = await voiceChannel.join();
1200 queueConstruct.connection = connection;
1201 play(message.guild, queueConstruct.songs[0]);
1202 } catch (error) {
1203 console.error(`I could not join the voice channel: ${error}`);
1204 queue.delete(message.guild.id);
1205 return message.channel.send({
1206 embed: {
1207 color: Math.floor(Math.random() * 16777214) + 1,
1208 title: "**Windows Media Player**",
1209 description: `I could not join the voice channel: ${error}`,
1210 timestamp: new Date(),
1211 footer: {
1212 text: "Made with ❤️ created by " + owner
1213 }
1214 }
1215 });
1216 }
1217 } else {
1218 serverQueue.songs.push(song);
1219 console.log(serverQueue.songs);
1220 if (playlist) return undefined;
1221 else
1222 return message.channel.send({
1223 embed: {
1224 color: Math.floor(Math.random() * 16777214) + 1,
1225 title: "**Windows Media Player**",
1226 description: `✅ **${song.title}** has been added to the queue!`,
1227 timestamp: new Date(),
1228 footer: {
1229 text: "Made with ❤️ created by " + owner
1230 }
1231 }
1232 });
1233 }
1234 return undefined;
1235}
1236
1237function play(guild, song) {
1238 const serverQueue = queue.get(guild.id);
1239
1240 if (!song) {
1241 serverQueue.voiceChannel.leave();
1242 queue.delete(guild.id);
1243 return;
1244 }
1245 console.log(serverQueue.songs);
1246
1247 const dispatcher = serverQueue.connection
1248 .play(ytdl(song.url))
1249 .on("end", reason => {
1250 if (reason === "Stream is not generating quickly enough.")
1251 console.log("Song ended.");
1252 else console.log(reason);
1253 serverQueue.songs.shift();
1254 play(guild, serverQueue.songs[0]);
1255 })
1256 .on("error", error => console.error(error));
1257 dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
1258
1259 serverQueue.textChannel.send({
1260 embed: {
1261 color: Math.floor(Math.random() * 16777214) + 1,
1262 title: "**Windows Media Player**",
1263 description: `Start playing: **${song.title}**`,
1264 timestamp: new Date(),
1265 footer: {
1266 text: "Made with ❤️ created by " + owner
1267 }
1268 }
1269 });
1270}
1271
1272const embed1 = () =>
1273 new Discord.MessageEmbed({
1274 color: Math.floor(Math.random() * 16777214) + 1,
1275 title: "**Commands List**",
1276 description:
1277 "Here's all the available commands! (Menu timeout is set to 10 minutes!)",
1278 fields: [
1279 {
1280 name: ":robot: Bot Prefix",
1281 value: "`rh!`",
1282 inline: true
1283 },
1284 {
1285 name: ":keyboard: Placeholder Requirements",
1286 value: "`<>` = REQUIRED, `[]` = OPTIONAL",
1287 inline: true
1288 },
1289 {
1290 name: ":information_source: Basic Commands",
1291 value: "Page 2"
1292 },
1293 {
1294 name: ":8ball: Fun Commands",
1295 value: "Page 3"
1296 },
1297 {
1298 name: ":cd: Misc Conmmands",
1299 value: "Page 4"
1300 },
1301 {
1302 name: ":musical_note: Music Commands",
1303 value: "Page 5"
1304 }
1305 ],
1306 timestamp: new Date(),
1307 footer: {
1308 text: "Page 1"
1309 }
1310 });
1311
1312const embed2 = () =>
1313 new Discord.MessageEmbed({
1314 color: Math.floor(Math.random() * 16777214) + 1,
1315 title: ":information_source: **Basic Commands**",
1316 fields: [
1317 {
1318 name: "`rh!help`",
1319 value: "Shows this command list!"
1320 },
1321 {
1322 name: "`rh!about`",
1323 value: "Shows you the info about the bot!"
1324 },
1325 {
1326 name: "`rh!uptime`",
1327 value: "Shows you the uptime of the bot!"
1328 }
1329 ],
1330 timestamp: new Date(),
1331 footer: {
1332 text: "Page 2"
1333 }
1334 });
1335
1336const embed3 = () =>
1337 new Discord.MessageEmbed({
1338 color: Math.floor(Math.random() * 16777214) + 1,
1339 title: ":8ball: **Fun Commands**",
1340 fields: [
1341 {
1342 name: "`rh!facts`",
1343 value: "Tells you a boring fact!"
1344 },
1345 {
1346 name: "`rh!skeppy`",
1347 value: "Tells you a random Skeppy meme!"
1348 },
1349 {
1350 name: "`rh!8`",
1351 value: "Ask any yes/no question, and it will answer you something!"
1352 },
1353 {
1354 name: "`rh!gif`",
1355 value: "Sends you a random GIF!"
1356 },
1357 {
1358 name: "`rh!say <Message>`",
1359 value: "Says something what you say!"
1360 },
1361 {
1362 name: "`rh!meme`",
1363 value: "Tells you a meme from Subreddits!"
1364 }
1365 ],
1366 timestamp: new Date(),
1367 footer: {
1368 text: "Page 3"
1369 }
1370 });
1371
1372const embed4 = () =>
1373 new Discord.MessageEmbed({
1374 color: Math.floor(Math.random() * 16777214) + 1,
1375 title: ":cd: **Misc Commands**",
1376 fields: [
1377 {
1378 name: "`rh!ping`",
1379 value: "Replies you the respond time of the bot!"
1380 },
1381 {
1382 name: "`rh!user [Other Users]`",
1383 value: "Sends your/other's Discord profile information!"
1384 },
1385 {
1386 name: "`rh!server`",
1387 value: "Sends the server's detail"
1388 },
1389 {
1390 name: "`rh!urban <search/random> [query]`",
1391 value: "Search the words across the Urban Dictionary!"
1392 }
1393 ],
1394 timestamp: new Date(),
1395 footer: {
1396 text: "Page 4"
1397 }
1398 });
1399
1400const embed5 = () =>
1401 new Discord.MessageEmbed({
1402 color: Math.floor(Math.random() * 16777214) + 1,
1403 title: ":musical_note: **Music Commands**",
1404 fields: [
1405 {
1406 name: "`rh!play <Song Name>`",
1407 value:
1408 "Plays music through fake Windows Media Player! *(Note: The bot usually lags, please wait a few seconds for the bot to load song.)*"
1409 },
1410 {
1411 name: "`rh!skip`",
1412 value:
1413 "Skips a song from the playlist! *(Note: If there's no more queued songs left, the bot will disconnect from the channel that the bot is in.)*"
1414 },
1415 {
1416 name: "`rh!stop`",
1417 value: "Stops the music player!"
1418 },
1419 {
1420 name: "`rh!volume [Volume]`",
1421 value:
1422 "See/Change the volume of the sound playing from the fake Windows Media Player!"
1423 },
1424 {
1425 name: "`rh!nowplaying`",
1426 value: "Sees what song is currently playing from the playlist!"
1427 },
1428 {
1429 name: "`rh!queue`",
1430 value: "Shows the entire list of the queue!"
1431 },
1432 {
1433 name: "`rh!pause`",
1434 value: "Pauses the song from playing!"
1435 },
1436 {
1437 name: "`rh!resume`",
1438 value: "Resumes the song from playinh"
1439 }
1440 ],
1441 timestamp: new Date(),
1442 footer: {
1443 text: "Page 5"
1444 }
1445 });
1446
1447const list = [embed1, embed2, embed3, embed4, embed5];
1448
1449function getList(i) {
1450 return list[i]()
1451 .setTimestamp()
1452 .setFooter(`Page ${i + 1}`); // i+1 because we start at 0
1453}
1454
1455function filter(reaction, user) {
1456 return !user.bot && reactionArrow.includes(reaction.emoji.name); // check if the emoji is inside the list of emojis, and if the user is not a bot
1457}
1458
1459function onCollect(emoji, message, i, getList) {
1460 if (emoji.name === emojiPrevious && i > 0) {
1461 message.edit(getList(--i));
1462 } else if (emoji.name === emojiNext && i < list.length - 1) {
1463 message.edit(getList(++i));
1464 }
1465 return i;
1466}
1467
1468function createCollectorMessage(message, getList) {
1469 let i = 0;
1470 const collector = message.createReactionCollector(filter, { time });
1471 collector.on("collect", r => {
1472 i = onCollect(r.emoji, message, i, getList);
1473 });
1474 collector.on("end", collected => message.clearReactions());
1475}
1476
1477function sendList(channel, getList) {
1478 channel
1479 .send(getList(0))
1480 .then(msg => msg.react(emojiPrevious))
1481 .then(msgReaction => msgReaction.message.react(emojiNext))
1482 .then(msgReaction => createCollectorMessage(msgReaction.message, getList));
1483}
1484
1485client.login(process.env.DISCORD);