This commit is contained in:
Lamp 2018-06-01 16:27:48 -04:00
commit 531f1fd2d4
12 changed files with 1795 additions and 0 deletions

13
.gitignore vendored Normal file

@ -0,0 +1,13 @@
midi/*
!midi/.gitkeep
music/*
!music/.gitkeep
music_metadata/*
!music_metadata/.gitkeep
node_modules
soundfonts/*
!soundfonts/.gitkeep
trash/*
!trash/.gitkeep
token.txt
ytplay-history.txt

481
archive/mmm copy.js Normal file

@ -0,0 +1,481 @@
console.log('Starting');
const Discord = require('discord.js');
const fs = require('fs');
const child_process = require('child_process');
const colors = require('colors');
const download = require('download-file');
//const ytdl = require('ytdl-core');
const youtubedl = require('youtube-dl');
const client = new Discord.Client();
/* token --> */ client.login(/* token redacted */);
////////////////////////////////////////////////////////////////////////////////
client.on('ready', ()=>{
console.log('Ready');
});
client.on('message', m => {
// var arg = m.content.split(' ');
// var cmd = arg[0].slice(1).toLowerCase();
// var txt = function(i) {return arg.slice(i).join(' ');}
var a = m.content.split(' ');
var t = function(i) {return a.slice(i).join(' ');}
message = m; arg = a;
cmd = a[0].slice(1).toLowerCase();
if (m.content.startsWith('!')) {
if (cmd === "join") joinc(m,a,t);
if (cmd === "leave") leavec(m,a,t);
if (cmd === "play" || cmd === 'p') playc(m,a,t);
if (cmd === "playaudio" || cmd === 'pa') playaudioc(m,a,t);
if (cmd === "playmidi" || cmd === 'pm') playmidic(m,a,t);
if (cmd === "search" || cmd === 's') searchc(m,a,t);
if (cmd === "upload" || cmd === 'u') uploadc(m,a,t);
if (cmd === "ytplay" || cmd === "ytp" || cmd === "pyt" || cmd === "py") youtubedlplayc(m,a,t);
if (cmd === "ytdl") youtubedlc(m,a,t);
if (cmd === "soundfontcfg") soundfontcfgc(m,a,t);
if (cmd === "soundfonts") soundfontsc(m,a,t);
if (cmd === "setsoundfonts") setsoundfontc(m,a,t);
if (typeof dispatcher !== 'undefined') {
if (cmd === "song") songc(m,a,t);
if (cmd === "pause") pausec(m,a,t);
if (cmd === "resume") resumec(m,a,t);
if (cmd === "volume") volumec(m,a,t);
if (cmd === "time") timec(m,a,t);
if (cmd === "stop") stopc(m,a,t);
}
}
});
////////////////////////////////////////////////////////////////////////////////
fs.readdir('./music/', function(err,files){music = files;});
fs.readdir('./midi/', function(err,files){midis = files;});
function search_music(query) {
var search_results = [];
music.forEach(function(filename){
if (filename.toLowerCase().includes(query.toLowerCase())) {
search_results.push(filename);
}
});
return search_results;
}
function search_midis(query) {
var search_results = [];
midis.forEach(function(filename){
if (filename.toLowerCase().includes(query.toLowerCase())) {
search_results.push(filename);
}
});
return search_results;
}
function play (filename, type, message) {
var vc = message.member.voiceChannel || client.channels.get('279769632599048194');
vc.join().then(c => {
connection = c;
if (type === "audio") {
//try{dispatcher.end();}catch(e){}
setTimeout(function(){
let path = './music/'+filename.split('/').join(':');
dispatcher = connection.playFile(path);
dispatcher.songname = filename;
message.channel.send('🎶 **Now playing:** `'+filename+'` 💿');
client.user.setGame(filename);
dispatcher.on('end', () => {
client.user.setGame();
});
},100);
}
else if (type === "midi") {
//try{dispatcher.end();}catch(e){}
setTimeout(function(){
const path = './midi/'+filename.split('/').join(':');
const timidity = child_process.spawn('timidity', [path, '-c', './timidity.cfg', '-o', '-']);
timidity.stderr.on('data', data => {
console.log(("[TiMidity] "+data.toString()).yellow);
});
dispatcher = connection.player.playPCMStream(timidity.stdout);
dispatcher.songname = filename;
message.channel.send('🎶 **Now playing:** `'+filename+'` 🎹');
client.user.setGame(filename);
dispatcher.on('end', () => {
timidity.kill();
client.user.setGame();
});
},100);
}
else if (type === "yt") {
if (!filename.startsWith('http')) filename = 'ytsearch:'+filename;
const dl = youtubedl(filename, ['-f bestaudio'], {maxBuffer: Infinity});
let video_filename;
dl.on('info', function(info) {
dispatcher = connection.playStream(dl);
message.channel.send('🎶 **Now playing:** `'+info.title+'` 📺');
fs.appendFile('./ytplay-history.txt', info._filename+'\n'); // ¯\_(ツ)_/¯
client.user.setGame(info.title);
dispatcher.on('end', ()=>{
client.user.setGame();
});
});
}
else console.log('something is wrong; play function was called with invalid type'.red);
});
}
/*
function playYT(query, message) {
if (!query.startsWith('http')) query = 'ytsearch:'+query;
const dl = youtubedl(query, ['-f bestaudio'], {maxBuffer: Infinity});
let video_filename;
dl.on('info', function(info) {
dispatcher = connection.playStream(dl);
message.channel.send('🎶 **Now playing:** `'+info.title+'` 📺');
fs.appendFile('./ytplay-history.txt', info._filename+'\n'); // ¯\_(ツ)_/¯
client.user.setGame(info.title);
dispatcher.on('end', ()=>{
client.user.setGame();
});
});
}
*/
// Commands --------------------------------------------------------------------
function joinc(message, arg, txt) {
if (message.member.voiceChannel) {
message.member.voiceChannel.join().then(c => {connection = c;});
message.react('🆗');
} else {
message.reply('⚠ **First connect to the voice channel that you want me to connect to.**');
}
}
function leavec(message, arg, txt) {
if (typeof connection !== 'undefined') {
connection.disconnect();
connection = undefined;
message.react('🆗');
} else {
message.react('⚠');
}
}
function playc(message, arg, txt) {
var query = txt(1);
if (query) {
if (fs.existsSync('./music/'+query)) play(query, 'audio', message);
else if (fs.existsSync('./midi/'+query)) play(query, 'midi', message);
else {
let music_search = search_music(query);
let midi_search = search_midis(query);
if (music_search.includes(query)) play(music_search.random(), 'audio', message);
else if (midi_search.includes(query)) play(midi_search.random(), 'midi', message);
else message.channel.send('Nothing was found ');
/*
let music_search = search_music(query);
let midi_search = search_midis(query);
let total_search = music_search.concat(midi_search);
if (total_search != "") {
play(total_search.random(), message);
} else {
//playYT(query, message);
play(music.concat(midis).random(), message);
}*/
}
} else {
if ([true,false].random()) play(music.random(), 'audio', message);
else play(midis.random(), 'midi', message);
}
}
function playaudioc(message, arg, txt) {
var query = txt(1);
if (query != "") {
if(fs.existsSync('./music/'+query)) {
play(query, 'audio', message);
} else {
let search = search_music(query);
if (search != "") {
play(search.random(), 'audio', message);
} else {
play(music.random(), 'audio', message);
}
}
} else {
play(music.random(), 'audio', message);
}
}
function playmidic(message, arg, txt) {
var query = txt(1);
if (query != "") {
if(fs.existsSync('./midi/'+query)) {
play(query, 'midi', message);
} else {
let search = search_midis(query);
if (search != "") {
play(search.random(), 'midi', message);
} else {
play(midis.random(), 'midi', message);
}
}
} else {
play(midis.random(), 'midi', message);
}
}
function searchc(message, arg, txt) {
if (txt(1)) {
let music_search = search_music(txt(1));
let midi_search = search_midis(txt(1));
if (music_search != "" || midi_search != "") {
if (music_search != "" && music_search.length < 100) {
let sr = "💿 **Audio Search results:**\n";
music_search.forEach((item, index, array) => {
sr += '`'+item+'`\n';
try {
if (sr.length+array[index+1].length >= 1950) {
message.channel.send(sr);
sr = "";
}
} catch(e) {
message.channel.send(sr);
}
});
}
if (midi_search != "" && midi_search.length < 100) {
let sr = "🎹 **MIDI Search results:**\n";
midi_search.forEach((item, index, array) => {
sr += '`'+item+'`\n';
try {
if (sr.length+array[index+1].length >= 1950) {
message.channel.send(sr);
sr = "";
}
} catch(e) {
message.channel.send(sr);
}
});
}
} else {
message.channel.send('⚠ **No results.**');
}
} else {
message.channel.send('**Usage:** `!search <query>`');
}
}
//var music_extensions = ["aac","aiff","aif","flac","m4a","mp3","ogg","wav","wma","webm","mkv","flv","avi","mov","qt","wmv","mp4","m4v"];
var music_extensions = ["3dostr","3g2","3gp","4xm","a64","aa","aac","ac3","acm","act","adf","adp","ads","adts","adx","aea","afc","aiff","aix","alaw","alias_pix","amr","anm","apc","ape","apng","aqtitle","asf","asf_o","asf_stream","ass","ast","au","avi","avm2","avr","avs","bethsoftvid","bfi","bfstm","bin","bink","bit","bmp_pipe","bmv","boa","brender_pix","brstm","c93","caf","cavsvideo","cdg","cdxl","cine","concat","crc","dash","data","daud","dcstr","dds_pipe","dfa","dirac","dnxhd","dpx_pipe","dsf","dsicin","dss","dts","dtshd","dv","dv1394","dvbsub","dvbtxt","dvd","dxa","ea","ea_cdata","eac3","epaf","exr_pipe","f32be","f32le","f4v","f64be","f64le","fbdev","ffm","ffmetadata","fifo","film_cpk","filmstrip","flac","flic","flv","framecrc","framehash","framemd5","frm","fsb","g722","g723_1","g729","genh","gif","gsm","gxf","h261","h263","h264","hash","hds","hevc","hls","hls","applehttp","hnm","ico","idcin","idf","iff","ilbc","image2","image2pipe","ingenient","ipmovie","ipod","ircam","ismv","iss","iv8","ivf","ivr","j2k_pipe","jacosub","jpeg_pipe","jpegls_pipe","jv","latm","lavfi","live_flv","lmlm4","loas","lrc","lvf","lxf","m4v","matroska","matroska","webm","md5","mgsts","microdvd","mjpeg","mkvtimestamp_v2","mlp","mlv","mm","mmf","mov","mov","mp4","m4a","3gp","3g2","mj2","mp2","mp3","mp4","mpc","mpc8","mpeg","mpeg1video","mpeg2video","mpegts","mpegtsraw","mpegvideo","mpjpeg","mpl2","mpsub","msf","msnwctcp","mtaf","mtv","mulaw","musx","mv","mvi","mxf","mxf_d10","mxf_opatom","mxg","nc","nistsphere","nsv","null","nut","nuv","oga","ogg","ogv","oma","opus","oss","paf","pam_pipe","pbm_pipe","pcx_pipe","pgm_pipe","pgmyuv_pipe","pictor_pipe","pjs","pmp","png_pipe","ppm_pipe","psp","psxstr","pva","pvf","qcp","qdraw_pipe","r3d","rawvideo","realtext","redspark","rl2","rm","roq","rpl","rsd","rso","rtp","rtp_mpegts","rtsp","s16be","s16le","s24be","s24le","s32be","s32le","s8","sami","sap","sbg","sdp","sdr2","segment","sgi_pipe","shn","siff","singlejpeg","sln","smjpeg","smk","smoothstreaming","smush","sol","sox","spdif","spx","srt","stl","stream_segment","ssegment","subviewer","subviewer1","sunrast_pipe","sup","svag","svcd","swf","tak","tedcaptions","tee","thp","tiertexseq","tiff_pipe","tmv","truehd","tta","tty","txd","u16be","u16le","u24be","u24le","u32be","u32le","u8","uncodedframecrc","v210","v210x","v4l2","vag","vc1","vc1test","vcd","video4linux2","v4l2","vivo","vmd","vob","vobsub","voc","vpk","vplayer","vqf","w64","wav","wc3movie","webm","webm_chunk","webm_dash_manife","webp","webp_pipe","webvtt","wsaud","wsd","wsvqa","wtv","wv","wve","x11grab","xa","xbin","xmv","xvag","xwma","yop","yuv4mpegpipe"];
var midi_extensions = ["mid","rmi","rcp","r36","g18","g36","mfi","kar","mod","wrd","xm","s3m","oct","med","ahx","it"];
function uploadc(message, arg, txt) {
if (typeof message.attachments.first() !== 'undefined') {
let attachment_name = message.attachments.first().filename;
let attachment_extension = attachment_name.split('.').pop().toLowerCase();
if (music_extensions.includes(attachment_extension.toLowerCase())) {
if (!fs.existsSync('./music/'+attachment_name)) {
message.react('🆗');
download(message.attachments.first().url, {directory: "./music/"}, function(err) {
if (err) {message.channel.send('An error occurred while downloading: ```'+err+'```'); return;}
music.push(attachment_name);
message.channel.send('📁 **Added** `'+attachment_name+'` **to the music collection.** 💿');
});
} else {
message.channel.send('⚠ **File** `'+attachment_name+'` **already exists.**');
}
} else if (midi_extensions.includes(attachment_extension.toLowerCase())) {
if (!fs.existsSync('./midi/'+attachment_name)) {
message.react('🆗');
download(message.attachments.first().url, {directory: "./midi/"}, function(err) {
if (err) {message.channel.send('An error occurred while downloading: ```'+err+'```'); return;}
midis.push(attachment_name);
message.channel.send('📁 **Added** `'+attachment_name+'` **to the MIDI collection.** 🎹');
});
} else {
message.channel.send('⚠ **File** `'+attachment_name+'` **already exists.**');
}
} else if (["sfx","sf2", "cfg"].includes(attachment_extension.toLowerCase())) {
if (!fs.existsSync('./soundfonts/'+attachment_name)) {
message.react('🆗');
download(message.attachments.first().url, {directory: "./soundfonts/"}, function(err) {
if (err) {message.channel.send('An error occurred while downloading: ```'+err+'```'); return;}
message.channel.send('📁 Added file `'+attachment_name+'` to the soundfont collection. 🎺');
});
} else {
message.channel.send('⚠ **File** `'+attachment_name+'` **already exists.**');
}
} else {
message.channel.send('⚠ **Format extension `'+attachment_extension+'` is not supported or unknown.**');
download(message.attachments.first().url, {directory: "./trash/"});
}
} else {
message.channel.send(' **To upload to the music database, type `!upload` and attach the file to your message.**');
}
}
/*
function ytplayc(message,arg,txt){
const query = txt(1);
if (query !== "") {
message.react('🆗');
if (query.startsWith('http')) {
dispatcher = connection.playStream(ytdl(query, {filter: "audioonly"}));
message.channel.send('Now playing whatever video u gave me');
dispatcher.on('end', ()=>{
message.channel.send('wutevr u gave me is now over');
});
} else {
}
} else {
message.reply('Usage: `!ytplay <youtube URL>`');
}
}
function ytdlc(message,arg,txt){
const query = txt(1);
if (query !== "") {
message.react('🆗');
if (query.startsWith('http')) {
ytdl.getInfo(query, (err,info)=>{
message.channel.send('[testing] Downloading '+info.title);
ytdl.downloadFromInfo(info, {filter: "audioonly"}).pipe(fs.createWriteStream('./music/'+info.title+'-'+info.video_id));
});
} else {
}
} else {
message.reply('Usage: `!ytdl <youtube URL>`');
}
}
*/
function youtubedlplayc(message,arg,txt){
if (txt(1)) {
message.react('🆗');
play(txt(1), 'yt', message);
} else {
message.reply(' **Usage:** `!ytplay <youtube URL or search query>`');
}
}
function youtubedlc(message, arg, txt) {
if (txt(1)) {
message.react('🆗');
let query = txt(1);
if (!query.startsWith('http')) query = 'ytsearch:'+query;
const dl = youtubedl(query, ['-f bestaudio'], {maxBuffer: Infinity});
let video_filename;
dl.on('info', function(info) {
// message.channel.send('Downloading `'+info.filename+ '`\n Size: `'+info.size+'`');
dl.pipe(fs.createWriteStream('./music/'+info._filename));
video_filename = info._filename;
});
dl.on('end', function() {
music.push(video_filename);
// message.channel.send('Download finished.');
message.channel.send('📁 **Added** `'+video_filename+'` **to the music collection.** 💿')
});
} else {
message.reply(' **Usage:** `!youtube-dl <youtube URL or search query>`');
}
}
function soundfontcfgc(message,arg,txt){
fs.readFile('./soundfonts.cfg', 'utf8', (err, data)=> {
message.channel.send('Contents of soundfont config:\n`'+data+'`');
});
}
function soundfontsc(message,arg,txt){
fs.readdir('./soundfonts/', (err, files)=>{
message.channel.send('Available soundfonts: \n`'+files.join('\n')+'`');
});
}
function setsoundfontc(message,arg,txt) {
arg.shift();
var newcfg = "";
arg.forEach(filename => {
if (fs.existsSync('./soundfonts/'+filename)) {
if (filename.split('.').pop() === "cfg") {
newcfg += 'source ./soundfonts/'+filename+'\n';
} else {
newcfg += 'soundfont ./soundfonts/'+filename+'\n';
}
} else {
message.channel.send('err: soundfont `'+filename+'` doesn\'t exist');
}
});
fs.writeFile('./soundfonts.cfg', newcfg, ()=>{
message.channel.send('Saved new soundfont config with the following contents:\n`'+newcfg+'`');
});
}
// Song control
function songc(message, arg, txt) {
message.channel.send('🎶 **Currently playing:** `'+dispatcher.songname+'`');
}
function pausec(message, arg, txt) {
dispatcher.pause();
message.react('🆗');
}
function resumec(message, arg, txt) {
dispatcher.resume();
message.react('🆗');
}
function volumec(message, arg, txt) {
if (arg[1]) {
dispatcher.setVolume(arg[1]);
message.react('🆗');
} else {
message.channel.send('🔊 **Volume:** `'+dispatcher._volume+'`')
}
}
function timec(message, arg, txt) {
message.channel.send(dispatcher.time);
}
function stopc(message, arg, txt) {
dispatcher.end();
// dispatcher = undefined;
message.react('🆗');
}
function reloadmusicc(message, arg, txt) {
message.react('🆗');
fs.readdir('./music/', function(err,files){music = files;});
fs.readdir('./midi/', function(err,files){midis = files;});
}
// Utility Functions
////////////////////////////////////////////////////////////////////////////////
Array.prototype.random = function () {
return this[Math.floor(Math.random()*this.length)];
}

