From 6942d4ec8a20d928d77f38e5ae8e0530fe40059f Mon Sep 17 00:00:00 2001 From: David Florness Date: Sun, 30 May 2021 15:26:32 -0400 Subject: [PATCH] deletemymsgs: allow passing -a flag to delete all messages not just the ones we sent. This is useful if we're the admin of the room and need to quickly batch delete. --- {deletemymsgs => deletemsgs}/cmd.go | 28 ++++++++++++++++++++-------- main.go | 4 ++-- 2 files changed, 22 insertions(+), 10 deletions(-) rename {deletemymsgs => deletemsgs}/cmd.go (73%) diff --git a/deletemymsgs/cmd.go b/deletemsgs/cmd.go similarity index 73% rename from deletemymsgs/cmd.go rename to deletemsgs/cmd.go index 928abc3..2779cec 100644 --- a/deletemymsgs/cmd.go +++ b/deletemsgs/cmd.go @@ -1,4 +1,4 @@ -package deletemymsgs +package deletemsgs import ( "fmt" @@ -12,21 +12,33 @@ import ( ) func init() { - x := cmdtab.New("deletemymsgs") - x.Summary = "delete the messages we've sent to a particular room of the given types" - x.Usage = " +" + x := cmdtab.New("deletemsgs") + x.Summary = "delete the messages with the given types that were sent to the given room" + x.Usage = `[-a] + + + -a delete all messages of the given types in the room, not + just those that were sent by us +` x.Method = func(args []string) error { + all := false if len(args) < 2 || args[0] == "-h" { return x.UsageError() } + if args[0] == "-a" { + all = true + args = args[1:] + } + if len(args) < 2 { + return x.UsageError() + } roomID := id.RoomID(args[0]) types := args[1:] - return deletemymsgs(roomID, types) + return deletemsgs(roomID, types, all) } } -func deletemymsgs(roomID id.RoomID, types []string) error { +func deletemsgs(roomID id.RoomID, types []string, all bool) error { authInfo, err := shared.GetAuthInfo() if err != nil { return err @@ -41,8 +53,8 @@ func deletemymsgs(roomID id.RoomID, types []string) error { // stop mautrix from ignoring unparsable events syncer.ParseEventContent = false syncer.OnEvent(func (source mautrix.EventSource, evt *event.Event) { - // skip events that we didn't send - if evt.Sender != client.UserID { + // skip events that we didn't send if -a wasn't provided + if !all && evt.Sender != client.UserID { return } // skip events that aren't in this room diff --git a/main.go b/main.go index 115f809..ecd1578 100644 --- a/main.go +++ b/main.go @@ -2,13 +2,13 @@ package main import ( _ "git.hnitbjorg.xyz/~edwargix/axon/autojoin" - _ "git.hnitbjorg.xyz/~edwargix/axon/deletemymsgs" + _ "git.hnitbjorg.xyz/~edwargix/axon/deletemsgs" _ "git.hnitbjorg.xyz/~edwargix/axon/echo" "github.com/rwxrob/cmdtab" ) func main() { - x := cmdtab.New("axon", "autojoin", "deletemymsgs", "echo") + x := cmdtab.New("axon", "autojoin", "deletemsgs", "echo") x.Summary = "a set of simple utility programs for the Matrix Client-Server API" x.Usage = "" x.Version = "v0.0.0" -- 2.38.4