rename files; show commands by access level

This commit is contained in:
Aine
2022-08-29 15:19:07 +03:00
parent bc30f59e96
commit 1a87929567
4 changed files with 10 additions and 7 deletions

View File

@@ -49,7 +49,7 @@ func (b *Bot) buildCommandList() commandList {
description: "Disable bridge for the room and clear all configuration", description: "Disable bridge for the room and clear all configuration",
allowed: b.allowOwner, allowed: b.allowOwner,
}, },
{}, // delimiter {allowed: b.allowOwner}, // delimiter
// options commands // options commands
{ {
key: optionMailbox, key: optionMailbox,
@@ -63,7 +63,7 @@ func (b *Bot) buildCommandList() commandList {
sanitizer: func(s string) string { return s }, sanitizer: func(s string) string { return s },
allowed: b.allowOwner, allowed: b.allowOwner,
}, },
{}, // delimiter {allowed: b.allowOwner}, // delimiter
{ {
key: optionNoSender, key: optionNoSender,
description: fmt.Sprintf( description: fmt.Sprintf(
@@ -109,7 +109,7 @@ func (b *Bot) buildCommandList() commandList {
sanitizer: utils.SanitizeBoolString, sanitizer: utils.SanitizeBoolString,
allowed: b.allowOwner, allowed: b.allowOwner,
}, },
{}, // delimiter {allowed: b.allowAdmin}, // delimiter
{ {
key: commandMailboxes, key: commandMailboxes,
description: "Show the list of all mailboxes", description: "Show the list of all mailboxes",
@@ -136,7 +136,7 @@ func (b *Bot) handleCommand(ctx context.Context, evt *event.Event, commandSlice
switch commandSlice[0] { switch commandSlice[0] {
case commandHelp: case commandHelp:
b.sendHelp(ctx, evt.RoomID) b.sendHelp(ctx)
case commandStop: case commandStop:
b.runStop(ctx) b.runStop(ctx)
case commandMailboxes: case commandMailboxes:
@@ -179,7 +179,7 @@ func (b *Bot) sendIntroduction(ctx context.Context, roomID id.RoomID) {
b.SendNotice(ctx, roomID, msg.String()) b.SendNotice(ctx, roomID, msg.String())
} }
func (b *Bot) sendHelp(ctx context.Context, roomID id.RoomID) { func (b *Bot) sendHelp(ctx context.Context) {
evt := eventFromContext(ctx) evt := eventFromContext(ctx)
cfg, serr := b.getSettings(evt.RoomID) cfg, serr := b.getSettings(evt.RoomID)
@@ -190,6 +190,9 @@ func (b *Bot) sendHelp(ctx context.Context, roomID id.RoomID) {
var msg strings.Builder var msg strings.Builder
msg.WriteString("The following commands are supported:\n\n") msg.WriteString("The following commands are supported:\n\n")
for _, cmd := range b.commands { for _, cmd := range b.commands {
if !cmd.allowed(evt.Sender, evt.RoomID) {
continue
}
if cmd.key == "" { if cmd.key == "" {
msg.WriteString("\n---\n") msg.WriteString("\n---\n")
continue continue
@@ -221,5 +224,5 @@ func (b *Bot) sendHelp(ctx context.Context, roomID id.RoomID) {
msg.WriteString("\n") msg.WriteString("\n")
} }
b.SendNotice(ctx, roomID, msg.String()) b.SendNotice(ctx, evt.RoomID, msg.String())
} }

View File

@@ -80,7 +80,7 @@ func (b *Bot) onBotJoin(ctx context.Context) {
} }
b.sendIntroduction(ctx, evt.RoomID) b.sendIntroduction(ctx, evt.RoomID)
b.sendHelp(ctx, evt.RoomID) b.sendHelp(ctx)
} }
func (b *Bot) onLeave(ctx context.Context) { func (b *Bot) onLeave(ctx context.Context) {