Move mailboxes admin command to a separate file

This commit is contained in:
Slavi Pantaleev
2022-08-29 14:20:20 +03:00
parent e59f5d5502
commit d20d4aa5bf
2 changed files with 53 additions and 45 deletions

53
bot/admin_command.go Normal file
View File

@@ -0,0 +1,53 @@
package bot
import (
"context"
"strings"
"maunium.net/go/mautrix/id"
)
func (b *Bot) sendMailboxes(ctx context.Context) {
evt := eventFromContext(ctx)
mailboxes := map[string]id.RoomID{}
b.rooms.Range(func(key any, value any) bool {
if key == nil {
return true
}
if value == nil {
return true
}
mailbox, ok := key.(string)
if !ok {
return true
}
roomID, ok := value.(id.RoomID)
if !ok {
return true
}
mailboxes[mailbox] = roomID
return true
})
if len(mailboxes) == 0 {
b.SendNotice(ctx, evt.RoomID, "No mailboxes are managed by the bot so far, kupo!")
return
}
var msg strings.Builder
msg.WriteString("The following mailboxes are managed by the bot:\n")
for mailbox, roomID := range mailboxes {
msg.WriteString("* `")
msg.WriteString(mailbox)
msg.WriteString("@")
msg.WriteString(b.domain)
msg.WriteString("` - `")
msg.WriteString(roomID.String())
msg.WriteString("`")
msg.WriteString("\n")
}
b.SendNotice(ctx, evt.RoomID, msg.String())
}

View File

@@ -224,51 +224,6 @@ func (b *Bot) sendHelp(ctx context.Context, roomID id.RoomID) {
b.SendNotice(ctx, roomID, msg.String())
}
func (b *Bot) sendMailboxes(ctx context.Context) {
evt := eventFromContext(ctx)
mailboxes := map[string]id.RoomID{}
b.rooms.Range(func(key any, value any) bool {
if key == nil {
return true
}
if value == nil {
return true
}
mailbox, ok := key.(string)
if !ok {
return true
}
roomID, ok := value.(id.RoomID)
if !ok {
return true
}
mailboxes[mailbox] = roomID
return true
})
if len(mailboxes) == 0 {
b.SendNotice(ctx, evt.RoomID, "No mailboxes are managed by the bot so far, kupo!")
return
}
var msg strings.Builder
msg.WriteString("The following mailboxes are managed by the bot:\n")
for mailbox, roomID := range mailboxes {
msg.WriteString("* `")
msg.WriteString(mailbox)
msg.WriteString("@")
msg.WriteString(b.domain)
msg.WriteString("` - `")
msg.WriteString(roomID.String())
msg.WriteString("`")
msg.WriteString("\n")
}
b.SendNotice(ctx, evt.RoomID, msg.String())
}
func (b *Bot) runStop(ctx context.Context) {
evt := eventFromContext(ctx)
cfg, err := b.getSettings(evt.RoomID)