From 88e06c726f0c981d994a734f3bfc8df45ca56ef4 Mon Sep 17 00:00:00 2001 From: lub Date: Thu, 14 Nov 2019 19:18:02 +0100 Subject: [PATCH] add pong subkey to sent matrix events --- bot.ps1 | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/bot.ps1 b/bot.ps1 index 21100f6..15b391e 100644 --- a/bot.ps1 +++ b/bot.ps1 @@ -48,7 +48,7 @@ function Send-MatrixEvent { Write-Host ('Event {0} sent to room {1}' -f $response.event_id,$RoomId) } } -function Send-MatrixNotice { +function Send-Pong { param ( [Parameter(Mandatory=$true)] [string] @@ -60,12 +60,29 @@ function Send-MatrixNotice { [Parameter(Mandatory=$false)] [string] - $FormattedBody + $FormattedBody, + + [Parameter(Mandatory=$true)] + [string] + $OriginHomeServer, + + [Parameter(Mandatory=$true)] + [int] + $Duration, + + [Parameter(Mandatory=$true)] + [string] + $PingEventId ) $event = @{ msgtype = 'm.notice' body = $Body + pong = @{ + from = $OriginHomeServer + ms = $Duration + ping = $PingEventId + } } if($FormattedBody) { @@ -174,7 +191,8 @@ function Open-MatrixEvent { #$bodies contains a hashtable with keys Body and FormattedBody $bodies = Join-Pong -RoomId $RoomId -PingEventId $Event.event_id -SenderMxId $Event.sender -ReadableTimespan $readable_timespan -Ball $Matches.ball - Send-MatrixNotice -RoomId $RoomId @bodies + $origin_homeserver = $Event.sender.Split(':')[1] + Send-Pong -RoomId $RoomId @bodies -OriginHomeServer $origin_homeserver -Duration $difference.TotalMilliseconds -PingEventId $Event.event_id } } function Start-MatrixSync {