From abe241c85f3ccbb48e5ef95cd247dd02b5055152 Mon Sep 17 00:00:00 2001 From: Gregory 'Rudi' Rudolph Date: Sun, 22 Sep 2019 08:14:21 -0400 Subject: [PATCH] Basic reactions added using last message --- README.md | 1 + main.go | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3aad0c4..9737a50 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ It started as a joke, then a bash script, and now here it is! ## Todo * Reactions to messages +* Message editing * Pretty format headers in List view from window size * Twitter-style feed reading public messages * Track multiple conversations at once diff --git a/main.go b/main.go index 12648a2..6897120 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,7 @@ var k = keybase.NewKeybase() var channel keybase.Channel var channels [] keybase.Channel var stream bool = false +var lastMessage keybase.ChatAPI func main() { if !k.LoggedIn { fmt.Println("You are not logged in.") @@ -45,8 +46,13 @@ func populateChat(g *gocui.Gui) { } else { var printMe []string var actuallyPrintMe string + firstmsg := true for _, message := range api.Result.Messages { if message.Msg.Content.Type == "text" { + if (firstmsg) { + firstmsg = false + lastMessage.ID = message.Msg.ID + } msgSender := message.Msg.Sender.Username msgBody := message.Msg.Content.Text.Body newMessage := fmt.Sprintf("[%s]: %s", msgSender, msgBody) @@ -238,9 +244,13 @@ func handleMessage(api keybase.ChatAPI, g *gocui.Gui) { printToView(g, "Chat", fmt.Sprintf("PM @%s [%s]: %s", cleanChannelName(channelName), msgSender, msgBody)) } } + lastMessage = api } } - +func reactToMessage(reaction string) { + chat := k.NewChat(channel) + chat.React(lastMessage.ID, reaction) +} func handleInput(g *gocui.Gui) error { inputString, _ := getInputString(g) command := strings.Split(inputString, " ") @@ -273,7 +283,11 @@ func handleInput(g *gocui.Gui) error { stream = true printToView(g, "Feed", "You have begun viewing the formatted stream.") default: - go sendChat(inputString) + if inputString[:1] == "+" { + reactToMessage(strings.Replace(inputString, "+", "", 1)) + } else { + go sendChat(inputString) + } } clearView(g, "Input") return nil