~edwargix/axon

6942d4ec8a20d928d77f38e5ae8e0530fe40059f — David Florness 3 years ago 55192e2
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.
2 files changed, 22 insertions(+), 10 deletions(-)

R deletemymsgs/cmd.go => deletemsgs/cmd.go
M main.go
R deletemymsgs/cmd.go => deletemsgs/cmd.go +20 -8
@@ 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 = "<roomID> <type>+"
	x := cmdtab.New("deletemsgs")
	x.Summary = "delete the messages with the given types that were sent to the given room"
	x.Usage = `[-a] <roomID> <type>+

	-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

M main.go => main.go +2 -2
@@ 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 = "<cmd>"
	x.Version = "v0.0.0"