mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-14 18:54: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 {
|
try {
|
||||||
const filepath = values.join(' ');
|
const filepath = values.join(' ');
|
||||||
const absolutePath = await resolve(filepath);
|
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);
|
bot.music.play(song);
|
||||||
if (discord) {
|
if (discord) {
|
||||||
const Embed = new MessageEmbed()
|
const Embed = new MessageEmbed()
|
||||||
.setColor('#FFFF00')
|
.setColor('#FFFF00')
|
||||||
.setTitle('Music')
|
.setTitle('Music')
|
||||||
.setDescription(`Now playing ${song.name}`);
|
.setDescription(`Added ${song.name} to the song queue`);
|
||||||
channeldc.send({embeds: [Embed]});
|
channeldc.send({embeds: [Embed]});
|
||||||
} else {
|
} 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) {
|
} catch (e) {
|
||||||
if (discord) {
|
if (discord) {
|
||||||
|
@ -52,16 +52,16 @@ async function playUrl(bot, values, discord, channeldc) {
|
||||||
},
|
},
|
||||||
responseType: 'arraybuffer',
|
responseType: 'arraybuffer',
|
||||||
});
|
});
|
||||||
const song = bot.music.load(response.data, url);
|
song = bot.music.load(response.data, url);
|
||||||
bot.music.play(song);
|
bot.music.play(song);
|
||||||
if (discord) {
|
if (discord) {
|
||||||
const Embed = new MessageEmbed()
|
const Embed = new MessageEmbed()
|
||||||
.setColor('#FFFF00')
|
.setColor('#FFFF00')
|
||||||
.setTitle('Music')
|
.setTitle('Music')
|
||||||
.setDescription(`Now playing ${song.name}`);
|
.setDescription(`Added ${song.name} to the song queue`);
|
||||||
channeldc.send({embeds: [Embed]});
|
channeldc.send({embeds: [Embed]});
|
||||||
} else {
|
} 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) {
|
} catch (e) {
|
||||||
if (discord) {
|
if (discord) {
|
||||||
|
@ -130,7 +130,7 @@ module.exports = {
|
||||||
description: 'Plays music',
|
description: 'Plays music',
|
||||||
alias: [],
|
alias: [],
|
||||||
trusted: 0,
|
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) {
|
execute: function(bot, username, usernameraw, sender, prefix, args) {
|
||||||
if (args[0]==='play') {
|
if (args[0]==='play') {
|
||||||
play(bot, args.slice(1));
|
play(bot, args.slice(1));
|
||||||
|
@ -147,9 +147,18 @@ module.exports = {
|
||||||
bot.music.stop();
|
bot.music.stop();
|
||||||
}
|
}
|
||||||
if (args[0]==='loop') {
|
if (args[0]==='loop') {
|
||||||
bot.music.loop = !bot.music.loop;
|
if (args[1] === 'off') {
|
||||||
const loop = bot.music.loop ? {text: 'enabled', color: 'green'} : {text: 'disabled', color: 'red'};
|
bot.music.loop = 0;
|
||||||
bot.core.run('minecraft:tellraw @a ' + JSON.stringify([{text: 'Looping is now '}, loop]));
|
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') {
|
if (args[0]==='list') {
|
||||||
list(bot);
|
list(bot);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/* eslint-disable max-len */
|
/* eslint-disable max-len */
|
||||||
const {Midi} = require('@tonejs/midi');
|
const {Midi} = require('@tonejs/midi');
|
||||||
const {convertMidi} = require('../util/midi_converter');
|
const {convertMidi} = require('../util/midi_converter');
|
||||||
|
const sleep = require('sleep-promise');
|
||||||
|
|
||||||
const soundNames = {
|
const soundNames = {
|
||||||
harp: 'minecraft:block.note_block.harp',
|
harp: 'minecraft:block.note_block.harp',
|
||||||
|
@ -24,13 +25,15 @@ const soundNames = {
|
||||||
function inject(bot) {
|
function inject(bot) {
|
||||||
bot.music = function() {};
|
bot.music = function() {};
|
||||||
bot.music.song = null;
|
bot.music.song = null;
|
||||||
bot.music.loop = false;
|
bot.music.loop = 0;
|
||||||
|
bot.music.queue = [];
|
||||||
time = 0;
|
time = 0;
|
||||||
startTime = 0;
|
startTime = 0;
|
||||||
noteIndex = 0;
|
noteIndex = 0;
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(async () => {
|
||||||
try {
|
try {
|
||||||
if (!bot.music.song) return;
|
if (!bot.music.queue.length) return;
|
||||||
|
bot.music.song = bot.music.queue[0];
|
||||||
time = Date.now() - startTime;
|
time = Date.now() - startTime;
|
||||||
while (bot.music.song.notes[noteIndex]?.time <= time) {
|
while (bot.music.song.notes[noteIndex]?.time <= time) {
|
||||||
const note = bot.music.song.notes[noteIndex];
|
const note = bot.music.song.notes[noteIndex];
|
||||||
|
@ -39,11 +42,24 @@ function inject(bot) {
|
||||||
noteIndex++;
|
noteIndex++;
|
||||||
bot.core.run('minecraft:title @a[tag=!nomusic] actionbar ' + JSON.stringify(toComponent()));
|
bot.core.run('minecraft:title @a[tag=!nomusic] actionbar ' + JSON.stringify(toComponent()));
|
||||||
if (noteIndex >= bot.music.song.notes.length) {
|
if (noteIndex >= bot.music.song.notes.length) {
|
||||||
if (bot.music.loop) {
|
if (bot.music.loop === 1) {
|
||||||
resetTime();
|
resetTime();
|
||||||
return;
|
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();
|
bot.music.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,14 +81,15 @@ function inject(bot) {
|
||||||
};
|
};
|
||||||
|
|
||||||
bot.music.play = function(song) {
|
bot.music.play = function(song) {
|
||||||
bot.music.song = song;
|
bot.music.queue.push(song);
|
||||||
loop = song.loop;
|
loop = song.loop;
|
||||||
resetTime();
|
if (bot.music.queue.length === 1) resetTime();
|
||||||
};
|
};
|
||||||
|
|
||||||
bot.music.stop = function() {
|
bot.music.stop = function() {
|
||||||
bot.music.song = null;
|
bot.music.song = null;
|
||||||
bot.music.loop = false;
|
bot.music.loop = 0;
|
||||||
|
bot.music.queue = [];
|
||||||
resetTime();
|
resetTime();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -104,9 +121,13 @@ function inject(bot) {
|
||||||
{text: bot.music.song.notes.length, color: 'gray'},
|
{text: bot.music.song.notes.length, color: 'gray'},
|
||||||
];
|
];
|
||||||
|
|
||||||
if (bot.music.loop) {
|
if (bot.music.loop === 1) {
|
||||||
component.push(' §8| ');
|
component.push(' §8| ');
|
||||||
component.push('§aLooping');
|
component.push('§aLooping Current');
|
||||||
|
}
|
||||||
|
if (bot.music.loop === 2) {
|
||||||
|
component.push(' §8| ');
|
||||||
|
component.push('§aLooping All');
|
||||||
}
|
}
|
||||||
|
|
||||||
return component;
|
return component;
|
||||||
|
|
|
@ -56,12 +56,9 @@ function inject(bot, dcclient, config) {
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
if (bot.options.host!=='0.tcp.ap.ngrok.io') {
|
if (bot.options.host!=='0.tcp.ap.ngrok.io') {
|
||||||
if (!prefix) bot.chat('/extras:prefix &8[&eChomeNS Bot&8]');
|
if (!prefix) bot.chat('/extras:prefix &8[&eChomeNS Bot&8]');
|
||||||
if (!op) {
|
if (!op) bot.chat('/minecraft:op @s[type=player]');
|
||||||
bot.chat('/minecraft:op @s[type=player]');
|
if (!cspy) bot.chat('/commandspy:commandspy on');
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!cspy) bot.chat('/commandspy:commandspy on');
|
|
||||||
if (!vanish) bot.chat('/essentials:vanish enable');
|
if (!vanish) bot.chat('/essentials:vanish enable');
|
||||||
if (gameMode !== 1) bot.chat('/minecraft:gamemode creative @s[type=player]');
|
if (gameMode !== 1) bot.chat('/minecraft:gamemode creative @s[type=player]');
|
||||||
if (muted) bot.chat('/essentials:mute ' + bot.uuid);
|
if (muted) bot.chat('/essentials:mute ' + bot.uuid);
|
||||||
|
|
Loading…
Reference in a new issue