Skip to content

Instantly share code, notes, and snippets.

@LevitatingBusinessMan
Created September 11, 2018 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LevitatingBusinessMan/4b7b103317559c45ab22b22e190e3c1e to your computer and use it in GitHub Desktop.
Save LevitatingBusinessMan/4b7b103317559c45ab22b22e190e3c1e to your computer and use it in GitHub Desktop.
Alexa reddit bot (meme)
const fs = require('fs');
const config = {
userAgent: 'Alexa bot/v1.0.0.',
clientId: 'FQmyKSMDo-o-Vg',
clientSecret: '4PNMTraK0fNlwYaCyyhtqSBH6dk',
username: 'Alexa_play',
password: 'Alexabot'
};
const foo = require('./index.js');
const r = new foo(config);
const commentStream = r.commentStream({
sub: ['teenagers'],
rate: 20000
});
const player = song => {
return (
`ɴᴏᴡ ᴘʟᴀʏɪɴɢ: ${song}
───────────────⚪────────────────────────────
◄◄⠀▐▐ ⠀►►⠀⠀ ⠀ 1:17 / 3:48 ⠀ ───○ 🔊⠀ ᴴᴰ ⚙ ❐ ⊏⊐
`)
}
let replied = [];
commentStream.on('post', comment => {
if (replied.includes(comment.id)) return;
if (comment.body.toLowerCase().includes("alexa play")) {
comment.save();
let song = comment.body.toLowerCase().split("alexa play")[1].split(/\n/)[0].trim();
if (song.length > 35)
song = [song.slice(0, 35), "\n\n", song.slice(35)].join('')
if (song.length > 80)
song = song.substring(0,80) + "..."
console.log(`Playing song: ${song}\n`);
comment.reply(player(song))
.then(replied.push(comment.id))
.catch(e => console.log(e.message))
}
});
process.on('exit', () => console.log(replied));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment