Compare commits

...
Author SHA1 Message Date
Parker Griffith 813e917429 Update src/index.js 2024-04-29 10:15:55 -04:00
Parker Griffith aa6216b6ef yaml funny 2024-04-29 10:12:22 -04:00
Parker Griffith 795093a705 Delete config.yml 2024-04-29 10:11:57 -04:00
Parker Griffith f6133ca7db yaml funny 2024-04-29 10:09:41 -04:00
Parker Griffith 5f2c073767 old file 2024-04-22 13:09:20 -04:00
3 changed files with 107 additions and 210 deletions
-201
View File
@@ -1,201 +0,0 @@
const path = require('path')
const fs = require('fs')
const { Midi } = require('@tonejs/midi')
const { convertMidi } = require('../util/midi_converter')
const convertNBS = require('../util/nbs_converter')
const parseTXTSong = require('../util/txt_song_parser')
const midiproxy = require('../util/midi-proxy')
midiproxy()
const soundNames = {
harp: 'minecraft:block.note_block.harp',
basedrum: 'minecraft:block.note_block.basedrum',
snare: 'minecraft:block.note_block.snare',
hat: 'minecraft:block.note_block.hat',
bass: 'minecraft:block.note_block.bass',
flute: 'minecraft:block.note_block.flute',
bell: 'minecraft:block.note_block.bell',
guitar: 'minecraft:block.note_block.guitar',
chime: 'minecraft:block.note_block.chime',
xylophone: 'minecraft:block.note_block.xylophone',
iron_xylophone: 'minecraft:block.note_block.iron_xylophone',
cow_bell: 'minecraft:block.note_block.cow_bell',
didgeridoo: 'minecraft:block.note_block.didgeridoo',
bit: 'minecraft:block.note_block.bit',
banjo: 'minecraft:block.note_block.banjo',
pling: 'minecraft:block.note_block.pling'
}
async function inject (bot) {
bot.music = function () {}
bot.music.song = null
bot.music.loop = 0
bot.music.queue = []
let time = 0
let startTime = 0
let noteIndex = 0
bot.music.skip = function () {
if (bot.music.loop === 2) {
bot.music.queue.push(bot.music.queue.shift())
bot.music.play(bot.music.queue[0])
} else {
bot.music.queue.shift()
}
resetTime()
}
const midisFolder = path.join(__dirname, '../../midis'); // idfk
//why is it not trying to find the folder tf
// i am having a stroke from this
try {
if (!fs.existsSync(midisFolder)) {
fs.mkdirSync(midisFolder);
}
}catch(e) {}
const bossbarName = 'music' // maybe make this in the config?
const selector = '@a[tag=!nomusic]'
const interval = setInterval(async () => {
if (!bot.music.queue.length) return
bot.music.song = bot.music.queue[0]
time = Date.now() - startTime
// bot.core.run('minecraft:title @a[tag=!nomusic] actionbar ' + JSON.stringify(toComponent()))
await bot.chatDelay(150)
bot.core.run(`minecraft:bossbar add ${bossbarName} ""`) // is setting the name to "" as a placeholder a good idea?
await bot.chatDelay(150)
bot.core.run(`minecraft:bossbar set ${bossbarName} players ${selector}`)
await bot.chatDelay(150)
bot.core.run(`minecraft:bossbar set ${bossbarName} name ${JSON.stringify(bot.getMessageAsPrismarine(toComponent()).toMotd())}`)
await bot.chatDelay(150)
bot.core.run(`minecraft:bossbar set ${bossbarName} color yellow`) // should i use purple lol
await bot.chatDelay(150)
bot.core.run(`minecraft:bossbar set ${bossbarName} visible true`)
await bot.chatDelay(150)
bot.core.run(`minecraft:bossbar set ${bossbarName} value ${Math.floor(time)}`)
await bot.chatDelay(150)
bot.core.run(`minecraft:bossbar set ${bossbarName} max ${bot.music.song.length}`)
await bot.chatDelay(150)
bot.core.run(`title @a actionbar ${JSON.stringify(bot.getMessageAsPrismarine(toComponent()).toMotd())}`)
await bot.chatDelay(150)
while (bot.music.song?.notes[noteIndex]?.time <= time) {
const note = bot.music.song.notes[noteIndex]
const floatingPitch = 2 ** ((note.pitch - 12) / 12.0)
bot.core.run(`minecraft:execute as ${selector} at @s run playsound ${soundNames[note.instrument]} record @s ~ ~ ~ ${note.volume} ${floatingPitch}`)
noteIndex++
if (noteIndex >= bot.music.song.notes.length) {
bot.tellraw([
{
text: 'Finished playing '
},
{
text: bot.music.song.name,
color: 'gold'
}
])
if (bot.music.loop === 1) {
resetTime()
return
}
if (bot.music.loop === 2) {
resetTime()
bot.music.queue.push(bot.music.queue.shift())
bot.music.play(bot.music.queue[0])
return
}
bot.music.queue.shift()
bot.music.song = null // useless?
if (!bot.music.queue[0]) {
bot.music.stop()
return
}
if (bot.music.queue[0].notes.length > 0) {
if (bot.music.queue.length !== 1) resetTime()
bot.music.play(bot.music.queue[0])
return
}
}
}
}, 100)
bot.on('end', () => {
// clearInterval(interval)
bot.music.stop()
})
bot.music.load = async function (buffer, fallbackName = '[unknown]') {
let song
switch (path.extname(fallbackName)) {
case '.nbs':
song = convertNBS(buffer)
if (song.name === '') song.name = fallbackName
break
case '.txt':
song = parseTXTSong(buffer.toString())
song.name = fallbackName
break
default:
// TODO: use worker_threads so the entire bot doesn't freeze (for example parsing we are number 1 black midi)
// eslint-disable-next-line no-case-declarations
const midi = new Midi(buffer)
song = convertMidi(midi)
if (song.name === '') song.name = fallbackName
break
}
return song
}
bot.music.play = function (song) {
if (bot.music.queue.length === 1) resetTime()
}
bot.music.stop = function () {
bot.music.song = null
bot.music.loop = 0
bot.music.queue = []
resetTime()
}
function resetTime () {
time = 0
startTime = Date.now()
noteIndex = 0
bot.core.run(`minecraft:bossbar remove ${bossbarName}`) // maybe not a good place to put it here but idk
}
function formatTime (time) {
const seconds = Math.floor(time / 1000)
return `${Math.floor(seconds / 60)}:${(seconds % 60).toString().padStart(2, '0')}`
}
function toComponent () {
const component = [
{ text: bot.music.song.name, color: 'green' },
{ text: ' | ', color: 'dark_gray' },
{ text: formatTime(time), color: 'gray' },
{ text: ' / ', color: 'dark_gray' },
{ text: formatTime(bot.music.song.length), color: 'gray' },
{ text: ' | ', color: 'dark_gray' },
{ text: noteIndex, color: 'gray' },
{ text: ' / ', color: 'dark_gray' },
{ text: bot.music.song.notes.length, color: 'gray' }
]
if (bot.music.loop === 1) {
component.push({ text: ' | ', color: 'dark_gray' })
component.push({ text: 'Looping Current', color: 'green' })
}
if (bot.music.loop === 2) {
component.push({ text: ' | ', color: 'dark_gray' })
component.push({ text: 'Looping All', color: 'green' })
}
return component
}
}
module.exports = inject
+89
View File
@@ -0,0 +1,89 @@
# i bet theres gonna be some whiny assholes complaining about this because config is .yml and not .js since most java bots use .yml and no other
# javascript bot uses .yml, all i got to say is go cry somewhere else about it you wont change my mind, you little shit,
# it looks cleaner than config.js - Parker2991
# FNFBoyfriendBot Config
Commands:
prefixes:
- '!'
colors:
discord:
error: "#ff0000"
embed: "#00ffff"
help:
pub_lickColor: "#00FFFF"
t_rustedColor: "dark_purple"
own_herColor: "dark_red"
error: "#FF0000"
Core:
JSON: ""
area:
start:
x: 0
y: 0
z: 0
end:
x: 15
y: 0
z: 15
validation:
discord:
roles:
trusted: "trusted"
owner: "owner"
channelId: "channel validation here"
trustedKey: "trusted key here"
ownerKey: "owner key here"
Discord:
enabled: false
invite: "https://discord.gg/GCKtG4erux"
commandPrefix: "!"
presence:
name: "amongus"
type: 4
status: "online"
console:
filelogging: false
prefix: "c."
bots :
- host: "localhost"
useChat: false
isKaboom: true
isCreayun: false
usernameGen: true
username: "FNFBoyfriendBot"
version: "1.20.2"
serverName: "localhost"
reconnectDelay: 6000
endcredits: false
Console:
enabled: true
ratelimit: 25
Core:
enabled: true
interval: 180000
discord:
channelId: ""
log: false
matrix:
roomId: ""
selfcare:
vanished: true
unmuted: true
prefix: true
cspy: true
tptoggle: true
skin: true
gmc: true
op: true
nickname: true
username: true
god: true
interval: 500
+18 -9
View File
@@ -2,16 +2,29 @@ const CommandError = require('./CommandModules/command_error.js');
const util = require("util");
const path = require('path');
const fs = require('fs');
if (!fs.existsSync('config.js')) {
const parseYaml = require('js-yaml')
/* if (!fs.existsSync('config.js')) {
console.log('Config not found creating config from default.js');
fs.copyFileSync(
path.join(__dirname, 'default.js'),
path.join(__dirname, 'default.yml'),
path.join(__dirname, 'config.js'),
);
}; */
if (!fs.existsSync('config.yml')) {
console.log('Config not found creating config from default.yml');
fs.copyFileSync(
path.join(__dirname, 'default.yml'),
path.join(__dirname, 'config.yml'),
);
};
const config = require(`../config.js`);
const createBot = require('./bot.js');
const fileExist = require("./util/file-exists");
// const config = require(`../config.js`);
try {
config = parseYaml.load(fs.readFileSync('config.yml', 'utf8'));
console.log(config)
} catch (e) {
console.log(e.toString())
}
const { createBot } = require('./bot.js');
const readline = require("readline");
const rl = readline.createInterface({
@@ -19,10 +32,6 @@ const rl = readline.createInterface({
output: process.stdout,
});
//const config = require('./config.js')
function load() {
require("dotenv").config();
const bots = [];