Last active
August 20, 2018 20:48
-
-
Save meganukebmp/e6f958e1abbac662b102a5b85049108b to your computer and use it in GitHub Desktop.
Alexa only exists to play despacito
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Discordie = require("discordie"); | |
var client = new Discordie(); | |
var fs = require("fs"); | |
client.connect({ token: "" }); | |
client.Dispatcher.on("GATEWAY_READY", e => { | |
console.log("Connected as: " + client.User.username); | |
}); | |
client.Dispatcher.on("MESSAGE_CREATE", e => { | |
var msg = e.message.content.toLowerCase(); // clean up | |
// check if we mentioned alexa | |
if (msg.includes("alexa") || client.User.isMentioned(e.message)) { | |
// check if despacito mentioned | |
if (msg.includes("despacito")) { | |
// check if we want ear rape | |
if ((msg.includes("ear") && msg.includes("rape")) || msg.includes("distorted")) { | |
e.message.channel.sendMessage("Ok, playing Despacito EarRape..."); | |
playDespacito(e, 3); | |
} | |
// check if we want three | |
else if (msg.includes("3") || msg.includes("three")) { | |
e.message.channel.sendMessage("Ok, playing Despacito 3..."); | |
playDespacito(e, 2); | |
} | |
// check if we want two | |
else if (msg.includes("2") || msg.includes("two")) { | |
e.message.channel.sendMessage("Ok, playing Despacito 2..."); | |
playDespacito(e, 1); | |
} | |
// play the OG shit | |
else { | |
e.message.channel.sendMessage("Ok, playing Despacito..."); | |
playDespacito(e, 0); | |
} | |
} | |
// if song is not despacito we tell people to fuck off | |
else if (msg.includes("play")) { | |
e.message.channel.sendMessage("Sorry, I don't know that one."); | |
} | |
// stop the sweet tunes | |
else if (msg.includes("stop")) { | |
stopDespacito(e); | |
} | |
} | |
}); | |
// list of despacitos | |
var despacilist = [ | |
"despacito.opus", | |
"despacito2.opus", | |
"despacito3.opus", | |
"despacitoEarRape.opus" | |
] | |
// DE-SPA-CITO! | |
function playDespacito(e, which) { | |
var voiceChannel = e.message.author.getVoiceChannel(e.message.guild); | |
if (!voiceChannel) return ("User not in voice channel!"); // if user not in voice chat | |
voiceChannel.join() | |
.then(function(succ) { | |
// successful join | |
//console.log("yay"); | |
// works for me | |
var info = client.VoiceConnections[0]; | |
if (!info) return console.log("Voice not connected"); | |
// pick which despacito | |
var source = fs.createReadStream(despacilist[which]); | |
// new encoder | |
var encoder = info.voiceConnection.createExternalEncoder({ | |
type: "OggOpusPlayer", | |
source: source | |
}); | |
if (!encoder) return console.log("Voice connection is disposed"); // when we kill the encoder | |
// kys after song end | |
encoder.once("end", () => { | |
console.log("stream end"); // when the file ends | |
stopDespacito(e); | |
}); | |
encoder.once("error", err => console.log("Ogg Error", err)); // if we encoutner an error | |
var encoderStream = encoder.play(); // start media stream | |
encoderStream.once("unpipe", () => source.destroy()); // close descriptor | |
encoderStream.resetTimestamp(); | |
encoderStream.removeAllListeners("timestamp"); | |
}) | |
.catch(function(err) { | |
// error out | |
console.log("\x1b[31m" + err + "\x1b[0m"); | |
}); | |
} | |
// sad | |
function stopDespacito(e) { | |
var info = client.VoiceConnections[0]; | |
if (!info) return console.log("Voice not connected"); | |
client.User.getVoiceChannel(e.message.guild).leave(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment