Made a working version of mumblemusicbot
This commit is contained in:
parent
9f32c88b28
commit
656f76ad90
32
app.js
Normal file
32
app.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
"use strict";
|
||||
|
||||
var lame = require('lame');
|
||||
var mumble = require('mumble');
|
||||
|
||||
mumble.connect('mumble://wallpiece:9648', function( error, client ) {
|
||||
if( error ) { throw new Error( error ); }
|
||||
|
||||
client.authenticate('MusicBot', 'yolo');
|
||||
client.on( 'initialized', function() {
|
||||
start( client );
|
||||
});
|
||||
});
|
||||
|
||||
var start = function( client ) {
|
||||
// client.outputStream().pipe(client.inputStream());
|
||||
var input = client.inputStream();
|
||||
var decoder = new lame.Decoder();
|
||||
|
||||
var stream;
|
||||
decoder.on( 'format', function( format ) {
|
||||
console.log( format );
|
||||
|
||||
stream.pipe( client.inputStream({
|
||||
channels: format.channels,
|
||||
sampleRate: format.sampleRate,
|
||||
gain: 1
|
||||
}));
|
||||
});
|
||||
|
||||
stream = require('fs').createReadStream(__dirname + '/test.mp3').pipe( decoder );
|
||||
};
|
|
@ -1,3 +0,0 @@
|
|||
|
||||
openssl pkcs12 -in *.p12 -out public.pem -clcerts -nokeys
|
||||
openssl pkcs12 -in *.p12 -out private.pem -nocerts -nodes
|
98
index.js
98
index.js
|
@ -1,98 +0,0 @@
|
|||
//Mumsix, mumble music bot
|
||||
var mumble = require('mumble');
|
||||
var GS = require('grooveshark-streaming');
|
||||
var fs = require('fs');
|
||||
var http = require('http');
|
||||
var lame = require('lame');
|
||||
var wav = require('wav');
|
||||
var celt = require('celt');
|
||||
|
||||
var connection;
|
||||
|
||||
var options = {
|
||||
key : fs.readFileSync(__dirname + '/private.pem'),
|
||||
cert : fs.readFileSync(__dirname + '/public.pem')
|
||||
}
|
||||
|
||||
console.log('Connecting');
|
||||
mumble.connect('mumble://wallpiece:9648', options, function (err, res) {
|
||||
if (err) throw new Error(err);
|
||||
connection = res;
|
||||
|
||||
res.authenticate('MusicBot', 'yolo');
|
||||
|
||||
res.on('initialized', function () {
|
||||
console.log('Connected!');
|
||||
// var speaker = new require('speaker')();
|
||||
// var decoder = new lame.Decoder();
|
||||
|
||||
// fs.createReadStream(__dirname + '/song.mp3')/*.pipe(decoder)*/.pipe(res.inputStream());
|
||||
res.outputStream().pipe(res.inputStream());
|
||||
|
||||
});
|
||||
// message('Hey there, I\'m music bot!');
|
||||
|
||||
|
||||
// On text message...
|
||||
res.on( 'textMessage', function (data) {
|
||||
console.log(data);
|
||||
if (data.message.split(' ')[0] == '/m' || data.message.split(' ')[0] == '/music') {
|
||||
var command = data.message.split(' ').splice(1);
|
||||
if (command[0] == 'g' || command[0] == 'grooveshark') {
|
||||
grooveshark(command);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// res.on( 'voice', function (event) {
|
||||
// console.log( 'Mixed voice' );
|
||||
// var pcmData = event.data;
|
||||
// });
|
||||
});
|
||||
|
||||
function message(message) {
|
||||
console.log('sending message', message);
|
||||
connection.sendMessage('TextMessage', {'message': message, channelId: [0]});
|
||||
}
|
||||
|
||||
function grooveshark(command) {
|
||||
var lookup = command.splice(1).join(' ');
|
||||
|
||||
GS.Tinysong.getSongInfo(lookup, null, function (err, info) {
|
||||
GS.Grooveshark.getStreamingUrl(info.SongID, function (err, url) {
|
||||
if (fs.existsSync(__dirname + '/song.mp3')) fs.unlinkSync(__dirname + '/song.mp3');
|
||||
if (fs.existsSync(__dirname + '/song.wav')) fs.unlinkSync(__dirname + '/song.wav');
|
||||
message('Got the song, downloading it now!');
|
||||
http.get(url, function (res) {
|
||||
|
||||
res.on("data", function (data){
|
||||
if (fs.existsSync(__dirname + '/song.mp3')) {
|
||||
fs.appendFileSync(__dirname + '/song.mp3', data);
|
||||
}
|
||||
else {
|
||||
fs.writeFileSync(__dirname + '/song.mp3', data);
|
||||
}
|
||||
});
|
||||
|
||||
res.on('end', function () {
|
||||
play(__dirname + '/song.mp3');
|
||||
message('Done downloading song!');
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function play(output) {
|
||||
var speaker = new require('speaker')();
|
||||
var decoder = new lame.Decoder();
|
||||
var spawn = require('child_process').spawn;
|
||||
var speex = spawn('speexenc', ['-', '-', '--16bit'/*, '-u'*/]);
|
||||
|
||||
fs.createReadStream(__dirname + '/song.mp3').pipe(decoder).pipe(speex.stdin);
|
||||
|
||||
speex.stderr.on('data', function (data) {console.log(data.toString())});
|
||||
|
||||
speex.stdout.pipe(speaker);
|
||||
|
||||
}
|
|
@ -4,8 +4,7 @@
|
|||
"description": "The bot to lighten that mumble channel up!",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"grooveshark-streaming": "0.0.8",
|
||||
"mumble": "0.0.2"
|
||||
"mumble": "^0.1.4"
|
||||
},
|
||||
"devDependencies": {},
|
||||
"scripts": {
|
||||
|
|
Reference in a new issue