Browse Source

WIP

pull/1/head
Gregory 'Rudi' Rudolph 5 years ago
parent
commit
b5e7986f00
  1. 54
      main.go

54
main.go

@ -12,8 +12,10 @@ import (
var k = keybase.NewKeybase() var k = keybase.NewKeybase()
var teamOrUser = "home" var teamOrUser = "home"
var channel = "" var channel = ""
var myUsername = ""
func main() { func main() {
if k.LoggedIn == true {
kbtui, err := gocui.NewGui(gocui.OutputNormal) kbtui, err := gocui.NewGui(gocui.OutputNormal)
if err != nil { if err != nil {
log.Panicln(err) log.Panicln(err)
@ -23,16 +25,21 @@ func main() {
kbtui.SetManagerFunc(layout) kbtui.SetManagerFunc(layout)
go loginGreeter(kbtui) go loginGreeter(kbtui)
go populateList(kbtui) go populateList(kbtui)
go updateChatWindow(kbtui)
if err := initKeybindings(kbtui); err != nil { if err := initKeybindings(kbtui); err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
if err := kbtui.MainLoop(); err != nil && err != gocui.ErrQuit { if err := kbtui.MainLoop(); err != nil && err != gocui.ErrQuit {
log.Panicln(err) log.Panicln(err)
} }
} else {
fmt.Println("You are not logged in.")
}
} }
func loginGreeter(g *gocui.Gui) { func loginGreeter(g *gocui.Gui) {
messg := "Welcome " + k.Username + "!" myUsername = k.Username
messg := "Welcome " + myUsername+ "!"
printToView(g, "Chat", messg) printToView(g, "Chat", messg)
} }
func sendToUser(msg string) { func sendToUser(msg string) {
@ -55,7 +62,7 @@ func populateList(g *gocui.Gui) {
} else { } else {
clearView(g, "List") clearView(g, "List")
for _, s := range testVar.Result.Conversations { for _, s := range testVar.Result.Conversations {
printToView(g, "List", s.Channel.Name + "\n") printToView(g, "List", s.Channel.Name)
} }
} }
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
@ -83,7 +90,7 @@ func printToView(kbtui *gocui.Gui, viewName string, message string) {
if err != nil { if err != nil {
return err return err
} else { } else {
fmt.Fprintf(updatingView, message) fmt.Fprintf(updatingView, message + "\n")
} }
return nil return nil
}) })
@ -149,12 +156,42 @@ func initKeybindings(g *gocui.Gui) error {
} }
return nil return nil
} }
func updateChatWindow() { func updateChatWindow(g *gocui.Gui) {
k.Run(func(api keybase.ChatAPI) {
handleMessage(api, g)
})
} }
func handleMessage(api keybase.ChatAPI, g *gocui.Gui) {
if api.Msg.Content.Type == "text" {
if strings.Contains(api.Msg.Content.Text.Body, myUsername) || strings.Contains(api.Msg.Channel.Name, myUsername) {
if api.Msg.Sender.Username != myUsername {
message := api.Msg.Content.Text.Body
sender := api.Msg.Sender.Username
team := api.Msg.Channel.Name
channel := api.Msg.Channel.TopicName
printMe := "@" + team + "#" + channel + " " + sender + ": " + message
printToView(g, "Feed", printMe)
}
}
if strings.Contains(api.Msg.Channel.Name, teamOrUser) {
if channel != "" && api.Msg.Channel.TopicName == channel {
} else {
message := api.Msg.Content.Text.Body
sender := api.Msg.Sender.Username
printToView(g, "Chat", sender+": "+message)
}
}
}
}
func handleInput(g *gocui.Gui) error { func handleInput(g *gocui.Gui) error {
inputString, _ := getInputString(g) inputString, _ := getInputString(g)
command := inputString[:2] command := ""
if len(inputString) > 2 {
command = inputString[:2]
}
if "/q" == command { if "/q" == command {
return gocui.ErrQuit return gocui.ErrQuit
} else if "/j" == command { } else if "/j" == command {
@ -163,13 +200,12 @@ func handleInput(g *gocui.Gui) error {
if len(arr) > 2 { if len(arr) > 2 {
teamOrUser = arr[1] teamOrUser = arr[1]
channel = arr[2] channel = arr[2]
printToView(g, "Feed", "You have joined: @" + teamOrUser + "#" + channel + "\n") printToView(g, "Feed", "You have joined: @" + teamOrUser + "#" + channel)
} else { } else {
teamOrUser = arr[1] teamOrUser = arr[1]
channel = "" channel = ""
printToView(g, "Feed", "You have joined: @" + teamOrUser + "\n") printToView(g, "Feed", "You have joined: @" + teamOrUser)
} }
updateChatWindow()
} else { } else {
if channel == "" { if channel == "" {
sendToUser(inputString) sendToUser(inputString)

Loading…
Cancel
Save