diff --git a/cmdEdit.go b/cmdEdit.go index 7c231dc..eaf1f4e 100644 --- a/cmdEdit.go +++ b/cmdEdit.go @@ -21,9 +21,21 @@ func init() { func cmdEdit(cmd []string) { var messageId int - if len(cmd) == 2 { - messageId, _ = strconv.Atoi(cmd[1]) - printToView("Input", fmt.Sprintf("/edit %d Type edit here", messageId)) + chat := k.NewChat(channel) + if len(cmd) == 2 || len(cmd) == 1 { + if len(cmd) == 2 { + messageId, _ = strconv.Atoi(cmd[1]) + } else { + messageId = lastMessage.ID + } + + origMessage, _ := chat.ReadMessage(messageId) + if origMessage.Result.Messages[0].Msg.Content.Type != "text" { + printToView("Feed", fmt.Sprintf("%+v", origMessage)) + return + } + editString := origMessage.Result.Messages[0].Msg.Content.Text.Body + printToView("Input", fmt.Sprintf("/edit %d %s", messageId, editString)) return } if len(cmd) < 3 { @@ -31,7 +43,6 @@ func cmdEdit(cmd []string) { return } messageId, _ = strconv.Atoi(cmd[1]) - chat := k.NewChat(channel) newMessage := strings.Join(cmd[2:], " ") _, err := chat.Edit(messageId, newMessage) if err != nil {