Add basic mailboxes command

This can be improved in the future, to show some additional information
about each mailbox like:

- "how many users are in that room"
- "which users are in that room"
- "who is the owner of the mailbox"

This can all be done later though.
This commit is contained in:
Slavi Pantaleev
2022-08-29 10:28:19 +03:00
parent a057654962
commit 79775c0c13
3 changed files with 51 additions and 0 deletions

39
bot/admin_command.go Normal file
View File

@@ -0,0 +1,39 @@
package bot
import (
"context"
"fmt"
"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(mailbox any, roomID any) bool {
mailboxes[mailbox.(string)] = roomID.(id.RoomID)
return true
})
if len(mailboxes) == 0 {
b.Notice(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 {
email := fmt.Sprintf("%s@%s", mailbox, b.domain)
msg.WriteString("* `")
msg.WriteString(email)
msg.WriteString("` - `")
msg.WriteString(roomID.String())
msg.WriteString("`")
msg.WriteString("\n")
}
b.Notice(ctx, evt.RoomID, msg.String())
}