-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #256 from ect0s/LogTickets
Improve round end information, and add DiscordRoundEnded plugin
- Loading branch information
Showing
7 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Matches when Map state Changes to PostMatch (ScoreBoard) | ||
* | ||
* Emits winner and loser from eventstore | ||
* | ||
* winner and loser may be null if the match ends with a draw | ||
*/ | ||
export default { | ||
regex: | ||
/^\[([0-9.:-]+)]\[([ 0-9]*)]LogGameState: Match State Changed from InProgress to WaitingPostMatch/, | ||
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, | ||
time: args[1] | ||
}; | ||
logParser.emit('ROUND_ENDED', data); | ||
delete logParser.eventStore.ROUND_WINNER; | ||
delete logParser.eventStore.ROUND_LOSER; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Matches when tickets appear in the log | ||
* | ||
* Will not match on Draw or Map Changes before the game has started | ||
*/ | ||
export default { | ||
regex: | ||
/^\[([0-9.:-]+)]\[([ 0-9]*)]LogSquadGameEvents: Display: Team ([0-9]), (.*) \( ?(.*?) ?\) has (won|lost) the match with ([0-9]+) Tickets on layer (.*) \(level (.*)\)!/, | ||
onMatch: (args, logParser) => { | ||
const data = { | ||
raw: args[0], | ||
time: args[1], | ||
chainID: args[2], | ||
team: args[3], | ||
subfaction: args[4], | ||
faction: args[5], | ||
action: args[6], | ||
tickets: args[7], | ||
layer: args[8], | ||
level: args[9] | ||
}; | ||
if (data.action === 'won') { | ||
logParser.eventStore.ROUND_WINNER = data; | ||
} else { | ||
logParser.eventStore.ROUND_LOSER = data; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import DiscordBasePlugin from './discord-base-plugin.js'; | ||
|
||
export default class DiscordRoundEnded extends DiscordBasePlugin { | ||
static get description() { | ||
return 'The <code>DiscordRoundEnded</code> 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.onRoundEnd = this.onRoundEnd.bind(this); | ||
} | ||
|
||
async mount() { | ||
this.server.on('ROUND_ENDED', this.onRoundEnd); | ||
} | ||
|
||
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() | ||
} | ||
}); | ||
return; | ||
} | ||
|
||
await this.sendDiscordMessage({ | ||
embed: { | ||
title: 'Round Ended', | ||
description: `${info.winner.layer} - ${info.winner.level}`, | ||
color: this.options.color, | ||
fields: [ | ||
{ | ||
name: `Team ${info.winner.team} Won`, | ||
value: `${info.winner.subfaction}\n ${info.winner.faction}\n won with ${info.winner.tickets} 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', | ||
value: `${info.winner.tickets - info.loser.tickets}.` | ||
} | ||
], | ||
timestamp: info.time.toISOString() | ||
} | ||
}); | ||
} | ||
} |