move parsing of !pm send to utils, update !pm send instructions

This commit is contained in:
Aine
2022-09-05 20:10:07 +03:00
parent e4c425fb2e
commit 2427d41ae3
2 changed files with 38 additions and 10 deletions

25
utils/command.go Normal file
View File

@@ -0,0 +1,25 @@
package utils
import (
"fmt"
"strings"
)
// ErrInvalidArgs returned when a command's arguments are invalid
var ErrInvalidArgs = fmt.Errorf("invalid arguments")
// ParseSend parses "!pm send" command, returns to, subject, body, err
func ParseSend(commandSlice []string) (string, string, string, error) {
if len(commandSlice) < 3 {
return "", "", "", ErrInvalidArgs
}
message := strings.Join(commandSlice, " ")
lines := strings.Split(message, "\n")
commandSlice = strings.Split(lines[0], " ")
to := commandSlice[1]
subject := lines[1]
body := strings.Join(lines[2:], "\n")
return to, subject, body, nil
}