From 0610b1478d51ece976af17dd6900d245e2615174 Mon Sep 17 00:00:00 2001 From: lub Date: Fri, 8 Feb 2019 19:56:21 +0100 Subject: [PATCH] add matrix_room_untag.ps1 --- matrix_room_untag.ps1 | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 matrix_room_untag.ps1 diff --git a/matrix_room_untag.ps1 b/matrix_room_untag.ps1 new file mode 100755 index 0000000..e0203d0 --- /dev/null +++ b/matrix_room_untag.ps1 @@ -0,0 +1,31 @@ +[CmdletBinding()] +Param ( + [Array]$Exceptions = @('m.lowpriority','m.favourite'), + [String]$HomeServer = 'https://imninja.net', + [String]$MxId = '@lub:imninja.net', + [String]$AccessToken +) + +function Invoke-MatrixMethod { + Param ( + $Method = 'Get', + $Endpoint + ) + + # add authorization header + $Headers = $Headers+@{'authorization' = 'Bearer '+$AccessToken} + + $uri = $HomeServer+$Endpoint + + Invoke-RestMethod -Method $Method -Headers $Headers -Uri $uri +} + +foreach($room in (Invoke-MatrixMethod -Endpoint '/_matrix/client/r0/joined_rooms').joined_rooms) { + foreach($tag in (Invoke-MatrixMethod -Endpoint ('/_matrix/client/r0/user/'+$MxId+'/rooms/'+$room+'/tags')).tags) { + $tag = ($tag | Get-Member)[4].Name + if($tag -and $tag -notin $Exceptions) { + 'delete '+$tag + Invoke-MatrixMethod -Method Delete -Endpoint ('/_matrix/client/r0/user/'+$MxId+'/rooms/'+$room+'/tags/'+$tag) + } + } +} \ No newline at end of file