├── .gitignore ├── LICENSE.md ├── README.md ├── config.json.example ├── index.js ├── package.json └── radio.json.example /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | # https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git 28 | node_modules 29 | 30 | # Optional npm cache directory 31 | .npm 32 | 33 | # Optional REPL history 34 | .node_repl_history 35 | 36 | # Config files 37 | config.json 38 | radio.json 39 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csprl/stream-bot/4ab4fafa037e647bcf07665928bfe6b223ca3df9/LICENSE.md -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # stream-bot 2 | **Development on this bot was stopped long ago and it most likely doesn't work anymore. Take a look at [CoreBot](https://github.com/casperlofgren/CoreBot) which has similar features but is being (somewhat) actively developed.** 3 | 4 | ## Usage 5 | - First install dependencies with `npm install` 6 | - Install [ffmpeg](https://www.ffmpeg.org) and make sure it's in your path 7 | - Copy `config.json.example` to `config.json` and fill in your Discord, Spotify and SoundCloud details 8 | - Copy `radio.json.example` to `radio.json` and modify it to your liking 9 | - Run with `node index.js` 10 | - To add the bot to a channel, type `!join ` 11 | - To stop streaming or playing, simply type `!stop` 12 | - If you want to remove the bot from the channel, use `!leave` 13 | - All radio channels and audio tracks are listed with `!radio` 14 | - To listen to an entry in `radio.json` type ! and the name of the entry, for example `!noisefm` or `!sample` from radio.json.example 15 | - Use `!spotify ` to play to a Spotify song 16 | - Use `!soundcloud ` to play a song from SoundCloud 17 | 18 | ## Notes 19 | - The values in the url fields in radio.json **have to be in mp3 format and readable by ffmpeg** in order to work 20 | - If the bot isn't playing anything, try typing `ffplay ` in cmd/terminal to make sure it's readable by ffmpeg 21 | - You can copy the track URI by right-clicking on a song in Spotify 22 | - SoundCloud links can not be a playlist 23 | -------------------------------------------------------------------------------- /config.json.example: -------------------------------------------------------------------------------- 1 | { 2 | "email" : "email address here", 3 | "password" : "password here", 4 | "spotifyuser" : "spotify username here", 5 | "spotifypass" : "spotify password here", 6 | "soundcloudcid" : "soundcloud client id from http://soundcloud.com/you/apps" 7 | } -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var Discord = require("discord.js"); 2 | 3 | var config = require("./config.json"); 4 | 5 | var radio = require("./radio.json"); 6 | 7 | var Spotify = require("spotify-web"); 8 | 9 | var soundcloudr = require('soundcloudr'); 10 | soundcloudr.setClientId(config.soundcloudcid); 11 | 12 | var bot = new Discord.Client(); 13 | 14 | var inChannel = false; 15 | 16 | bot.on("ready", function () { 17 | console.log("Bot is up and running in " + bot.channels.length + " channels"); 18 | }); 19 | 20 | bot.on("disconnected", function () { 21 | console.log("Disconnected from Discord"); 22 | process.exit(1); 23 | }); 24 | 25 | bot.on("message", function (message) { 26 | if (message.author.id != bot.user.id && (message.content[0] === "!" || message.content.indexOf (bot.user.mention()) == 0 )) { 27 | //console.log("Incoming command '" + message.content + "' from user " + message.author); 28 | var cmdTxt = message.content.split(" ")[0].substring(1); 29 | var suffix = message.content.substring(cmdTxt.length + 2); 30 | if (message.content.indexOf(bot.user.mention()) == 0){ 31 | try { 32 | cmdTxt = message.content.split(" ")[1]; 33 | suffix = message.content.substring(bot.user.mention().length+cmdTxt.length + 2); 34 | } catch (e){ 35 | bot.sendMessage(message.channel,"Yes?"); 36 | return; 37 | } 38 | } 39 | 40 | var rstat = radio[cmdTxt] 41 | 42 | if (cmdTxt === "radio") { 43 | bot.sendMessage(message.channel, "__**Available radio stations:**__", function () { // message.author 44 | for(var fxes in radio) { 45 | var info = "**!" + fxes + "**"; 46 | var usage = radio[fxes].usage; 47 | 48 | var name = radio[fxes].name; 49 | if (name) { 50 | info += "\n\t" + name; 51 | } 52 | 53 | var url = radio[fxes].url; 54 | if (url) { 55 | info += "\n\t" + url; 56 | } 57 | bot.sendMessage(message.channel, info); // message.author 58 | } 59 | }); 60 | } 61 | 62 | if (rstat && inChannel) { 63 | if (bot.voiceConnection.playing) { 64 | bot.voiceConnection.stopPlaying(); 65 | } 66 | bot.voiceConnection.playFile(rstat.url); 67 | bot.setStatus("idle", rstat.name); 68 | } 69 | 70 | if (cmdTxt === "spotify" && inChannel) { 71 | if (suffix) { 72 | Spotify.login(config.spotifyuser, config.spotifypass, function (err, spotify) { 73 | if (err) throw err; 74 | 75 | spotify.get(suffix, function (err, track) { 76 | if (err) { 77 | bot.sendMessage(message.channel, "An error occured: " + err); 78 | } else { 79 | bot.sendMessage(message.channel, "Playing **" + track.name + "** by **" + track.artist[0].name + "**"); 80 | bot.setStatus("idle", track.name + " by " + track.artist[0].name); 81 | bot.voiceConnection.playRawStream(track.play().on('finish', function () { bot.setStatus("idle"); spotify.disconnect(); }) ); 82 | } 83 | }); 84 | }); 85 | } else { 86 | bot.sendMessage(message.channel, "Please specify a Spotify track URI"); 87 | } 88 | } 89 | 90 | if (cmdTxt === "soundcloud" && inChannel) { 91 | if (suffix) { 92 | soundcloudr.getStreamUrl(suffix, function(err, url) { 93 | if (err) { 94 | bot.sendMessage(message.channel, "An error occured: " + err.message); 95 | } else { 96 | bot.voiceConnection.playFile(url); 97 | //bot.setStatus("idle", "SoundCloud track"); // TODO: fetch track name 98 | } 99 | }); 100 | } 101 | } 102 | 103 | if (cmdTxt === "join") { 104 | if (suffix) { 105 | for (var channel of message.channel.server.channels) { 106 | if (!suffix || channel.name === suffix) { 107 | bot.joinVoiceChannel(channel, function (error) { 108 | if (error != null) { 109 | console.log(error); 110 | process.exit(1); 111 | } 112 | }); 113 | inChannel = true; 114 | } 115 | } 116 | } 117 | } 118 | 119 | if (cmdTxt === "leave") { 120 | if (inChannel) { 121 | bot.setStatus("idle"); 122 | bot.leaveVoiceChannel(); 123 | inChannel = false; 124 | } 125 | } 126 | 127 | if (cmdTxt === "stop") { 128 | if (inChannel) { 129 | bot.voiceConnection.stopPlaying(); 130 | bot.setStatus("idle"); 131 | } 132 | } 133 | 134 | if (message.author == bot.user) { 135 | return; 136 | } 137 | } 138 | }); 139 | 140 | bot.login(config.email, config.password); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "stream-bot", 3 | "version": "0.1.0", 4 | "description": "Simple music and radio streaming bot for Discord", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/casperlofgren/stream-bot.git" 12 | }, 13 | "author": "Casper Löfgren", 14 | "license": "ISC", 15 | "bugs": { 16 | "url": "https://github.com/casperlofgren/stream-bot/issues" 17 | }, 18 | "homepage": "https://github.com/casperlofgren/stream-bot#readme", 19 | "dependencies": { 20 | "discord.js": "^6.0.x", 21 | "soundcloudr": "^1.1.0", 22 | "spotify-web": "git+https://github.com/mattyway/node-spotify-web.git" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /radio.json.example: -------------------------------------------------------------------------------- 1 | { 2 | "noisefm": { 3 | "name" : "Noise FM", 4 | "url" : "https://play.sas-media.ru/play" 5 | }, 6 | "sample": { 7 | "name" : "Sample Audio File", 8 | "url" : "sample.mp3" 9 | } 10 | } 11 | --------------------------------------------------------------------------------