Compare commits
5 commits
d6a302ecee
...
00a90e9d5a
Author | SHA1 | Date | |
---|---|---|---|
|
00a90e9d5a | ||
|
86b83e400e | ||
|
7329570cb7 | ||
|
b9c25ec3e6 | ||
|
13ff55efe0 |
3 changed files with 40 additions and 9 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
|
Loading…
Reference in a new issue