405
archive/mmm.1.js Normal file

@ -0,0 +1,405 @@
console.log('Starting');
const Discord = require('discord.js');
const fs = require('fs');
const child_process = require('child_process');
const colors = require('colors');
const download = require('download-file');
//const ytdl = require('ytdl-core');
const youtubedl = require('youtube-dl');
const client = new Discord.Client();
/* token --> */ client.login(/* token redacted */);
client.on('ready', ()=>{
console.log('Ready');
});
fs.readdir('./music/', function(err,files){music = files;});
fs.readdir('./midi/', function(err,files){midis = files;});
//var music_extensions = ["aac","aiff","aif","flac","m4a","mp3","ogg","wav","wma","webm","mkv","flv","avi","mov","qt","wmv","mp4","m4v"];
var music_extensions = ["3dostr","3g2","3gp","4xm","a64","aa","aac","ac3","acm","act","adf","adp","ads","adts","adx","aea","afc","aiff","aix","alaw","alias_pix","amr","anm","apc","ape","apng","aqtitle","asf","asf_o","asf_stream","ass","ast","au","avi","avm2","avr","avs","bethsoftvid","bfi","bfstm","bin","bink","bit","bmp_pipe","bmv","boa","brender_pix","brstm","c93","caf","cavsvideo","cdg","cdxl","cine","concat","crc","dash","data","daud","dcstr","dds_pipe","dfa","dirac","dnxhd","dpx_pipe","dsf","dsicin","dss","dts","dtshd","dv","dv1394","dvbsub","dvbtxt","dvd","dxa","ea","ea_cdata","eac3","epaf","exr_pipe","f32be","f32le","f4v","f64be","f64le","fbdev","ffm","ffmetadata","fifo","film_cpk","filmstrip","flac","flic","flv","framecrc","framehash","framemd5","frm","fsb","g722","g723_1","g729","genh","gif","gsm","gxf","h261","h263","h264","hash","hds","hevc","hls","hls","applehttp","hnm","ico","idcin","idf","iff","ilbc","image2","image2pipe","ingenient","ipmovie","ipod","ircam","ismv","iss","iv8","ivf","ivr","j2k_pipe","jacosub","jpeg_pipe","jpegls_pipe","jv","latm","lavfi","live_flv","lmlm4","loas","lrc","lvf","lxf","m4v","matroska","matroska","webm","md5","mgsts","microdvd","mjpeg","mkvtimestamp_v2","mlp","mlv","mm","mmf","mov","mov","mp4","m4a","3gp","3g2","mj2","mp2","mp3","mp4","mpc","mpc8","mpeg","mpeg1video","mpeg2video","mpegts","mpegtsraw","mpegvideo","mpjpeg","mpl2","mpsub","msf","msnwctcp","mtaf","mtv","mulaw","musx","mv","mvi","mxf","mxf_d10","mxf_opatom","mxg","nc","nistsphere","nsv","null","nut","nuv","oga","ogg","ogv","oma","opus","oss","paf","pam_pipe","pbm_pipe","pcx_pipe","pgm_pipe","pgmyuv_pipe","pictor_pipe","pjs","pmp","png_pipe","ppm_pipe","psp","psxstr","pva","pvf","qcp","qdraw_pipe","r3d","rawvideo","realtext","redspark","rl2","rm","roq","rpl","rsd","rso","rtp","rtp_mpegts","rtsp","s16be","s16le","s24be","s24le","s32be","s32le","s8","sami","sap","sbg","sdp","sdr2","segment","sgi_pipe","shn","siff","singlejpeg","sln","smjpeg","smk","smoothstreaming","smush","sol","sox","spdif","spx","srt","stl","stream_segment","ssegment","subviewer","subviewer1","sunrast_pipe","sup","svag","svcd","swf","tak","tedcaptions","tee","thp","tiertexseq","tiff_pipe","tmv","truehd","tta","tty","txd","u16be","u16le","u24be","u24le","u32be","u32le","u8","uncodedframecrc","v210","v210x","v4l2","vag","vc1","vc1test","vcd","video4linux2","v4l2","vivo","vmd","vob","vobsub","voc","vpk","vplayer","vqf","w64","wav","wc3movie","webm","webm_chunk","webm_dash_manife","webp","webp_pipe","webvtt","wsaud","wsd","wsvqa","wtv","wv","wve","x11grab","xa","xbin","xmv","xvag","xwma","yop","yuv4mpegpipe"];
var midi_extensions = ["mid","rmi","rcp","r36","g18","g36","mfi","kar","mod","wrd","xm","s3m","oct","med","ahx","it"];
client.on('message', message => {
if (!message.content.startsWith('!')) return;
var arg = message.content.split(' ');
var cmd = arg[0].slice(1).toLowerCase();
var txt = function(i) {return arg.slice(i).join(' ')}
function search_music(query) {
let search_results = [];
music.forEach(function(filename){
if (filename.toLowerCase().includes(query.toLowerCase())) {
search_results.push(filename);
}
});
return search_results;
}
function search_midis(query) {
let search_results = [];
midis.forEach(function(filename){
if (filename.toLowerCase().includes(query.toLowerCase())) {
search_results.push(filename);
}
});
return search_results;
}
function play (filename, type) {
((message.member && message.member.voiceChannel) || client.channels.get('279769632599048194')).join().then(c => {
connection = c;
if (type === "audio") {
//try{dispatcher.end();}catch(e){}
setTimeout(function(){
let path = './music/'+filename.split('/').join(':');
dispatcher = connection.playFile(path);
dispatcher.songname = filename;
message.channel.send('🎶 **Now playing:** `'+filename+'` 💿');
client.user.setGame(filename);
dispatcher.on('end', () => {
client.user.setGame();
});
},100);
}
else if (type === "midi") {
//try{dispatcher.end();}catch(e){}
setTimeout(function(){
const path = './midi/'+filename.split('/').join(':');
const timidity = child_process.spawn('timidity', [path, '-c', './timidity.cfg', '-o', '-']);
timidity.stderr.on('data', data => {
console.log(("[TiMidity] "+data.toString()).yellow);
});
dispatcher = connection.playConvertedStream(timidity.stdout);
dispatcher.songname = filename;
message.channel.send('🎶 **Now playing:** `'+filename+'` 🎹');
client.user.setGame(filename);
dispatcher.on('end', () => {
timidity.kill();
client.user.setGame();
});
},100);
}
else if (type === "yt") {
if (!filename.startsWith('http')) filename = 'ytsearch:'+filename;
const dl = youtubedl(filename, ['-f bestaudio'], {maxBuffer: Infinity});
let video_filename;
dl.on('info', function(info) {
dispatcher = connection.playStream(dl);
message.channel.send('🎶 **Now playing:** `'+info.title+'` 📺');
fs.appendFile('./ytplay-history.txt', info._filename+'\n'); // ¯\_(ツ)_/¯
client.user.setGame(info.title);
dispatcher.on('end', ()=>{
client.user.setGame();
});
});
}
});
}
if (cmd === 'join') {
if (message.member.voiceChannel) {
message.member.voiceChannel.join().then(c => {connection = c;});
message.react('🆗');
} else {
message.reply('⚠ **First connect to the voice channel that you want me to connect to.**');
}
}
if (cmd === 'leave') {
if (typeof connection !== 'undefined') {
connection.disconnect();
// connection = undefined;
message.react('🆗');
} else {
message.react('⚠');
}
}
if (cmd === "play" || cmd === 'p') {
let query = txt(1);
if (query) {
if (fs.existsSync('./music/'+query)) play(query, 'audio');
else if (fs.existsSync('./midi/'+query)) play(query, 'midi');
else {
let music_search = search_music(query);
if (music_search) play(music_search.random(), 'audio');
else {
let midi_search = search_midis(query);
if (midi_search) play(midi_search.random(), 'midi');
else {
message.channel.send('⚠ **Nothing was found.** Try narrowing your keyword or use a different command (use `!help` for command list)');
}
}
}
} else {
if ([true,false].random()) play(music.random(), 'audio');
else play(midis.random(), 'midi');
}
}
if (cmd === "playaudio" || cmd === 'pa') {
let query = txt(1);
if (query) {
if (fs.existsSync('./music/'+query)) play(query, 'audio');
else {
let search = search_music(query);
if (search) play(search.random(), 'audio');
else play(music.random(), 'audio');
}
} else play(music.random(), 'audio');
}
if (cmd === "playmidi" || cmd === 'pm') {
let query = txt(1);
if (query) {
if (fs.existsSync('./midi/'+query)) play(query, 'midi');
else {
let search = search_midis(query);
if (search != "") play(search.random(), 'midi');
else play(midis.random(), 'midi');
}
} else play(midis.random(), 'midi');
}
if (cmd === "search" || cmd === 's') {
if (txt(1)) {
let music_search = search_music(txt(1));
let midi_search = search_midis(txt(1));
if (music_search != "" || midi_search != "") {
if (music_search != "" && music_search.length < 100) {
let sr = "💿 **Audio Search results:**\n";
music_search.forEach((item, index, array) => {
sr += '`'+item+'`\n';
try {
if (sr.length+array[index+1].length >= 1950) {
message.channel.send(sr);
sr = "";
}
} catch(e) {
message.channel.send(sr);
}
});
}
if (midi_search != "" && midi_search.length < 100) {
let sr = "🎹 **MIDI Search results:**\n";
midi_search.forEach((item, index, array) => {
sr += '`'+item+'`\n';
try {
if (sr.length+array[index+1].length >= 1950) {
message.channel.send(sr);
sr = "";
}
} catch(e) {
message.channel.send(sr);
}
});
}
} else {
message.channel.send('⚠ **No results.**');
}
} else {
message.channel.send('**Usage:** `!search <query>`');
}
}
if (cmd === "upload" || cmd === 'u') {
if (typeof message.attachments.first() !== 'undefined') {
let attachment_name = message.attachments.first().filename;
let attachment_extension = attachment_name.split('.').pop().toLowerCase();
if (music_extensions.includes(attachment_extension.toLowerCase())) {
if (!fs.existsSync('./music/'+attachment_name)) {
message.react('🆗');
download(message.attachments.first().url, {directory: "./music/"}, function(err) {
if (err) {message.channel.send('⚠ **An error occurred while downloading:** ```'+err+'```'); return;}
music.push(attachment_name);
message.channel.send('📁 **Added** `'+attachment_name+'` **to the music collection.** 💿');
});
} else {
message.channel.send('⚠ **File** `'+attachment_name+'` **already exists.**');
}
} else if (midi_extensions.includes(attachment_extension.toLowerCase())) {
if (!fs.existsSync('./midi/'+attachment_name)) {
message.react('🆗');
download(message.attachments.first().url, {directory: "./midi/"}, function(err) {
if (err) {message.channel.send('⚠ **An error occurred while downloading:** ```'+err+'```'); return;}
midis.push(attachment_name);
message.channel.send('📁 **Added** `'+attachment_name+'` **to the MIDI collection.** 🎹');
});
} else {
message.channel.send('⚠ **File** `'+attachment_name+'` **already exists.**');
}
} else if (["sfx","sf2", "cfg"].includes(attachment_extension.toLowerCase())) {
if (!fs.existsSync('./soundfonts/'+attachment_name)) {
message.react('🆗');
download(message.attachments.first().url, {directory: "./soundfonts/"}, function(err) {
if (err) {message.channel.send('⚠ **An error occurred while downloading:** ```'+err+'```'); return;}
message.channel.send('📁 **Added** `'+attachment_name+'` **to the soundfont collection.** 🎺');
});
} else {
message.channel.send('⚠ **File** `'+attachment_name+'` **already exists.**');
}
} else {
message.channel.send('⚠ **Format extension `'+attachment_extension+'` is not supported or unknown.**');
download(message.attachments.first().url, {directory: "./trash/"});
}
} else {
message.channel.send(' **To upload to the music database, type `!upload` and attach the file to your message.**');
}
}
/*
function ytplayc(message,arg,txt){
const query = txt(1);
if (query !== "") {
message.react('🆗');
if (query.startsWith('http')) {
dispatcher = connection.playStream(ytdl(query, {filter: "audioonly"}));
message.channel.send('Now playing whatever video u gave me');
dispatcher.on('end', ()=>{
message.channel.send('wutevr u gave me is now over');
});
} else {
}
} else {
message.reply('Usage: `!ytplay <youtube URL>`');
}
}
function ytdlc(message,arg,txt){
const query = txt(1);
if (query !== "") {
message.react('🆗');
if (query.startsWith('http')) {
ytdl.getInfo(query, (err,info)=>{
message.channel.send('[testing] Downloading '+info.title);
ytdl.downloadFromInfo(info, {filter: "audioonly"}).pipe(fs.createWriteStream('./music/'+info.title+'-'+info.video_id));
});
} else {
}
} else {
message.reply('Usage: `!ytdl <youtube URL>`');
}
}
*/
if (cmd === "ytplay" || cmd === "ytp" || cmd === "pyt" || cmd === "py") {
if (txt(1)) {
message.react('🆗');
play(txt(1), 'yt');
} else {
message.reply(' **Usage:** `!ytplay <youtube URL or search query>`');
}
}
if (cmd === 'youtube-dl' || cmd === "ytdl") {
if (txt(1)) {
message.react('🆗');
let query = txt(1);
if (!query.startsWith('http')) query = 'ytsearch:'+query;
const dl = youtubedl(query, ['-f bestaudio'], {maxBuffer: Infinity});
let video_filename;
dl.on('info', function(info) {
// message.channel.send('Downloading `'+info.filename+ '`\n Size: `'+info.size+'`');
dl.pipe(fs.createWriteStream('./music/'+info._filename));
video_filename = info._filename;
});
dl.on('end', function() {
music.push(video_filename);
// message.channel.send('Download finished.');
message.channel.send('📁 **Added** `'+video_filename+'` **to the music collection.** 💿')
});
} else {
message.reply(' **Usage:** `!ytdl <youtube URL or search query>`');
}
}
if (cmd === 'sf') {
if (arg[1] === 'cfg') {
fs.readFile('./soundfonts.cfg', 'utf8', (err, data)=> {
message.channel.send('Contents of soundfont config:\n`'+data+'`');
});
} else if (arg[1] === 'list') {
fs.readdir('./soundfonts/', (err, files)=>{
message.channel.send('Available soundfonts: \n`'+files.join('\n')+'`');
});
} else if (arg[1] === 'set') {
arg.shift();
let newcfg = "";
arg.forEach(filename => {
if (fs.existsSync('./soundfonts/'+filename)) {
if (filename.split('.').pop() === "cfg") {
newcfg += 'source ./soundfonts/'+filename+'\n';
} else {
newcfg += 'soundfont ./soundfonts/'+filename+'\n';
}
} else {
message.channel.send('err: soundfont `'+filename+'` doesn\'t exist');
}
});
fs.writeFile('./soundfonts.cfg', newcfg, ()=>{
message.channel.send('Saved new soundfont config with the following contents:\n`'+newcfg+'`');
});
} else {
message.channel.send('`!sf cfg` shows soundfont config; `!sf list` shows available soundfonts; `!sf set` writes new soundfont config');
}
}
if (typeof dispatcher !== 'undefined') {
// Song control
if (cmd === 'song') {
message.channel.send('🎶 **Currently playing:** `'+dispatcher.songname+'`');
}
if (cmd === 'pause') {
dispatcher.pause();
message.react('🆗');
}
if (cmd === 'resume') {
dispatcher.resume();
message.react('🆗');
}
if (cmd === 'volume') {
if (arg[1]) {
dispatcher.setVolume(arg[1]);
message.react('🆗');
} else {
message.channel.send('🔊 **Volume:** `'+dispatcher._volume+'`')
}
}
if (cmd === 'time') {
message.channel.send(dispatcher.time);
}
if (cmd === 'stop') {
dispatcher.end();
// dispatcher = undefined;
message.react('🆗');
}
}
if (cmd === 'rlm') {
message.react('🆗');
fs.readdir('./music/', function(err,files){music = files;});
fs.readdir('./midi/', function(err,files){midis = files;});
}
});
// Utility Functions
////////////////////////////////////////////////////////////////////////////////
Array.prototype.random = function () {
return this[Math.floor(Math.random()*this.length)];
}

