From 71e0596f96266b71b8d54208c1f21b06451a21ee Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Fri, 4 Oct 2019 13:13:02 -0400 Subject: [PATCH] Updated command from changes to framework --- cmdEdit.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) 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 {