mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-23 07:38:00 -05:00
move cloop and eaglercrash to plugins + improve
This commit is contained in:
parent
b9fd9a56fc
commit
d7be828fad
4 changed files with 105 additions and 54 deletions
|
@ -1,25 +1,12 @@
|
|||
|
||||
const { MessageEmbed } = require('discord.js')
|
||||
function add (command, interval, bot) {
|
||||
const id = setInterval(() => bot.core.run(command), interval)
|
||||
|
||||
bot.cloops.push({ id, interval, command })
|
||||
}
|
||||
function remove (item, bot) {
|
||||
clearInterval(bot.cloops[item].id)
|
||||
|
||||
bot.cloops.splice(item, 1)
|
||||
}
|
||||
function clear (bot) {
|
||||
for (const interval of bot.cloops) clearInterval(interval.id)
|
||||
|
||||
bot.cloops = []
|
||||
}
|
||||
function list (bot, discord, channeldc, selector, config) {
|
||||
const message = []
|
||||
|
||||
if (discord) {
|
||||
for (const [id, cloop] of Object.entries(bot.cloops)) {
|
||||
for (const { id, cloop, list } of Object.entries(bot.cloop.list)) {
|
||||
if (!list) continue
|
||||
message.push(id)
|
||||
message.push(' > ')
|
||||
message.push(`\`${cloop.command}\``)
|
||||
|
@ -35,25 +22,26 @@ function list (bot, discord, channeldc, selector, config) {
|
|||
.setTitle('Cloops')
|
||||
.setDescription(message.join(''))
|
||||
channeldc.send({ embeds: [Embed] })
|
||||
return
|
||||
}
|
||||
|
||||
message.push({ text: 'Cloops:', color: 'green' })
|
||||
message.push('\n')
|
||||
|
||||
for (const [id, cloop] of Object.entries(bot.cloops)) {
|
||||
message.push({ text: id, color: 'aqua' })
|
||||
message.push({ text: ' > ', color: 'gold' })
|
||||
message.push({ text: cloop.command, color: 'green' })
|
||||
message.push({ text: ' - ', color: 'gold' })
|
||||
message.push({ text: cloop.interval, color: 'green' })
|
||||
} else {
|
||||
message.push({ text: 'Cloops:', color: 'green' })
|
||||
message.push('\n')
|
||||
|
||||
for (const { id, cloop, list } of Object.entries(bot.cloop.list)) {
|
||||
if (!list) continue
|
||||
message.push({ text: id, color: 'aqua' })
|
||||
message.push({ text: ' > ', color: 'gold' })
|
||||
message.push({ text: cloop.command, color: 'green' })
|
||||
message.push({ text: ' - ', color: 'gold' })
|
||||
message.push({ text: cloop.interval, color: 'green' })
|
||||
message.push('\n')
|
||||
}
|
||||
|
||||
message.pop()
|
||||
|
||||
bot.tellraw(selector, message)
|
||||
}
|
||||
|
||||
message.pop()
|
||||
|
||||
bot.tellraw(selector, message)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
name: 'cloop',
|
||||
alias: [],
|
||||
|
@ -61,33 +49,31 @@ module.exports = {
|
|||
usage: [
|
||||
'<hash> <add> <interval> <command>',
|
||||
'<hash> <remove> <index>',
|
||||
'<hash> <removeall>',
|
||||
'<hash> <removeall|clear>',
|
||||
'<hash> <list>'
|
||||
],
|
||||
trusted: 1,
|
||||
execute (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
|
||||
if (!bot.cloops) bot.cloops = []
|
||||
if (args[1] === 'add' && args[3]) {
|
||||
if (!Number(args[2]) && Number(args[2]) !== 0) throw new SyntaxError('Invalid interval')
|
||||
add(args.slice(3).join(' '), args[2], bot)
|
||||
bot.cloop.add(args.slice(3).join(' '), args[2])
|
||||
bot.tellraw(selector, [{ text: 'Added command ', color: 'white' }, { text: `${args.slice(3).join(' ')}`, color: 'aqua' }, { text: ' with interval ', color: 'white' }, { text: `${args[2]}`, color: 'green' }, { text: ' to the cloops', color: 'white' }])
|
||||
} else if (args[1] === 'list') {
|
||||
list(bot, false, null, selector)
|
||||
} else if (args[1] === 'remove') {
|
||||
remove(args[2], bot)
|
||||
bot.cloop.remove(args[2])
|
||||
bot.tellraw(selector, [{ text: 'Removed cloop ' }, { text: args[2], color: 'aqua' }])
|
||||
} else if (args[1] === 'removeall') {
|
||||
clear(bot)
|
||||
} else if (args[1] === 'removeall' || args[1] === 'clear') {
|
||||
bot.cloop.clear()
|
||||
bot.tellraw(selector, [{ text: 'Removed all looped commands', color: 'white' }])
|
||||
} else {
|
||||
throw new SyntaxError('Invalid argument')
|
||||
}
|
||||
},
|
||||
discordExecute (bot, username, usernameraw, sender, prefix, args, channeldc, message, config) {
|
||||
if (!bot.cloops) bot.cloops = []
|
||||
if (args[0] === 'add' && args[2]) {
|
||||
if (!Number(args[1]) && Number(args[1]) !== 0) throw new SyntaxError('Invalid interval')
|
||||
add(args.slice(2).join(' '), args[1], bot)
|
||||
bot.cloop.add(args.slice(2).join(' '), args[1])
|
||||
const Embed = new MessageEmbed()
|
||||
.setColor(config.discord.embedsColors.normal)
|
||||
.setTitle('Cloop')
|
||||
|
@ -96,14 +82,14 @@ module.exports = {
|
|||
} else if (args[0] === 'list') {
|
||||
list(bot, true, channeldc, '@a', config)
|
||||
} else if (args[0] === 'remove') {
|
||||
remove(args[1], bot)
|
||||
bot.cloop.remove(args[1])
|
||||
const Embed = new MessageEmbed()
|
||||
.setColor(config.discord.embedsColors.normal)
|
||||
.setTitle('Cloop')
|
||||
.setDescription(`Removed cloop \`${args[1]}\``)
|
||||
channeldc.send({ embeds: [Embed] })
|
||||
} else if (args[0] === 'removeall') {
|
||||
clear(bot)
|
||||
} else if (args[0] === 'removeall' || args[0] === 'clear') {
|
||||
bot.cloop.clear()
|
||||
const Embed = new MessageEmbed()
|
||||
.setColor(config.discord.embedsColors.normal)
|
||||
.setTitle('Cloop')
|
||||
|
|
|
@ -2,20 +2,38 @@ module.exports = {
|
|||
name: 'eaglercrash',
|
||||
alias: [],
|
||||
description: 'Lags Eaglercraft and crashes it',
|
||||
usage: '<on|off> <hash>',
|
||||
usage: '<hash> <on|off>',
|
||||
trusted: 1,
|
||||
execute (bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) {
|
||||
if (args[1] === 'on') {
|
||||
bot.eaglercrashstarted = true
|
||||
bot.eaglercrash = setInterval(async function () {
|
||||
if (bot.eaglercrashstarted === true) return bot.core.run('minecraft:playsound block.note_block.harp record @a ~ ~ ~ 100000000000000000000000000000000000000 1 0')
|
||||
}, 0)
|
||||
bot.core.run('minecraft:tellraw @a ["",{"text":"Eaglercrash started","color":"white"}]')
|
||||
}
|
||||
if (args[1] === 'off') {
|
||||
clearInterval(bot.eaglercrash)
|
||||
bot.eaglercrashstarted = false
|
||||
bot.core.run('minecraft:tellraw @a ["",{"text":"Eaglercrash stopped","color":"white"}]')
|
||||
switch (args[1]) {
|
||||
case 'on':
|
||||
bot.eaglercrash.on()
|
||||
bot.tellraw(selector, [
|
||||
{
|
||||
text: 'Eaglercrash is now ',
|
||||
color: 'white'
|
||||
},
|
||||
{
|
||||
text: 'on',
|
||||
color: 'green'
|
||||
}
|
||||
])
|
||||
break
|
||||
case 'off':
|
||||
bot.eaglercrash.off()
|
||||
bot.tellraw(selector, [
|
||||
{
|
||||
text: 'Eaglercrash is now ',
|
||||
color: 'white'
|
||||
},
|
||||
{
|
||||
text: 'off',
|
||||
color: 'red'
|
||||
}
|
||||
])
|
||||
break
|
||||
default:
|
||||
throw new Error('Invalid argument')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
25
plugins/cloop.js
Normal file
25
plugins/cloop.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
function inject (bot) {
|
||||
bot.cloop = {
|
||||
list: [],
|
||||
add (command, interval, list = true /* list is used in the cloop command listing and eaglercrash */) {
|
||||
const id = setInterval(() => bot.core.run(command), interval)
|
||||
|
||||
const thingsToPush /* ig not the best variable name */ = { id, interval, command, list }
|
||||
bot.cloop.list.push(thingsToPush)
|
||||
|
||||
return thingsToPush
|
||||
},
|
||||
remove (item) {
|
||||
clearInterval(bot.cloop.list[item].id)
|
||||
|
||||
bot.cloop.list.splice(item, 1)
|
||||
},
|
||||
clear () {
|
||||
for (const interval of bot.cloop.list) clearInterval(interval.id)
|
||||
|
||||
bot.cloop.list = []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { inject }
|
22
plugins/eaglercrash.js
Normal file
22
plugins/eaglercrash.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
function inject (bot) {
|
||||
let id = NaN
|
||||
bot.eaglercrash = {
|
||||
on () {
|
||||
if (!isNaN(id)) throw new Error('Eaglercrash is currently enabled')
|
||||
const command = 'minecraft:execute as @a[tag=!nomusic] at @s run playsound block.note_block.harp record @a ~ ~ ~ 100000000000000000000000000000000000000 1 0'
|
||||
bot.cloop.add(
|
||||
command,
|
||||
0,
|
||||
false
|
||||
)
|
||||
id = bot.cloop.list.findIndex((cloop) => cloop.command === command) // ig not the best way to find the eaglercrash cloop
|
||||
},
|
||||
off () {
|
||||
if (isNaN(id) /* you can't use !id */) throw new Error('Eaglercrash is currently not enabled')
|
||||
bot.cloop.remove(id)
|
||||
id = NaN
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { inject }
|
Loading…
Reference in a new issue