Added commands
This commit is contained in:
parent
64f1d76778
commit
35f3635096
|
@ -0,0 +1,11 @@
|
|||
const { spotify} = require('../utilities/spotify')
|
||||
|
||||
exports.command = 'mute'
|
||||
exports.handler = async () => {
|
||||
try {
|
||||
await spotify.ensure();
|
||||
await spotify.setVolume(0);
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
};
|
|
@ -2,7 +2,10 @@ const { spotify} = require('../utilities/spotify')
|
|||
|
||||
exports.command = 'next'
|
||||
exports.handler = async () => {
|
||||
spotify.ensure()
|
||||
.then(spotify => spotify.skipToNext())
|
||||
.catch(e => console.error(e.message))
|
||||
try {
|
||||
await spotify.ensure();
|
||||
await spotify.skipToNext();
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,11 @@
|
|||
const { spotify} = require('../utilities/spotify')
|
||||
|
||||
exports.command = 'pause'
|
||||
exports.handler = async () => {
|
||||
try {
|
||||
await spotify.ensure();
|
||||
await spotify.pause();
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,11 @@
|
|||
const { spotify} = require('../utilities/spotify')
|
||||
|
||||
exports.command = 'play'
|
||||
exports.handler = async () => {
|
||||
try {
|
||||
await spotify.ensure();
|
||||
await spotify.play();
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,11 @@
|
|||
const { spotify} = require('../utilities/spotify')
|
||||
|
||||
exports.command = ['previous', 'prev']
|
||||
exports.handler = async () => {
|
||||
try {
|
||||
await spotify.ensure();
|
||||
await spotify.skipToPrevious();
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,34 @@
|
|||
const { spotify} = require('../utilities/spotify')
|
||||
|
||||
exports.command = 'repeat'
|
||||
exports.handler = argv => argv
|
||||
.option('all', {
|
||||
type: 'boolean',
|
||||
description: 'Repeat every track once',
|
||||
})
|
||||
.option('one', {
|
||||
type: 'boolean',
|
||||
description: 'Repeat one track',
|
||||
})
|
||||
.option('off', {
|
||||
type: 'boolean',
|
||||
description: 'Turn repeat off',
|
||||
})
|
||||
exports.handler = async ({ all, one }) => {
|
||||
let state = 'off';
|
||||
switch (true) {
|
||||
case all:
|
||||
state = 'context';
|
||||
break;
|
||||
case one:
|
||||
state = 'track';
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
await spotify.ensure();
|
||||
await spotify.setRepeat(state);
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,37 @@
|
|||
const { spotify} = require('../utilities/spotify')
|
||||
|
||||
exports.command = 'shuffle'
|
||||
exports.handler = argv => argv
|
||||
.option('on', {
|
||||
type: 'boolean',
|
||||
description: 'Enables shuffle',
|
||||
})
|
||||
.option('off', {
|
||||
type: 'boolean',
|
||||
description: 'Disables shuffle',
|
||||
})
|
||||
exports.handler = async ({ on, off }) => {
|
||||
try {
|
||||
let state;
|
||||
|
||||
if (!on && !off) {
|
||||
const { body } = await spotify.getMyCurrentPlaybackState();
|
||||
const { shuffle_state } = body
|
||||
state = !shuffle_state; // toggle state
|
||||
}
|
||||
|
||||
switch (true) {
|
||||
case on:
|
||||
state = true;
|
||||
break;
|
||||
case off:
|
||||
state = false;
|
||||
break;
|
||||
}
|
||||
|
||||
await spotify.ensure();
|
||||
await spotify.setShuffle(state);
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,11 @@
|
|||
const { spotify} = require('../utilities/spotify')
|
||||
|
||||
exports.command = ['volume <volume>', 'vol <volume>']
|
||||
exports.handler = async ({ volume }) => {
|
||||
try {
|
||||
await spotify.ensure();
|
||||
await spotify.setVolume(Math.min(Math.max(volume, 0), 100));
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue