diff --git a/scripts/minecraft.js b/scripts/minecraft.js index b578d7d..69b5119 100644 --- a/scripts/minecraft.js +++ b/scripts/minecraft.js @@ -148,14 +148,44 @@ async function sendBridgeMessageAs(guildId, channelId, content, username=undefin }); } -async function sendMinecraftMessageAs(rcon, username, content) { - rcon.send(`tellraw @a ${JSON.stringify([ +async function sendMinecraftMessageAs(rcon, username, content, attachments=[], referencedMessage=null) { + const tellrawPayload = [ { text: "[" }, { text: `${username}`, color: "gray" }, { text: "]" }, { text: " " }, - { text: content }, - ])}`); + ]; + + if (referencedMessage) { + let trimmedContent = referencedMessage.content.substring(0, 50); + if (trimmedContent !== referencedMessage.content) { + trimmedContent += "..."; + } + tellrawPayload.push({ + text: `` + }); + tellrawPayload.push({ + text: " " + }); + } + + attachments.forEach((e) => { + tellrawPayload.push({ + text: ``, + color: "gray", + clickEvent: { + action: "open_url", + value: e.proxy_url + } + }); + tellrawPayload.push({ + text: " " + }); + }); + + tellrawPayload.push({ text: content }); + + rcon.send(`tellraw @a ${JSON.stringify(tellrawPayload)}`); } async function main() { @@ -171,7 +201,7 @@ async function main() { const gateway = new GatewayClient(GATEWAY_ORIGIN); gateway.onEvent = (e) => { if (e.eventType === "MESSAGE_CREATE" && e.message.channel_id === TARGET_CHANNEL_ID && e.message.guild_id === TARGET_GUILD_ID && !e.message.webhook_id) { - sendMinecraftMessageAs(rconConnection, e.message.author.username, e.message.content); + sendMinecraftMessageAs(rconConnection, e.message.author.username, e.message.content, e.message.attachments, e.message.referenced_message); } }; rconConnection.connect();