From 715ec1ef2a5d17612f66cf605acc5e1dbce3f0ad Mon Sep 17 00:00:00 2001 From: Aine Date: Wed, 7 Sep 2022 20:24:49 +0300 Subject: [PATCH] fix #19 --- bot/command.go | 12 ++++++++---- bot/message.go | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/bot/command.go b/bot/command.go index 9aa3925..8c9bfd6 100644 --- a/bot/command.go +++ b/bot/command.go @@ -168,7 +168,7 @@ func (b *Bot) handleCommand(ctx context.Context, evt *event.Event, commandSlice case commandStop: b.runStop(ctx) case commandSend: - b.runSend(ctx, commandSlice) + b.runSend(ctx) case commandDKIM: b.runDKIM(ctx) case commandUsers: @@ -182,7 +182,7 @@ func (b *Bot) handleCommand(ctx context.Context, evt *event.Event, commandSlice } } -func (b *Bot) parseCommand(message string) []string { +func (b *Bot) parseCommand(message string, toLower bool) []string { if message == "" { return nil } @@ -192,7 +192,10 @@ func (b *Bot) parseCommand(message string) []string { return nil } - message = strings.ToLower(strings.TrimSpace(strings.Replace(message, b.prefix, "", 1))) + message = strings.Replace(message, b.prefix, "", 1) + if toLower { + message = strings.ToLower(message) + } return strings.Split(message, " ") } @@ -263,11 +266,12 @@ func (b *Bot) sendHelp(ctx context.Context) { b.SendNotice(ctx, evt.RoomID, msg.String()) } -func (b *Bot) runSend(ctx context.Context, commandSlice []string) { +func (b *Bot) runSend(ctx context.Context) { evt := eventFromContext(ctx) if !b.allowSend(evt.Sender, evt.RoomID) { return } + commandSlice := b.parseCommand(evt.Content.AsMessage().Body, false) to, subject, body, err := utils.ParseSend(commandSlice) if err == utils.ErrInvalidArgs { b.SendNotice(ctx, evt.RoomID, fmt.Sprintf( diff --git a/bot/message.go b/bot/message.go index 48d8063..b618bd0 100644 --- a/bot/message.go +++ b/bot/message.go @@ -13,7 +13,7 @@ func (b *Bot) handle(ctx context.Context) { return } message := strings.TrimSpace(content.Body) - cmd := b.parseCommand(message) + cmd := b.parseCommand(message, true) if cmd == nil { return }