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",
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())
}

View File

@@ -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) {