Skip to content
This repository was archived by the owner on Nov 8, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
"start": "node server.js"
},
"dependencies": {
"discord.js" : "github:hydrabolt/discord.js#master",
"ytdl-core" : "github:fent/node-ytdl-core#master",
"node-opus" : "^0.2.1"
"discord.js" : "11.0.0",
"ytdl-core" : "github:fent/node-ytdl-core#master",
"node-opus" : "^0.2.1",
"youtube-node" : "^4.2.0"
},
"author": "BDISTIN",
"license": "MIT"
Expand Down
45 changes: 36 additions & 9 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ const { Client } = require('discord.js');
const yt = require('ytdl-core');
const tokens = require('./tokens.json');
const client = new Client();
const YouTube = require('youtube-node');
const youTube = new YouTube();
youTube.setKey(tokens.yt_token);

let queue = {};

Expand Down Expand Up @@ -62,15 +65,39 @@ const commands = {
});
},
'add': (msg) => {
let url = msg.content.split(' ')[1];
if (url == '' || url === undefined) return msg.channel.sendMessage(`You must add a YouTube video url, or id after ${tokens.prefix}add`);
yt.getInfo(url, (err, info) => {
if(err) return msg.channel.sendMessage('Invalid YouTube Link: ' + err);
if (!queue.hasOwnProperty(msg.guild.id)) queue[msg.guild.id] = {}, queue[msg.guild.id].playing = false, queue[msg.guild.id].songs = [];
queue[msg.guild.id].songs.push({url: url, title: info.title, requester: msg.author.username});
msg.channel.sendMessage(`added **${info.title}** to the queue`);
});
},
function addFromUrl(url) {
msg.channel.sendMessage("*Adding...*");
if (url == '' || url === undefined) return msg.channel.sendMessage(`You must add a YouTube video url after ${tokens.prefix}add`);
yt.getInfo(url, (err, info) => {
if (err) return msg.channel.sendMessage('Invalid YouTube Link: ' + err);
if (!queue.hasOwnProperty(msg.guild.id)) queue[msg.guild.id] = {}, queue[msg.guild.id].playing = false, queue[msg.guild.id].songs = [];
queue[msg.guild.id].songs.push({
url: url,
title: info.title,
requester: msg.author.username
});
msg.channel.sendMessage(`Added **${info.title}** to the queue`);
});
}
function addFromQuery(query) {
youTube.search(query, 2, function(error, result) {
if (error) {
msg.channel.sendMessage('Error:\n' + error);
} else {
let url = `https://www.youtube.com/watch?v=${result.items[0]["id"].videoId}`;
addFromUrl(url);
}
});
}
if (msg.content === `${tokens.prefix}add`) return msg.reply(`You must add a YouTube video url after ${tokens.prefix}add`);
let url = msg.content.split(' ')[1];
if (url.includes("https://youtube.com/") || url.includes("https://www.youtube.com/") || url.includes("http://youtube.com/") || url.includes("http://www.youtube.com/") || url.includes("https://youtu.be/") || url.includes("https://www.youtu.be/") || url.includes("http://youtu.be/") || url.includes("http://www.youtu.be/")) {
addFromUrl(url);
} else {
let query = msg.content.replace(`${tokens.prefix}add`, '');
addFromQuery(query);
}
},
'queue': (msg) => {
if (queue[msg.guild.id] === undefined) return msg.channel.sendMessage(`Add some songs to the queue first with ${tokens.prefix}add`);
let tosend = [];
Expand Down
5 changes: 3 additions & 2 deletions tokens.json.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"d_token" : "YOUR DISCORD APP TOKEN",
"adminID" : "YOUR DISCORD USER ID",
"adminID" : "YOUR DISCORD USER ID",
"prefix" : "++",
"passes" : 1 //can be increased to reduce packetloss at the expense of upload bandwidth, 4-5 should be lossless at the expense of 4-5x upload
"yt_token" : "YOUR YOUTUBE API TOKEN",
"passes" : 1 //can be increased to reduce packetloss at the expense of upload bandwidth, 4-5 should be lossless at the expense of 4-5x upload
}