mirror of
https://code.chipmunk.land/Parker2991/NitoriBot/
synced 2026-12-06 01:15:42 -05:00
v8.0.0-alpha
This commit is contained in:
+306
-150
@@ -1,168 +1,324 @@
|
||||
const loadPrismarineChat = require('prismarine-chat');
|
||||
const KaboomChatParser = require('../util/ChatParsers/Kaboom');
|
||||
const ChipmunkModChatParser = require('../util/ChatParsers/ChipmunkMod');
|
||||
const CreayunChatParser = require('../util/ChatParsers/Creayun');
|
||||
const sayConsoleChatParser = require('../util/ChatParsers/sayConsole');
|
||||
const VanillaChatParser = require("../util/ChatParsers/VanillaChat");
|
||||
const yfdCustomChatParser = require('../util/ChatParsers/yfdCustomChat');
|
||||
const loadPrismarineChat = require("prismarine-chat");
|
||||
const KaboomChatParser = require("../chatparsers/kaboom");
|
||||
const CreayunChatParser = require("../chatparsers/creayun");
|
||||
const convertNbtComponentToJson = require("../util/nbt_parser");
|
||||
|
||||
function tryParse (json) {
|
||||
function tryParse(json) {
|
||||
try {
|
||||
return JSON.parse(json)
|
||||
return JSON.parse(json);
|
||||
} catch (error) {
|
||||
return { text: '' }
|
||||
return { text: "" };
|
||||
}
|
||||
}
|
||||
|
||||
function inject (context) {
|
||||
const bot = context.bot;
|
||||
const config = context.config;
|
||||
const options = context.options;
|
||||
let ChatMessage
|
||||
bot.on('registry_ready', registry => {
|
||||
ChatMessage = loadPrismarineChat(registry)
|
||||
})
|
||||
if (options.mode === "savageFriends" || options.mode === "creayun") {
|
||||
bot.chatParsers = [CreayunChatParser, sayConsoleChatParser]
|
||||
} else {
|
||||
bot.chatParsers = [KaboomChatParser, ChipmunkModChatParser, VanillaChatParser, sayConsoleChatParser, yfdCustomChatParser]
|
||||
}
|
||||
bot.on('packet.profileless_chat', packet => {
|
||||
const message = tryParse(packet.message)
|
||||
const sender = tryParse(packet.name)
|
||||
|
||||
switch (packet.type) {
|
||||
case 1:
|
||||
bot.emit('message', { translate: "chat.type.emote", with: [ sender, message ]})
|
||||
break
|
||||
case 2:
|
||||
bot.emit('message', { translate: "commands.message.display.incoming", with: [ sender, message ], color: "gray", italic: true })
|
||||
break
|
||||
case 3:
|
||||
bot.emit('message', [{ translate: "commands.message.display.outgoing", with: [ sender, message ], color: "gray", italic: true }])
|
||||
break
|
||||
case 4:
|
||||
bot.emit('message', [message]);
|
||||
break
|
||||
case 5:
|
||||
bot.emit('message', [{ translate: 'chat.type.announcement', with: [ sender, message ]}])
|
||||
break
|
||||
class ChatModule {
|
||||
constructor(context) {
|
||||
const bot = context.bot;
|
||||
const config = context.config;
|
||||
const options = context.options;
|
||||
let ChatMessage;
|
||||
bot.on("registry_ready", (registry) => {
|
||||
ChatMessage = loadPrismarineChat(registry);
|
||||
});
|
||||
if (options.mode === "savageFriends") {
|
||||
bot.chatParsers = [CreayunChatParser];
|
||||
} else {
|
||||
bot.chatParsers = [KaboomChatParser];
|
||||
}
|
||||
tryParsingMessage(message, { senderName: sender, players: bot.players, getMessageAsPrismarine: bot.getMessageAsPrismarine })
|
||||
})
|
||||
|
||||
bot.on('packet.player_chat', (packet, data) => {
|
||||
const unsigned = tryParse(packet.unsignedChatContent)
|
||||
|
||||
switch (packet.type) {
|
||||
case 5:
|
||||
bot.emit('message', { translate: "chat.type.announcement", with: [ bot.players.find(player => player.uuid === packet.senderUuid).profile.name, packet.plainMessage ]})
|
||||
break
|
||||
case 4:
|
||||
bot.emit('message', unsigned);
|
||||
break
|
||||
case 3:
|
||||
bot.emit('message', { translate: "commands.message.display.outgoing", with: [ bot.players.find(player => player.uuid === packet.senderUuid).profile.name, packet.plainMessage ], color: "gray", italic: true });
|
||||
break
|
||||
case 2:
|
||||
bot.emit('message', { translate: "commands.message.display.incoming", with: [ bot.players.find(player => player.uuid === packet.senderUuid).profile.name, packet.plainMessage ], color: "gray", italic: true })
|
||||
break
|
||||
case 1:
|
||||
bot.emit('message', { translate: "chat.type.emote", with: [ bot.players.find(player => player.uuid === packet.senderUuid).profile.name, packet.plainMessage ]})
|
||||
break
|
||||
}
|
||||
tryParsingMessage(unsigned, { senderUuid: packet.senderUuid, players: bot.players, getMessageAsPrismarine: bot.getMessageAsPrismarine })
|
||||
})
|
||||
|
||||
bot.on('packet.system_chat', packet => {
|
||||
const message = tryParse(packet.content)
|
||||
if (message.translate === "advMode.setCommand.success" && config?.debug?.commandSetMessage === false) return;
|
||||
if (message.translate === 'multiplayer.message_not_delivered') return
|
||||
|
||||
if (packet.isActionBar) {
|
||||
return
|
||||
}
|
||||
|
||||
if (message.translate === "advMode.notAllowed") return;
|
||||
|
||||
bot.emit('message', message);
|
||||
|
||||
tryParsingMessage(message, { players: bot.players, getMessageAsPrismarine: bot.getMessageAsPrismarine });
|
||||
})
|
||||
|
||||
function tryParsingMessage (message, data) {
|
||||
let parsed
|
||||
for (const parser of bot.chatParsers) {
|
||||
parsed = parser(message, data)
|
||||
if (parsed) break
|
||||
}
|
||||
|
||||
if (!parsed) return
|
||||
bot.emit('parsed_message', parsed)
|
||||
}
|
||||
|
||||
bot.getMessageAsPrismarine = message => {
|
||||
try {
|
||||
if (ChatMessage !== undefined) {
|
||||
return new ChatMessage(message)
|
||||
bot.on("packet.profileless_chat", (packet) => {
|
||||
let message
|
||||
let sender
|
||||
if (bot._client.version === "1.21" || bot.options.version === "1.21.1") {
|
||||
message = convertNbtComponentToJson(null, packet.message);
|
||||
sender = convertNbtComponentToJson(null, packet.name);
|
||||
} else {
|
||||
message = tryParse(packet.message);
|
||||
sender = tryParse(packet.name);
|
||||
}
|
||||
} catch {}
|
||||
|
||||
return undefined
|
||||
}
|
||||
if (bot.options.version === "1.21" || bot._client.version === "1.21.1") {
|
||||
switch (packet.type.registryIndex) {
|
||||
case 6:
|
||||
bot.emit("message", {
|
||||
translate: "chat.type.announcement",
|
||||
with: [sender, message],
|
||||
});
|
||||
break;
|
||||
case 5:
|
||||
bot.emit("message", message);
|
||||
break;
|
||||
case 4:
|
||||
bot.emit("message", {
|
||||
translate: "commands.message.display.outgoing",
|
||||
with: [sender, message],
|
||||
color: "gray",
|
||||
italic: true,
|
||||
});
|
||||
break;
|
||||
case 3:
|
||||
bot.emit("message", {
|
||||
translate: "commands.message.display.incoming",
|
||||
with: [sender, message],
|
||||
color: "gray",
|
||||
italic: true,
|
||||
});
|
||||
break;
|
||||
case 2:
|
||||
bot.emit("message", {
|
||||
translate: "chat.type.emote",
|
||||
with: [sender, message],
|
||||
});
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (packet.type) {
|
||||
case 1:
|
||||
bot.emit("message", {
|
||||
translate: "chat.type.emote",
|
||||
with: [sender, message],
|
||||
});
|
||||
break;
|
||||
case 2:
|
||||
bot.emit("message", {
|
||||
translate: "commands.message.display.incoming",
|
||||
with: [sender, message],
|
||||
color: "gray",
|
||||
italic: true,
|
||||
});
|
||||
break;
|
||||
case 3:
|
||||
bot.emit("message", [
|
||||
{
|
||||
translate: "commands.message.display.outgoing",
|
||||
with: [sender, message],
|
||||
color: "gray",
|
||||
italic: true,
|
||||
},
|
||||
]);
|
||||
break;
|
||||
case 4:
|
||||
bot.emit("message", [message]);
|
||||
break;
|
||||
case 5:
|
||||
bot.emit("message", [
|
||||
{ translate: "chat.type.announcement", with: [sender, message] },
|
||||
]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
bot.chat = {
|
||||
message (message) {
|
||||
const acc = 0;
|
||||
const bitset = Buffer.allocUnsafe(3);
|
||||
bitset[0] = acc & 0xFF;
|
||||
bitset[1] = (acc >> 8) & 0xFF;
|
||||
bitset[2] = (acc >> 16) & 0xFF;
|
||||
bot._client.write('chat_message', {
|
||||
message: message?.substring(0, 256)?.replaceAll('§','&'),
|
||||
timestamp: BigInt(Date.now()),
|
||||
salt: 0n,
|
||||
offset: 0,
|
||||
acknowledged: bitset
|
||||
})
|
||||
},
|
||||
bot.on("packet.player_chat", (packet, data) => {
|
||||
let unsigned;
|
||||
|
||||
command (command) {
|
||||
bot._client.write('chat_command', {
|
||||
command: command?.substring(0, 256)?.replaceAll('§','&'),
|
||||
timestamp: BigInt(Date.now()),
|
||||
salt: 0n,
|
||||
argumentSignatures: [],
|
||||
signedPreview: false,
|
||||
messageCount: 0,
|
||||
acknowledged: Buffer.alloc(3),
|
||||
previousMessages: []
|
||||
})
|
||||
},
|
||||
if (bot.options.version === "1.21" || bot.options.version === "1.21.1") {
|
||||
unsigned = convertNbtComponentToJson(null, packet.unsignedChatContent);
|
||||
} else {
|
||||
unsigned = tryParse(packet.unsignedChatContent);
|
||||
}
|
||||
|
||||
send (message) {
|
||||
if (message.startsWith('/')) {
|
||||
bot.chat.command(message.substring(1))
|
||||
if (bot.options.version === "1.21" || bot.options.version === "1.21.1") {
|
||||
switch (packet.type.registryIndex) {
|
||||
case 6:
|
||||
bot.emit("message", {
|
||||
translate: "chat.type.announcement",
|
||||
with: [
|
||||
bot.players.find((player) => player.uuid === packet.senderUuid)
|
||||
.profile.name,
|
||||
packet.plainMessage,
|
||||
],
|
||||
});
|
||||
break;
|
||||
case 5:
|
||||
bot.emit("message", unsigned);
|
||||
break;
|
||||
case 4:
|
||||
bot.emit("message", {
|
||||
translate: "commands.message.display.outgoing",
|
||||
with: [
|
||||
bot.players.find((player) => player.uuid === packet.senderUuid)
|
||||
.profile.name,
|
||||
packet.plainMessage,
|
||||
],
|
||||
color: "gray",
|
||||
italic: true,
|
||||
});
|
||||
break;
|
||||
case 3:
|
||||
bot.emit("message", {
|
||||
translate: "commands.message.display.incoming",
|
||||
with: [
|
||||
bot.players.find((player) => player.uuid === packet.senderUuid)
|
||||
.profile.name,
|
||||
packet.plainMessage,
|
||||
],
|
||||
color: "gray",
|
||||
italic: true,
|
||||
});
|
||||
break;
|
||||
case 2:
|
||||
bot.emit("message", {
|
||||
translate: "chat.type.emote",
|
||||
with: [
|
||||
bot.players.find((player) => player.uuid === packet.senderUuid)
|
||||
.profile.name,
|
||||
packet.plainMessage,
|
||||
],
|
||||
});
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (packet.type) {
|
||||
case 5:
|
||||
bot.emit("message", {
|
||||
translate: "chat.type.announcement",
|
||||
with: [
|
||||
bot.players.find((player) => player.uuid === packet.senderUuid)
|
||||
.profile.name,
|
||||
packet.plainMessage,
|
||||
],
|
||||
});
|
||||
break;
|
||||
case 4:
|
||||
bot.emit("message", unsigned);
|
||||
break;
|
||||
case 3:
|
||||
bot.emit("message", {
|
||||
translate: "commands.message.display.outgoing",
|
||||
with: [
|
||||
bot.players.find((player) => player.uuid === packet.senderUuid)
|
||||
.profile.name,
|
||||
packet.plainMessage,
|
||||
],
|
||||
color: "gray",
|
||||
italic: true,
|
||||
});
|
||||
break;
|
||||
case 2:
|
||||
bot.emit("message", {
|
||||
translate: "commands.message.display.incoming",
|
||||
with: [
|
||||
bot.players.find((player) => player.uuid === packet.senderUuid)
|
||||
.profile.name,
|
||||
packet.plainMessage,
|
||||
],
|
||||
color: "gray",
|
||||
italic: true,
|
||||
});
|
||||
break;
|
||||
case 1:
|
||||
bot.emit("message", {
|
||||
translate: "chat.type.emote",
|
||||
with: [
|
||||
bot.players.find((player) => player.uuid === packet.senderUuid)
|
||||
.profile.name,
|
||||
packet.plainMessage,
|
||||
],
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
tryParsingMessage(unsigned, {
|
||||
senderUuid: packet.senderUuid,
|
||||
players: bot.players,
|
||||
getMessageAsPrismarine: bot.getMessageAsPrismarine,
|
||||
});
|
||||
});
|
||||
|
||||
bot.on("packet.system_chat", (packet) => {
|
||||
let message;
|
||||
|
||||
if (bot.options.version === "1.21" || bot.options.version === "1.21.1") {
|
||||
message = convertNbtComponentToJson(null, packet.content);
|
||||
} else {
|
||||
message = tryParse(packet.content);
|
||||
}
|
||||
|
||||
if (
|
||||
message.translate === "advMode.setCommand.success" &&
|
||||
config?.debug?.commandSetMessage === false
|
||||
)
|
||||
return;
|
||||
if (message.translate === "multiplayer.message_not_delivered") return;
|
||||
|
||||
if (packet.isActionBar) {
|
||||
return;
|
||||
}
|
||||
bot.chat.message(message)
|
||||
}
|
||||
}
|
||||
|
||||
bot.tellraw = (selector, message) => {
|
||||
if (bot.options.mode === "savageFriends") {
|
||||
bot.core.run(`minecraft:tellraw ${selector} ` + JSON.stringify(bot.getMessageAsPrismarine(message)?.toMotd()))
|
||||
} else {
|
||||
bot.core.run(`minecraft:tellraw ${selector} ` + JSON.stringify(message))
|
||||
if (message.translate === "advMode.notAllowed") return;
|
||||
|
||||
bot.emit("message", message);
|
||||
|
||||
tryParsingMessage(message, {
|
||||
players: bot.players,
|
||||
getMessageAsPrismarine: bot.getMessageAsPrismarine,
|
||||
});
|
||||
});
|
||||
|
||||
function tryParsingMessage(message, data) {
|
||||
let parsed;
|
||||
|
||||
for (const parser of bot.chatParsers) {
|
||||
parsed = parser(message, data);
|
||||
if (parsed) break;
|
||||
}
|
||||
|
||||
if (!parsed) return;
|
||||
bot.emit("parsed_message", parsed);
|
||||
}
|
||||
|
||||
bot.getMessageAsPrismarine = (message) => {
|
||||
try {
|
||||
if (ChatMessage !== undefined) {
|
||||
return new ChatMessage(message);
|
||||
}
|
||||
} catch {}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
bot.chat = {
|
||||
message(message) {
|
||||
const acc = 0;
|
||||
const bitset = Buffer.allocUnsafe(3);
|
||||
bitset[0] = acc & 0xff;
|
||||
bitset[1] = (acc >> 8) & 0xff;
|
||||
bitset[2] = (acc >> 16) & 0xff;
|
||||
bot._client.write("chat_message", {
|
||||
message: message?.substring(0, 256)?.replaceAll("§", "&"),
|
||||
timestamp: BigInt(Date.now()),
|
||||
salt: 0n,
|
||||
offset: 0,
|
||||
acknowledged: bitset,
|
||||
});
|
||||
},
|
||||
|
||||
command(command) {
|
||||
bot._client.write("chat_command", {
|
||||
command: command?.substring(0, 256)?.replaceAll("§", "&"),
|
||||
timestamp: BigInt(Date.now()),
|
||||
salt: 0n,
|
||||
argumentSignatures: [],
|
||||
signedPreview: false,
|
||||
messageCount: 0,
|
||||
acknowledged: Buffer.alloc(3),
|
||||
previousMessages: [],
|
||||
});
|
||||
},
|
||||
|
||||
send(message) {
|
||||
if (message.startsWith("/")) {
|
||||
bot.chat.command(message.substring(1));
|
||||
return;
|
||||
}
|
||||
bot.chat.message(message);
|
||||
},
|
||||
};
|
||||
|
||||
bot.tellraw = (selector, message) => {
|
||||
bot.core.run(`minecraft:tellraw ${selector} ` + JSON.stringify(message));
|
||||
};
|
||||
}
|
||||
}
|
||||
module.exports = {
|
||||
data: {
|
||||
enabled: true,
|
||||
name: "chat",
|
||||
type: "logging"
|
||||
},
|
||||
inject
|
||||
};
|
||||
|
||||
module.exports = ChatModule;
|
||||
|
||||
+255
-295
@@ -1,319 +1,279 @@
|
||||
const nbt = require('prismarine-nbt');
|
||||
const sleep = require('../util/sleep');
|
||||
const nbt = require("prismarine-nbt");
|
||||
const sleep = require("../util/sleep");
|
||||
const convertNbtComponentToJson = require("../util/nbt_parser");
|
||||
|
||||
function inject (context) {
|
||||
const bot = context.bot;
|
||||
const config = context.config;
|
||||
const options = context.options;
|
||||
bot.core = {
|
||||
area: {
|
||||
start: config.core?.area.start ?? { x: 0, y: 0, z: 0 },
|
||||
end: config.core?.area.end ?? { x: 15, y: 0, z: 15 }
|
||||
},
|
||||
class CommandCoreModule {
|
||||
constructor(context) {
|
||||
const bot = context.bot;
|
||||
const config = context.config;
|
||||
const options = context.options;
|
||||
const Item = require("prismarine-item")(bot.options.version);
|
||||
let command;
|
||||
|
||||
position: null,
|
||||
bot.core = {
|
||||
area: {
|
||||
start: config.core?.area.start ?? { x: 0, y: 0, z: 0 },
|
||||
end: config.core?.area.end ?? { x: 15, y: 0, z: 15 },
|
||||
},
|
||||
|
||||
itemPosition: null,
|
||||
position: null,
|
||||
|
||||
currentBlockRelative: { x: 0, y: 0, z: 0 },
|
||||
itemPosition: null,
|
||||
|
||||
usePlacedCommandBlock: false,
|
||||
currentBlockRelative: { x: 0, y: 0, z: 0 },
|
||||
|
||||
chatRefill () {
|
||||
const pos = bot.core.position
|
||||
const { start, end } = bot.core.area
|
||||
usePlacedCommandBlock: false,
|
||||
|
||||
if (!pos) return
|
||||
if (bot.options.mode === "creayun") return;
|
||||
refill() {
|
||||
const pos = bot.core.position;
|
||||
const { start, end } = bot.core.area;
|
||||
const itemPosition = bot.core.itemPosition;
|
||||
|
||||
if (bot.options.mode === "savageFriends") {
|
||||
command = `minecraft:fill ${pos.x + start.x} ${pos.y + start.y} ${pos.z + start.z} ${pos.x + end.x} ${pos.y + end.y} ${pos.z + end.z} command_block`
|
||||
} else {
|
||||
command = `minecraft:fill ${pos.x + start.x} ${pos.y + start.y} ${pos.z + start.z} ${pos.x + end.x} ${pos.y + end.y} ${pos.z + end.z} repeating_command_block{CustomName:'${JSON.stringify(config.core.name)}'} destroy`
|
||||
}
|
||||
if (!pos || !itemPosition) return;
|
||||
|
||||
bot.chat.command(`${command}`)
|
||||
},
|
||||
|
||||
itemRefill () {
|
||||
const pos = bot.core.position;
|
||||
const { start, end } = bot.core.area;
|
||||
const itemPosition = bot.core.itemPosition;
|
||||
|
||||
if (!pos) return;
|
||||
|
||||
const command = `minecraft:fill ${pos.x + start.x} ${pos.y + start.y} ${pos.z + start.z} ${pos.x + end.x} ${pos.y + end.y} ${pos.z + end.z} repeating_command_block{CustomName:'${JSON.stringify(config.core.name)}'} destroy`
|
||||
|
||||
bot._client.write('set_creative_slot', {
|
||||
slot: 36,
|
||||
item: {
|
||||
present: true,
|
||||
itemId: bot.registry.itemsByName.repeating_command_block.id,
|
||||
itemCount: 1,
|
||||
/* nbtData: nbt.comp({
|
||||
BlockEntityTag: nbt.comp({
|
||||
CustomName: nbt.string(JSON.stringify(config.core.itemName))
|
||||
})
|
||||
})*/
|
||||
if (bot.options.mode === "savageFriends") {
|
||||
command = `minecraft:fill ${pos.x + start.x} ${pos.y + start.y} ${pos.z + start.z} ${pos.x + end.x} ${pos.y + end.y} ${pos.z + end.z} command_block`;
|
||||
} else {
|
||||
command = `minecraft:fill ${pos.x + start.x} ${pos.y + start.y} ${pos.z + start.z} ${pos.x + end.x} ${pos.y + end.y} ${pos.z + end.z} command_block{CustomName:'${JSON.stringify(config.core.name)}'}`;
|
||||
}
|
||||
});
|
||||
|
||||
bot._client.write('block_dig', {
|
||||
status: 0,
|
||||
location: itemPosition,
|
||||
face: 0
|
||||
});
|
||||
if (config.core.itemRefill && bot.options.mode !== "savageFriends") {
|
||||
bot._client.write("set_creative_slot", {
|
||||
slot: 36,
|
||||
item: Item.toNotch(
|
||||
new Item(
|
||||
bot.registry.itemsByName.repeating_command_block.id,
|
||||
1,
|
||||
0,
|
||||
),
|
||||
),
|
||||
/* item: {
|
||||
present: true,
|
||||
// itemId: 492,
|
||||
itemId: Item.toNotch(new Item(bot.registry.itemsByName.repeating_command_block.id, 1, 0)),
|
||||
itemCount: 1,
|
||||
},*/
|
||||
});
|
||||
|
||||
bot._client.write('block_place', {
|
||||
hand: 0,
|
||||
location: itemPosition,
|
||||
direction: 0,
|
||||
cursorX: 0,
|
||||
cursorY: 0,
|
||||
cursorZ: 0,
|
||||
insideBlock: false
|
||||
});
|
||||
|
||||
if (bot.core.usePlacedCommandBlock) {
|
||||
return
|
||||
} else {
|
||||
bot._client.write('update_command_block', {
|
||||
location: itemPosition,
|
||||
command,
|
||||
flags: 5,
|
||||
mode: 1
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
move (pos = bot.position) {
|
||||
bot.core.position = {
|
||||
x: Math.floor(pos.x / 16) * 16,
|
||||
y: 0,
|
||||
z: Math.floor(pos.z / 16) * 16
|
||||
};
|
||||
|
||||
bot.core.itemPosition = {
|
||||
x: Math.floor(pos.x - 2),
|
||||
y: Math.floor(pos.y - 2),
|
||||
z: Math.floor(pos.z - 2)
|
||||
}
|
||||
|
||||
if (config.core.itemRefill && bot.options.mode !== "savageFriends") {
|
||||
bot.core.itemRefill();
|
||||
} else {
|
||||
bot.core.chatRefill();
|
||||
}
|
||||
},
|
||||
|
||||
currentBlock () {
|
||||
const relativePosition = bot.core.currentBlockRelative
|
||||
const corePosition = bot.core.position
|
||||
if (!corePosition) return null
|
||||
return { x: relativePosition.x + corePosition.x, y: relativePosition.y + corePosition.y, z: relativePosition.z + corePosition.z }
|
||||
},
|
||||
|
||||
incrementCurrentBlock () {
|
||||
const relativePosition = bot.core.currentBlockRelative
|
||||
const { start, end } = bot.core.area
|
||||
|
||||
relativePosition.x++
|
||||
|
||||
if (relativePosition.x > end.x) {
|
||||
relativePosition.x = start.x
|
||||
relativePosition.z++
|
||||
}
|
||||
|
||||
if (relativePosition.z > end.z) {
|
||||
relativePosition.z = start.z
|
||||
relativePosition.y++
|
||||
}
|
||||
|
||||
if (relativePosition.y > end.y) {
|
||||
relativePosition.x = start.x
|
||||
relativePosition.y = start.y
|
||||
relativePosition.z = start.z
|
||||
}
|
||||
},
|
||||
|
||||
run (command) {
|
||||
const location = bot.core.currentBlock();
|
||||
const itemPosition = bot.core.itemPosition;
|
||||
|
||||
if (!location) return;
|
||||
if (bot.options.mode === "creayun") {
|
||||
return;
|
||||
} else if (bot.options.mode === "savageFriends") {
|
||||
bot._client.write('update_command_block', {
|
||||
command: command.substring(0, 32767),
|
||||
location: location,
|
||||
mode: 2,
|
||||
flags: 0b101,
|
||||
});
|
||||
|
||||
bot.core.incrementCurrentBlock();
|
||||
} else {
|
||||
if (bot.core.usePlacedCommandBlock) {
|
||||
bot._client.write('update_command_block', {
|
||||
command: command.substring(0, 32767),
|
||||
bot._client.write("block_dig", {
|
||||
status: 0,
|
||||
location: itemPosition,
|
||||
mode: 1,
|
||||
flags: 5,
|
||||
face: 0,
|
||||
});
|
||||
|
||||
bot._client.write("block_place", {
|
||||
hand: 0,
|
||||
location: itemPosition,
|
||||
direction: 0,
|
||||
cursorX: 0,
|
||||
cursorY: 0,
|
||||
cursorZ: 0,
|
||||
insideBlock: false,
|
||||
});
|
||||
|
||||
if (bot.core.usePlacedCommandBlock) {
|
||||
return;
|
||||
} else {
|
||||
bot._client.write("update_command_block", {
|
||||
location: itemPosition,
|
||||
command,
|
||||
flags: 5,
|
||||
mode: 1,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
bot.chat.command(`${command}`);
|
||||
}
|
||||
},
|
||||
|
||||
move(pos = bot.position) {
|
||||
bot.core.position = {
|
||||
x: Math.floor(pos.x / 16) * 16,
|
||||
y: 0,
|
||||
z: Math.floor(pos.z / 16) * 16,
|
||||
};
|
||||
|
||||
bot.core.itemPosition = {
|
||||
x: Math.floor(pos.x),
|
||||
y: Math.floor(pos.y - 1),
|
||||
z: Math.floor(pos.z),
|
||||
};
|
||||
|
||||
bot.core.refill();
|
||||
},
|
||||
|
||||
currentBlock() {
|
||||
const relativePosition = bot.core.currentBlockRelative;
|
||||
const corePosition = bot.core.position;
|
||||
if (!corePosition) return null;
|
||||
return {
|
||||
x: relativePosition.x + corePosition.x,
|
||||
y: relativePosition.y + corePosition.y,
|
||||
z: relativePosition.z + corePosition.z,
|
||||
};
|
||||
},
|
||||
|
||||
incrementCurrentBlock() {
|
||||
const relativePosition = bot.core.currentBlockRelative;
|
||||
const { start, end } = bot.core.area;
|
||||
|
||||
relativePosition.x++;
|
||||
|
||||
if (relativePosition.x > end.x) {
|
||||
relativePosition.x = start.x;
|
||||
relativePosition.z++;
|
||||
}
|
||||
|
||||
if (relativePosition.z > end.z) {
|
||||
relativePosition.z = start.z;
|
||||
relativePosition.y++;
|
||||
}
|
||||
|
||||
if (relativePosition.y > end.y) {
|
||||
relativePosition.x = start.x;
|
||||
relativePosition.y = start.y;
|
||||
relativePosition.z = start.z;
|
||||
}
|
||||
},
|
||||
|
||||
run(command) {
|
||||
const location = bot.core.currentBlock();
|
||||
const itemPosition = bot.core.itemPosition;
|
||||
|
||||
if (!location) return;
|
||||
if (bot.options.mode === "creayun") {
|
||||
return;
|
||||
} else if (bot.options.mode === "savageFriends") {
|
||||
bot._client.write("update_command_block", {
|
||||
command: command.substring(0, 32767),
|
||||
location: location,
|
||||
mode: 2,
|
||||
flags: 0b101,
|
||||
});
|
||||
|
||||
bot.core.incrementCurrentBlock();
|
||||
} else {
|
||||
bot._client.write('update_command_block', {
|
||||
command: command.substring(0, 32767),
|
||||
location,
|
||||
mode: 1,
|
||||
flags: 5
|
||||
});
|
||||
if (bot.core.usePlacedCommandBlock) {
|
||||
bot._client.write("update_command_block", {
|
||||
command: command.substring(0, 32767),
|
||||
location: itemPosition,
|
||||
mode: 1,
|
||||
flags: 5,
|
||||
});
|
||||
|
||||
bot.core.incrementCurrentBlock();
|
||||
}
|
||||
}
|
||||
},
|
||||
bot.core.incrementCurrentBlock();
|
||||
} else {
|
||||
bot._client.write("update_command_block", {
|
||||
command: command.substring(0, 32767),
|
||||
location,
|
||||
mode: 1,
|
||||
flags: 5,
|
||||
});
|
||||
|
||||
async runTracked (command, selector) {
|
||||
const location = bot.core.itemPosition;
|
||||
let transactionId = Math.floor(Math.random() * 10000);
|
||||
|
||||
bot._client.write('set_creative_slot', {
|
||||
slot: 36,
|
||||
item: {
|
||||
present: true,
|
||||
itemId: bot.registry.itemsByName.repeating_command_block.id,
|
||||
itemCount: 1,
|
||||
/* nbtData: nbt.comp({
|
||||
BlockEntityTag: nbt.comp({
|
||||
CustomName: nbt.string(JSON.stringify(config.core.itemName))
|
||||
})
|
||||
})*/
|
||||
}
|
||||
});
|
||||
|
||||
bot._client.write('block_dig', {
|
||||
status: 0,
|
||||
location: {
|
||||
x: location.x,
|
||||
y: location.y - 1,
|
||||
z: location.z
|
||||
},
|
||||
face: 0
|
||||
});
|
||||
|
||||
bot._client.write('block_place', {
|
||||
hand: 0,
|
||||
location,
|
||||
direction: 0,
|
||||
cursorX: 0,
|
||||
cursorY: 0,
|
||||
cursorZ: 0,
|
||||
insideBlock: false
|
||||
});
|
||||
|
||||
bot._client.write('update_command_block', {
|
||||
command: command.substring(0, 32767),
|
||||
location: {
|
||||
x: location.x,
|
||||
y: location.y,
|
||||
z: location.z
|
||||
},
|
||||
flags: 0b101,
|
||||
mode: 1
|
||||
});
|
||||
|
||||
await sleep(100);
|
||||
|
||||
bot._client.write('query_block_nbt', { location, transactionId });
|
||||
|
||||
bot.on('packet.nbt_query_response', (data) => {
|
||||
try {
|
||||
if (data.transactionId == transactionId) {
|
||||
if (data?.nbt?.value?.LastOutput) {
|
||||
bot.tellraw("@a", JSON.parse(data.nbt.value.LastOutput.value).extra);
|
||||
}
|
||||
bot.core.incrementCurrentBlock();
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e.stack)
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
bot._client.removeListener('nbt_query_response');
|
||||
}
|
||||
async runTracked(command, selector) {
|
||||
const location = bot.core.currentBlock();
|
||||
let transactionId = Math.floor(Math.random() * 10000);
|
||||
|
||||
bot._client.write("update_command_block", {
|
||||
command: command.substring(0, 32767),
|
||||
location,
|
||||
flags: 0b101,
|
||||
mode: 1,
|
||||
});
|
||||
|
||||
bot.core.incrementCurrentBlock();
|
||||
|
||||
await sleep(100);
|
||||
|
||||
bot._client.write("query_block_nbt", { location, transactionId });
|
||||
|
||||
bot.on("packet.nbt_query_response", (data) => {
|
||||
try {
|
||||
if (data.transactionId == transactionId) {
|
||||
if (data?.nbt?.value?.LastOutput) {
|
||||
bot.tellraw(
|
||||
"@a",
|
||||
JSON.parse(data.nbt.value.LastOutput.value).extra,
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e.stack);
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
let timer;
|
||||
bot.on("packet.block_change", (data) => {
|
||||
try {
|
||||
if (
|
||||
data?.location?.x === bot?.core?.position?.x &&
|
||||
data?.location?.y === bot?.core?.position?.y &&
|
||||
data?.location?.z === bot?.core?.position?.z &&
|
||||
data.type === 0
|
||||
) {
|
||||
bot.core.move(bot.position);
|
||||
}
|
||||
} catch (e) {
|
||||
bot.console.warn(e.toString());
|
||||
}
|
||||
});
|
||||
|
||||
bot.on("move", async () => {
|
||||
try {
|
||||
if (bot.options.mode === "savageFriends") {
|
||||
await sleep(2000);
|
||||
bot.chat.command("/removenear commandblock");
|
||||
await sleep(2000);
|
||||
bot.core.move(bot.position);
|
||||
} else {
|
||||
bot.core.move(bot.position);
|
||||
}
|
||||
} catch (e) {
|
||||
bot.console.warn(e.toString());
|
||||
}
|
||||
});
|
||||
|
||||
bot.on("packet.login", () => {
|
||||
timer = setInterval(() => {
|
||||
bot.core.move(bot.position);
|
||||
}, config.core.refillInterval);
|
||||
});
|
||||
|
||||
bot.on("end", () => {
|
||||
if (timer) clearInterval(timer);
|
||||
});
|
||||
|
||||
bot.on("packet.multi_block_change", (data) => {
|
||||
try {
|
||||
if (bot.options.mode !== "kaboom") return;
|
||||
|
||||
let broken = true;
|
||||
|
||||
if (
|
||||
data.chunkCoordinates.x === Math.floor(bot.core.position.x / 16) &&
|
||||
data.chunkCoordinates.y === Math.floor(bot.core.position.y / 16) &&
|
||||
data.chunkCoordinates.z === Math.floor(bot.core.position.z / 16)
|
||||
) {
|
||||
for (const state of data.records) {
|
||||
if (state >= 7906 && state >= 7917) broken = false;
|
||||
if (state >= 12527 && state >= 12538) broken = false;
|
||||
if (state >= 12515 && state >= 12526) broken = false;
|
||||
else broken = true;
|
||||
}
|
||||
|
||||
if (broken === true) bot.core.move(bot.position);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e.stack);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (options.mode === "creayun") return;
|
||||
let timer;
|
||||
bot.on('packet.block_change', (data) => {
|
||||
try {
|
||||
if (data?.location?.x === bot?.core?.position?.x && data?.location?.y === bot?.core?.position?.y && data?.location?.z === bot?.core?.position?.z && data.type === 0) {
|
||||
bot.core.move(bot.position);
|
||||
}
|
||||
} catch (e) {
|
||||
bot.console.warn(e.toString());
|
||||
}
|
||||
});
|
||||
|
||||
bot.on('move', async () => {
|
||||
try {
|
||||
if (bot.options.mode === "savageFriends") {
|
||||
await sleep(2000);
|
||||
bot.chat.command('/removenear commandblock');
|
||||
await sleep(2000);
|
||||
bot.core.move(bot.position);
|
||||
|
||||
} else {
|
||||
bot.core.move(bot.position);
|
||||
}
|
||||
} catch (e) {
|
||||
bot.console.warn(e.toString());
|
||||
}
|
||||
});
|
||||
|
||||
bot.on('packet.login', () => {
|
||||
timer = setInterval(() => {
|
||||
bot.core.move(bot.position)
|
||||
}, config.core.refillInterval)
|
||||
});
|
||||
|
||||
bot.on('end', () => {
|
||||
if (timer) clearInterval(timer);
|
||||
});
|
||||
|
||||
bot.on('packet.multi_block_change', (data) => {
|
||||
try {
|
||||
if (bot.options.mode !== "kaboom") return;
|
||||
|
||||
let broken = true;
|
||||
|
||||
if (
|
||||
data.chunkCoordinates.x === Math.floor(bot.core.position.x / 16)
|
||||
&&
|
||||
data.chunkCoordinates.y === Math.floor(bot.core.position.y / 16)
|
||||
&&
|
||||
data.chunkCoordinates.z === Math.floor(bot.core.position.z / 16)
|
||||
) {
|
||||
for (const state of data.records) {
|
||||
if ((state >= 7906) && (state >= 7917)) broken = false;
|
||||
if ((state >= 12527) && (state >= 12538)) broken = false;
|
||||
if ((state >= 12515) && (state >= 12526)) broken = false;
|
||||
else broken = true;
|
||||
}
|
||||
|
||||
if (broken === true) bot.core.move(bot.position);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e.stack);
|
||||
}
|
||||
})
|
||||
}
|
||||
module.exports = {
|
||||
data: {
|
||||
enabled: true,
|
||||
name: "core",
|
||||
type: "extras"
|
||||
},
|
||||
inject
|
||||
};
|
||||
module.exports = CommandCoreModule;
|
||||
|
||||
@@ -1,39 +1,47 @@
|
||||
const CommandSource = require('../util/command_source');
|
||||
const CommandSource = require("../command_util/command_source");
|
||||
|
||||
function inject (context) {
|
||||
let ratelimit = 0;
|
||||
const bot = context.bot;
|
||||
const config = context.config;
|
||||
const options = context.options;
|
||||
class CommandHandlerModule {
|
||||
constructor(context) {
|
||||
let ratelimit = 0;
|
||||
const bot = context.bot;
|
||||
const config = context.config;
|
||||
const options = context.options;
|
||||
|
||||
bot.on("parsed_message", (data) => {
|
||||
if (data.type !== "minecraft:chat") return;
|
||||
const prefixes = config.prefixes;
|
||||
prefixes.map((prefix) => {
|
||||
const plainMessage = bot.getMessageAsPrismarine(data.contents)?.toString();
|
||||
bot.on("parsed_message", (data) => {
|
||||
try {
|
||||
// console.log(data.contents)
|
||||
if (data.type !== "minecraft:chat") return;
|
||||
const prefixes = config.prefixes;
|
||||
prefixes.map((prefix) => {
|
||||
const plainMessage = bot
|
||||
.getMessageAsPrismarine(data.contents)
|
||||
?.toMotd();
|
||||
|
||||
if (!plainMessage.startsWith(prefix)) return
|
||||
const command = plainMessage.substring(prefix.length)
|
||||
const source = new CommandSource(data.sender, { discord: false, console: false }, true)
|
||||
ratelimit++
|
||||
setTimeout(() => {
|
||||
ratelimit--
|
||||
}, 1000)
|
||||
if (ratelimit > 2) {
|
||||
bot.tellraw('@a', { text: 'You are using commands too fast!', color: 'dark_red'})
|
||||
} else if (command.split(" ")[0].length === 0) {
|
||||
} else {
|
||||
bot.commandManager.executeString(source, command)
|
||||
if (!plainMessage?.startsWith(prefix)) return;
|
||||
const command = plainMessage.substring(prefix.length);
|
||||
const source = new CommandSource(
|
||||
data.sender,
|
||||
{ discord: false, console: false },
|
||||
true,
|
||||
);
|
||||
ratelimit++;
|
||||
setTimeout(() => {
|
||||
ratelimit--;
|
||||
}, 1000);
|
||||
if (ratelimit > config.ratelimit.commands) {
|
||||
bot.tellraw("@a", {
|
||||
text: "You are using commands too fast!",
|
||||
color: "dark_red",
|
||||
});
|
||||
} else if (command.split(" ")[0].length === 0) {
|
||||
} else {
|
||||
bot.commandManager.executeString(source, command);
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e.stack);
|
||||
}
|
||||
})
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
data: {
|
||||
enabled: true,
|
||||
name: "command handler",
|
||||
type: "commands"
|
||||
},
|
||||
inject
|
||||
};
|
||||
module.exports = CommandHandlerModule;
|
||||
|
||||
+37
-35
@@ -1,40 +1,42 @@
|
||||
function inject (context) {
|
||||
const bot = context.bot;
|
||||
bot.cloop = {
|
||||
list: [],
|
||||
add (command, interval) {
|
||||
let timer;
|
||||
timer = ({ timer: setInterval(() => bot.core.run(command), interval), command, interval })
|
||||
this.list.push(timer)
|
||||
|
||||
bot.on('end', () => {
|
||||
this.clear()
|
||||
})
|
||||
|
||||
bot.on('packet.login', () => {
|
||||
if (this.list.length === 0) return
|
||||
timer = ({ timer: setInterval(() => bot.core.run(command), interval), command, interval })
|
||||
class CommandLoopModule {
|
||||
constructor(context) {
|
||||
const bot = context.bot;
|
||||
bot.cloop = {
|
||||
list: [],
|
||||
add(command, interval) {
|
||||
let timer;
|
||||
timer = {
|
||||
timer: setInterval(() => bot.core.run(command), interval),
|
||||
command,
|
||||
interval,
|
||||
};
|
||||
this.list.push(timer);
|
||||
})
|
||||
},
|
||||
|
||||
remove (index) {
|
||||
clearInterval(this.list[index].timer)
|
||||
bot.cloop.list.splice(index, 1)
|
||||
},
|
||||
bot.on("end", () => {
|
||||
this.clear();
|
||||
});
|
||||
|
||||
clear () {
|
||||
for (const cloop of this.list) clearInterval(cloop.timer)
|
||||
this.list = []
|
||||
}
|
||||
bot.on("packet.login", () => {
|
||||
if (this.list.length === 0) return;
|
||||
timer = {
|
||||
timer: setInterval(() => bot.core.run(command), interval),
|
||||
command,
|
||||
interval,
|
||||
};
|
||||
this.list.push(timer);
|
||||
});
|
||||
},
|
||||
|
||||
remove(index) {
|
||||
clearInterval(this.list[index].timer);
|
||||
bot.cloop.list.splice(index, 1);
|
||||
},
|
||||
|
||||
clear() {
|
||||
for (const cloop of this.list) clearInterval(cloop.timer);
|
||||
this.list = [];
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
data: {
|
||||
enabled: true,
|
||||
name: "command loop",
|
||||
type: "extras"
|
||||
},
|
||||
inject
|
||||
};
|
||||
module.exports = CommandLoopModule;
|
||||
|
||||
+236
-137
@@ -1,155 +1,254 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const CommandError = require('../util/command_error.js');
|
||||
const CommandSource = require('../util/command_source');
|
||||
const fixansi = require('../util/ansi');
|
||||
const cmdMgrUtil = require('../util/command_manager_util');
|
||||
const sleep = require('../util/sleep.js');
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const CommandError = require("../command_util/command_error.js");
|
||||
const CommandSource = require("../command_util/command_source");
|
||||
const fixansi = require("../util/ansi");
|
||||
const sleep = require("../util/sleep.js");
|
||||
|
||||
async function inject (context) {
|
||||
const bot = context.bot;
|
||||
const config = context.config;
|
||||
const discordClient = context.discordClient;
|
||||
const options = context.options;
|
||||
const { MessageBuilder } = require('prismarine-chat')(bot.options.version);
|
||||
bot.commandManager = {
|
||||
commands: {},
|
||||
commandlist: [],
|
||||
execute (source, commandName, args) {
|
||||
const command = this.getCommand(commandName.toLowerCase());
|
||||
try {
|
||||
if (!command) {
|
||||
if (source?.sources?.console) {
|
||||
bot.console.warn(bot.getMessageAsPrismarine({
|
||||
translate: "%s%s%s %s",
|
||||
color: "dark_gray",
|
||||
with: [
|
||||
{ translate: "command.unknown.command", color: "red" },
|
||||
{ text: "\n" },
|
||||
{ text: `${commandName}` },
|
||||
{ translate: "command.context.here", color: "red" }
|
||||
]
|
||||
})?.toAnsi());
|
||||
class CommandManagerModule {
|
||||
constructor(context) {
|
||||
const bot = context.bot;
|
||||
const config = context.config;
|
||||
const discordClient = context.discordClient;
|
||||
const options = context.options;
|
||||
bot.commandManager = {
|
||||
commands: {},
|
||||
commandlist: [],
|
||||
execute(source, commandName, args) {
|
||||
const command = this.getCommand(commandName.toLowerCase());
|
||||
try {
|
||||
if (!command) {
|
||||
if (source?.sources?.console) {
|
||||
bot.console.warn(
|
||||
bot
|
||||
.getMessageAsPrismarine({
|
||||
translate: "%s%s%s %s",
|
||||
color: "dark_gray",
|
||||
with: [
|
||||
{ translate: "command.unknown.command", color: "red" },
|
||||
{ text: "\n" },
|
||||
{ text: `${commandName}` },
|
||||
{ translate: "command.context.here", color: "red" },
|
||||
],
|
||||
})
|
||||
?.toAnsi(),
|
||||
);
|
||||
} else {
|
||||
throw new CommandError({
|
||||
translate: "%s%s%s %s",
|
||||
color: "dark_gray",
|
||||
with: [
|
||||
{ translate: "command.unknown.command", color: "red" },
|
||||
{ text: "\n" },
|
||||
{ text: `${commandName}` },
|
||||
{ translate: "command.context.here", color: "red" },
|
||||
],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const event = bot.discord.message;
|
||||
const roles = event?.member?.roles?.cache;
|
||||
switch (command?.data?.trustLevel) {
|
||||
case 0:
|
||||
// do nothing since trust level 0 is public
|
||||
break;
|
||||
case 1:
|
||||
if (source?.sources?.discord) {
|
||||
const hasRole = roles?.some(
|
||||
(role) =>
|
||||
role.name === `${config.discord.roles.trusted}` ||
|
||||
role.name === `${config.discord.roles.admin}` ||
|
||||
role.name === `${config.discord.roles.fullAccess}` ||
|
||||
role.name === `${config.discord.roles.owner}`,
|
||||
);
|
||||
if (!hasRole)
|
||||
throw new CommandError({
|
||||
translate:
|
||||
"You dont have the trusted, admin, or owner role!",
|
||||
color: "dark_red",
|
||||
});
|
||||
} else if (!source?.sources.console) {
|
||||
if (args.length === 0)
|
||||
throw new CommandError({
|
||||
text: "Please provide a trusted, admin or owner hash",
|
||||
color: "dark_red",
|
||||
});
|
||||
if (
|
||||
args[0] !== bot.validation.trusted &&
|
||||
args[0] !== bot.validation.admin &&
|
||||
args[0] !== bot.validation.owner
|
||||
)
|
||||
throw new CommandError({
|
||||
translate: "Invalid trusted, admin or owner hash",
|
||||
color: "dark_red",
|
||||
});
|
||||
}
|
||||
|
||||
break;
|
||||
case 2:
|
||||
if (source?.sources?.discord) {
|
||||
const hasRole = roles?.some(
|
||||
(role) =>
|
||||
role.name === `${config.discord.roles.admin}` ||
|
||||
role.name === `${config.discord.roles.fullAccess}` ||
|
||||
role.name === `${config.discord.roles.owner}`,
|
||||
);
|
||||
if (!hasRole)
|
||||
throw new CommandError({
|
||||
translate: "You dont have the admin, or owner role!",
|
||||
color: "dark_red",
|
||||
});
|
||||
} else if (!source?.sources?.console) {
|
||||
if (args.length === 0)
|
||||
throw new CommandError({
|
||||
text: "Please provide an admin or owner hash",
|
||||
color: "dark_red",
|
||||
});
|
||||
if (
|
||||
args[0] !== bot.validation.admin &&
|
||||
args[0] !== bot.validation.owner
|
||||
)
|
||||
throw new CommandError({
|
||||
translate: "Invalid admin or owner hash",
|
||||
color: "dark_red",
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (source?.sources?.discord) {
|
||||
const hasRole = roles?.some(
|
||||
(role) =>
|
||||
role.name === `${config.discord.roles.owner}` ||
|
||||
role.name === `${config.discord.roles.fullAccess}`,
|
||||
);
|
||||
if (!hasRole)
|
||||
throw new CommandError({
|
||||
translate: "You do not have the owner role!",
|
||||
color: "dark_red",
|
||||
});
|
||||
} else if (!source?.sources?.console) {
|
||||
if (args.length === 0 && bot.validation.owner)
|
||||
throw new CommandError({
|
||||
text: "Please provide an owner hash",
|
||||
color: "dark_red",
|
||||
});
|
||||
if (args[0] !== bot.validation.owner)
|
||||
throw new CommandError({
|
||||
translate: "Invalid owner hash",
|
||||
color: "dark_red",
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (!source?.sources?.console) {
|
||||
throw new CommandError({
|
||||
text: "This command can only be ran via console",
|
||||
color: "dark_red",
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (source.sources.discord) {
|
||||
discordClient.channels.cache
|
||||
.get("1361739286113685534")
|
||||
.send(
|
||||
`User: ${source.player.profile.name}, Command: ${command.data.name}, Args: ${args.join(" ")}, Time/Date: ${new Date().toLocaleString("en-us", { TimeZone: "America/Chicago" })}, Source: Discord`,
|
||||
);
|
||||
} else if (!source.sources.console) {
|
||||
discordClient.channels.cache
|
||||
.get("1361739286113685534")
|
||||
.send(
|
||||
`User: ${source.player.profile.name}, Command: ${command.data.name}, Args: ${args.join(" ")}, Time/Date: ${new Date().toLocaleString("en-us", { TimeZone: "America/Chicago" })}, Source: Minecraft, Server: ${bot.options.host}:${bot.options.port}`,
|
||||
);
|
||||
}
|
||||
|
||||
return command?.execute({
|
||||
bot,
|
||||
source,
|
||||
arguments: args,
|
||||
config,
|
||||
discordClient,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof CommandError) {
|
||||
if (source.sources.discord) {
|
||||
bot.discord.message.reply(
|
||||
`\`\`\`ansi\n${new fixansi(bot.getMessageAsPrismarine(error._message)?.toAnsi()).ansi}\`\`\``,
|
||||
);
|
||||
} else if (source.sources.console) {
|
||||
bot.console.warn(error._message);
|
||||
} else {
|
||||
bot.tellraw("@a", error._message);
|
||||
}
|
||||
} else {
|
||||
throw new CommandError({
|
||||
translate: "%s%s%s %s",
|
||||
color: "dark_gray",
|
||||
with: [
|
||||
{ translate: "command.unknown.command", color: "red" },
|
||||
{ text: "\n" },
|
||||
{ text: `${commandName}` },
|
||||
{ translate: "command.context.here", color: "red" }
|
||||
]
|
||||
});
|
||||
if (source.sources.discord) {
|
||||
bot.discord.message.reply(
|
||||
`\`\`\`ansi\n${new fixansi(bot.getMessageAsPrismarine({ text: error.stack, color: "red"})?.toAnsi()).ansi}\`\`\``,
|
||||
);
|
||||
} else {
|
||||
bot.tellraw("@a", {
|
||||
translate: "command.failed",
|
||||
color: "red",
|
||||
hoverEvent: {
|
||||
action: "show_text",
|
||||
contents: String(error.stack),
|
||||
},
|
||||
});
|
||||
|
||||
bot?.console?.warn(error.stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
cmdMgrUtil(bot, command, args, source, config);
|
||||
executeString(source, command) {
|
||||
const [commandName, ...args] = command.split(" ");
|
||||
|
||||
return command?.execute({ bot, source, arguments: args, config, discordClient });
|
||||
} catch (error) {
|
||||
if (error instanceof CommandError) {
|
||||
bot.tellraw("@a", error._message);
|
||||
} else {
|
||||
bot.tellraw("@a", {
|
||||
translate: "command.failed",
|
||||
color: "red",
|
||||
hoverEvent: {
|
||||
action: "show_text",
|
||||
contents: String(error.stack)
|
||||
}
|
||||
});
|
||||
|
||||
bot?.console?.warn(error.stack);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
executeString (source, command) {
|
||||
const [commandName, ...args] = command.split(' ');
|
||||
if (source?.sources?.discord) {
|
||||
return this.discordExecute(source, commandName, args);
|
||||
} else if (!source?.sources?.discord) {
|
||||
return this.execute(source, commandName, args);
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
discordExecute(source, commandName, args) {
|
||||
const command = this.getCommand(commandName.toLowerCase());
|
||||
|
||||
try {
|
||||
if (!command) {
|
||||
throw new CommandError(`Unknown Command: ${commandName}`);
|
||||
register(command) {
|
||||
this.commands[command.data.name] = command;
|
||||
if (command.data.aliases) {
|
||||
command.data.aliases.map((a) => (this.commands[a] = command));
|
||||
}
|
||||
},
|
||||
|
||||
cmdMgrUtil(bot, command, args, source, config);
|
||||
getCommand(name) {
|
||||
return this.commands[name];
|
||||
},
|
||||
|
||||
if (!command?.discordExecute) {
|
||||
throw new CommandError(`${command.data.name} command is not supported in discord!`);
|
||||
} else if (source.sources.discord) {
|
||||
return command?.discordExecute({ bot, source, arguments: args, config, discordClient, fixansi });
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof CommandError) {
|
||||
bot?.discord?.message?.reply(`${bot.getMessageAsPrismarine(error._message)}`);
|
||||
} else {
|
||||
bot?.discord?.message?.reply(`\`\`\`${error.stack}\`\`\``);
|
||||
bot?.console?.warn(error.stack);
|
||||
}
|
||||
}
|
||||
},
|
||||
getCommands() {
|
||||
return Object.values(this.commands);
|
||||
},
|
||||
};
|
||||
|
||||
register (command) {
|
||||
this.commands[command.data.name] = command
|
||||
if (command.data.aliases) {
|
||||
command.data.aliases.map((a) => (this.commands[a] = command));
|
||||
}
|
||||
},
|
||||
|
||||
getCommand (name) {
|
||||
return this.commands[name]
|
||||
},
|
||||
|
||||
getCommands () {
|
||||
return Object.values(this.commands)
|
||||
},
|
||||
}
|
||||
|
||||
/*
|
||||
file loader ported from my discord bot SkiBot
|
||||
and edited to support mjs files and to support FNFBoyfriendBot's command format
|
||||
/*
|
||||
command loader ported from my discord bot SkiBot
|
||||
*/
|
||||
commandlist = [];
|
||||
const foldersPath = path.join(__dirname, '../commands');
|
||||
const commandFolders = fs.readdirSync(foldersPath);
|
||||
for (const folder of commandFolders) {
|
||||
const commandsPath = path.join(foldersPath, folder);
|
||||
const commandFiles = fs.readdirSync(commandsPath)
|
||||
for (const filename of commandFiles) {
|
||||
try {
|
||||
const filePath = path.join(commandsPath, filename);
|
||||
if (filename.endsWith('.mjs')) {
|
||||
let command = await import(filePath);
|
||||
bot.commandManager.register(command.default);
|
||||
bot.commandManager.commandlist.push(command.default);
|
||||
let commandlist = [];
|
||||
const foldersPath = path.join(__dirname, "../commands");
|
||||
const commandFolders = fs.readdirSync(foldersPath);
|
||||
for (const folder of commandFolders) {
|
||||
const commandsPath = path.join(foldersPath, folder);
|
||||
const commandFiles = fs.readdirSync(commandsPath);
|
||||
for (const filename of commandFiles) {
|
||||
try {
|
||||
const filePath = path.join(commandsPath, filename);
|
||||
|
||||
if (filename.endsWith(".js")) {
|
||||
const command = require(filePath);
|
||||
const commands = new command();
|
||||
bot.commandManager.register(commands);
|
||||
bot.commandManager.commandlist.push(commands);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to load command ", filename, ":", error);
|
||||
}
|
||||
if (filename.endsWith('.js')) {
|
||||
let command = require(filePath);
|
||||
bot.commandManager.register(command);
|
||||
bot.commandManager.commandlist.push(command);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load command ', filename, ':', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
data: {
|
||||
enabled: true,
|
||||
name: "command manager",
|
||||
type: "commands"
|
||||
},
|
||||
inject
|
||||
};
|
||||
module.exports = CommandManagerModule;
|
||||
|
||||
+114
-68
@@ -1,73 +1,119 @@
|
||||
const CommandSource = require('../util/command_source');
|
||||
const prismarineChat = require('prismarine-chat')('1.20.2');
|
||||
const CommandSource = require("../command_util/command_source");
|
||||
const prismarineChat = require("prismarine-chat")("1.20.2");
|
||||
|
||||
function inject (context) {
|
||||
const bot = context.bot;
|
||||
const config = context.config;
|
||||
const options = context.options;
|
||||
let ratelimit = 0;
|
||||
bot.console = {
|
||||
readline: null,
|
||||
server: 'all',
|
||||
readlineInterface (rl) {
|
||||
this.readline = rl
|
||||
rl.on('line', (args) => {
|
||||
if (bot.options.serverName !== this.server && this.server !== 'all') return
|
||||
if (args.startsWith(config.console.prefix)) {
|
||||
return bot.commandManager.executeString(bot.console.source, args.substring(config.console.prefix.length))
|
||||
} else if (args.startsWith("")) {
|
||||
bot.chat.send(args);
|
||||
}
|
||||
rl.on('close', () => {
|
||||
this.readline = null;
|
||||
})
|
||||
})
|
||||
},
|
||||
source: new CommandSource({
|
||||
profile: {
|
||||
name: bot._client.username
|
||||
}, uuid: bot._client.uuid },
|
||||
{ console: true, discord: false
|
||||
}),
|
||||
class ConsoleModule {
|
||||
constructor(context) {
|
||||
const bot = context.bot;
|
||||
const config = context.config;
|
||||
const options = context.options;
|
||||
let ratelimit = 0;
|
||||
|
||||
refreshLine (...args) {
|
||||
this.readline.output.write("\x1b[2K\r");
|
||||
console.log.apply(console, arguments);
|
||||
this.readline._refreshLine();
|
||||
},
|
||||
log (message) {
|
||||
this.refreshLine(bot.getMessageAsPrismarine(`§8[§1${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO" })} §3${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO" })} §6logs§8] §8[${options.serverName}§8] `)?.toAnsi() + message)
|
||||
},
|
||||
warn (error) {
|
||||
this.refreshLine(prismarineChat.fromNotch(`§8[§1${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO", })} §3${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO", })} §ewarn§8] §8[${options.serverName}§8] `)?.toAnsi() + error)
|
||||
},
|
||||
error (error) {
|
||||
this.refreshLine(bot.getMessageAsPrismarine(`§8[§1${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO", })} §3${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO", })} §4error§8] §8[${options.serverName}§8] `)?.toAnsi() + error)
|
||||
},
|
||||
info (message) {
|
||||
this.refreshLine(prismarineChat.fromNotch(`§8[§1${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO", })} §3${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO", })} §2info§8] §8[${options.serverName}§8] `)?.toAnsi() + message)
|
||||
},
|
||||
debug (message) {
|
||||
console.log(prismarineChat.fromNotch(`§8[§1${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO", })} §3${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO", })} §6debug§8] §8[${options.serverName}§8] `)?.toAnsi() + message)
|
||||
let serverName;
|
||||
|
||||
if (options.private) {
|
||||
serverName = `${options.serverName}`;
|
||||
} else {
|
||||
serverName = `§1${bot.options.host}:§9${bot.options.port}`;
|
||||
}
|
||||
|
||||
bot.console = {
|
||||
readline: null,
|
||||
server: "all",
|
||||
readlineInterface(rl) {
|
||||
this.readline = rl;
|
||||
rl.on("line", (args) => {
|
||||
if (bot.options.serverName !== this.server && this.server !== "all")
|
||||
return;
|
||||
if (args.startsWith(config.console.prefix)) {
|
||||
return bot.commandManager.executeString(
|
||||
bot.console.source,
|
||||
args.substring(config.console.prefix.length),
|
||||
);
|
||||
} else if (args.startsWith("")) {
|
||||
bot.chat.send(args);
|
||||
}
|
||||
rl.on("close", () => {
|
||||
this.readline = null;
|
||||
});
|
||||
});
|
||||
},
|
||||
source: new CommandSource(
|
||||
{
|
||||
profile: {
|
||||
name: bot._client.username,
|
||||
},
|
||||
uuid: bot._client.uuid,
|
||||
},
|
||||
{ console: true, discord: false },
|
||||
),
|
||||
|
||||
refreshLine(...args) {
|
||||
this.readline.output.write("\x1b[2K\r");
|
||||
console.log.apply(console, arguments);
|
||||
this.readline._refreshLine();
|
||||
},
|
||||
log(message) {
|
||||
this.refreshLine(
|
||||
bot
|
||||
.getMessageAsPrismarine(
|
||||
`§8[§1${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO" })} §3${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO" })} §6logs§8] §8[${serverName}§8] `,
|
||||
)
|
||||
?.toAnsi() + message,
|
||||
);
|
||||
},
|
||||
warn(error) {
|
||||
this.refreshLine(
|
||||
prismarineChat
|
||||
.fromNotch(
|
||||
`§8[§1${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO" })} §3${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO" })} §ewarn§8] §8[${serverName}§8] `,
|
||||
)
|
||||
?.toAnsi() + error,
|
||||
);
|
||||
},
|
||||
error(error) {
|
||||
this.refreshLine(
|
||||
bot
|
||||
.getMessageAsPrismarine(
|
||||
`§8[§1${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO" })} §3${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO" })} §4error§8] §8[${serverName}§8] `,
|
||||
)
|
||||
?.toAnsi() + error,
|
||||
);
|
||||
},
|
||||
info(message) {
|
||||
this.refreshLine(
|
||||
prismarineChat
|
||||
.fromNotch(
|
||||
`§8[§1${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO" })} §3${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO" })} §2info§8] §8[${serverName}§8] `,
|
||||
)
|
||||
?.toAnsi() + message,
|
||||
);
|
||||
},
|
||||
debug(message) {
|
||||
console.log(
|
||||
prismarineChat
|
||||
.fromNotch(
|
||||
`§8[§1${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO" })} §3${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO" })} §6debug§8] §8[${serverName}§8] `,
|
||||
)
|
||||
?.toAnsi() + message,
|
||||
);
|
||||
},
|
||||
};
|
||||
setInterval(() => (ratelimit = 0), 1000 * 2);
|
||||
|
||||
bot.on("message", (message) => {
|
||||
if (options.logging.console) {
|
||||
if (ratelimit > config.ratelimit.console) return;
|
||||
|
||||
bot.console.log(bot.getMessageAsPrismarine(message)?.toAnsi());
|
||||
}
|
||||
if (options.logging.file) {
|
||||
bot.console.fileLogger(
|
||||
`[${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO" })} ${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO" })} logs] [${serverName}] ${bot.getMessageAsPrismarine(message)?.toString()}`,
|
||||
);
|
||||
}
|
||||
|
||||
ratelimit++;
|
||||
});
|
||||
}
|
||||
setInterval(() => ratelimit = 0, 1000 * 2);
|
||||
|
||||
bot.on('message', (message) => {
|
||||
if (!options.logging) return;
|
||||
|
||||
if (ratelimit > 10) return;
|
||||
bot.console.log(bot.getMessageAsPrismarine(message)?.toAnsi());
|
||||
bot.console.fileLogger(`[${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO", })} ${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO", })} logs] [${options.serverName}] ${bot.getMessageAsPrismarine(message)?.toString()}`);
|
||||
ratelimit++
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
data: {
|
||||
enabled: true,
|
||||
name: "console",
|
||||
type: "logging"
|
||||
},
|
||||
inject
|
||||
};
|
||||
module.exports = ConsoleModule;
|
||||
|
||||
+192
-166
@@ -1,176 +1,202 @@
|
||||
const fixansi = require('../util/ansi');
|
||||
const CommandSource = require('../util/command_source');
|
||||
const fixansi = require("../util/ansi");
|
||||
const CommandSource = require("../command_util/command_source");
|
||||
|
||||
class DiscordModule {
|
||||
constructor(context) {
|
||||
const bot = context.bot;
|
||||
const config = context.config;
|
||||
const discordClient = context.discordClient;
|
||||
const options = context.options;
|
||||
if (options.channelId.length == 0) {
|
||||
bot.discord = {
|
||||
invite: config.discord?.invite,
|
||||
client: discordClient,
|
||||
prefix: config.discord.prefix,
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
function inject (context) {
|
||||
const bot = context.bot;
|
||||
const config = context.config;
|
||||
const discordClient = context.discordClient;
|
||||
const options = context.options;
|
||||
if (!options.channelId) {
|
||||
bot.discord = {
|
||||
invite: config.discord?.invite,
|
||||
client: discordClient,
|
||||
prefix: config.discord.prefix
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
bot.discord = {
|
||||
client: discordClient,
|
||||
channel: undefined,
|
||||
invite: config.discord.invite || undefined,
|
||||
prefix: config.discord.prefix,
|
||||
}
|
||||
discordClient.once('ready', (context) => {
|
||||
bot.discord.channel = discordClient.channels.cache.get(options.channelId)
|
||||
discordClient.user.setPresence({
|
||||
activities: [{
|
||||
name: `${config.discord.presence.name}`,
|
||||
type: 0
|
||||
}],
|
||||
status: `${config.discord.presence.status}`
|
||||
});
|
||||
})
|
||||
|
||||
let discordQueue = []
|
||||
setInterval(() => {
|
||||
if (discordQueue.length === 0) return
|
||||
try {
|
||||
bot?.discord?.channel?.send(`\`\`\`ansi\n${discordQueue.join('\n').substring(0, 1984)}\n\`\`\``)
|
||||
} catch (error) {
|
||||
}
|
||||
discordQueue = []
|
||||
}, 2000)
|
||||
|
||||
function sendDiscordMessage(message) {
|
||||
discordQueue.push(message)
|
||||
}
|
||||
|
||||
function sendComponent(message) {
|
||||
const ansi = bot.getMessageAsPrismarine(message)?.toAnsi(bot.registry.language).replaceAll('```\u001b[9```' + '```\u001b[3```').replaceAll('https://discord','https:\rdiscord')?.replaceAll('discord.gg', 'discord.\rgg').replaceAll('BlackStone Mafia On Top!', "Fuck off you god damn cunt");
|
||||
try {
|
||||
sendDiscordMessage(fixansi(ansi?.replaceAll('`', '`\u200b')))
|
||||
} catch (e) {
|
||||
bot.console.warn(`Error sending a message to Discord: ${e.message}`)
|
||||
sendDiscordMessage(e.message)
|
||||
}
|
||||
}
|
||||
|
||||
bot.on('message', (message) => {
|
||||
sendComponent(message);
|
||||
});
|
||||
|
||||
function messageCreate(message, source) {
|
||||
bot.discord.message = message;
|
||||
if (message.author.id === bot.discord.client.user.id) return
|
||||
|
||||
if (message.channel.id !== bot.discord.channel.id) return
|
||||
|
||||
if (message.content.startsWith(config.discord.prefix)) { // TODO: Don't hardcode this
|
||||
const source = new CommandSource({
|
||||
profile: {
|
||||
name: `${message?.member.nickname || message?.author.displayName}`
|
||||
}
|
||||
}, {
|
||||
discord: true,
|
||||
console: false
|
||||
}, false, message);
|
||||
|
||||
sendComponent(message);
|
||||
|
||||
bot.commandManager.executeString(source, message.content.substring(config.discord.prefix.length))
|
||||
return
|
||||
}
|
||||
const tag = {
|
||||
translate: '[%s] %s \u203a ',
|
||||
with: [{
|
||||
translate: '%s%s%s %s',
|
||||
bold: false,
|
||||
with: [{
|
||||
text: 'FNF',
|
||||
bold: false,
|
||||
color: 'blue'
|
||||
},
|
||||
{
|
||||
text: 'Boyfriend',
|
||||
bold: false,
|
||||
color: 'dark_aqua'
|
||||
},
|
||||
{
|
||||
text: 'Bot',
|
||||
bold: false,
|
||||
color: 'dark_blue'
|
||||
},
|
||||
{
|
||||
text: 'Discord',
|
||||
bold: false,
|
||||
color: 'blue'
|
||||
}
|
||||
],
|
||||
clickEvent: bot.discord.invite ? {
|
||||
action: 'open_url',
|
||||
value: bot.discord.invite
|
||||
} : undefined,
|
||||
hoverEvent: {
|
||||
action: 'show_text',
|
||||
contents: 'Click to join the discord'
|
||||
}
|
||||
},
|
||||
{
|
||||
text: `${message.member.nickname || message.author.displayName}`,
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
try {
|
||||
if (message.attachments.size > 0) {
|
||||
message.attachments.forEach(Attachment => {
|
||||
let attachment = {
|
||||
text: `[Attachment: ${Attachment.name}] ${message?.content}`,
|
||||
color: "blue",
|
||||
hoverEvent: {
|
||||
action: "show_text",
|
||||
contents: "click here to view attachment"
|
||||
channel: undefined,
|
||||
invite: config.discord.invite || undefined,
|
||||
prefix: config.discord.prefix,
|
||||
};
|
||||
discordClient.once("ready", (context) => {
|
||||
bot.discord.channel = discordClient.channels.cache.get(options.channelId);
|
||||
discordClient.user.setPresence({
|
||||
activities: [
|
||||
{
|
||||
name: `${config.discord.presence.name}`,
|
||||
type: 0,
|
||||
},
|
||||
clickEvent: {
|
||||
action: "open_url",
|
||||
value: `${Attachment?.url}`
|
||||
}
|
||||
}
|
||||
],
|
||||
status: `${config.discord.presence.status}`,
|
||||
});
|
||||
});
|
||||
|
||||
bot.tellraw("@a", [tag, attachment]);
|
||||
})
|
||||
} else if (message?.reference?.type === 0) {
|
||||
// this is for messages that are replied to
|
||||
const repliedMessage = message.channel.messages.cache.get(message.reference.messageId);
|
||||
let reply = [
|
||||
tag,
|
||||
{ text: `[Replying to: ${repliedMessage.author.username}] `, color: "blue" },
|
||||
message.content
|
||||
];
|
||||
let discordQueue = [];
|
||||
setInterval(() => {
|
||||
if (discordQueue.length === 0) return;
|
||||
try {
|
||||
bot?.discord?.channel?.send(
|
||||
`\`\`\`ansi\n${discordQueue.join("\n").substring(0, 1984)}\n\`\`\``,
|
||||
);
|
||||
} catch (error) {}
|
||||
discordQueue = [];
|
||||
}, 2000);
|
||||
|
||||
bot.tellraw("@a", [ reply ]);
|
||||
} else if (message?.reference?.type === 1) {
|
||||
// this is for messages that are forwarded
|
||||
} else {
|
||||
if (options.mode === "creayun") {
|
||||
bot.chat.message(bot.getMessageAsPrismarine(`&7[&9FNF&3Boyfriend&1Bot Discord&7] ${message?.member?.displayName} \u203a ${message?.content}`)?.toMotd().replaceAll('§','&'))
|
||||
} else {
|
||||
bot.tellraw('@a', [tag, message.content]);
|
||||
function sendDiscordMessage(message) {
|
||||
discordQueue.push(message);
|
||||
}
|
||||
|
||||
function sendComponent(message) {
|
||||
const ansi = bot
|
||||
.getMessageAsPrismarine(message)
|
||||
?.toAnsi(bot.registry.language)
|
||||
.replaceAll("```\u001b[9```" + "```\u001b[3```")
|
||||
.replaceAll("https://discord", "https:\rdiscord");
|
||||
try {
|
||||
sendDiscordMessage(new fixansi(ansi?.replaceAll("`", "`\u200b")).ansi);
|
||||
} catch (e) {
|
||||
bot.console.warn(`Error sending a message to Discord: ${e.message}`);
|
||||
sendDiscordMessage(e.message);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e.stack);
|
||||
}
|
||||
}
|
||||
discordClient.on('messageCreate', messageCreate)
|
||||
|
||||
bot.on("message", (message) => {
|
||||
sendComponent(message);
|
||||
});
|
||||
|
||||
function messageCreate(message, source) {
|
||||
bot.discord.message = message;
|
||||
if (message.author.id === bot.discord.client.user.id) return;
|
||||
|
||||
if (message.channel.id !== bot.discord.channel.id) return;
|
||||
|
||||
if (message.content.startsWith(config.discord.prefix)) {
|
||||
// TODO: Don't hardcode this
|
||||
const source = new CommandSource(
|
||||
{
|
||||
profile: {
|
||||
name: `${message?.member.nickname || message?.author.displayName}`,
|
||||
},
|
||||
},
|
||||
{
|
||||
discord: true,
|
||||
console: false,
|
||||
},
|
||||
false,
|
||||
message,
|
||||
);
|
||||
|
||||
sendComponent(message);
|
||||
|
||||
bot.commandManager.executeString(
|
||||
source,
|
||||
message.content.substring(config.discord.prefix.length),
|
||||
);
|
||||
return;
|
||||
}
|
||||
const tag = {
|
||||
translate: "[%s] %s \u203a ",
|
||||
with: [
|
||||
{
|
||||
translate: "%s%s%s %s",
|
||||
bold: false,
|
||||
with: [
|
||||
{
|
||||
text: "FNF",
|
||||
bold: false,
|
||||
color: "blue",
|
||||
},
|
||||
{
|
||||
text: "Boyfriend",
|
||||
bold: false,
|
||||
color: "dark_aqua",
|
||||
},
|
||||
{
|
||||
text: "Bot",
|
||||
bold: false,
|
||||
color: "dark_blue",
|
||||
},
|
||||
{
|
||||
text: "Discord",
|
||||
bold: false,
|
||||
color: "blue",
|
||||
},
|
||||
],
|
||||
clickEvent: bot.discord.invite
|
||||
? {
|
||||
action: "open_url",
|
||||
value: bot.discord.invite,
|
||||
}
|
||||
: undefined,
|
||||
hoverEvent: {
|
||||
action: "show_text",
|
||||
contents: "Click to join the discord",
|
||||
},
|
||||
},
|
||||
{
|
||||
text: `${message.member.nickname || message.author.displayName}`,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
try {
|
||||
if (message.attachments.size > 0) {
|
||||
message.attachments.forEach((Attachment) => {
|
||||
let attachment = {
|
||||
text: `[Attachment: ${Attachment.name}] ${message?.content}`,
|
||||
color: "blue",
|
||||
hoverEvent: {
|
||||
action: "show_text",
|
||||
contents: "click here to view attachment",
|
||||
},
|
||||
clickEvent: {
|
||||
action: "open_url",
|
||||
value: `${Attachment?.url}`,
|
||||
},
|
||||
};
|
||||
|
||||
bot.tellraw("@a", [tag, attachment]);
|
||||
});
|
||||
} else if (message?.reference?.type === 0) {
|
||||
// this is for messages that are replied to
|
||||
const repliedMessage = message.channel.messages.cache.get(
|
||||
message.reference.messageId,
|
||||
);
|
||||
let reply = [
|
||||
tag,
|
||||
{
|
||||
text: `[Replying to: ${repliedMessage.author.username}] `,
|
||||
color: "blue",
|
||||
},
|
||||
message.content,
|
||||
];
|
||||
|
||||
bot.tellraw("@a", [reply]);
|
||||
} else if (message?.reference?.type === 1) {
|
||||
// this is for messages that are forwarded
|
||||
} else {
|
||||
if (options.mode === "creayun") {
|
||||
bot.chat.message(
|
||||
bot
|
||||
.getMessageAsPrismarine(
|
||||
`&7[&9FNF&3Boyfriend&1Bot Discord&7] ${message?.member?.displayName} \u203a ${message?.content}`,
|
||||
)
|
||||
?.toMotd()
|
||||
.replaceAll("§", "&"),
|
||||
);
|
||||
} else {
|
||||
bot.tellraw("@a", [tag, message.content]);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e.stack);
|
||||
}
|
||||
}
|
||||
discordClient.on("messageCreate", messageCreate);
|
||||
}
|
||||
}
|
||||
module.exports = {
|
||||
data: {
|
||||
enabled: true,
|
||||
name: "discord",
|
||||
type: "logging"
|
||||
},
|
||||
inject
|
||||
};
|
||||
module.exports = DiscordModule;
|
||||
|
||||
+63
-57
@@ -1,68 +1,74 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { createGzip } = require("zlib");
|
||||
const readline = require('readline');
|
||||
const readline = require("readline");
|
||||
const { Console } = require("console");
|
||||
|
||||
function inject (context) {
|
||||
const bot = context.bot;
|
||||
const config = context.config;
|
||||
const options = context.options;
|
||||
const currentDate = new Date();
|
||||
const timestamp = `${currentDate.getFullYear()}-${(currentDate.getMonth() + 1)
|
||||
.toString()
|
||||
.padStart(2, "0")}-${currentDate.getDate().toString().padStart(2, "0")}`;
|
||||
const logFolder = path.join(__dirname, `${config.logsFolder.path}`, `${config.logsFolder.name}`);
|
||||
const logFileName = "latest.log";
|
||||
const logFilePath = path.join(logFolder, logFileName);
|
||||
const logStream = fs.createWriteStream(logFilePath, { flags: "a" });
|
||||
try {
|
||||
if (!fs.existsSync(logFolder)) {
|
||||
console.info(`logs folder not found recreating it at ${config.logsFolder.path}${config.logsFolder.name}`);
|
||||
fs.mkdirSync(logFolder);
|
||||
class FileloggerModule {
|
||||
constructor(context) {
|
||||
const bot = context.bot;
|
||||
const config = context.config;
|
||||
const options = context.options;
|
||||
const currentDate = new Date();
|
||||
|
||||
if (!options.logging.file) return;
|
||||
|
||||
const timestamp = `${currentDate.getFullYear()}-${(
|
||||
currentDate.getMonth() + 1
|
||||
)
|
||||
.toString()
|
||||
.padStart(2, "0")}-${currentDate.getDate().toString().padStart(2, "0")}`;
|
||||
const logFolder = path.join(
|
||||
__dirname,
|
||||
`${config.logsFolder.path}`,
|
||||
`${config.logsFolder.name}`,
|
||||
);
|
||||
const logFileName = "latest.log";
|
||||
const logFilePath = path.join(logFolder, logFileName);
|
||||
const logStream = fs.createWriteStream(logFilePath, { flags: "a" });
|
||||
try {
|
||||
if (!fs.existsSync(logFolder)) {
|
||||
console.info(
|
||||
`logs folder not found recreating it at ${config.logsFolder.path}${config.logsFolder.name}`,
|
||||
);
|
||||
fs.mkdirSync(logFolder);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`Unable to create log folder: ${e}`);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`Unable to create log folder: ${e}`);
|
||||
}
|
||||
|
||||
function compressFile(input, output) {
|
||||
const plainOutput = output.slice(0, -3);
|
||||
function compressFile(input, output) {
|
||||
const plainOutput = output.slice(0, -3);
|
||||
|
||||
fs.renameSync(input, plainOutput);
|
||||
const gzip = createGzip();
|
||||
fs.createReadStream(plainOutput)
|
||||
.pipe(gzip)
|
||||
.pipe(fs.createWriteStream(output + ".tmp"))
|
||||
.once("finish", () => {
|
||||
fs.unlinkSync(plainOutput);
|
||||
fs.renameSync(output + ".tmp", output);
|
||||
});
|
||||
}
|
||||
|
||||
if (fs.existsSync(logFilePath)) {
|
||||
const plainName = fs
|
||||
.statSync(logFilePath)
|
||||
.ctime.toISOString()
|
||||
.split("T")[0];
|
||||
let name = plainName;
|
||||
let counter = 1;
|
||||
let newFileName = path.join(logFolder, `${name}.log.gz`);
|
||||
while (fs.existsSync(newFileName)) {
|
||||
name = `${plainName}-${counter}`;
|
||||
newFileName = path.join(logFolder, `${name}.log.gz`);
|
||||
counter++;
|
||||
fs.renameSync(input, plainOutput);
|
||||
const gzip = createGzip();
|
||||
fs.createReadStream(plainOutput)
|
||||
.pipe(gzip)
|
||||
.pipe(fs.createWriteStream(output + ".tmp"))
|
||||
.once("finish", () => {
|
||||
fs.unlinkSync(plainOutput);
|
||||
fs.renameSync(output + ".tmp", output);
|
||||
});
|
||||
}
|
||||
compressFile(logFilePath, newFileName);
|
||||
|
||||
if (fs.existsSync(logFilePath)) {
|
||||
const plainName = fs
|
||||
.statSync(logFilePath)
|
||||
.ctime.toISOString()
|
||||
.split("T")[0];
|
||||
let name = plainName;
|
||||
let counter = 1;
|
||||
let newFileName = path.join(logFolder, `${name}.log.gz`);
|
||||
while (fs.existsSync(newFileName)) {
|
||||
name = `${plainName}-${counter}`;
|
||||
newFileName = path.join(logFolder, `${name}.log.gz`);
|
||||
counter++;
|
||||
}
|
||||
compressFile(logFilePath, newFileName);
|
||||
}
|
||||
bot.console.fileLogger = function logging(message) {
|
||||
logStream.write(message + "\n");
|
||||
};
|
||||
}
|
||||
bot.console.fileLogger = function logging (message) {
|
||||
logStream.write(message + "\n");
|
||||
};
|
||||
}
|
||||
module.exports = {
|
||||
data: {
|
||||
enabled: true,
|
||||
name: "file logger",
|
||||
type: "logging"
|
||||
},
|
||||
inject
|
||||
};
|
||||
module.exports = FileloggerModule;
|
||||
|
||||
+105
-99
@@ -1,106 +1,112 @@
|
||||
function inject (context) {
|
||||
const bot = context.bot;
|
||||
const config = context.config;
|
||||
const options = context.options;
|
||||
bot.players = []
|
||||
const convertNbtComponentToJson = require("../util/nbt_parser");
|
||||
|
||||
bot.on('packet.player_info', async (packet) => {
|
||||
const actions = []
|
||||
if (packet.action & 0b000001) actions.push(addPlayer)
|
||||
if (packet.action & 0b000010) actions.push(initializeChat)
|
||||
if (packet.action & 0b000100) actions.push(updateGamemode)
|
||||
if (packet.action & 0b001000) actions.push(updateListed)
|
||||
if (packet.action & 0b010000) actions.push(updateLatency)
|
||||
if (packet.action & 0b100000) actions.push(updateDisplayName)
|
||||
class PlayerListModule {
|
||||
constructor(context) {
|
||||
const bot = context.bot;
|
||||
const config = context.config;
|
||||
const options = context.options;
|
||||
bot.players = [];
|
||||
|
||||
for (const entry of packet.data) {
|
||||
for (const action of actions) {
|
||||
action(entry)
|
||||
bot.on("packet.player_info", async (packet) => {
|
||||
const actions = [];
|
||||
if (packet.action & 0b000001) actions.push(addPlayer);
|
||||
if (packet.action & 0b000010) actions.push(initializeChat);
|
||||
if (packet.action & 0b000100) actions.push(updateGamemode);
|
||||
if (packet.action & 0b001000) actions.push(updateListed);
|
||||
if (packet.action & 0b010000) actions.push(updateLatency);
|
||||
if (packet.action & 0b100000) actions.push(updateDisplayName);
|
||||
|
||||
for (const entry of packet.data) {
|
||||
for (const action of actions) {
|
||||
action(entry);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
bot.on("packet.player_remove", async ({ players }) => {
|
||||
// players has uuids of the players
|
||||
let player_completion = (
|
||||
await bot.tab_complete("scoreboard players add ")
|
||||
).filter((_) => _.tooltip == undefined); // exclude @a, @r, @s, @e, @p -aaa
|
||||
bot.players.forEach(async (player) => {
|
||||
if (!players.includes(player.uuid)) return;
|
||||
|
||||
const a = player_completion.filter(
|
||||
(_) => _.match == player.profile.name,
|
||||
);
|
||||
if (a.length >= 1) {
|
||||
player.vanished = true;
|
||||
} else {
|
||||
bot.players = bot.players.filter((_) => _.uuid != player.uuid);
|
||||
bot.emit("player_left", players);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function addPlayer(entry) {
|
||||
bot.players = bot.players.filter((_entry) => _entry.uuid !== entry.uuid);
|
||||
bot.players.push({
|
||||
uuid: entry.uuid,
|
||||
mcUUID: "",
|
||||
profile: {
|
||||
name: entry.player.name,
|
||||
properties: entry.player.properties,
|
||||
},
|
||||
chatSession: undefined,
|
||||
gamemode: undefined,
|
||||
listed: undefined,
|
||||
latency: undefined,
|
||||
displayName: undefined,
|
||||
vanished: false,
|
||||
});
|
||||
// console.log(entry)
|
||||
}
|
||||
|
||||
function initializeChat(entry) {}
|
||||
|
||||
function updateGamemode(entry) {
|
||||
const target = bot.players.find((_entry) => _entry.uuid === entry.uuid);
|
||||
if (!target) return;
|
||||
|
||||
target.gamemode = entry.gamemode;
|
||||
}
|
||||
|
||||
function updateListed(entry) {
|
||||
const target = bot.players.find((_entry) => _entry.uuid === entry.uuid);
|
||||
if (!target) return;
|
||||
|
||||
target.listed = entry.listed;
|
||||
}
|
||||
|
||||
function updateLatency(entry) {
|
||||
const target = bot.players.find((_entry) => _entry.uuid === entry.uuid);
|
||||
if (!target) return;
|
||||
|
||||
target.latency = entry.latency;
|
||||
}
|
||||
|
||||
function updateDisplayName(entry) {
|
||||
const target = bot.players.find((_entry) => _entry.uuid === entry.uuid);
|
||||
if (!target) return;
|
||||
|
||||
try {
|
||||
if (
|
||||
bot.options.version === "1.21" ||
|
||||
bot.options.version === "1.21.1"
|
||||
) {
|
||||
target.displayName = convertNbtComponentToJson(
|
||||
null,
|
||||
entry.displayName,
|
||||
);
|
||||
} else {
|
||||
target.displayName = JSON.parse(entry.displayName);
|
||||
}
|
||||
} catch {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
bot.emit("player_info", packet);
|
||||
})
|
||||
|
||||
bot.on('packet.player_remove', async ({players}) => { // players has uuids of the players
|
||||
let player_completion = (await bot.tab_complete('scoreboard players add ')).filter(_ => _.tooltip == undefined) // exclude @a, @r, @s, @e, @p -aaa
|
||||
bot.players.forEach(async player => {
|
||||
if (!players.includes(player.uuid)) return
|
||||
|
||||
const a = player_completion.filter(_ => _.match == player.profile.name)
|
||||
if (a.length >= 1) {
|
||||
player.vanished = true;
|
||||
} else {
|
||||
bot.players = bot.players.filter(_ => _.uuid != player.uuid);
|
||||
bot._client.removeListener('tab_complete');
|
||||
bot.emit("player_left", player);
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
function addPlayer (entry) {
|
||||
bot.players = bot.players.filter(_entry => _entry.uuid !== entry.uuid)
|
||||
bot.players.push({
|
||||
uuid: entry.uuid,
|
||||
mcUUID: "",
|
||||
profile: { name: entry.player.name, properties: entry.player.properties },
|
||||
chatSession: undefined,
|
||||
gamemode: undefined,
|
||||
listed: undefined,
|
||||
latency: undefined,
|
||||
displayName: undefined,
|
||||
vanished: false
|
||||
})
|
||||
if (entry.vanished) {
|
||||
bot.emit("player_vanished", entry);
|
||||
} else {
|
||||
bot.emit("player_joined", entry);
|
||||
}
|
||||
bot.on("end", () => (bot.players = []));
|
||||
}
|
||||
|
||||
function initializeChat (entry) {
|
||||
|
||||
}
|
||||
|
||||
function updateGamemode (entry) {
|
||||
const target = bot.players.find(_entry => _entry.uuid === entry.uuid)
|
||||
if (!target) return
|
||||
|
||||
target.gamemode = entry.gamemode
|
||||
}
|
||||
|
||||
function updateListed (entry) {
|
||||
const target = bot.players.find(_entry => _entry.uuid === entry.uuid)
|
||||
if (!target) return
|
||||
|
||||
target.listed = entry.listed
|
||||
}
|
||||
|
||||
function updateLatency (entry) {
|
||||
const target = bot.players.find(_entry => _entry.uuid === entry.uuid)
|
||||
if (!target) return
|
||||
|
||||
target.latency = entry.latency
|
||||
}
|
||||
|
||||
function updateDisplayName (entry) {
|
||||
const target = bot.players.find(_entry => _entry.uuid === entry.uuid)
|
||||
if (!target) return
|
||||
|
||||
try {
|
||||
target.displayName = JSON.parse(entry.displayName)
|
||||
} catch {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
bot.on('end', () => (bot.players = []))
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
data: {
|
||||
enabled: true,
|
||||
name: "player list",
|
||||
type: "client"
|
||||
},
|
||||
inject
|
||||
};
|
||||
module.exports = PlayerListModule;
|
||||
|
||||
+19
-23
@@ -1,28 +1,24 @@
|
||||
function inject (context) {
|
||||
const bot = context.bot;
|
||||
const config = context.config;
|
||||
bot.position = null;
|
||||
class PositionModule {
|
||||
constructor(context) {
|
||||
const bot = context.bot;
|
||||
const config = context.config;
|
||||
bot.position = null;
|
||||
|
||||
bot.on('packet.position', packet => {
|
||||
bot.position = {
|
||||
x: packet.x,
|
||||
y: packet.y,
|
||||
z: packet.z
|
||||
}
|
||||
bot.on("packet.position", (packet) => {
|
||||
bot.position = {
|
||||
x: packet.x,
|
||||
y: packet.y,
|
||||
z: packet.z,
|
||||
};
|
||||
|
||||
bot._client.write('teleport_confirm', { teleportId: packet.teleportId })
|
||||
bot._client.write("teleport_confirm", { teleportId: packet.teleportId });
|
||||
|
||||
bot.emit('move')
|
||||
})
|
||||
bot.emit("move");
|
||||
});
|
||||
|
||||
bot.on('end', () => { bot.position = null })
|
||||
bot.on("end", () => {
|
||||
bot.position = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
data: {
|
||||
enabled: true,
|
||||
name: "position",
|
||||
type: "client"
|
||||
},
|
||||
inject
|
||||
};
|
||||
module.exports = PositionModule;
|
||||
|
||||
+25
-26
@@ -1,28 +1,27 @@
|
||||
const mc = require('minecraft-protocol');
|
||||
const mc = require("minecraft-protocol");
|
||||
const usernameGen = require("../util/usernameGen");
|
||||
function inject (context) {
|
||||
const bot = context.bot;
|
||||
const config = context.config;
|
||||
const options = context.options;
|
||||
bot.on('end', () => {
|
||||
bot._client.removeAllListeners();
|
||||
setTimeout(() => {
|
||||
if (options.usernameGen) {
|
||||
client = options.client ?? mc.createClient(options, options.username = usernameGen(bot))
|
||||
} else {
|
||||
client = options.client ?? mc.createClient(options)
|
||||
}
|
||||
bot._client = client
|
||||
bot.emit('init_client', bot._client)
|
||||
}, options.reconnectDelay);
|
||||
})
|
||||
}
|
||||
class ReconnectModule {
|
||||
constructor(context) {
|
||||
const bot = context.bot;
|
||||
const config = context.config;
|
||||
const options = context.options;
|
||||
let client
|
||||
bot.reconnectDelay = options.reconnectDelay;
|
||||
|
||||
module.exports = {
|
||||
data: {
|
||||
enabled: true,
|
||||
name: "reconnect",
|
||||
type: "client"
|
||||
},
|
||||
inject
|
||||
};
|
||||
bot.on("end", () => {
|
||||
bot._client.removeAllListeners();
|
||||
setTimeout(() => {
|
||||
if (options.usernameGen) {
|
||||
client =
|
||||
options.client ??
|
||||
mc.createClient(options, (options.username = new usernameGen().username()));
|
||||
} else {
|
||||
client = options.client ?? mc.createClient(options);
|
||||
}
|
||||
bot._client = client;
|
||||
bot.emit("init_client", bot._client);
|
||||
}, bot.reconnectDelay);
|
||||
});
|
||||
}
|
||||
}
|
||||
module.exports = ReconnectModule;
|
||||
|
||||
+11
-17
@@ -1,19 +1,13 @@
|
||||
const createRegistry = require('prismarine-registry')
|
||||
const createRegistry = require("prismarine-registry");
|
||||
|
||||
function inject (context) {
|
||||
const bot = context.bot;
|
||||
bot.on('packet.login', packet => {
|
||||
bot.registry = createRegistry(bot._client.version);
|
||||
bot.registry.language = require('../data/language.json');
|
||||
bot.emit('registry_ready', bot.registry);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
data: {
|
||||
enabled: true,
|
||||
name: "registry",
|
||||
type: "client"
|
||||
},
|
||||
inject
|
||||
class RegistryModule {
|
||||
constructor(context) {
|
||||
const bot = context.bot;
|
||||
bot.on("packet.login", (packet) => {
|
||||
bot.registry = createRegistry(bot._client.version);
|
||||
bot.registry.language = require("../data/language.json");
|
||||
bot.emit("registry_ready", bot.registry);
|
||||
});
|
||||
}
|
||||
}
|
||||
module.exports = RegistryModule;
|
||||
|
||||
+241
-138
@@ -1,147 +1,250 @@
|
||||
const sleep = require('../util/sleep');
|
||||
const sleep = require("../util/sleep");
|
||||
|
||||
function inject (context) {
|
||||
const bot = context.bot;
|
||||
const config = context.config;
|
||||
const options = context.options;
|
||||
let entityId;
|
||||
let permissionLevel = 2;
|
||||
let unmuted = false;
|
||||
let gameMode;
|
||||
let commandSpy = false;
|
||||
let vanished = false;
|
||||
let prefix = false;
|
||||
let god = false;
|
||||
let teleportToggle = false;
|
||||
let username = false;
|
||||
let nickname = false;
|
||||
let login = false;
|
||||
let register = false;
|
||||
let positionCount = 0;
|
||||
bot.vanished = true
|
||||
bot.on('message', (data) => {
|
||||
try {
|
||||
const stringMessage = bot.getMessageAsPrismarine(data)?.toString();
|
||||
if (options.mode === "savageFriends") {
|
||||
if (stringMessage === "Please, login with the command: /login <password>") login = true;
|
||||
else if (stringMessage === "Successful login!") login = false;
|
||||
else if (stringMessage === "You're already logged in!") login = false;
|
||||
else if (stringMessage === "Please, register to the server with the command: /register <password> <ConfirmPassword>") register = true;
|
||||
else if (stringMessage === "This user isn't registered!") register = true;
|
||||
else if (stringMessage === "Successfully registered!") register = false;
|
||||
else if (stringMessage === "You're already logged in!") register = false;
|
||||
else if (stringMessage === "Successful login!") register = false;
|
||||
else if (stringMessage === ` > Prefix for user ${bot.options.username} set to: [Prefix: ${config.prefixes[0]}]`) prefix = true;
|
||||
else if (stringMessage?.startsWith(` > Prefix for user ${bot.options.username} set to: `) || stringMessage === ` > Prefix for user ${bot.options.username} removed.`) prefix = false;
|
||||
else if (stringMessage === `You no longer have a nickname.`) nickname = false;
|
||||
else if (stringMessage?.startsWith('Your nickname is now ')) nickname = true;
|
||||
else if (stringMessage === `Vanish for ${bot.options.username}: enabled`) vanished = true;
|
||||
else if (stringMessage === `Vanish for ${bot.options.username}: disabled`) vanished = false;
|
||||
} else if (options.mode === "kaboom") {
|
||||
if (stringMessage === "Successfully enabled CommandSpy") commandSpy = true;
|
||||
else if (stringMessage === "Successfully enabled CommandSpy.") commandSpy = true;
|
||||
else if (stringMessage === "Successfully disabled CommandSpy") commandSpy = false;
|
||||
else if (stringMessage === "Successfully disabled CommandSpy.") commandSpy = false;
|
||||
else if (stringMessage === `Vanish for ${bot._client.username}: enabled`) vanished = true;
|
||||
else if (stringMessage === `Vanish for ${bot._client.username}: disabled`) vanished = false;
|
||||
else if (stringMessage === `You now have the tag: &8[&bPrefix&8: &3${config.prefixes[0]}&8]` || stringMessage === "Something went wrong while saving the prefix. Please check console.") prefix = true;
|
||||
else if (stringMessage?.startsWith("You now have the tag: ") || stringMessage === "You no longer have a tag") prefix = false
|
||||
else if (stringMessage?.startsWith("You have been muted")) unmuted = true;
|
||||
else if (stringMessage?.startsWith("You have been unmuted")) unmuted = false;
|
||||
else if (stringMessage?.startsWith("Your voice has been silenced")) unmuted = true;
|
||||
else if (stringMessage === "God mode disabled.") god = false;
|
||||
else if (stringMessage === "God mode enabled.") god = true;
|
||||
else if (stringMessage === "Teleportation disabled.") teleportToggle = true;
|
||||
else if (stringMessage === "Teleportation enabled.") teleportToggle = false;
|
||||
else if (stringMessage === `Successfully set your username to "${bot._client.username}"`) {
|
||||
username = false
|
||||
return
|
||||
class SelfcareModule {
|
||||
constructor(context) {
|
||||
const bot = context.bot;
|
||||
const config = context.config;
|
||||
const options = context.options;
|
||||
let clientLock;
|
||||
let entityId;
|
||||
let permissionLevel = 2;
|
||||
let unmuted = false;
|
||||
let gameMode;
|
||||
let commandSpy = false;
|
||||
let vanished = false;
|
||||
let prefix = false;
|
||||
let god = false;
|
||||
let teleportToggle = false;
|
||||
let username = false;
|
||||
let nickname = false;
|
||||
let login = false;
|
||||
let register = false;
|
||||
let positionCount = 0;
|
||||
bot.vanished = true;
|
||||
bot.on("message", (data) => {
|
||||
try {
|
||||
const stringMessage = bot.getMessageAsPrismarine(data)?.toString();
|
||||
if (options.mode === "savageFriends") {
|
||||
if (
|
||||
stringMessage ===
|
||||
"Please, login with the command: /login <password>"
|
||||
)
|
||||
login = true;
|
||||
else if (stringMessage === "Successful login!") login = false;
|
||||
else if (stringMessage === "You're already logged in!") login = false;
|
||||
else if (
|
||||
stringMessage ===
|
||||
"Please, register to the server with the command: /register <password> <ConfirmPassword>"
|
||||
)
|
||||
register = true;
|
||||
else if (stringMessage === "This user isn't registered!")
|
||||
register = true;
|
||||
else if (stringMessage === "Successfully registered!")
|
||||
register = false;
|
||||
else if (stringMessage === "You're already logged in!")
|
||||
register = false;
|
||||
else if (stringMessage === "Successful login!") register = false;
|
||||
else if (
|
||||
stringMessage ===
|
||||
` > Prefix for user ${bot.options.username} set to: [Prefix: ${config.prefixes[0]}]`
|
||||
)
|
||||
prefix = true;
|
||||
else if (
|
||||
stringMessage?.startsWith(
|
||||
` > Prefix for user ${bot.options.username} set to: `,
|
||||
) ||
|
||||
stringMessage ===
|
||||
` > Prefix for user ${bot.options.username} removed.`
|
||||
)
|
||||
prefix = false;
|
||||
else if (stringMessage === `You no longer have a nickname.`)
|
||||
nickname = false;
|
||||
else if (stringMessage?.startsWith("Your nickname is now "))
|
||||
nickname = true;
|
||||
else if (
|
||||
stringMessage === `Vanish for ${bot.options.username}: enabled`
|
||||
)
|
||||
vanished = true;
|
||||
else if (
|
||||
stringMessage === `Vanish for ${bot.options.username}: disabled`
|
||||
)
|
||||
vanished = false;
|
||||
} else if (options.mode === "kaboom") {
|
||||
if (stringMessage === "Successfully enabled CommandSpy")
|
||||
commandSpy = true;
|
||||
else if (stringMessage === "Successfully enabled CommandSpy.")
|
||||
commandSpy = true;
|
||||
else if (stringMessage === "Successfully disabled CommandSpy")
|
||||
commandSpy = false;
|
||||
else if (stringMessage === "Successfully disabled CommandSpy.")
|
||||
commandSpy = false;
|
||||
else if (
|
||||
stringMessage === `Vanish for ${bot._client.username}: enabled`
|
||||
)
|
||||
vanished = true;
|
||||
else if (
|
||||
stringMessage === `Vanish for ${bot._client.username}: disabled`
|
||||
)
|
||||
vanished = false;
|
||||
else if (
|
||||
stringMessage ===
|
||||
`You now have the tag: &8[&bPrefix&8: &3${config.prefixes[0]}&8]` ||
|
||||
stringMessage ===
|
||||
"Something went wrong while saving the prefix. Please check console."
|
||||
)
|
||||
prefix = true;
|
||||
else if (
|
||||
stringMessage?.startsWith("You now have the tag: ") ||
|
||||
stringMessage === "You no longer have a tag"
|
||||
)
|
||||
prefix = false;
|
||||
else if (stringMessage?.startsWith("You have been muted"))
|
||||
unmuted = true;
|
||||
else if (stringMessage?.startsWith("You have been unmuted"))
|
||||
unmuted = false;
|
||||
else if (stringMessage?.startsWith("Your voice has been silenced"))
|
||||
unmuted = true;
|
||||
else if (stringMessage === "God mode disabled.") god = false;
|
||||
else if (stringMessage === "God mode enabled.") god = true;
|
||||
else if (stringMessage === "Teleportation disabled.")
|
||||
teleportToggle = true;
|
||||
else if (stringMessage === "Teleportation enabled.")
|
||||
teleportToggle = false;
|
||||
else if (
|
||||
stringMessage ===
|
||||
`Successfully set your username to "${bot._client.username}"`
|
||||
) {
|
||||
username = false;
|
||||
return;
|
||||
} else if (
|
||||
stringMessage?.startsWith("Successfully set your username to ")
|
||||
)
|
||||
username = true;
|
||||
else if (
|
||||
stringMessage ===
|
||||
`You already have the username "${bot._client.username}"`
|
||||
)
|
||||
username = false;
|
||||
else if (stringMessage === `You no longer have a nickname.`)
|
||||
nickname = false;
|
||||
else if (stringMessage?.startsWith("Your nickname is now "))
|
||||
nickname = true;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e.stack);
|
||||
}
|
||||
else if (stringMessage?.startsWith("Successfully set your username to ")) username = true
|
||||
else if (stringMessage === `You already have the username "${bot._client.username}"`) username = false
|
||||
else if (stringMessage === `You no longer have a nickname.`) nickname = false;
|
||||
else if (stringMessage?.startsWith('Your nickname is now ')) nickname = true;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e.stack);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
bot.on('packet.entity_status', packet => {
|
||||
if (packet.entityId !== entityId || packet.entityStatus < 24 || packet.entityStatus > 28) return
|
||||
permissionLevel = packet.entityStatus - 24
|
||||
})
|
||||
bot.on("packet.entity_status", (packet) => {
|
||||
if (
|
||||
packet.entityId !== entityId ||
|
||||
packet.entityStatus < 24 ||
|
||||
packet.entityStatus > 28
|
||||
)
|
||||
return;
|
||||
permissionLevel = packet.entityStatus - 24;
|
||||
});
|
||||
|
||||
bot.on('packet.game_state_change', packet => {
|
||||
if (packet.reason !== 3) return // Reason 3 = Change Game Mode
|
||||
gameMode = packet.gameMode;
|
||||
});
|
||||
bot.on("packet.game_state_change", (packet) => {
|
||||
if (packet.reason !== 3) return; // Reason 3 = Change Game Mode
|
||||
gameMode = packet.gameMode;
|
||||
});
|
||||
|
||||
bot.on("packet.game_state.change", packet => {
|
||||
if (packet.reason !== 4) return // checks if the bot is seeing the endcredits or died
|
||||
clientLock = packet.gameMode;
|
||||
})
|
||||
bot.on("packet.position", (packet, position) => {
|
||||
if (options.mode === "savageFriends" || options.mode === "creayun")
|
||||
return;
|
||||
positionCount++;
|
||||
setTimeout(() => {
|
||||
positionCount--;
|
||||
if (positionCount > 4) {
|
||||
bot._client.end("anti icu");
|
||||
}
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
bot.on("packet.position", (packet, position) => {
|
||||
if (options.mode === "savageFriends" || options.mode === "creayun") return;
|
||||
positionCount++
|
||||
setTimeout(() => {
|
||||
positionCount--
|
||||
if (positionCount > 4) {
|
||||
bot._client.end('anti icu')
|
||||
let timer;
|
||||
bot.on("packet.login", async (packet) => {
|
||||
entityId = packet.entityId;
|
||||
if (bot.options.version === "1.21" || bot.options.version === "1.21.1") {
|
||||
clientLock = packet.worldState.gameMode;
|
||||
switch (packet.worldState.gamemode) {
|
||||
case "survival":
|
||||
gameMode = 0;
|
||||
break;
|
||||
case "creative":
|
||||
gameMode = 1;
|
||||
break;
|
||||
case "adventure":
|
||||
gameMode = 2;
|
||||
break;
|
||||
case "spectator":
|
||||
gameMode = 3;
|
||||
break;
|
||||
default:
|
||||
gameMode = 0;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
gameMode = packet.gameMode;
|
||||
clientLock = packet.gameMode;
|
||||
}
|
||||
}, 1000)
|
||||
})
|
||||
|
||||
let timer;
|
||||
bot.on('packet.login', async (packet) => {
|
||||
entityId = packet.entityId;
|
||||
gameMode = packet.gameMode;
|
||||
clientLock = packet.gameMode;
|
||||
timer = setInterval(() => {
|
||||
if (bot.options.mode === "savageFriends") {
|
||||
if (login) bot.chat.command('login amogusissus');
|
||||
else if (register) bot.chat.command('register amogusissus amogusissus');
|
||||
else if (gameMode !== 1) bot.chat.command('minecraft:gamemode creative');
|
||||
else if (permissionLevel < 2) bot.chat.command(`minecraft:op ${bot.options.username}`);
|
||||
else if (!prefix) bot.chat.command(`rank ${bot.options.username} &8[&bPrefix&8: &3${config.prefixes[0]}&8]`);
|
||||
else if (nickname) bot.chat.command('nick off');
|
||||
else if (!vanished && bot.vanished) bot.chat.command('essentials:vanish on');
|
||||
else if (clientLock !== 4) bot._client.write("client_command", { actionId: 0 });
|
||||
} else if (bot.options.isCreayun && !bot.options.isKaboom && !bot.options.isSavage) {
|
||||
|
||||
} else if (bot.options.mode === "kaboom") {
|
||||
if (permissionLevel < 2) bot.chat.command('op @s[type=player]');
|
||||
else if (gameMode !== 1) bot.chat.command('minecraft:gamemode creative');
|
||||
else if (username) bot.chat.command(`username ${bot._client.username}`)
|
||||
// else if (nickname) bot.chat.command(`nick off`)
|
||||
else if (!prefix) bot.chat.command(`prefix &8[&bPrefix&8: &3${config.prefixes[0]}&8]`);
|
||||
else if (!vanished && bot.vanished) bot.core.run(`essentials:vanish ${bot._client.username} on`);
|
||||
else if (!commandSpy) bot.core.run(`commandspy ${bot.uuid} on`);
|
||||
else if (unmuted) bot.core.run(`essentials:mute ${bot.uuid}`);
|
||||
else if (!god) bot.core.run(`god ${bot.options.username} enable`);
|
||||
else if (!teleportToggle) bot.core.run(`tptoggle ${bot.options.username} disable`);
|
||||
else if (clientLock !== 4) bot._client.write("client_command", { actionId: 0 });
|
||||
}
|
||||
}, options.selfcareInterval);
|
||||
});
|
||||
bot.on('end', () => {
|
||||
if (timer) clearInterval(timer)
|
||||
prefix = false;
|
||||
commandSpy = false;
|
||||
vanished = false;
|
||||
prefix = false;
|
||||
god = false;
|
||||
unmuted = false;
|
||||
username = false;
|
||||
});
|
||||
timer = setInterval(() => {
|
||||
if (bot.options.mode === "savageFriends") {
|
||||
if (login) bot.chat.command("login amogusissus");
|
||||
else if (register)
|
||||
bot.chat.command("register amogusissus amogusissus");
|
||||
else if (gameMode !== 1)
|
||||
bot.chat.command("minecraft:gamemode creative");
|
||||
else if (permissionLevel < 2)
|
||||
bot.chat.command(`minecraft:op ${bot.options.username}`);
|
||||
// else if (!prefix)
|
||||
// bot.chat.command(
|
||||
// `rank ${bot.options.username} &8[&bPrefix&8: &3${config.prefixes[0]}&8]`,
|
||||
// );
|
||||
else if (nickname) bot.chat.command("nick off");
|
||||
else if (!vanished && bot.vanished)
|
||||
bot.chat.command("essentials:vanish on");
|
||||
else if (clientLock !== 4)
|
||||
bot._client.write("client_command", { actionId: 0 });
|
||||
} else if (
|
||||
bot.options.isCreayun &&
|
||||
!bot.options.isKaboom &&
|
||||
!bot.options.isSavage
|
||||
) {
|
||||
} else if (bot.options.mode === "kaboom") {
|
||||
if (permissionLevel < 2) bot.chat.command("op @s[type=player]");
|
||||
else if (gameMode !== 1)
|
||||
bot.chat.command("minecraft:gamemode creative");
|
||||
else if (username)
|
||||
bot.chat.command(`username ${bot._client.username}`);
|
||||
else if (nickname) bot.chat.command(`nick off`);
|
||||
else if (!prefix)
|
||||
bot.chat.command(
|
||||
`prefix &8[&bPrefix&8: &3${config.prefixes[0]}&8]`,
|
||||
);
|
||||
else if (!vanished && bot.vanished)
|
||||
bot.core.run(`essentials:vanish ${bot._client.username} on`);
|
||||
else if (!commandSpy) bot.core.run(`commandspy ${bot.uuid} on`);
|
||||
else if (unmuted) bot.core.run(`essentials:mute ${bot.uuid}`);
|
||||
else if (!god) bot.core.run(`god ${bot.options.username} enable`);
|
||||
else if (!teleportToggle)
|
||||
bot.core.run(`tptoggle ${bot.options.username} disable`);
|
||||
else if (clientLock !== 4)
|
||||
bot._client.write("client_command", { actionId: 0 });
|
||||
}
|
||||
}, options.selfcareInterval);
|
||||
});
|
||||
bot.on("end", () => {
|
||||
if (timer) clearInterval(timer);
|
||||
prefix = false;
|
||||
commandSpy = false;
|
||||
vanished = false;
|
||||
prefix = false;
|
||||
god = false;
|
||||
unmuted = false;
|
||||
username = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
data: {
|
||||
enabled: true,
|
||||
name: "selfcare",
|
||||
type: "extras"
|
||||
},
|
||||
inject
|
||||
};
|
||||
module.exports = SelfcareModule;
|
||||
|
||||
+19
-22
@@ -1,24 +1,21 @@
|
||||
function inject (context) {
|
||||
const bot = context.bot;
|
||||
// let aaa cook
|
||||
bot.tab_complete = (str) => {
|
||||
return new Promise((resolve) => {
|
||||
bot._client.write('tab_complete', {
|
||||
text: str, assumeCommand: false, sendBlockInSight: false
|
||||
})
|
||||
const tab_completeH = (packet) => {
|
||||
bot._client.removeListener('tab_complete', tab_completeH)
|
||||
resolve(packet.matches)
|
||||
}
|
||||
bot._client.once('tab_complete', tab_completeH)
|
||||
})
|
||||
class TabCompleteModule {
|
||||
constructor(context) {
|
||||
const bot = context.bot;
|
||||
// let aaa cook
|
||||
bot.tab_complete = (str) => {
|
||||
return new Promise((resolve) => {
|
||||
bot._client.write("tab_complete", {
|
||||
text: str,
|
||||
assumeCommand: false,
|
||||
sendBlockInSight: false,
|
||||
});
|
||||
const tab_completeH = (packet) => {
|
||||
bot._client.removeListener("tab_complete", tab_completeH);
|
||||
resolve(packet.matches);
|
||||
};
|
||||
bot._client.once("tab_complete", tab_completeH);
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
module.exports = {
|
||||
data: {
|
||||
enabled: true,
|
||||
name: "tab complete",
|
||||
type: "extras"
|
||||
},
|
||||
inject
|
||||
};
|
||||
module.exports = TabCompleteModule;
|
||||
|
||||
+27
-19
@@ -1,20 +1,28 @@
|
||||
const crypto = require('crypto')
|
||||
function inject (context) {
|
||||
const bot = context.bot;
|
||||
const config = context.config;
|
||||
setInterval(() => {
|
||||
bot.validation = {
|
||||
trusted: crypto.createHash('sha256').update(Math.floor(Date.now() / 2000) + config.keys.trusted).digest('hex').substring(0, 16),
|
||||
admin: crypto.createHash('sha256').update(Math.floor(Date.now() / 2000) + config.keys.admin).digest('hex').substring(0, 16),
|
||||
owner: crypto.createHash('sha256').update(Math.floor(Date.now() / 2000) + config.keys.owner).digest('hex').substring(0, 16),
|
||||
}
|
||||
}, 100)
|
||||
const crypto = require("crypto");
|
||||
|
||||
class ValidationModule {
|
||||
constructor(context) {
|
||||
const bot = context.bot;
|
||||
const config = context.config;
|
||||
setInterval(() => {
|
||||
bot.validation = {
|
||||
trusted: crypto
|
||||
.createHash("sha256")
|
||||
.update(Math.floor(Date.now() / 2000) + config.keys.trusted)
|
||||
.digest("hex")
|
||||
.substring(0, 16),
|
||||
admin: crypto
|
||||
.createHash("sha256")
|
||||
.update(Math.floor(Date.now() / 2000) + config.keys.admin)
|
||||
.digest("hex")
|
||||
.substring(0, 16),
|
||||
owner: crypto
|
||||
.createHash("sha256")
|
||||
.update(Math.floor(Date.now() / 2000) + config.keys.owner)
|
||||
.digest("hex")
|
||||
.substring(0, 16),
|
||||
};
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
module.exports = {
|
||||
data: {
|
||||
enabled: true,
|
||||
name: "validation",
|
||||
type: "extras"
|
||||
},
|
||||
inject
|
||||
};
|
||||
module.exports = ValidationModule;
|
||||
|
||||
Reference in New Issue
Block a user