0
midi/.gitkeep Normal file

0
music/.gitkeep Normal file

0
music_metadata/.gitkeep Normal file

490
musicbot.js Normal file

@ -0,0 +1,490 @@
console.log('Starting');
const Discord = require('discord.js');
const fs = require('fs');
const child_process = require('child_process');
const colors = require('colors');
const download = require('download-file');
//const ytdl = require('ytdl-core');
const youtubedl = require('youtube-dl');
//const ffprobe = require('ffprobe');
const client = new Discord.Client();
client.login(fs.readFileSync('token.txt', 'utf8'));
client.on('ready', ()=>{
console.log('Ready');
});
fs.readdir('./music/', function(err,files){music = files});
fs.readdir('./midi/', function(err,files){midis = files});
//var music_extensions = ["aac","aiff","aif","flac","m4a","mp3","ogg","wav","wma","webm","mkv","flv","avi","mov","qt","wmv","mp4","m4v"];
const music_extensions = ["3dostr","3g2","3gp","4xm","a64","aa","aac","ac3","acm","act","adf","adp","ads","adts","adx","aea","afc","aiff","aix","alaw","alias_pix","amr","anm","apc","ape","apng","aqtitle","asf","asf_o","asf_stream","ass","ast","au","avi","avm2","avr","avs","bethsoftvid","bfi","bfstm","bin","bink","bit","bmp_pipe","bmv","boa","brender_pix","brstm","c93","caf","cavsvideo","cdg","cdxl","cine","concat","crc","dash","data","daud","dcstr","dds_pipe","dfa","dirac","dnxhd","dpx_pipe","dsf","dsicin","dss","dts","dtshd","dv","dv1394","dvbsub","dvbtxt","dvd","dxa","ea","ea_cdata","eac3","epaf","exr_pipe","f32be","f32le","f4v","f64be","f64le","fbdev","ffm","ffmetadata","fifo","film_cpk","filmstrip","flac","flic","flv","framecrc","framehash","framemd5","frm","fsb","g722","g723_1","g729","genh","gif","gsm","gxf","h261","h263","h264","hash","hds","hevc","hls","hls","applehttp","hnm","ico","idcin","idf","iff","ilbc","image2","image2pipe","ingenient","ipmovie","ipod","ircam","ismv","iss","iv8","ivf","ivr","j2k_pipe","jacosub","jpeg_pipe","jpegls_pipe","jv","latm","lavfi","live_flv","lmlm4","loas","lrc","lvf","lxf","m4v","matroska","matroska","webm","md5","mgsts","microdvd","mjpeg","mkvtimestamp_v2","mlp","mlv","mm","mmf","mov","mov","mp4","m4a","3gp","3g2","mj2","mp2","mp3","mp4","mpc","mpc8","mpeg","mpeg1video","mpeg2video","mpegts","mpegtsraw","mpegvideo","mpjpeg","mpl2","mpsub","msf","msnwctcp","mtaf","mtv","mulaw","musx","mv","mvi","mxf","mxf_d10","mxf_opatom","mxg","nc","nistsphere","nsv","null","nut","nuv","oga","ogg","ogv","oma","opus","oss","paf","pam_pipe","pbm_pipe","pcx_pipe","pgm_pipe","pgmyuv_pipe","pictor_pipe","pjs","pmp","png_pipe","ppm_pipe","psp","psxstr","pva","pvf","qcp","qdraw_pipe","r3d","rawvideo","realtext","redspark","rl2","rm","roq","rpl","rsd","rso","rtp","rtp_mpegts","rtsp","s16be","s16le","s24be","s24le","s32be","s32le","s8","sami","sap","sbg","sdp","sdr2","segment","sgi_pipe","shn","siff","singlejpeg","sln","smjpeg","smk","smoothstreaming","smush","sol","sox","spdif","spx","srt","stl","stream_segment","ssegment","subviewer","subviewer1","sunrast_pipe","sup","svag","svcd","swf","tak","tedcaptions","tee","thp","tiertexseq","tiff_pipe","tmv","truehd","tta","tty","txd","u16be","u16le","u24be","u24le","u32be","u32le","u8","uncodedframecrc","v210","v210x","v4l2","vag","vc1","vc1test","vcd","video4linux2","v4l2","vivo","vmd","vob","vobsub","voc","vpk","vplayer","vqf","w64","wav","wc3movie","webm","webm_chunk","webm_dash_manife","webp","webp_pipe","webvtt","wsaud","wsd","wsvqa","wtv","wv","wve","x11grab","xa","xbin","xmv","xvag","xwma","yop","yuv4mpegpipe"];
const midi_extensions = ["mid","rmi","rcp","r36","g18","g36","mfi","kar","mod","wrd","xm","s3m","oct","med","ahx","it"];
const myVoiceChannelID = "279769632599048194";
const myGuildID = "279769632599048193";
const cmdChar = "!";
let myVoiceConnection;
function play(filename, type, channel) {
client.channels.get(myVoiceChannelID).join().then(connection => {
myVoiceConnection = connection;
if (type === "audio") {
const filtered_filename = filename.replace(/\//g, ':');
const path = './music/'+filtered_filename;
const metadata_path = './music_metadata/'+filtered_filename+'.json';
connection.playFile(path);
connection.dispatcher.songname = filename;
let np_message;
channel.send('🎶 **Now playing:** `'+filename+'` 💿').then(m => mp_message = m);
fs.readFile(metadata_path, 'utf8', (err,data)=>{
if (err) { // make metadata file
console.log(`creating metadata file ${metadata_path}`);
const metadata = {
plays: 1,
lastPlay: new Date().toJSON(),
};
// ffprobe(path, {path: '/usr/bin/ffprobe'}, (err, info) => {
// metadata.ffprobe = info;
connection.dispatcher.meta = metadata;
fs.writeFile(metadata_path, JSON.stringify(metadata));
// });
} else { // load & update metadata file
console.log(`using metadata file ${metadata_path}`);
const metadata = JSON.parse(data);
metadata.plays++;
metadata.lastPlay = new Date().toJSON();
connection.dispatcher.meta = metadata;
fs.writeFile(metadata_path, JSON.stringify(metadata));
}
});
client.user.setGame(filename);
connection.dispatcher.on('end', () => {
client.user.setGame();
});
}
else if (type === "midi") {
const path = './midi/'+filename.split('/').join(':');
const timidity = child_process.spawn('timidity', [path, '-c', './timidity.cfg', '-o', '-']);
timidity.stderr.on('data', data => {
console.log(("[TiMidity] "+data.toString()).yellow);
});
connection.playConvertedStream(timidity.stdout);
connection.dispatcher.songname = filename;
if (channel) channel.send('🎶 **Now playing:** `'+filename+'` 🎹');
client.user.setGame(filename);
connection.dispatcher.on('end', () => {
timidity.kill();
client.user.setGame();
});
}
else if (type === "yt") {
if (!filename.startsWith('http')) filename = 'ytsearch:'+filename;
const dl = youtubedl(filename, ['-f bestaudio'], {maxBuffer: Infinity});
let video_filename;
dl.on('info', function(info) {
connection.playStream(dl);
if (channel) channel.send('🎶 **Now playing:** `'+info.title+'` 📺');
fs.appendFile('./ytplay-history.txt', info._filename+'\n'); // ¯\_(ツ)_/¯
client.user.setGame(info.title);
connection.dispatcher.on('end', ()=>{
client.user.setGame();
});
});
}
});
}
const commands = {
mhelp: {
description: "Shows command list",
execute: function (message, args, txt) {
const embed = {
color: client.guilds.get(myGuildID).me.colorRole.color,
author: {name: "Music Bot Commands", icon_url: client.user.avatarURL},
fields: []
}
for (const commandName in commands) {
const command = commands[commandName];
if (command.hidden) continue;
embed.fields.push({name: cmdChar+commandName,value: command.description || "(no description)"});
}
let scl = [];
Object.keys(songCommands).forEach(c => scl.push(cmdChar+c));
embed.fields.push({name: scl.join(', '), value: "These commands control a playing song."});
message.channel.send({embed});
}
},
//join: {},
leave: {
description: "Disconnects the bot from the voice channel.",
execute: function (message, args, txt) {
if (myVoiceConnection) {
myVoiceConnection.disconnect();
message.react('🆗');
} else {
message.react('⚠');
}
}
},
play: {
aliases: ["p"],
description: "Plays something. If no arguments are given, a random audio or MIDI is played. If given the name of an existing audio or MIDI file, that will be played, else the query will be searched and a random result will be played.",
execute: function (message, args, txt) {
let query = txt(1);
if (query) {
if (music.includes(query)) play(query, 'audio', message.channel);
else if (midis.includes(query)) play(query, 'midi', message.channel);
else {
let music_search = music.search(query);
if (music_search) play(music_search.random(), 'audio', message.channel);
else {
let midi_search = midis.search(query);
if (midi_search) play(midi_search.random(), 'midi', message.channel);
else {
message.channel.send('⚠ **Nothing was found.** Try narrowing your keyword or use a different command (use `!help` for command list)');
}
}
}
} else {
if ([true,false].random()) play(music.random(), 'audio', message.channel);
else play(midis.random(), 'midi', message.channel);
}
}
},
playaudio: {
aliases: ["pa"],
description: "Like play but restricted to audio.",
execute: function (message, args, txt) {
let query = txt(1);
if (query) {
if (fs.existsSync('./music/'+query)) play(query, 'audio', message.channel);
else {
let search = music.search(query);
if (search) play(search.random(), 'audio', message.channel);
else play(music.random(), 'audio', message.channel);
}
} else play(music.random(), 'audio', message.channel);
}
},
playmidi: {
aliases: ["pm"],
description: "Like play but restricted to MIDIs.",
execute: function (message, args, txt) {
let query = txt(1);
if (query) {
if (fs.existsSync('./midi/'+query)) play(query, 'midi', message.channel);
else {
let search = midis.search(query);
if (search != "") play(search.random(), 'midi', message.channel);
else play(midis.random(), 'midi', message.channel);
}
} else play(midis.random(), 'midi', message.channel);
}
},
search: {
aliases: ["s"],
description: "Searches the audio and midi collections. All results that **include** the given query are returned.",
execute: function (message, args, txt) {
if (txt(1)) {
let music_search = music.search(txt(1));
let midi_search = midis.search(txt(1));
if (music_search != "" || midi_search != "") {
if (music_search != "" && music_search.length < 100) {
let sr = "💿 **Audio Search results:**\n";
music_search.forEach((item, index, array) => {
sr += '`'+item+'`\n';
try {
if (sr.length+array[index+1].length >= 1950) {
message.channel.send(sr);
sr = "";
}
} catch(e) {
message.channel.send(sr);
}
});
}
if (midi_search != "" && midi_search.length < 100) {
let sr = "🎹 **MIDI Search results:**\n";
midi_search.forEach((item, index, array) => {
sr += '`'+item+'`\n';
try {
if (sr.length+array[index+1].length >= 1950) {
message.channel.send(sr);
sr = "";
}
} catch(e) {
message.channel.send(sr);
}
});
}
} else {
message.channel.send('⚠ **No results.**');
}
} else {
message.channel.send('**Usage:** `!search <query>`');
}
}
},
upload: {
aliases: ["u"],
description: "Adds the attached file to the audio, midi, or soundfont collection.",
execute: function (message, args, txt) {
if (typeof message.attachments.first() !== 'undefined') {
let attachment_name = message.attachments.first().filename;
let attachment_extension = attachment_name.split('.').pop().toLowerCase();
if (music_extensions.includes(attachment_extension.toLowerCase())) {
if (!fs.existsSync('./music/'+attachment_name)) {
message.react('🆗');
download(message.attachments.first().url, {directory: "./music/"}, function(err) {
if (err) {message.channel.send('⚠ **An error occurred while downloading:** ```'+err+'```'); return;}
music.push(attachment_name);
message.channel.send('📁 **Added** `'+attachment_name+'` **to the music collection.** 💿');
});
} else {
message.channel.send('⚠ **File** `'+attachment_name+'` **already exists.**');
}
} else if (midi_extensions.includes(attachment_extension.toLowerCase())) {
if (!fs.existsSync('./midi/'+attachment_name)) {
message.react('🆗');
download(message.attachments.first().url, {directory: "./midi/"}, function(err) {
if (err) {message.channel.send('⚠ **An error occurred while downloading:** ```'+err+'```'); return;}
midis.push(attachment_name);
message.channel.send('📁 **Added** `'+attachment_name+'` **to the MIDI collection.** 🎹');
});
} else {
message.channel.send('⚠ **File** `'+attachment_name+'` **already exists.**');
}
} else if (["sfx","sf2", "cfg"].includes(attachment_extension.toLowerCase())) {
if (!fs.existsSync('./soundfonts/'+attachment_name)) {
message.react('🆗');
download(message.attachments.first().url, {directory: "./soundfonts/"}, function(err) {
if (err) {message.channel.send('⚠ **An error occurred while downloading:** ```'+err+'```'); return;}
message.channel.send('📁 **Added** `'+attachment_name+'` **to the soundfont collection.** 🎺');
});
} else {
message.channel.send('⚠ **File** `'+attachment_name+'` **already exists.**');
}
} else {
message.channel.send('⚠ **Format extension `'+attachment_extension+'` is not supported or unknown.**');
download(message.attachments.first().url, {directory: "./trash/"});
}
} else {
message.channel.send(' **To upload your music, type `!upload` and attach the file to your message.**');
}
}
},
ytplay: {
description: "Plays something from YouTube!",
hidden: true,
execute: function (message, args, txt) {
if (txt(1)) {
message.react('🆗');
play(txt(1), 'yt', message.channel);
} else {
message.reply(' **Usage:** `!ytplay <youtube URL or search query>`');
}
}
},
ytdl: {
description: "Adds a YouTube video to the audio collection.",
hidden: true,
execute: function (message, args, txt) {
if (txt(1)) {
message.react('🆗');
let query = txt(1);
if (!query.startsWith('http')) query = 'ytsearch:'+query;
const dl = youtubedl(query, ['-f bestaudio'], {maxBuffer: Infinity});
let video_filename;
dl.on('info', function(info) {
// message.channel.send('Downloading `'+info.filename+ '`\n Size: `'+info.size+'`');
dl.pipe(fs.createWriteStream('./music/'+info._filename));
video_filename = info._filename;
});
dl.on('end', function() {
music.push(video_filename);
// message.channel.send('Download finished.');
message.channel.send('📁 **Added** `'+video_filename+'` **to the music collection.** 💿')
});
} else {
message.reply(' **Usage:** `!ytdl <youtube URL or search query>`');
}
}
},
soundfonts: {
aliases: ["sf"],
description: "modifies soundfont config",
hidden: true,
execute: function (message, args, txt) {
if (args[1] === 'cfg') {
fs.readFile('./soundfonts.cfg', 'utf8', (err, data)=> {
message.channel.send('Contents of soundfont config:\n`'+data+'`');
});
} else if (args[1] === 'list') {
fs.readdir('./soundfonts/', (err, files)=>{
message.channel.send('Available soundfonts: \n`'+files.join('\n')+'`');
});
} else if (args[1] === 'set') {
args.shift();
let newcfg = "";
args.forEach(filename => {
if (fs.existsSync('./soundfonts/'+filename)) {
if (filename.split('.').pop() === "cfg") {
newcfg += 'source ./soundfonts/'+filename+'\n';
} else {
newcfg += 'soundfont ./soundfonts/'+filename+'\n';
}
} else {
message.channel.send('err: soundfont `'+filename+'` doesn\'t exist');
}
});
fs.writeFile('./soundfonts.cfg', newcfg, ()=>{
message.channel.send('Saved new soundfont config with the following contents:\n`'+newcfg+'`');
});
} else {
message.channel.send('`!sf cfg` shows soundfont config; `!sf list` shows available soundfonts; `!sf set` writes new soundfont config');
}
}
},
}
const songCommands = {
song: function (message, args, txt) {
message.channel.send('🎶 **Currently playing:** `'+myVoiceConnection.dispatcher.songname+'`');
/*const embed = {
color: client.guilds.get(myGuildID).me.colorRole.color,
author: {name: "🎶 **Currently playing**"},
description: `**${myVoiceConnection.dispatcher.songname}**`,
fields: []
}
const metadata = myVoiceConnection.dispatcher.meta;
if (metadata) {
embed.fields.push({name: "Duration", value: metadata.duration});
}
message.channel.send({embed});*/
},
pause: function (message, args, txt) {
myVoiceConnection.dispatcher.pause();
message.react('🆗');
},
resume: function (message, args, txt) {
myVoiceConnection.dispatcher.resume();
message.react('🆗');
},
volume: function (message, args, txt) {
if (!isNaN(args[1])) myVoiceConnection.dispatcher.setVolume(args[1]*0.01);
message.channel.send('🔊 **Volume:** `'+myVoiceConnection.dispatcher._volume*100+'%`');
},
time: function (message, args, txt) {
message.channel.send('⏱ **Time Elapsed:** `'+getYoutubeLikeToDisplay(myVoiceConnection.dispatcher.time)+'`');
},
stop: function (message, args, txt) {
myVoiceConnection.dispatcher.end('!stop command');
message.react('🆗');
}
}
client.on('message', message => {
if (!message.content.startsWith(cmdChar)) return;
try {
const args = message.content.split(' ');
const cmd = args[0].slice(1).toLowerCase();
const txt = (i) => {return args.slice(i).join(' ')};
for (const commandName in commands) {
const command = commands[commandName];
if ( commandName === cmd ||command.aliases && (command.aliases.includes(cmd)) )
command.execute(message, args, txt);
}
for (const commandName in songCommands) {
if (commandName === cmd) {
if (myVoiceConnection && myVoiceConnection.dispatcher) {
songCommands[commandName](message, args, txt);
} else {
message.channel.send('🚫 **Nothing is playing.**');
}
}
}
} catch (e) {
message.reply('💥 **An error has been encountered while processing your command.** 💥');
console.error(colors.red(`Command failure with message "${message.content}": `+e.stack));
}
});
// Utility Functions
////////////////////////////////////////////////////////////////////////////////
Array.prototype.random = function () {
return this[Math.floor(Math.random()*this.length)];
}
/*Array.prototype.search = function (query) {
let results = [];
this.forEach(item => {
if (item.toLowerCase().includes(query.toLowerCase())) results.push(item);
});
return results;
}*/
Array.prototype.search = function (query) {
return this.filter( item => item.toLowerCase().includes(query.toLowerCase()) );
}
function getYoutubeLikeToDisplay(millisec) {
var seconds = (millisec / 1000).toFixed(0);
var minutes = Math.floor(seconds / 60);
var hours = "";
if (minutes > 59) {
hours = Math.floor(minutes / 60);
hours = (hours >= 10) ? hours : "0" + hours;
minutes = minutes - (hours * 60);
minutes = (minutes >= 10) ? minutes : "0" + minutes;
}
seconds = Math.floor(seconds % 60);
seconds = (seconds >= 10) ? seconds : "0" + seconds;
if (hours != "") {
return hours + ":" + minutes + ":" + seconds;
}
return minutes + ":" + seconds;
}
////////////////////////////////////////////////////////////////////////////////
client.on('error', error => console.error(error));

379
package-lock.json generated Normal file

@ -0,0 +1,379 @@
{
"requires": true,
"lockfileVersion": 1,
"dependencies": {
"async-limiter": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz",
"integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg=="
},
"asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
},
"balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
},
"block-stream": {
"version": "0.0.9",
"resolved": "https://registry.npmjs.org/block-stream/-/block-stream-0.0.9.tgz",
"integrity": "sha1-E+v+d4oDIFz+A3UUgeu0szAMEmo=",
"requires": {
"inherits": "2.0.3"
}
},
"bluebird": {
"version": "2.11.0",
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-2.11.0.tgz",
"integrity": "sha1-U0uQM8AiyVecVro7Plpcqvu2UOE="
},
"brace-expansion": {
"version": "1.1.8",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz",
"integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=",
"requires": {
"balanced-match": "1.0.0",
"concat-map": "0.0.1"
}
},
"combined-stream": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.5.tgz",
"integrity": "sha1-k4NwpXtKUd6ix3wV1cX9+JUWQAk=",
"requires": {
"delayed-stream": "1.0.0"
}
},
"commander": {
"version": "2.13.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.13.0.tgz",
"integrity": "sha512-MVuS359B+YzaWqjCL/c+22gfryv+mCBPHAv3zyVI2GN8EY6IRP8VwtasXn8jyyhvvq84R4ImN1OKRtcbIasjYA=="
},
"component-emitter": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.2.1.tgz",
"integrity": "sha1-E3kY1teCg/ffemt8WmPhQOaUJeY="
},
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
},
"cookiejar": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.1.tgz",
"integrity": "sha1-Qa1XsbVVlR7BcUEqgZQrHoIA00o="
},
"core-util-is": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
},
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"requires": {
"ms": "2.0.0"
}
},
"delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
},
"discord.js": {
"version": "11.3.0",
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-11.3.0.tgz",
"integrity": "sha512-xM3ydvb4urHjCP3N+Mgpw53a7ZGtmPwllwVgwPqdF2SHNPvTDr4So/+55VVx76s5eO9IMrOWpczsEuIr0/MAgQ==",
"requires": {
"long": "3.2.0",
"prism-media": "0.0.1",
"snekfetch": "3.6.1",
"tweetnacl": "1.0.0",
"ws": "4.0.0"
}
},
"extend": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz",
"integrity": "sha1-p1Xqe8Gt/MWjHOfnYtuq3F5jZEQ="
},
"ffmpeg-binaries": {
"version": "3.2.2-3",
"resolved": "https://registry.npmjs.org/ffmpeg-binaries/-/ffmpeg-binaries-3.2.2-3.tgz",
"integrity": "sha1-nKM7aM0wTs8Qwz5tz3HiuT637hQ=",
"requires": {
"superagent": "3.8.2",
"tar.gz": "1.0.7"
}
},
"form-data": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.1.tgz",
"integrity": "sha1-b7lPvXGIUwbXPRXMSX/kzE7NRL8=",
"requires": {
"asynckit": "0.4.0",
"combined-stream": "1.0.5",
"mime-types": "2.1.17"
}
},
"formidable": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/formidable/-/formidable-1.1.1.tgz",
"integrity": "sha1-lriIb3w8NQi5Mta9cMTTqI818ak="
},
"fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
},
"fstream": {
"version": "1.0.11",
"resolved": "https://registry.npmjs.org/fstream/-/fstream-1.0.11.tgz",
"integrity": "sha1-XB+x8RdHcRTwYyoOtLcbPLD9MXE=",
"requires": {
"graceful-fs": "4.1.11",
"inherits": "2.0.3",
"mkdirp": "0.5.1",
"rimraf": "2.6.2"
}
},
"glob": {
"version": "7.1.2",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz",
"integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==",
"requires": {
"fs.realpath": "1.0.0",
"inflight": "1.0.6",
"inherits": "2.0.3",
"minimatch": "3.0.4",
"once": "1.4.0",
"path-is-absolute": "1.0.1"
}
},
"graceful-fs": {
"version": "4.1.11",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz",
"integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg="
},
"inflight": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
"requires": {
"once": "1.4.0",
"wrappy": "1.0.2"
}
},
"inherits": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
},
"isarray": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
},
"long": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/long/-/long-3.2.0.tgz",
"integrity": "sha1-2CG3E4yhy1gcFymQ7xTbIAtcR0s="
},
"methods": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",
"integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4="
},
"mime": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz",
"integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg=="
},
"mime-db": {
"version": "1.30.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.30.0.tgz",
"integrity": "sha1-dMZD2i3Z1qRTmZY0ZbJtXKfXHwE="
},
"mime-types": {
"version": "2.1.17",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.17.tgz",
"integrity": "sha1-Cdejk/A+mVp5+K+Fe3Cp4KsWVXo=",
"requires": {
"mime-db": "1.30.0"
}
},
"minimatch": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
"requires": {
"brace-expansion": "1.1.8"
}
},
"minimist": {
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
},
"mkdirp": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
"requires": {
"minimist": "0.0.8"
}
},
"mout": {
"version": "0.11.1",
"resolved": "https://registry.npmjs.org/mout/-/mout-0.11.1.tgz",
"integrity": "sha1-ujYR318OWx/7/QEWa48C0fX6K5k="
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"requires": {
"wrappy": "1.0.2"
}
},
"path-is-absolute": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18="
},
"prism-media": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/prism-media/-/prism-media-0.0.1.tgz",
"integrity": "sha1-o0JcnKvVDRxsAuVDlBoRiVZnvRA="
},
"process-nextick-args": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz",
"integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M="
},
"qs": {
"version": "6.5.1",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.1.tgz",
"integrity": "sha512-eRzhrN1WSINYCDCbrz796z37LOe3m5tmW7RQf6oBntukAG1nmovJvhnwHHRMAfeoItc1m2Hk02WER2aQ/iqs+A=="
},
"readable-stream": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.3.tgz",
"integrity": "sha512-m+qzzcn7KUxEmd1gMbchF+Y2eIUbieUaxkWtptyHywrX0rE8QEYqPC07Vuy4Wm32/xE16NcdBctb8S0Xe/5IeQ==",
"requires": {
"core-util-is": "1.0.2",
"inherits": "2.0.3",
"isarray": "1.0.0",
"process-nextick-args": "1.0.7",
"safe-buffer": "5.1.1",
"string_decoder": "1.0.3",
"util-deprecate": "1.0.2"
}
},
"rimraf": {
"version": "2.6.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz",
"integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==",
"requires": {
"glob": "7.1.2"
}
},
"safe-buffer": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz",
"integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg=="
},
"snekfetch": {
"version": "3.6.1",
"resolved": "https://registry.npmjs.org/snekfetch/-/snekfetch-3.6.1.tgz",
"integrity": "sha512-aLEvf1YR440pINb0LEo/SL2Q2s/A26+YEqPlx09A0XpGH7qWp8iqIFFolVILHn2yudWXJne9QWyQu+lzDp+ksQ=="
},
"string_decoder": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz",
"integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==",
"requires": {
"safe-buffer": "5.1.1"
}
},
"superagent": {
"version": "3.8.2",
"resolved": "https://registry.npmjs.org/superagent/-/superagent-3.8.2.tgz",
"integrity": "sha512-gVH4QfYHcY3P0f/BZzavLreHW3T1v7hG9B+hpMQotGQqurOvhv87GcMCd6LWySmBuf+BDR44TQd0aISjVHLeNQ==",
"requires": {
"component-emitter": "1.2.1",
"cookiejar": "2.1.1",
"debug": "3.1.0",
"extend": "3.0.1",
"form-data": "2.3.1",
"formidable": "1.1.1",
"methods": "1.1.2",
"mime": "1.6.0",
"qs": "6.5.1",
"readable-stream": "2.3.3"
}
},
"tar": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/tar/-/tar-2.2.1.tgz",
"integrity": "sha1-jk0qJWwOIYXGsYrWlK7JaLg8sdE=",
"requires": {
"block-stream": "0.0.9",
"fstream": "1.0.11",
"inherits": "2.0.3"
}
},
"tar.gz": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/tar.gz/-/tar.gz-1.0.7.tgz",
"integrity": "sha512-uhGatJvds/3diZrETqMj4RxBR779LKlIE74SsMcn5JProZsfs9j0QBwWO1RW+IWNJxS2x8Zzra1+AW6OQHWphg==",
"requires": {
"bluebird": "2.11.0",
"commander": "2.13.0",
"fstream": "1.0.11",
"mout": "0.11.1",
"tar": "2.2.1"
}
},
"tweetnacl": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.0.tgz",
"integrity": "sha1-cT2LgY2kIGh0C/aDhtBHnmb8ins="
},
"ultron": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.1.tgz",
"integrity": "sha512-UIEXBNeYmKptWH6z8ZnqTeS8fV74zG0/eRU9VGkpzz+LIJNs8W/zM/L+7ctCkRrgbNnnR0xxw4bKOr0cW0N0Og=="
},
"util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
},
"wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
},
"ws": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-4.0.0.tgz",
"integrity": "sha512-QYslsH44bH8O7/W2815u5DpnCpXWpEK44FmaHffNwgJI4JMaSZONgPBTOfrxJ29mXKbXak+LsJ2uAkDTYq2ptQ==",
"requires": {
"async-limiter": "1.0.0",
"safe-buffer": "5.1.1",
"ultron": "1.1.1"
}
}
}
}

3
soundfonts.cfg Normal file

@ -0,0 +1,3 @@
soundfont ./soundfonts/yamaha_xg_sound_set.sf2
soundfont ./soundfonts/mt32-gs-2.51.sf2
soundfont ./soundfonts/4GMGSMT.SF2

0
soundfonts/.gitkeep Normal file

24
timidity.cfg Normal file

@ -0,0 +1,24 @@
opt s48kHz
opt Or1sl
# juest
opt p100
opt A100
opt Ewpvsetoz
opt EFvlpf=d
opt anti-alias=d
#opt EFresamp=d #disable resampling
#opt EFvlpf=d #disable VLPF
#opt EFreverb=d #disable reverb
#opt anti-alias=d #disable sample anti-aliasing
#opt EFchorus=s
#opt s48kHz
#opt Or1sl
#opt --volume=100
#opt --drum-power=100
#opt Ewpvsetoz
#opt idq
#opt W-
source ./soundfonts.cfg

0
trash/.gitkeep Normal file