Compare commits
No commits in common. "00a90e9d5ac1ea03ca207f47f32e2f2b4c093706" and "d6a302ecee9d208f4dc04ca936569a2fe80640ce" have entirely different histories.
00a90e9d5a
...
d6a302ecee
3 changed files with 9 additions and 40 deletions
|
@ -49,7 +49,6 @@ 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_redeem": {
|
case "token_handoff": {
|
||||||
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>[a-zA-Z0-9]+)\> (?<message>.*)/;
|
const chatMessageRegex = /^\[(?:.*?)\]: \<(?<username>.*)\> (?<message>.*)/;
|
||||||
const joinNotificationRegex = /^\[(?:.*?)\]: (?<username>[a-zA-Z0-9]+) joined the game/;
|
const joinNotificationRegex = /^\[(?:.*?)\]: (?<username>.*) joined the game/;
|
||||||
const leaveNotificationRegex = /^\[(?:.*?)\]: (?<username>[a-zA-Z0-9]+) left the game/;
|
const leaveNotificationRegex = /^\[(?:.*?)\]: (?<username>.*) 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,44 +148,14 @@ async function sendBridgeMessageAs(guildId, channelId, content, username=undefin
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendMinecraftMessageAs(rcon, username, content, attachments=[], referencedMessage=null) {
|
async function sendMinecraftMessageAs(rcon, username, content) {
|
||||||
const tellrawPayload = [
|
rcon.send(`tellraw @a ${JSON.stringify([
|
||||||
{ 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() {
|
||||||
|
@ -201,7 +171,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, e.message.attachments, e.message.referenced_message);
|
sendMinecraftMessageAs(rconConnection, e.message.author.username, e.message.content);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
rconConnection.connect();
|
rconConnection.connect();
|
||||||
|
|
Loading…
Reference in a new issue