add !pm delete, closes #13
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
commandHelp = "help"
|
commandHelp = "help"
|
||||||
commandStop = "stop"
|
commandStop = "stop"
|
||||||
|
commandDelete = "delete"
|
||||||
commandMailboxes = "mailboxes"
|
commandMailboxes = "mailboxes"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -115,6 +116,11 @@ func (b *Bot) buildCommandList() commandList {
|
|||||||
description: "Show the list of all mailboxes",
|
description: "Show the list of all mailboxes",
|
||||||
allowed: b.allowAdmin,
|
allowed: b.allowAdmin,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: commandDelete,
|
||||||
|
description: "Delete specific mailbox",
|
||||||
|
allowed: b.allowAdmin,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,6 +140,8 @@ func (b *Bot) handleCommand(ctx context.Context, evt *event.Event, commandSlice
|
|||||||
b.sendHelp(ctx)
|
b.sendHelp(ctx)
|
||||||
case commandStop:
|
case commandStop:
|
||||||
b.runStop(ctx)
|
b.runStop(ctx)
|
||||||
|
case commandDelete:
|
||||||
|
b.runDelete(ctx, commandSlice)
|
||||||
case commandMailboxes:
|
case commandMailboxes:
|
||||||
b.sendMailboxes(ctx)
|
b.sendMailboxes(ctx)
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -2,9 +2,12 @@ package bot
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"maunium.net/go/mautrix/id"
|
"maunium.net/go/mautrix/id"
|
||||||
|
|
||||||
|
"gitlab.com/etke.cc/postmoogle/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (b *Bot) sendMailboxes(ctx context.Context) {
|
func (b *Bot) sendMailboxes(ctx context.Context) {
|
||||||
@@ -51,3 +54,28 @@ func (b *Bot) sendMailboxes(ctx context.Context) {
|
|||||||
|
|
||||||
b.SendNotice(ctx, evt.RoomID, msg.String())
|
b.SendNotice(ctx, evt.RoomID, msg.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Bot) runDelete(ctx context.Context, commandSlice []string) {
|
||||||
|
evt := eventFromContext(ctx)
|
||||||
|
if len(commandSlice) < 2 {
|
||||||
|
b.SendNotice(ctx, evt.RoomID, fmt.Sprintf("Usage: `%s delete MAILBOX`", b.prefix))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
mailbox := utils.Mailbox(commandSlice[1])
|
||||||
|
|
||||||
|
v, ok := b.rooms.Load(mailbox)
|
||||||
|
if v == nil || !ok {
|
||||||
|
b.SendError(ctx, evt.RoomID, "mailbox does not exists, kupo")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
roomID := v.(id.RoomID)
|
||||||
|
|
||||||
|
b.rooms.Delete(mailbox)
|
||||||
|
err := b.setSettings(roomID, settings{})
|
||||||
|
if err != nil {
|
||||||
|
b.Error(ctx, evt.RoomID, "cannot update settings: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
b.SendNotice(ctx, evt.RoomID, "mailbox has been deleted")
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user