Added TODO

pull/9/head
Trivernis 6 years ago
parent 08091ba15a
commit 540007318e

@ -5,14 +5,16 @@ const Discord = require("discord.js"),
cmd = require("./lib/cmd"),
client = new Discord.Client(),
args = require('args-parser')(process.argv),
authToken = args.token;
authToken = args.token,
prefix = args.prefix || '~',
gamepresence = args.game || 'NieR:Automata';
let savedplaylists = {};
function main() {
music.setLogger(logger);
cmd.setLogger(logger);
cmd.init();
cmd.init(prefix);
if (fs.existsSync('./data/savedplaylists.json')) {
savedplaylists = JSON.parse(fs.readFileSync('./data/savedplaylists.json'))
}
@ -30,7 +32,7 @@ function savePlaylist(url, name) {
}
function registerCommands() {
cmd.createCommand('~', 'play', (msg, argv) => {
cmd.createCommand(prefix, 'play', (msg, argv) => {
let vc = msg.member.voiceChannel;
let url = argv['url'];
if (!url) return 'No url given.';
@ -47,7 +49,7 @@ function registerCommands() {
}
}, ['url'], "Adds the url to the YouTube video/playlist into the queue.");
cmd.createCommand('~', 'playnext', (msg, argv) => {
cmd.createCommand(prefix, 'playnext', (msg, argv) => {
let vc = msg.member.voiceChannel;
let url = argv['url'];
if (!url) return 'No url given.';
@ -64,11 +66,11 @@ function registerCommands() {
}
}, ['url'], "Plays the YouTube video after the currently playing song.");
cmd.createCommand('~', 'ping', () => {
cmd.createCommand(prefix, 'ping', () => {
return 'Pong!';
}, [], "Try it yourself.");
cmd.createCommand('~', 'join', (msg) => {
cmd.createCommand(prefix, 'join', (msg) => {
if (msg.member.voiceChannel) {
music.connect(msg.member.voiceChannel);
}
@ -77,33 +79,33 @@ function registerCommands() {
}
}, [], "Joins the VC you are in.");
cmd.createCommand('~', 'stop', (msg) => {
cmd.createCommand(prefix, 'stop', (msg) => {
let gid = msg.guild.id;
music.stop(gid);
}, [], "Stops playling music and leavs.");
cmd.createCommand('~', 'pause', (msg) => {
cmd.createCommand(prefix, 'pause', (msg) => {
let gid = msg.guild.id;
music.pause(gid);
}, [], "Pauses playing.");
cmd.createCommand('~', 'resume', (msg) => {
cmd.createCommand(prefix, 'resume', (msg) => {
let gid = msg.guild.id;
music.resume(gid);
}, [], "Resumes playing.");
cmd.createCommand('~', 'skip', (msg) => {
cmd.createCommand(prefix, 'skip', (msg) => {
let gid = msg.guild.id;
music.skip(gid);
}, [], "Skips the current song.");
cmd.createCommand('~', 'clear', (msg) => {
cmd.createCommand(prefix, 'clear', (msg) => {
let gid = msg.guild.id;
music.clearQueue(gid);
return "All songs have been deleted, commander :no_mouth: "
}, [],"Clears the playlist.");
cmd.createCommand('~', 'playlist', (msg) => {
cmd.createCommand(prefix, 'playlist', (msg) => {
let gid = msg.guild.id;
let songs = music.getQueue(gid);
logger.debug(`found ${songs.length} songs`);
@ -115,33 +117,33 @@ function registerCommands() {
return songlist;
}, [], "Shows the next ten songs.");
cmd.createCommand('~', 'shuffle', (msg) => {
cmd.createCommand(prefix, 'shuffle', (msg) => {
let gid = msg.guild.id;
music.shuffle(gid);
return "The queue has successfully been shuffled :slight_smile:"
}, [], "Shuffles the playlist.");
cmd.createCommand('~', 'current', (msg) => {
cmd.createCommand(prefix, 'current', (msg) => {
let gid = msg.guild.id;
let song = music.nowPlaying(gid);
return `Playing: ${song.title}\n ${song.url}`;
}, [], "Shows the currently playing song.");
cmd.createCommand('~', 'repeatafterme', (msg, argv) => {
cmd.createCommand(prefix, 'repeatafterme', (msg, argv) => {
return argv['word'];
}, ['word'], "Repeats a single word you say.");
cmd.createCommand('~', 'save', (msg, argv) => {
cmd.createCommand(prefix, 'save', (msg, argv) => {
savePlaylist(argv['url'], argv['name']);
return `Saved song/playlist as ${argv['name']}`
}, ['url', 'name'], "Saves the YouTube song/playlist with a specific name. ~play [name] to play the playlist");
}, ['url', 'name'], "Saves the YouTube song/playlist with a specific name");
}
// defining the client's handlers
client.on('ready', () => {
logger.info(`logged in as ${client.user.tag}!`);
client.user.setPresence({game: {name: "Trivernis' bot testing", type: "PLAYING"}, status: 'online'});
client.user.setPresence({game: {name: gamepresence, type: "PLAYING"}, status: 'online'});
});
client.on('message', msg => {

@ -74,9 +74,9 @@ exports.parseMessage = function(msg) {
/**
* Initializes the module by creating a help command
*/
exports.init = function() {
exports.init = function(prefix) {
logger.verbose("Created help command");
this.createCommand("~", "help", () => {
this.createCommand(prefix || '~', "help", () => {
let helpstr = "```markdown\n";
helpstr += "Commands\n---\n";
Object.keys(commands).forEach((key) => {

@ -9,9 +9,14 @@ let djs = {};
let connections = {};
/* Function Definition */
// TODO: initCommands function that takes the cmd.js module as variable and uses it to create commands
class DJ {
/*
TODO: Disconnect when no user is left in the channel after a (not constant) amout of time.
Could be accomplished by checking after every song, if the VoiceChannel (saved in class) still contains
users. If not, trigger a Timeout (e.g. 5 min) that executes the stop command. (Invoking the skip command should
reconnect the bot).
*/
constructor(voiceChannel) {
this.conn = null;
this.disp = null;
@ -63,7 +68,7 @@ class DJ {
* @param url
*/
playYouTube(url, playnext) {
if (!this.conn) this.connect(this.voiceChannel).then(this.playYouTube(url));
if (!this.conn) this.connect().then(this.playYouTube(url));
let plist = url.match(/(?<=\?list=)[\w\-]+/g);
if (plist) {
logger.debug(`Adding playlist ${plist} to queue`);

Loading…
Cancel
Save