add skip + remove sleep

This commit is contained in:
ChomeNS 2022-10-31 19:17:42 +07:00
parent 390852f890
commit daf4b2a50e
2 changed files with 15 additions and 5 deletions

View file

@ -148,6 +148,14 @@ module.exports = {
}
bot.music.stop();
}
if (args[0]==='skip') {
try {
bot.core.run('minecraft:tellraw @a ' + JSON.stringify([{text: 'Skipped '}, {text: bot.music.song.name, color: 'gold'}]));
bot.music.skip();
} catch (e) {
throw new Error('No music is currently playing!');
}
}
if (args[0]==='loop') {
if (args[1] === 'off') {
bot.music.loop = 0;

View file

@ -1,7 +1,6 @@
/* eslint-disable max-len */
const {Midi} = require('@tonejs/midi');
const {convertMidi} = require('../util/midi_converter');
const sleep = require('sleep-promise');
const soundNames = {
harp: 'minecraft:block.note_block.harp',
@ -30,6 +29,11 @@ function inject(bot) {
time = 0;
startTime = 0;
noteIndex = 0;
bot.music.skip = function() {
bot.music.queue.shift();
resetTime();
};
const interval = setInterval(async () => {
try {
if (!bot.music.queue.length) return;
@ -48,16 +52,14 @@ function inject(bot) {
}
if (bot.music.loop === 2) {
resetTime();
await sleep(100);
bot.music.queue.push(song);
bot.music.play(bot.music.queue.shift());
bot.music.queue.push(bot.music.queue.shift());
bot.music.play(bot.music.queue[0]);
return;
}
bot.music.queue.shift();
if (!bot.music.queue[0]) return;
if (bot.music.queue[0].notes.length > 0) {
if (bot.music.queue.length !== 1) resetTime();
await sleep(100);
bot.music.play(bot.music.queue[0]);
return;
}