mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-14 10:44:55 -05:00
fix music loop and use sleep-promise in index.js
bro this REALLY TOOK AGES
This commit is contained in:
parent
26bc7f8fd8
commit
390852f890
3 changed files with 37 additions and 21 deletions
|
@ -20,6 +20,7 @@ async function play(bot, values, discord, channeldc) {
|
|||
const filepath = values.join(' ');
|
||||
const absolutePath = await resolve(filepath);
|
||||
song = bot.music.load(await fs.readFile(absolutePath), path.basename(absolutePath));
|
||||
bot.music.queue.push(song);
|
||||
bot.music.play(song);
|
||||
if (discord) {
|
||||
const Embed = new MessageEmbed()
|
||||
|
@ -53,6 +54,7 @@ async function playUrl(bot, values, discord, channeldc) {
|
|||
responseType: 'arraybuffer',
|
||||
});
|
||||
song = bot.music.load(response.data, url);
|
||||
bot.music.queue.push(song);
|
||||
bot.music.play(song);
|
||||
if (discord) {
|
||||
const Embed = new MessageEmbed()
|
||||
|
@ -140,7 +142,7 @@ module.exports = {
|
|||
}
|
||||
if (args[0]==='stop') {
|
||||
try {
|
||||
bot.core.run('minecraft:tellraw @a ' + JSON.stringify([{text: 'Stopped playing '}, {text: bot.music.song.name, color: 'gold'}]));
|
||||
bot.core.run('minecraft:tellraw @a ' + JSON.stringify({text: 'Cleared the song queue'}));
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
|
@ -157,7 +159,7 @@ module.exports = {
|
|||
}
|
||||
if (args[1] === 'all') {
|
||||
bot.music.loop = 2;
|
||||
bot.core.run('minecraft:tellraw @a ' + JSON.stringify({text: 'Now Looping every song in the queue'}));
|
||||
bot.core.run('minecraft:tellraw @a ' + JSON.stringify({text: 'Now looping every song in the queue'}));
|
||||
}
|
||||
}
|
||||
if (args[0]==='list') {
|
||||
|
@ -179,7 +181,7 @@ module.exports = {
|
|||
const Embed = new MessageEmbed()
|
||||
.setColor('#FFFF00')
|
||||
.setTitle('Stop')
|
||||
.setDescription(`Stopped playing ${bot.music.song.name}`);
|
||||
.setDescription('Cleared the song queue');
|
||||
channeldc.send({embeds: [Embed]});
|
||||
} catch (e) {
|
||||
return;
|
||||
|
@ -187,13 +189,30 @@ module.exports = {
|
|||
bot.music.stop();
|
||||
}
|
||||
if (args[0]==='loop') {
|
||||
bot.music.loop = !bot.music.loop;
|
||||
const loop = bot.music.loop ? 'enabled' : 'disabled';
|
||||
const Embed = new MessageEmbed()
|
||||
.setColor('#FFFF00')
|
||||
.setTitle('Loop')
|
||||
.setDescription(`Looping is now ${loop}`);
|
||||
channeldc.send({embeds: [Embed]});
|
||||
if (args[1] === 'off') {
|
||||
bot.music.loop = 0;
|
||||
const Embed = new MessageEmbed()
|
||||
.setColor('#FFFF00')
|
||||
.setTitle('Loop')
|
||||
.setDescription(`Looping is now disabled`);
|
||||
channeldc.send({embeds: [Embed]});
|
||||
}
|
||||
if (args[1] === 'current') {
|
||||
bot.music.loop = 1;
|
||||
const Embed = new MessageEmbed()
|
||||
.setColor('#FFFF00')
|
||||
.setTitle('Loop')
|
||||
.setDescription(`Now looping ${song.name}`);
|
||||
channeldc.send({embeds: [Embed]});
|
||||
}
|
||||
if (args[1] === 'all') {
|
||||
bot.music.loop = 2;
|
||||
const Embed = new MessageEmbed()
|
||||
.setColor('#FFFF00')
|
||||
.setTitle('Loop')
|
||||
.setDescription('Now looping every song in the queue');
|
||||
channeldc.send({embeds: [Embed]});
|
||||
}
|
||||
}
|
||||
if (args[0]==='list') {
|
||||
list(bot, true, channeldc);
|
||||
|
|
8
index.js
8
index.js
|
@ -7,6 +7,7 @@ const mc = require('minecraft-protocol');
|
|||
const config = require('./config');
|
||||
const crypto = require('crypto');
|
||||
const colorConvert = require('color-convert');
|
||||
const sleep = require('sleep-promise');
|
||||
const {containsIllegalCharacters} = require('./util/containsIllegalCharacters');
|
||||
const generateEaglerUsername = require('./util/generateEaglerUsername');
|
||||
const {EventEmitter} = require('events');
|
||||
|
@ -32,10 +33,6 @@ console.log = function() {
|
|||
rl._refreshLine();
|
||||
};
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
// Load discord.js
|
||||
const {
|
||||
Client,
|
||||
|
@ -154,14 +151,13 @@ function main() {
|
|||
|
||||
bot.hash = '';
|
||||
|
||||
sleep = (time) => new Promise((a)=>setTimeout(a, time)),
|
||||
bot.chat = (message) => {
|
||||
bot.queue.push(String(message));
|
||||
};
|
||||
|
||||
discordQueue = setInterval(function() {
|
||||
if (dcmsg.queue!='') {
|
||||
channel.send('```ansi\n' + dcmsg.queue.substring(0, 1986) + '\n```');
|
||||
channel.send({content: '```ansi\n' + dcmsg.queue.substring(0, 1986) + '\n```', allowedMentions: {parse: []}});
|
||||
dcmsg.queue = '';
|
||||
}
|
||||
}, 1000);
|
||||
|
|
|
@ -48,14 +48,16 @@ function inject(bot) {
|
|||
}
|
||||
if (bot.music.loop === 2) {
|
||||
resetTime();
|
||||
await sleep(500);
|
||||
await sleep(100);
|
||||
bot.music.queue.push(song);
|
||||
bot.music.play(bot.music.queue.shift());
|
||||
return;
|
||||
}
|
||||
bot.music.queue.shift();
|
||||
if (bot.music.queue[0]) {
|
||||
resetTime();
|
||||
await sleep(500);
|
||||
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;
|
||||
}
|
||||
|
@ -81,7 +83,6 @@ function inject(bot) {
|
|||
};
|
||||
|
||||
bot.music.play = function(song) {
|
||||
bot.music.queue.push(song);
|
||||
loop = song.loop;
|
||||
if (bot.music.queue.length === 1) resetTime();
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue