From 1a87929567b765c6660885d98fe4fb29da478a4b Mon Sep 17 00:00:00 2001 From: Aine Date: Mon, 29 Aug 2022 15:19:07 +0300 Subject: [PATCH] rename files; show commands by access level --- bot/command.go | 15 +++++++++------ bot/{admin_command.go => command_admin.go} | 0 bot/{owner_command.go => command_owner.go} | 0 bot/sync.go | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) rename bot/{admin_command.go => command_admin.go} (100%) rename bot/{owner_command.go => command_owner.go} (100%) diff --git a/bot/command.go b/bot/command.go index b6931bc..606436e 100644 --- a/bot/command.go +++ b/bot/command.go @@ -49,7 +49,7 @@ func (b *Bot) buildCommandList() commandList { description: "Disable bridge for the room and clear all configuration", allowed: b.allowOwner, }, - {}, // delimiter + {allowed: b.allowOwner}, // delimiter // options commands { key: optionMailbox, @@ -63,7 +63,7 @@ func (b *Bot) buildCommandList() commandList { sanitizer: func(s string) string { return s }, allowed: b.allowOwner, }, - {}, // delimiter + {allowed: b.allowOwner}, // delimiter { key: optionNoSender, description: fmt.Sprintf( @@ -109,7 +109,7 @@ func (b *Bot) buildCommandList() commandList { sanitizer: utils.SanitizeBoolString, allowed: b.allowOwner, }, - {}, // delimiter + {allowed: b.allowAdmin}, // delimiter { key: commandMailboxes, 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] { case commandHelp: - b.sendHelp(ctx, evt.RoomID) + b.sendHelp(ctx) case commandStop: b.runStop(ctx) case commandMailboxes: @@ -179,7 +179,7 @@ func (b *Bot) sendIntroduction(ctx context.Context, roomID id.RoomID) { 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) cfg, serr := b.getSettings(evt.RoomID) @@ -190,6 +190,9 @@ func (b *Bot) sendHelp(ctx context.Context, roomID id.RoomID) { var msg strings.Builder msg.WriteString("The following commands are supported:\n\n") for _, cmd := range b.commands { + if !cmd.allowed(evt.Sender, evt.RoomID) { + continue + } if cmd.key == "" { msg.WriteString("\n---\n") continue @@ -221,5 +224,5 @@ func (b *Bot) sendHelp(ctx context.Context, roomID id.RoomID) { msg.WriteString("\n") } - b.SendNotice(ctx, roomID, msg.String()) + b.SendNotice(ctx, evt.RoomID, msg.String()) } diff --git a/bot/admin_command.go b/bot/command_admin.go similarity index 100% rename from bot/admin_command.go rename to bot/command_admin.go diff --git a/bot/owner_command.go b/bot/command_owner.go similarity index 100% rename from bot/owner_command.go rename to bot/command_owner.go diff --git a/bot/sync.go b/bot/sync.go index f23eeb3..b46a7d7 100644 --- a/bot/sync.go +++ b/bot/sync.go @@ -80,7 +80,7 @@ func (b *Bot) onBotJoin(ctx context.Context) { } b.sendIntroduction(ctx, evt.RoomID) - b.sendHelp(ctx, evt.RoomID) + b.sendHelp(ctx) } func (b *Bot) onLeave(ctx context.Context) {