Skip to content

Commit 3f7cda5

Browse files
committed
fix: 修正Text结构体中的CmdKey方法为CmdValue,并更新相关注释
1 parent f79f801 commit 3f7cda5

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

examples/command/command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func main() {
3535
} else {
3636
slog.Info("Command index", "arg", arg)
3737
}
38-
value, err := text.CmdKey("key")
38+
value, err := text.CmdValue("key")
3939
if err != nil {
4040
slog.Error("Error parsing command key", "error", err)
4141
} else {

schema/message.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type Text struct {
2626
Text string `json:"text"`
2727
}
2828

29+
// return cmd name by prefix
2930
func (t Text) Cmd(prefix string) (string, error) {
3031
trimmed := strings.TrimSpace(t.Text)
3132
if !strings.HasPrefix(trimmed, prefix) {
@@ -38,6 +39,7 @@ func (t Text) Cmd(prefix string) (string, error) {
3839
return parts[0], nil
3940
}
4041

42+
// return cmd index value by prefix
4143
func (t Text) CmdIndex(prefix string, index int) (string, error) {
4244
if _, err := t.Cmd(prefix); err != nil {
4345
return "", err
@@ -50,10 +52,11 @@ func (t Text) CmdIndex(prefix string, index int) (string, error) {
5052
return parts[index+1], nil
5153
}
5254

53-
func (t Text) CmdKey(key string) (string, error) {
55+
// return cmd value by key
56+
func (t Text) CmdValue(key string) (value string, err error) {
5457
trimmed := strings.TrimSpace(t.Text)
5558
parts := strings.Fields(trimmed)
56-
if len(parts) < 3 {
59+
if len(parts) <= 2 {
5760
return "", errors.New("not enough parts")
5861
}
5962
for i := 1; i+1 < len(parts); i = i + 2 {

0 commit comments

Comments
 (0)