Compare commits

..

5 commits

Author SHA1 Message Date
hippoz
00a90e9d5a
frontend: change token_handoff to token_redeem 2022-02-16 14:06:29 +02:00
hippoz
86b83e400e
DiscordClient: remove debug code 2022-02-16 14:03:46 +02:00
hippoz
7329570cb7
DiscordClient: add logging for lack of heartbeat ACK 2022-02-16 14:03:03 +02:00
hippoz
b9c25ec3e6
add attachments and reply support to minecraft bridge 2022-02-16 14:02:37 +02:00
hippoz
13ff55efe0
improve regex 2022-02-15 17:07:03 +02:00
3 changed files with 40 additions and 9 deletions

View file

@ -49,6 +49,7 @@ class DiscordClient extends EventEmitter {
this._heartbeatInterval = setInterval(() => { this._heartbeatInterval = setInterval(() => {
if (!this.gotServerHeartbeatACK) { if (!this.gotServerHeartbeatACK) {
logError("Closing due to no heartbeat ACK...");
this.ws.close(1000, "No heartbeat ACK."); this.ws.close(1000, "No heartbeat ACK.");
return; return;
} }

View file

@ -188,7 +188,7 @@
if (routeInfo.length >= 2) { if (routeInfo.length >= 2) {
switch (routeInfo[0]) { switch (routeInfo[0]) {
case "token_handoff": { case "token_redeem": {
view = { type: "REDEEM_TOKEN_CONFIRM_PROMPT", token: routeInfo[1] }; view = { type: "REDEEM_TOKEN_CONFIRM_PROMPT", token: routeInfo[1] };
break; break;
} }

View file

@ -22,9 +22,9 @@ const messageTypes = {
EVENT: 3 EVENT: 3
}; };
const chatMessageRegex = /^\[(?:.*?)\]: \<(?<username>.*)\> (?<message>.*)/; const chatMessageRegex = /^\[(?:.*?)\]: \<(?<username>[a-zA-Z0-9]+)\> (?<message>.*)/;
const joinNotificationRegex = /^\[(?:.*?)\]: (?<username>.*) joined the game/; const joinNotificationRegex = /^\[(?:.*?)\]: (?<username>[a-zA-Z0-9]+) joined the game/;
const leaveNotificationRegex = /^\[(?:.*?)\]: (?<username>.*) left the game/; const leaveNotificationRegex = /^\[(?:.*?)\]: (?<username>[a-zA-Z0-9]+) left the game/;
const rconConnection = new Rcon("localhost", "25575", process.env.RCON_PASSWORD); const rconConnection = new Rcon("localhost", "25575", process.env.RCON_PASSWORD);
export default class GatewayClient { export default class GatewayClient {
@ -148,14 +148,44 @@ async function sendBridgeMessageAs(guildId, channelId, content, username=undefin
}); });
} }
async function sendMinecraftMessageAs(rcon, username, content) { async function sendMinecraftMessageAs(rcon, username, content, attachments=[], referencedMessage=null) {
rcon.send(`tellraw @a ${JSON.stringify([ const tellrawPayload = [
{ text: "[" }, { text: "[" },
{ text: `${username}`, color: "gray" }, { text: `${username}`, color: "gray" },
{ text: "]" }, { text: "]" },
{ 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() { async function main() {
@ -171,7 +201,7 @@ async function main() {
const gateway = new GatewayClient(GATEWAY_ORIGIN); const gateway = new GatewayClient(GATEWAY_ORIGIN);
gateway.onEvent = (e) => { 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) { 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(); rconConnection.connect();