fix #19
This commit is contained in:
@@ -168,7 +168,7 @@ func (b *Bot) handleCommand(ctx context.Context, evt *event.Event, commandSlice
|
|||||||
case commandStop:
|
case commandStop:
|
||||||
b.runStop(ctx)
|
b.runStop(ctx)
|
||||||
case commandSend:
|
case commandSend:
|
||||||
b.runSend(ctx, commandSlice)
|
b.runSend(ctx)
|
||||||
case commandDKIM:
|
case commandDKIM:
|
||||||
b.runDKIM(ctx)
|
b.runDKIM(ctx)
|
||||||
case commandUsers:
|
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 == "" {
|
if message == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -192,7 +192,10 @@ func (b *Bot) parseCommand(message string) []string {
|
|||||||
return nil
|
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, " ")
|
return strings.Split(message, " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,11 +266,12 @@ func (b *Bot) sendHelp(ctx context.Context) {
|
|||||||
b.SendNotice(ctx, evt.RoomID, msg.String())
|
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)
|
evt := eventFromContext(ctx)
|
||||||
if !b.allowSend(evt.Sender, evt.RoomID) {
|
if !b.allowSend(evt.Sender, evt.RoomID) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
commandSlice := b.parseCommand(evt.Content.AsMessage().Body, false)
|
||||||
to, subject, body, err := utils.ParseSend(commandSlice)
|
to, subject, body, err := utils.ParseSend(commandSlice)
|
||||||
if err == utils.ErrInvalidArgs {
|
if err == utils.ErrInvalidArgs {
|
||||||
b.SendNotice(ctx, evt.RoomID, fmt.Sprintf(
|
b.SendNotice(ctx, evt.RoomID, fmt.Sprintf(
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ func (b *Bot) handle(ctx context.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
message := strings.TrimSpace(content.Body)
|
message := strings.TrimSpace(content.Body)
|
||||||
cmd := b.parseCommand(message)
|
cmd := b.parseCommand(message, true)
|
||||||
if cmd == nil {
|
if cmd == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user