From a6b2f0d5417347a31452e8d242d3d388b236cb81 Mon Sep 17 00:00:00 2001 From: ale Date: Mon, 28 Dec 2020 18:55:06 +0100 Subject: [PATCH] Initial commit --- README.md | 26 ++++++++++++++++++++++++++ index.js | 27 +++++++++++++++++++++++++++ package.json | 13 +++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 README.md create mode 100644 index.js create mode 100644 package.json diff --git a/README.md b/README.md new file mode 100644 index 0000000..dfb6a1d --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# grumble-youtube + +## Install + +`npm i` or `yarn` + +## Usage + +``` +$ MUMBLE_SERVER=server.domain.com node index.js +``` + +## Play + +``` +Write in grumble: play + +Example: +play https://www.youtube.com/watch?v=XXXXXXX + +You can use other links sites such as youtube-dl software +``` + +## License + +### MIT \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..cc21d05 --- /dev/null +++ b/index.js @@ -0,0 +1,27 @@ +const { NodeGrumble, Events, MessageType } = require('node-grumble'), + ytdl = require('ytdl-core'), + ytdlcore = require('youtube-dl'), + grumble = NodeGrumble.create({ + url: String(process.env.MUMBLE_SERVER), + name: String('grumble-youtube'), + }), + volume = 0.6 + +console.log('Connecting'); +(async () => { + grumble.on(Events.Connected, () => { + console.log('Connected to ' + process.env.MUMBLE_SERVER) + }) + const connection = await grumble.connect() + grumble.on(MessageType.TextMessage, message => { + const msg = message.message.replace(/<[^>]*>?/gm, '') + if (msg.split(' ')[0] === 'play' && msg.split(' ').length === 2) { + if (msg.split(' ')[1].match(/^https?:\/\/www\.youtube\.com\/watch\?v=/i)) { + connection.playFile(ytdl(msg.split(' ')[1], { filter: 'audioonly' }), volume) + } else if (msg.split(' ')[1].match(/^https?:\/\//i)) { + connection.playFile(ytdlcore(msg.split(' ')[1], ['-x']), volume) + } + connection.sendTextMessage('Playing... ' + msg.split(' ')[1]) + } + }) +})() \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..9e30f1b --- /dev/null +++ b/package.json @@ -0,0 +1,13 @@ +{ + "name": "grumble-youtube", + "version": "1.0.0", + "description": "Play audio in Grumble", + "main": "index.js", + "author": "ale", + "license": "MIT", + "dependencies": { + "node-grumble": "latest", + "youtube-dl": "latest", + "ytdl-core": "latest" + } +}