add attachments and reply support to minecraft bridge
This commit is contained in:
parent
13ff55efe0
commit
b9c25ec3e6
1 changed files with 35 additions and 5 deletions
|
@ -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: `<replying to ${referencedMessage.author.username}: ${trimmedContent}>`
|
||||
});
|
||||
tellrawPayload.push({
|
||||
text: " "
|
||||
});
|
||||
}
|
||||
|
||||
attachments.forEach((e) => {
|
||||
tellrawPayload.push({
|
||||
text: `<open attachment: ${e.filename || "[unknown]"}>`,
|
||||
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();
|
||||
|
|
Loading…
Reference in a new issue