diff --git a/src/modules/music.js b/src/modules/music.js new file mode 100644 index 0000000..90e0a29 --- /dev/null +++ b/src/modules/music.js @@ -0,0 +1,46 @@ +const fetch = require("node-fetch"); +const ytdl = require("ytdl-core"); +const Eris = require("eris"); + +const REGEX_YOUTUBE = /^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.?be)\/.+$/; +const REGEX_YOUTUBE_PLAYLIST = + /^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.?be)\/playlist\?list=(.+)$/; +const REGEX_YOUTUBE_PLAYLIST_SHORT = /^PL[a-zA-Z0-9-_]{1,32}$/; +const REGEX_SOUNDCLOUD = + /^((https?:\/\/)?(www\.|m\.)?soundcloud\.com\/|sc:).+\/.+$/; +const REGEX_SOUNDCLOUD_PLAYLIST = + /^((https?:\/\/)?(www\.|m\.)?soundcloud\.com\/|sc:).+\/(sets\/.+|likes|tracks)$/; +const REGEX_FILE = + /^(https?:\/\/)?.*\..*\/.+\.(mp3|ogg|flac|wav|webm|mp4|mov|mkv)$/; + +let SOUNDCLOUD_CLIENTID; + +hf.voiceStorage = hf.voiceStorage || new Eris.Collection(); + +// https://stackoverflow.com/a/12646864 ยง "Updating to ES6 / ECMAScript 2015" +function shuffleArray(array) { + for (let i = array.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [array[i], array[j]] = [array[j], array[i]]; + } +} + +async function getSoundcloudClientID() { + if (SOUNDCLOUD_CLIENTID != null) { + return SOUNDCLOUD_CLIENTID; + } + const page = await fetch("https://soundcloud.com").then((res) => res.text()); + const scripts = page + .match(/