From 3f3be7c027eb9b4d27567a9028b928c5894f76b0 Mon Sep 17 00:00:00 2001 From: ect0s <73128770+ect0s@users.noreply.github.com> Date: Wed, 28 Sep 2022 21:11:11 -0400 Subject: [PATCH 1/5] Add round-tickets and round-ended events; discord-roundended plugin Adds round-tickets regex to logparser; this will fire when the server prints new log lines related to tickets and factions. Adds round-ended regex to log parser and event; this event forwards round tickets where we have both a winner and a loser to the main server object. discord-roundended: This plugin is similar but functionally different from round winner, due to cases where the server experiences a draw. --- README.md | 23 +++++++ config.json | 7 ++ squad-server/index.js | 4 ++ squad-server/log-parser/index.js | 4 ++ squad-server/log-parser/round-ended.js | 20 ++++++ squad-server/log-parser/round-tickets.js | 28 ++++++++ squad-server/plugins/discord-roundended.js | 78 ++++++++++++++++++++++ 7 files changed, 164 insertions(+) create mode 100644 squad-server/log-parser/round-ended.js create mode 100644 squad-server/log-parser/round-tickets.js create mode 100644 squad-server/plugins/discord-roundended.js diff --git a/README.md b/README.md index a21144e9..e1b720e3 100644 --- a/README.md +++ b/README.md @@ -639,6 +639,29 @@ Grafana:
16761867
+The DiscordRoundEnded
plugin will send the round winner to a Discord channel.
Discord connector name.
+discord
The ID of the channel to log round end events to.
+
667741905228136459
+The color of the embed.
+16761867
DiscordRoundEnded
plugin will send the round winner to a Discord channel.';
+ }
+
+ static get defaultEnabled() {
+ return true;
+ }
+
+ static get optionsSpecification() {
+ return {
+ ...DiscordBasePlugin.optionsSpecification,
+ channelID: {
+ required: true,
+ description: 'The ID of the channel to log round end events to.',
+ default: '',
+ example: '667741905228136459'
+ },
+ color: {
+ required: false,
+ description: 'The color of the embed.',
+ default: 16761867
+ }
+ };
+ }
+
+ constructor(server, options, connectors) {
+ super(server, options, connectors);
+
+ this.onNewGame = this.onNewGame.bind(this);
+ }
+
+ async mount() {
+ this.server.on('ROUND_ENDED', this.onNewGame);
+ }
+
+ async unmount() {
+ this.server.removeEventListener('ROUND_ENDED', this.onRoundEnd);
+ }
+
+ async onRoundEnd(info) {
+ if (!info.winner || !info.loser) {
+ await this.sendDiscordMessage({
+ embed: {
+ title: 'Round Ended',
+ description: 'This match Ended in a Draw',
+ color: this.options.color,
+ timestamp: info.time.toISOString()
+ }
+ });
+ }
+
+ await this.sendDiscordMessage({
+ embed: {
+ title: 'Round Ended',
+ description: `${info.winner.layer} - ${info.winner.level}`,
+ color: this.options.color,
+ fields: [
+ {
+ name: 'Winner',
+ value: `${info.winner.subfaction} : ${info.winner.faction} won with ${info.winner.tickets}.`
+ },
+ {
+ name: 'Loser',
+ value: `${info.loser.subfaction} : ${info.loser.faction} lost with ${info.loser.tickets}.`
+ },
+ {
+ name: 'Ticket Difference',
+ value: `${info.winner.tickets - info.loser.tickets}.`
+ }
+ ],
+ timestamp: info.time.toISOString()
+ }
+ });
+ }
+}
From 9a0d0f613b171ca0302436f323307bea97b89b3f Mon Sep 17 00:00:00 2001
From: ect0s <73128770+ect0s@users.noreply.github.com>
Date: Wed, 28 Sep 2022 22:17:50 -0400
Subject: [PATCH 2/5] fix binding
---
squad-server/plugins/discord-roundended.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/squad-server/plugins/discord-roundended.js b/squad-server/plugins/discord-roundended.js
index 7cc08997..ffb19c4a 100644
--- a/squad-server/plugins/discord-roundended.js
+++ b/squad-server/plugins/discord-roundended.js
@@ -29,11 +29,11 @@ export default class DiscordRoundEnded extends DiscordBasePlugin {
constructor(server, options, connectors) {
super(server, options, connectors);
- this.onNewGame = this.onNewGame.bind(this);
+ this.onRoundEnd = this.onRoundEnd.bind(this);
}
async mount() {
- this.server.on('ROUND_ENDED', this.onNewGame);
+ this.server.on('ROUND_ENDED', this.onRoundEnd);
}
async unmount() {
From 49127ca404766c29a03f25eca2166fa4372c5d58 Mon Sep 17 00:00:00 2001
From: ect0s <73128770+ect0s@users.noreply.github.com>
Date: Wed, 28 Sep 2022 23:00:55 -0400
Subject: [PATCH 3/5] Add time
---
squad-server/log-parser/round-ended.js | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/squad-server/log-parser/round-ended.js b/squad-server/log-parser/round-ended.js
index f4ab96fe..4b441992 100644
--- a/squad-server/log-parser/round-ended.js
+++ b/squad-server/log-parser/round-ended.js
@@ -11,7 +11,8 @@ export default {
onMatch: (args, logParser) => {
const data = {
winner: logParser.eventStore.ROUND_WINNER ? logParser.eventStore.ROUND_WINNER : null,
- loser: logParser.eventStore.ROUND_LOSER ? logParser.eventStore.ROUND_LOSER : null
+ loser: logParser.eventStore.ROUND_LOSER ? logParser.eventStore.ROUND_LOSER : null,
+ time: args[1]
};
logParser.emit('ROUND_ENDED', data);
delete logParser.eventStore.ROUND_WINNER;
From 2ba6edc4ee0c7d691337d50fe1f8bcbee20ff145 Mon Sep 17 00:00:00 2001
From: ect0s <73128770+ect0s@users.noreply.github.com>
Date: Thu, 29 Sep 2022 04:53:25 -0400
Subject: [PATCH 4/5] Embed Format Tweak
---
squad-server/plugins/discord-roundended.js | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/squad-server/plugins/discord-roundended.js b/squad-server/plugins/discord-roundended.js
index ffb19c4a..8759bbf6 100644
--- a/squad-server/plugins/discord-roundended.js
+++ b/squad-server/plugins/discord-roundended.js
@@ -59,12 +59,12 @@ export default class DiscordRoundEnded extends DiscordBasePlugin {
color: this.options.color,
fields: [
{
- name: 'Winner',
- value: `${info.winner.subfaction} : ${info.winner.faction} won with ${info.winner.tickets}.`
+ name: `Team ${info.winner.team} Won`,
+ value: `${info.winner.subfaction}\n ${info.winner.faction}\n won with ${info.winner.tickets} tickets.`
},
{
- name: 'Loser',
- value: `${info.loser.subfaction} : ${info.loser.faction} lost with ${info.loser.tickets}.`
+ name: `Team ${info.loser.team} Lost`,
+ value: `${info.loser.subfaction}\n ${info.loser.faction}\n lost with ${info.loser.tickets} tickets.`
},
{
name: 'Ticket Difference',
From 915d42d35582858df13cbc47401e1e8145732c31 Mon Sep 17 00:00:00 2001
From: ect0s <73128770+ect0s@users.noreply.github.com>
Date: Thu, 6 Oct 2022 23:08:04 -0400
Subject: [PATCH 5/5] Update discord-roundended.js
Missing Early Return
---
squad-server/plugins/discord-roundended.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/squad-server/plugins/discord-roundended.js b/squad-server/plugins/discord-roundended.js
index 8759bbf6..f9757b16 100644
--- a/squad-server/plugins/discord-roundended.js
+++ b/squad-server/plugins/discord-roundended.js
@@ -50,6 +50,7 @@ export default class DiscordRoundEnded extends DiscordBasePlugin {
timestamp: info.time.toISOString()
}
});
+ return;
}
await this.sendDiscordMessage({