mirror of
https://github.com/Rudi9719/kbtui.git
synced 2026-03-22 09:57:24 +00:00
40
cmdJoin.go
40
cmdJoin.go
@ -4,8 +4,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"samhofi.us/x/keybase"
|
"samhofi.us/x/keybase"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -21,23 +21,31 @@ func init() {
|
|||||||
|
|
||||||
func cmdJoin(cmd []string) {
|
func cmdJoin(cmd []string) {
|
||||||
stream = false
|
stream = false
|
||||||
if len(cmd) == 3 {
|
switch l := len(cmd); l {
|
||||||
channel.MembersType = keybase.TEAM
|
case 3:
|
||||||
channel.Name = cmd[1]
|
fallthrough
|
||||||
channel.TopicName = cmd[2]
|
case 2:
|
||||||
printToView("Feed", fmt.Sprintf("You are joining: @%s#%s", channel.Name, channel.TopicName))
|
// if people write it in one singular line, with a `#`
|
||||||
|
firstArgSplit := strings.Split(cmd[1], "#")
|
||||||
|
channel.Name = strings.Replace(firstArgSplit[0], "@", "", 1)
|
||||||
|
joinedName := fmt.Sprintf("@%s", channel.Name)
|
||||||
|
if l == 3 || len(firstArgSplit) == 2 {
|
||||||
|
channel.MembersType = keybase.TEAM
|
||||||
|
if l == 3 {
|
||||||
|
channel.TopicName = strings.Replace(cmd[2], "#", "", 1)
|
||||||
|
} else {
|
||||||
|
channel.TopicName = firstArgSplit[1]
|
||||||
|
}
|
||||||
|
joinedName = fmt.Sprintf("%s#%s", joinedName, channel.TopicName)
|
||||||
|
} else {
|
||||||
|
channel.TopicName = ""
|
||||||
|
channel.MembersType = keybase.USER
|
||||||
|
}
|
||||||
|
printToView("Feed", fmt.Sprintf("You are joining: %s", joinedName))
|
||||||
clearView("Chat")
|
clearView("Chat")
|
||||||
viewTitle("Input", fmt.Sprintf(" @%s#%s ", channel.Name, channel.TopicName))
|
viewTitle("Input", fmt.Sprintf(" %s ", joinedName))
|
||||||
go populateChat()
|
go populateChat()
|
||||||
} else if len(cmd) == 2 {
|
default:
|
||||||
channel.MembersType = keybase.USER
|
|
||||||
channel.Name = cmd[1]
|
|
||||||
channel.TopicName = ""
|
|
||||||
printToView("Feed", fmt.Sprintf("You are joining: @%s", channel.Name))
|
|
||||||
clearView("Chat")
|
|
||||||
viewTitle("Input", fmt.Sprintf(" @%s ", channel.Name))
|
|
||||||
go populateChat()
|
|
||||||
} else {
|
|
||||||
printToView("Feed", fmt.Sprintf("To join a team use %sjoin <team> <channel>", cmdPrefix))
|
printToView("Feed", fmt.Sprintf("To join a team use %sjoin <team> <channel>", cmdPrefix))
|
||||||
printToView("Feed", fmt.Sprintf("To join a PM use %sjoin <user>", cmdPrefix))
|
printToView("Feed", fmt.Sprintf("To join a PM use %sjoin <user>", cmdPrefix))
|
||||||
}
|
}
|
||||||
|
|||||||
16
main.go
16
main.go
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -295,7 +296,7 @@ func handleTab() error {
|
|||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
// if you successfully get an input string, grab the last word from the string
|
// if you successfully get an input string, grab the last word from the string
|
||||||
ss := strings.Split(inputString, " ")
|
ss := regexp.MustCompile(`[ #]`).Split(inputString, -1)
|
||||||
s := ss[len(ss)-1]
|
s := ss[len(ss)-1]
|
||||||
// now in case the word (s) is a mention @something, lets remove it to normalize
|
// now in case the word (s) is a mention @something, lets remove it to normalize
|
||||||
if strings.HasPrefix(s, "@") {
|
if strings.HasPrefix(s, "@") {
|
||||||
@ -535,6 +536,17 @@ func handleMessage(api keybase.ChatAPI) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// It seems that golang doesn't have filter and other high order functions :'(
|
||||||
|
func delete_empty(s []string) []string {
|
||||||
|
var r []string
|
||||||
|
for _, str := range s {
|
||||||
|
if str != "" {
|
||||||
|
r = append(r, str)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
func handleInput(viewName string) error {
|
func handleInput(viewName string) error {
|
||||||
clearView(viewName)
|
clearView(viewName)
|
||||||
inputString, _ := getInputString(viewName)
|
inputString, _ := getInputString(viewName)
|
||||||
@ -542,7 +554,7 @@ func handleInput(viewName string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(inputString, cmdPrefix) {
|
if strings.HasPrefix(inputString, cmdPrefix) {
|
||||||
cmd := strings.Split(inputString[len(cmdPrefix):], " ")
|
cmd := delete_empty(strings.Split(inputString[len(cmdPrefix):], " "))
|
||||||
if c, ok := commands[cmd[0]]; ok {
|
if c, ok := commands[cmd[0]]; ok {
|
||||||
c.Exec(cmd)
|
c.Exec(cmd)
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user