mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-14 10:44:55 -05:00
add music queue and fix cspy self care
bro this takes hours to make
This commit is contained in:
parent
c46e26096b
commit
26bc7f8fd8
3 changed files with 52 additions and 25 deletions
|
@ -19,16 +19,16 @@ async function play(bot, values, discord, channeldc) {
|
|||
try {
|
||||
const filepath = values.join(' ');
|
||||
const absolutePath = await resolve(filepath);
|
||||
const song = bot.music.load(await fs.readFile(absolutePath), path.basename(absolutePath));
|
||||
song = bot.music.load(await fs.readFile(absolutePath), path.basename(absolutePath));
|
||||
bot.music.play(song);
|
||||
if (discord) {
|
||||
const Embed = new MessageEmbed()
|
||||
.setColor('#FFFF00')
|
||||
.setTitle('Music')
|
||||
.setDescription(`Now playing ${song.name}`);
|
||||
.setDescription(`Added ${song.name} to the song queue`);
|
||||
channeldc.send({embeds: [Embed]});
|
||||
} else {
|
||||
bot.core.run('minecraft:tellraw @a ' + JSON.stringify([{text: 'Now playing '}, {text: song.name, color: 'gold'}]));
|
||||
bot.core.run('minecraft:tellraw @a ' + JSON.stringify([{text: 'Added ', color: 'white'}, {text: song.name, color: 'gold'}, {text: ' to the song queue', color: 'white'}]));
|
||||
}
|
||||
} catch (e) {
|
||||
if (discord) {
|
||||
|
@ -52,16 +52,16 @@ async function playUrl(bot, values, discord, channeldc) {
|
|||
},
|
||||
responseType: 'arraybuffer',
|
||||
});
|
||||
const song = bot.music.load(response.data, url);
|
||||
song = bot.music.load(response.data, url);
|
||||
bot.music.play(song);
|
||||
if (discord) {
|
||||
const Embed = new MessageEmbed()
|
||||
.setColor('#FFFF00')
|
||||
.setTitle('Music')
|
||||
.setDescription(`Now playing ${song.name}`);
|
||||
.setDescription(`Added ${song.name} to the song queue`);
|
||||
channeldc.send({embeds: [Embed]});
|
||||
} else {
|
||||
bot.core.run('minecraft:tellraw @a ' + JSON.stringify([{text: 'Now playing '}, {text: song.name, color: 'gold'}]));
|
||||
bot.core.run('minecraft:tellraw @a ' + JSON.stringify([{text: 'Added ', color: 'white'}, {text: song.name, color: 'gold'}, {text: ' to the song queue', color: 'white'}]));
|
||||
}
|
||||
} catch (e) {
|
||||
if (discord) {
|
||||
|
@ -130,7 +130,7 @@ module.exports = {
|
|||
description: 'Plays music',
|
||||
alias: [],
|
||||
trusted: 0,
|
||||
usage: '<play|playurl|stop|loop|list|nowplaying> <song>',
|
||||
usage: '<play|playurl|stop|loop|list|nowplaying|loop> <song|all|current|off>',
|
||||
execute: function(bot, username, usernameraw, sender, prefix, args) {
|
||||
if (args[0]==='play') {
|
||||
play(bot, args.slice(1));
|
||||
|
@ -147,9 +147,18 @@ module.exports = {
|
|||
bot.music.stop();
|
||||
}
|
||||
if (args[0]==='loop') {
|
||||
bot.music.loop = !bot.music.loop;
|
||||
const loop = bot.music.loop ? {text: 'enabled', color: 'green'} : {text: 'disabled', color: 'red'};
|
||||
bot.core.run('minecraft:tellraw @a ' + JSON.stringify([{text: 'Looping is now '}, loop]));
|
||||
if (args[1] === 'off') {
|
||||
bot.music.loop = 0;
|
||||
bot.core.run('minecraft:tellraw @a ' + JSON.stringify([{text: 'Looping is now '}, {text: 'disabled', color: 'red'}]));
|
||||
}
|
||||
if (args[1] === 'current') {
|
||||
bot.music.loop = 1;
|
||||
bot.core.run('minecraft:tellraw @a ' + JSON.stringify([{text: 'Now Looping '}, {text: song.name, color: 'gold'}]));
|
||||
}
|
||||
if (args[1] === 'all') {
|
||||
bot.music.loop = 2;
|
||||
bot.core.run('minecraft:tellraw @a ' + JSON.stringify({text: 'Now Looping every song in the queue'}));
|
||||
}
|
||||
}
|
||||
if (args[0]==='list') {
|
||||
list(bot);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/* 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',
|
||||
|
@ -24,13 +25,15 @@ const soundNames = {
|
|||
function inject(bot) {
|
||||
bot.music = function() {};
|
||||
bot.music.song = null;
|
||||
bot.music.loop = false;
|
||||
bot.music.loop = 0;
|
||||
bot.music.queue = [];
|
||||
time = 0;
|
||||
startTime = 0;
|
||||
noteIndex = 0;
|
||||
const interval = setInterval(() => {
|
||||
const interval = setInterval(async () => {
|
||||
try {
|
||||
if (!bot.music.song) return;
|
||||
if (!bot.music.queue.length) return;
|
||||
bot.music.song = bot.music.queue[0];
|
||||
time = Date.now() - startTime;
|
||||
while (bot.music.song.notes[noteIndex]?.time <= time) {
|
||||
const note = bot.music.song.notes[noteIndex];
|
||||
|
@ -39,11 +42,24 @@ function inject(bot) {
|
|||
noteIndex++;
|
||||
bot.core.run('minecraft:title @a[tag=!nomusic] actionbar ' + JSON.stringify(toComponent()));
|
||||
if (noteIndex >= bot.music.song.notes.length) {
|
||||
if (bot.music.loop) {
|
||||
if (bot.music.loop === 1) {
|
||||
resetTime();
|
||||
return;
|
||||
}
|
||||
bot.core.run('minecraft:tellraw @a ' + JSON.stringify([{text: 'Finished playing '}, {text: bot.music.song.name, color: 'gold'}]));
|
||||
if (bot.music.loop === 2) {
|
||||
resetTime();
|
||||
await sleep(500);
|
||||
bot.music.play(bot.music.queue.shift());
|
||||
return;
|
||||
}
|
||||
bot.music.queue.shift();
|
||||
if (bot.music.queue[0]) {
|
||||
resetTime();
|
||||
await sleep(500);
|
||||
bot.music.play(bot.music.queue[0]);
|
||||
return;
|
||||
}
|
||||
bot.core.run('minecraft:tellraw @a ' + JSON.stringify({text: 'Finished playing every song in the queue'}));
|
||||
bot.music.stop();
|
||||
}
|
||||
}
|
||||
|
@ -65,14 +81,15 @@ function inject(bot) {
|
|||
};
|
||||
|
||||
bot.music.play = function(song) {
|
||||
bot.music.song = song;
|
||||
bot.music.queue.push(song);
|
||||
loop = song.loop;
|
||||
resetTime();
|
||||
if (bot.music.queue.length === 1) resetTime();
|
||||
};
|
||||
|
||||
bot.music.stop = function() {
|
||||
bot.music.song = null;
|
||||
bot.music.loop = false;
|
||||
bot.music.loop = 0;
|
||||
bot.music.queue = [];
|
||||
resetTime();
|
||||
};
|
||||
|
||||
|
@ -104,9 +121,13 @@ function inject(bot) {
|
|||
{text: bot.music.song.notes.length, color: 'gray'},
|
||||
];
|
||||
|
||||
if (bot.music.loop) {
|
||||
if (bot.music.loop === 1) {
|
||||
component.push(' §8| ');
|
||||
component.push('§aLooping');
|
||||
component.push('§aLooping Current');
|
||||
}
|
||||
if (bot.music.loop === 2) {
|
||||
component.push(' §8| ');
|
||||
component.push('§aLooping All');
|
||||
}
|
||||
|
||||
return component;
|
||||
|
|
|
@ -56,12 +56,9 @@ function inject(bot, dcclient, config) {
|
|||
const interval = setInterval(() => {
|
||||
if (bot.options.host!=='0.tcp.ap.ngrok.io') {
|
||||
if (!prefix) bot.chat('/extras:prefix &8[&eChomeNS Bot&8]');
|
||||
if (!op) {
|
||||
bot.chat('/minecraft:op @s[type=player]');
|
||||
return;
|
||||
}
|
||||
if (!op) bot.chat('/minecraft:op @s[type=player]');
|
||||
if (!cspy) bot.chat('/commandspy:commandspy on');
|
||||
}
|
||||
if (!cspy) bot.chat('/commandspy:commandspy on');
|
||||
if (!vanish) bot.chat('/essentials:vanish enable');
|
||||
if (gameMode !== 1) bot.chat('/minecraft:gamemode creative @s[type=player]');
|
||||
if (muted) bot.chat('/essentials:mute ' + bot.uuid);
|
||||
|
|
Loading…
Reference in a new issue