mirror of
https://github.com/Rudi9719/kbtui.git
synced 2026-03-22 08:47:24 +00:00
34
cmdFollow.go
Normal file
34
cmdFollow.go
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// +build !rm_basic_commands allcommands followcmd
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
command := Command{
|
||||||
|
Cmd: []string{"follow"},
|
||||||
|
Description: "$username - Follows the given user",
|
||||||
|
Help: "",
|
||||||
|
Exec: cmdFollow,
|
||||||
|
}
|
||||||
|
RegisterCommand(command)
|
||||||
|
}
|
||||||
|
|
||||||
|
func cmdFollow(cmd []string) {
|
||||||
|
if len(cmd) == 2 {
|
||||||
|
go follow(cmd[1])
|
||||||
|
} else {
|
||||||
|
printFollowHelp()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func follow(username string) {
|
||||||
|
k.Exec("follow", username, "-y")
|
||||||
|
printInfoF("Now follows $TEXT", config.Colors.Message.LinkKeybase.stylize(username))
|
||||||
|
followedInSteps[username] = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
func printFollowHelp() {
|
||||||
|
printInfo(fmt.Sprintf("To follow a user use %sfollow <username>", config.Basics.CmdPrefix))
|
||||||
|
}
|
||||||
135
cmdInspect.go
Normal file
135
cmdInspect.go
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
// +build !rm_basic_commands allcommands inspectcmd
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"regexp"
|
||||||
|
"samhofi.us/x/keybase"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
command := Command{
|
||||||
|
Cmd: []string{"inspect", "id"},
|
||||||
|
Description: "$identifier - shows info about $identifier ($identifier is either username, messageId or team)",
|
||||||
|
Help: "",
|
||||||
|
Exec: cmdInspect,
|
||||||
|
}
|
||||||
|
|
||||||
|
RegisterCommand(command)
|
||||||
|
}
|
||||||
|
|
||||||
|
func cmdInspect(cmd []string) {
|
||||||
|
if len(cmd) == 2 {
|
||||||
|
regexIsNumeric := regexp.MustCompile(`^\d+$`)
|
||||||
|
if regexIsNumeric.MatchString(cmd[1]) {
|
||||||
|
// Then it must be a message id
|
||||||
|
id, _ := strconv.Atoi(cmd[1])
|
||||||
|
go printMessage(id)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
go printUser(strings.ReplaceAll(cmd[1], "@", ""))
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
printInfo(fmt.Sprintf("To inspect something use %sid <username/messageId>", config.Basics.CmdPrefix))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
func printMessage(id int) {
|
||||||
|
chat := k.NewChat(channel)
|
||||||
|
messages, err := chat.ReadMessage(id)
|
||||||
|
if err == nil {
|
||||||
|
var response StyledString
|
||||||
|
if messages != nil && len((*messages).Result.Messages) > 0 {
|
||||||
|
message := (*messages).Result.Messages[0].Msg
|
||||||
|
var apiCast keybase.ChatAPI
|
||||||
|
apiCast.Msg = &message
|
||||||
|
response = formatOutput(apiCast)
|
||||||
|
} else {
|
||||||
|
response = config.Colors.Feed.Error.stylize("message not found")
|
||||||
|
}
|
||||||
|
printToView("Chat", response.string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func formatProofs(userLookup keybase.UserAPI) StyledString {
|
||||||
|
messageColor := config.Colors.Message
|
||||||
|
message := basicStyle.stylize("")
|
||||||
|
for _, proof := range userLookup.Them[0].ProofsSummary.All {
|
||||||
|
style := config.Colors.Feed.Success
|
||||||
|
if proof.State != 1 {
|
||||||
|
style = config.Colors.Feed.Error
|
||||||
|
}
|
||||||
|
proofString := style.stylize("Proof [$NAME@$SITE]: $URL\n")
|
||||||
|
proofString = proofString.replace("$NAME", messageColor.SenderDefault.stylize(proof.Nametag))
|
||||||
|
proofString = proofString.replace("$SITE", messageColor.SenderDevice.stylize(proof.ProofType))
|
||||||
|
proofString = proofString.replace("$URL", messageColor.LinkURL.stylize(proof.HumanURL))
|
||||||
|
message = message.append(proofString)
|
||||||
|
}
|
||||||
|
return message.appendString("\n")
|
||||||
|
}
|
||||||
|
func formatProfile(userLookup keybase.UserAPI) StyledString {
|
||||||
|
messageColor := config.Colors.Message
|
||||||
|
user := userLookup.Them[0]
|
||||||
|
profileText := messageColor.Body.stylize("Name: $FNAME\nLocation: $LOC\nBio: $BIO\n")
|
||||||
|
profileText = profileText.replaceString("$FNAME", user.Profile.FullName)
|
||||||
|
profileText = profileText.replaceString("$LOC", user.Profile.Location)
|
||||||
|
profileText = profileText.replaceString("$BIO", user.Profile.Bio)
|
||||||
|
|
||||||
|
return profileText
|
||||||
|
}
|
||||||
|
|
||||||
|
func formatFollowState(userLookup keybase.UserAPI) StyledString {
|
||||||
|
username := userLookup.Them[0].Basics.Username
|
||||||
|
followSteps := followedInSteps[username]
|
||||||
|
if followSteps == 1 {
|
||||||
|
return config.Colors.Feed.Success.stylize("<Followed!>\n\n")
|
||||||
|
} else if followSteps > 1 {
|
||||||
|
var steps []string
|
||||||
|
for head := username; head != ""; head = trustTreeParent[head] {
|
||||||
|
steps = append(steps, fmt.Sprintf("[%s]", head))
|
||||||
|
}
|
||||||
|
trustLine := fmt.Sprintf("Indirect follow: <%s>\n\n", strings.Join(steps, " Followed by "))
|
||||||
|
return config.Colors.Message.Body.stylize(trustLine)
|
||||||
|
}
|
||||||
|
|
||||||
|
return basicStyle.stylize("")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func formatFollowerAndFollowedList(username string, listType string) StyledString {
|
||||||
|
messageColor := config.Colors.Message
|
||||||
|
response := basicStyle.stylize("")
|
||||||
|
bytes, _ := k.Exec("list-"+listType, username)
|
||||||
|
bigString := string(bytes)
|
||||||
|
lines := strings.Split(bigString, "\n")
|
||||||
|
response = response.appendString(fmt.Sprintf("%s (%d): ", listType, len(lines)-1))
|
||||||
|
for i, user := range lines[:len(lines)-1] {
|
||||||
|
if i != 0 {
|
||||||
|
response = response.appendString(", ")
|
||||||
|
}
|
||||||
|
response = response.append(messageColor.LinkKeybase.stylize(user))
|
||||||
|
response = response.append(getUserFlags(user))
|
||||||
|
}
|
||||||
|
return response.appendString("\n\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func printUser(username string) {
|
||||||
|
messageColor := config.Colors.Message
|
||||||
|
|
||||||
|
userLookup, _ := k.UserLookup(username)
|
||||||
|
|
||||||
|
response := messageColor.Header.stylize("[Inspecting `$USER`]\n")
|
||||||
|
response = response.replace("$USER", messageColor.SenderDefault.stylize(username))
|
||||||
|
response = response.append(formatProfile(userLookup))
|
||||||
|
response = response.append(formatFollowState(userLookup))
|
||||||
|
|
||||||
|
response = response.append(formatProofs(userLookup))
|
||||||
|
response = response.append(formatFollowerAndFollowedList(username, "followers"))
|
||||||
|
response = response.append(formatFollowerAndFollowedList(username, "following"))
|
||||||
|
|
||||||
|
printToView("Chat", response.string())
|
||||||
|
}
|
||||||
33
cmdUnfollow.go
Normal file
33
cmdUnfollow.go
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// +build !rm_basic_commands allcommands followcmd
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
command := Command{
|
||||||
|
Cmd: []string{"unfollow"},
|
||||||
|
Description: "$username - Unfollows the given user",
|
||||||
|
Help: "",
|
||||||
|
Exec: cmdUnfollow,
|
||||||
|
}
|
||||||
|
RegisterCommand(command)
|
||||||
|
}
|
||||||
|
|
||||||
|
func cmdUnfollow(cmd []string) {
|
||||||
|
if len(cmd) == 2 {
|
||||||
|
go unfollow(cmd[1])
|
||||||
|
} else {
|
||||||
|
printUnfollowHelp()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func unfollow(username string) {
|
||||||
|
k.Exec("unfollow", username)
|
||||||
|
printInfoF("Now unfollows $TEXT", config.Colors.Message.LinkKeybase.stylize(username))
|
||||||
|
}
|
||||||
|
|
||||||
|
func printUnfollowHelp() {
|
||||||
|
printInfo(fmt.Sprintf("To unfollow a user use %sunfollow <username>", config.Basics.CmdPrefix))
|
||||||
|
}
|
||||||
@ -81,7 +81,7 @@ func cmdPopulateWall(cmd []string) {
|
|||||||
apiCast.Msg = &api.Result.Messages[i].Msg
|
apiCast.Msg = &api.Result.Messages[i].Msg
|
||||||
result[apiCast.Msg.SentAt] = apiCast
|
result[apiCast.Msg.SentAt] = apiCast
|
||||||
newMessage := formatOutput(apiCast)
|
newMessage := formatOutput(apiCast)
|
||||||
printMe = append(printMe, newMessage)
|
printMe = append(printMe, newMessage.string())
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,7 +96,7 @@ func cmdPopulateWall(cmd []string) {
|
|||||||
sort.Ints(keys)
|
sort.Ints(keys)
|
||||||
time.Sleep(1 * time.Millisecond)
|
time.Sleep(1 * time.Millisecond)
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
actuallyPrintMe += formatOutput(result[k]) + "\n"
|
actuallyPrintMe += formatOutput(result[k]).string() + "\n"
|
||||||
}
|
}
|
||||||
printToView("Chat", fmt.Sprintf("\n<Wall>\n\n%s\nYour wall query took %s\n</Wall>\n", actuallyPrintMe, time.Since(start)))
|
printToView("Chat", fmt.Sprintf("\n<Wall>\n\n%s\nYour wall query took %s\n</Wall>\n", actuallyPrintMe, time.Since(start)))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,9 +11,9 @@ cmd_prefix = "/"
|
|||||||
|
|
||||||
[formatting]
|
[formatting]
|
||||||
# BASH-like PS1 variable equivalent
|
# BASH-like PS1 variable equivalent
|
||||||
output_format = "┌──[$USER@$DEVICE] [$ID] [$DATE - $TIME]\n└╼ $MSG"
|
output_format = "┌──[$USER@$DEVICE$TAGS] [$ID] [$DATE - $TIME]\n└╼ $MSG"
|
||||||
output_stream_format = "┌──[$USER@$DEVICE] [$ID] [$DATE - $TIME]\n└╼ $MSG"
|
output_stream_format = "┌──[$USER@$DEVICE$TAGS] [$ID] [$DATE - $TIME]\n└╼ $MSG"
|
||||||
output_mention_format = "┌──[$USER@$DEVICE] [$ID] [$DATE - $TIME]\n└╼ $MSG"
|
output_mention_format = "┌──[$USER@$DEVICE$TAGS] [$ID] [$DATE - $TIME]\n└╼ $MSG"
|
||||||
pm_format = "PM from $USER@$DEVICE: $MSG"
|
pm_format = "PM from $USER@$DEVICE: $MSG"
|
||||||
|
|
||||||
# 02 = Day, Jan = Month, 06 = Year
|
# 02 = Day, Jan = Month, 06 = Year
|
||||||
@ -22,6 +22,8 @@ date_format = "02Jan06"
|
|||||||
# 15 = hours, 04 = minutes, 05 = seconds
|
# 15 = hours, 04 = minutes, 05 = seconds
|
||||||
time_format = "15:04"
|
time_format = "15:04"
|
||||||
|
|
||||||
|
icon_following_user = "[*]"
|
||||||
|
icon_indirect_following_user = "[?]"
|
||||||
|
|
||||||
[colors]
|
[colors]
|
||||||
[colors.channels]
|
[colors.channels]
|
||||||
@ -34,44 +36,52 @@ time_format = "15:04"
|
|||||||
foreground = "green"
|
foreground = "green"
|
||||||
italic = true
|
italic = true
|
||||||
|
|
||||||
[colors.message]
|
[colors.message]
|
||||||
[colors.message.body]
|
[colors.message.body]
|
||||||
foreground = "normal"
|
foreground = "normal"
|
||||||
[colors.message.header]
|
[colors.message.header]
|
||||||
foreground = "grey"
|
foreground = "grey"
|
||||||
bold = true
|
bold = true
|
||||||
[colors.message.mention]
|
[colors.message.mention]
|
||||||
foreground = "green"
|
foreground = "green"
|
||||||
italic = true
|
italic = true
|
||||||
bold = true
|
bold = true
|
||||||
[colors.message.id]
|
[colors.message.id]
|
||||||
foreground = "yellow"
|
foreground = "yellow"
|
||||||
[colors.message.time]
|
bold = true
|
||||||
foreground = "magenta"
|
[colors.message.time]
|
||||||
[colors.message.sender_default]
|
foreground = "magenta"
|
||||||
foreground = "cyan"
|
bold = true
|
||||||
bold = true
|
[colors.message.sender_default]
|
||||||
[colors.message.sender_device]
|
foreground = "cyan"
|
||||||
foreground = "cyan"
|
bold = true
|
||||||
[colors.message.attachment]
|
[colors.message.sender_device]
|
||||||
foreground = "red"
|
foreground = "cyan"
|
||||||
[colors.message.link_url]
|
bold = true
|
||||||
foreground = "yellow"
|
[colors.message.sender_tags]
|
||||||
[colors.message.link_keybase]
|
foreground = "yellow"
|
||||||
foreground = "yellow"
|
[colors.message.attachment]
|
||||||
[colors.message.reaction]
|
foreground = "red"
|
||||||
foreground = "magenta"
|
[colors.message.link_url]
|
||||||
bold = true
|
foreground = "yellow"
|
||||||
|
[colors.message.link_keybase]
|
||||||
|
foreground = "cyan"
|
||||||
|
[colors.message.reaction]
|
||||||
|
foreground = "magenta"
|
||||||
|
bold = true
|
||||||
[colors.message.quote]
|
[colors.message.quote]
|
||||||
foreground = "green"
|
foreground = "green"
|
||||||
[colors.message.code]
|
[colors.message.code]
|
||||||
foreground = "green"
|
foreground = "cyan"
|
||||||
background = "grey"
|
background = "grey"
|
||||||
[colors.feed]
|
|
||||||
[colors.feed.basic]
|
[colors.feed]
|
||||||
foreground = "grey"
|
[colors.feed.basic]
|
||||||
[colors.feed.error]
|
foreground = "grey"
|
||||||
foreground = "red"
|
[colors.feed.error]
|
||||||
|
foreground = "red"
|
||||||
|
[colors.feed.success]
|
||||||
|
foreground = "green"
|
||||||
[colors.feed.file]
|
[colors.feed.file]
|
||||||
foreground = "yellow"
|
foreground = "yellow"
|
||||||
`
|
`
|
||||||
|
|||||||
88
kbtui.toml
88
kbtui.toml
@ -8,9 +8,9 @@ cmd_prefix = "/"
|
|||||||
|
|
||||||
[formatting]
|
[formatting]
|
||||||
# BASH-like PS1 variable equivalent
|
# BASH-like PS1 variable equivalent
|
||||||
output_format = "┌──[$USER@$DEVICE] [$ID] [$DATE - $TIME]\n└╼ $MSG"
|
output_format = "┌──[$USER@$DEVICE$TAGS] [$ID] [$DATE - $TIME]\n└╼ $MSG"
|
||||||
output_stream_format = "┌──[$USER@$DEVICE] [$ID] [$DATE - $TIME]\n└╼ $MSG"
|
output_stream_format = "┌──[$USER@$DEVICE$TAGS] [$ID] [$DATE - $TIME]\n└╼ $MSG"
|
||||||
output_mention_format = "┌──[$USER@$DEVICE] [$ID] [$DATE - $TIME]\n└╼ $MSG"
|
output_mention_format = "┌──[$USER@$DEVICE$TAGS] [$ID] [$DATE - $TIME]\n└╼ $MSG"
|
||||||
pm_format = "PM from $USER@$DEVICE: $MSG"
|
pm_format = "PM from $USER@$DEVICE: $MSG"
|
||||||
|
|
||||||
# 02 = Day, Jan = Month, 06 = Year
|
# 02 = Day, Jan = Month, 06 = Year
|
||||||
@ -19,6 +19,8 @@ date_format = "02Jan06"
|
|||||||
# 15 = hours, 04 = minutes, 05 = seconds
|
# 15 = hours, 04 = minutes, 05 = seconds
|
||||||
time_format = "15:04"
|
time_format = "15:04"
|
||||||
|
|
||||||
|
icon_following_user = "[*]"
|
||||||
|
icon_indirect_following_user = "[?]"
|
||||||
|
|
||||||
[colors]
|
[colors]
|
||||||
[colors.channels]
|
[colors.channels]
|
||||||
@ -31,43 +33,51 @@ time_format = "15:04"
|
|||||||
foreground = "green"
|
foreground = "green"
|
||||||
italic = true
|
italic = true
|
||||||
|
|
||||||
[colors.message]
|
[colors.message]
|
||||||
[colors.message.body]
|
[colors.message.body]
|
||||||
foreground = "normal"
|
foreground = "normal"
|
||||||
[colors.message.header]
|
[colors.message.header]
|
||||||
foreground = "grey"
|
foreground = "grey"
|
||||||
bold = true
|
bold = true
|
||||||
[colors.message.mention]
|
[colors.message.mention]
|
||||||
foreground = "green"
|
foreground = "green"
|
||||||
italic = true
|
italic = true
|
||||||
bold = true
|
bold = true
|
||||||
[colors.message.id]
|
[colors.message.id]
|
||||||
foreground = "yellow"
|
foreground = "yellow"
|
||||||
[colors.message.time]
|
bold = true
|
||||||
foreground = "magenta"
|
[colors.message.time]
|
||||||
[colors.message.sender_default]
|
foreground = "magenta"
|
||||||
foreground = "cyan"
|
bold = true
|
||||||
bold = true
|
[colors.message.sender_default]
|
||||||
[colors.message.sender_device]
|
foreground = "cyan"
|
||||||
foreground = "cyan"
|
bold = true
|
||||||
[colors.message.attachment]
|
[colors.message.sender_device]
|
||||||
foreground = "red"
|
foreground = "cyan"
|
||||||
[colors.message.link_url]
|
bold = true
|
||||||
foreground = "yellow"
|
[colors.message.sender_tags]
|
||||||
[colors.message.link_keybase]
|
foreground = "yellow"
|
||||||
foreground = "yellow"
|
[colors.message.attachment]
|
||||||
[colors.message.reaction]
|
foreground = "red"
|
||||||
foreground = "magenta"
|
[colors.message.link_url]
|
||||||
bold = true
|
foreground = "yellow"
|
||||||
|
[colors.message.link_keybase]
|
||||||
|
foreground = "cyan"
|
||||||
|
[colors.message.reaction]
|
||||||
|
foreground = "magenta"
|
||||||
|
bold = true
|
||||||
[colors.message.quote]
|
[colors.message.quote]
|
||||||
foreground = "green"
|
foreground = "green"
|
||||||
[colors.message.code]
|
[colors.message.code]
|
||||||
foreground = "green"
|
foreground = "cyan"
|
||||||
background = "grey"
|
background = "grey"
|
||||||
[colors.feed]
|
|
||||||
[colors.feed.basic]
|
[colors.feed]
|
||||||
foreground = "grey"
|
[colors.feed.basic]
|
||||||
[colors.feed.error]
|
foreground = "grey"
|
||||||
foreground = "red"
|
[colors.feed.error]
|
||||||
|
foreground = "red"
|
||||||
|
[colors.feed.success]
|
||||||
|
foreground = "green"
|
||||||
[colors.feed.file]
|
[colors.feed.file]
|
||||||
foreground = "yellow"
|
foreground = "yellow"
|
||||||
|
|||||||
43
main.go
43
main.go
@ -49,6 +49,8 @@ func main() {
|
|||||||
RunCommand(os.Args...)
|
RunCommand(os.Args...)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// Create map of users following users, to populate flags
|
||||||
|
go generateFollowersList()
|
||||||
fmt.Println("initKeybindings")
|
fmt.Println("initKeybindings")
|
||||||
if err := initKeybindings(); err != nil {
|
if err := initKeybindings(); err != nil {
|
||||||
fmt.Printf("%+v", err)
|
fmt.Printf("%+v", err)
|
||||||
@ -405,7 +407,7 @@ func populateChat() {
|
|||||||
}
|
}
|
||||||
var apiCast keybase.ChatAPI
|
var apiCast keybase.ChatAPI
|
||||||
apiCast.Msg = &message.Msg
|
apiCast.Msg = &message.Msg
|
||||||
newMessage := formatOutput(apiCast)
|
newMessage := formatOutput(apiCast).string()
|
||||||
printMe = append(printMe, newMessage)
|
printMe = append(printMe, newMessage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -424,6 +426,7 @@ func populateList() {
|
|||||||
log.Printf("%+v", err)
|
log.Printf("%+v", err)
|
||||||
} else {
|
} else {
|
||||||
clearView("List")
|
clearView("List")
|
||||||
|
|
||||||
var textBase = config.Colors.Channels.Basic.stylize("")
|
var textBase = config.Colors.Channels.Basic.stylize("")
|
||||||
var recentPMs = textBase.append(config.Colors.Channels.Header.stylize("---[PMs]---\n"))
|
var recentPMs = textBase.append(config.Colors.Channels.Header.stylize("---[PMs]---\n"))
|
||||||
var recentPMsCount = 0
|
var recentPMsCount = 0
|
||||||
@ -465,7 +468,9 @@ func populateList() {
|
|||||||
func formatMessageBody(body string) StyledString {
|
func formatMessageBody(body string) StyledString {
|
||||||
message := config.Colors.Message.Body.stylize(body)
|
message := config.Colors.Message.Body.stylize(body)
|
||||||
|
|
||||||
|
message = message.colorRegex(`@[\w_]*([\.#][\w_]+)*`, config.Colors.Message.LinkKeybase)
|
||||||
message = colorReplaceMentionMe(message)
|
message = colorReplaceMentionMe(message)
|
||||||
|
|
||||||
// TODO when gocui actually fixes there shit with formatting, then un comment these lines
|
// TODO when gocui actually fixes there shit with formatting, then un comment these lines
|
||||||
// message = message.colorRegex(`_[^_]*_`, config.Colors.Message.Body.withItalic())
|
// message = message.colorRegex(`_[^_]*_`, config.Colors.Message.Body.withItalic())
|
||||||
// message = message.colorRegex(`~[^~]*~`, config.Colors.Message.Body.withStrikethrough())
|
// message = message.colorRegex(`~[^~]*~`, config.Colors.Message.Body.withStrikethrough())
|
||||||
@ -487,6 +492,7 @@ func formatMessageBody(body string) StyledString {
|
|||||||
}
|
}
|
||||||
output += line + strings.Repeat(" ", spaces) + "\n"
|
output += line + strings.Repeat(" ", spaces) + "\n"
|
||||||
}
|
}
|
||||||
|
// TODO stylize should remove formatting - in general everything should
|
||||||
return config.Colors.Message.Code.stylize(output).stringFollowedByStyle(message.style)
|
return config.Colors.Message.Code.stylize(output).stringFollowedByStyle(message.style)
|
||||||
})
|
})
|
||||||
message = message.colorRegex("`[^`]*`", config.Colors.Message.Code)
|
message = message.colorRegex("`[^`]*`", config.Colors.Message.Code)
|
||||||
@ -517,43 +523,46 @@ func cleanChannelName(c string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func formatMessage(api keybase.ChatAPI, formatString string) StyledString {
|
func formatMessage(api keybase.ChatAPI, formatString string) StyledString {
|
||||||
|
msg := api.Msg
|
||||||
ret := config.Colors.Message.Header.stylize("")
|
ret := config.Colors.Message.Header.stylize("")
|
||||||
msgType := api.Msg.Content.Type
|
msgType := msg.Content.Type
|
||||||
switch msgType {
|
switch msgType {
|
||||||
case "text", "attachment":
|
case "text", "attachment":
|
||||||
ret = config.Colors.Message.Header.stylize(formatString)
|
ret = config.Colors.Message.Header.stylize(formatString)
|
||||||
tm := time.Unix(int64(api.Msg.SentAt), 0)
|
tm := time.Unix(int64(msg.SentAt), 0)
|
||||||
var msg = formatMessageBody(api.Msg.Content.Text.Body)
|
var body = formatMessageBody(msg.Content.Text.Body)
|
||||||
if msgType == "attachment" {
|
if msgType == "attachment" {
|
||||||
msg = config.Colors.Message.Body.stylize("$TITLE\n$FILE")
|
body = config.Colors.Message.Body.stylize("$TITLE\n$FILE")
|
||||||
attachment := api.Msg.Content.Attachment
|
attachment := msg.Content.Attachment
|
||||||
msg = msg.replaceString("$TITLE", attachment.Object.Title)
|
body = body.replaceString("$TITLE", attachment.Object.Title)
|
||||||
msg = msg.replace("$FILE", config.Colors.Message.Attachment.stylize(fmt.Sprintf("[Attachment: %s]", attachment.Object.Filename)))
|
body = body.replace("$FILE", config.Colors.Message.Attachment.stylize(fmt.Sprintf("[Attachment: %s]", attachment.Object.Filename)))
|
||||||
}
|
}
|
||||||
|
|
||||||
user := colorUsername(api.Msg.Sender.Username)
|
user := colorUsername(msg.Sender.Username)
|
||||||
device := config.Colors.Message.SenderDevice.stylize(api.Msg.Sender.DeviceName)
|
device := config.Colors.Message.SenderDevice.stylize(msg.Sender.DeviceName)
|
||||||
msgID := config.Colors.Message.ID.stylize(fmt.Sprintf("%d", api.Msg.ID))
|
msgID := config.Colors.Message.ID.stylize(fmt.Sprintf("%d", msg.ID))
|
||||||
date := config.Colors.Message.Time.stylize(tm.Format(config.Formatting.DateFormat))
|
date := config.Colors.Message.Time.stylize(tm.Format(config.Formatting.DateFormat))
|
||||||
msgTime := config.Colors.Message.Time.stylize(tm.Format(config.Formatting.TimeFormat))
|
msgTime := config.Colors.Message.Time.stylize(tm.Format(config.Formatting.TimeFormat))
|
||||||
|
|
||||||
channelName := config.Colors.Message.ID.stylize(fmt.Sprintf("@%s#%s", api.Msg.Channel.Name, api.Msg.Channel.TopicName))
|
channelName := config.Colors.Message.ID.stylize(fmt.Sprintf("@%s#%s", msg.Channel.Name, msg.Channel.TopicName))
|
||||||
ret = ret.replace("$MSG", msg)
|
ret = ret.replace("$MSG", body)
|
||||||
ret = ret.replace("$USER", user)
|
ret = ret.replace("$USER", user)
|
||||||
ret = ret.replace("$DEVICE", device)
|
ret = ret.replace("$DEVICE", device)
|
||||||
ret = ret.replace("$ID", msgID)
|
ret = ret.replace("$ID", msgID)
|
||||||
ret = ret.replace("$TIME", msgTime)
|
ret = ret.replace("$TIME", msgTime)
|
||||||
ret = ret.replace("$DATE", date)
|
ret = ret.replace("$DATE", date)
|
||||||
ret = ret.replace("$TEAM", channelName)
|
ret = ret.replace("$TEAM", channelName)
|
||||||
|
ret = ret.replace("$TAGS", getUserFlags(api.Msg.Sender.Username))
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
func formatOutput(api keybase.ChatAPI) string {
|
|
||||||
|
func formatOutput(api keybase.ChatAPI) StyledString {
|
||||||
format := config.Formatting.OutputFormat
|
format := config.Formatting.OutputFormat
|
||||||
if stream {
|
if stream {
|
||||||
format = config.Formatting.OutputStreamFormat
|
format = config.Formatting.OutputStreamFormat
|
||||||
}
|
}
|
||||||
return formatMessage(api, format).string()
|
return formatMessage(api, format)
|
||||||
}
|
}
|
||||||
|
|
||||||
// End formatting
|
// End formatting
|
||||||
@ -596,7 +605,7 @@ func handleMessage(api keybase.ChatAPI) {
|
|||||||
}
|
}
|
||||||
if api.Msg.Channel.MembersType == channel.MembersType && cleanChannelName(api.Msg.Channel.Name) == channel.Name {
|
if api.Msg.Channel.MembersType == channel.MembersType && cleanChannelName(api.Msg.Channel.Name) == channel.Name {
|
||||||
if channel.MembersType == keybase.USER || channel.MembersType == keybase.TEAM && channel.TopicName == api.Msg.Channel.TopicName {
|
if channel.MembersType == keybase.USER || channel.MembersType == keybase.TEAM && channel.TopicName == api.Msg.Channel.TopicName {
|
||||||
printToView("Chat", formatOutput(api))
|
printToView("Chat", formatOutput(api).string())
|
||||||
chat := k.NewChat(channel)
|
chat := k.NewChat(channel)
|
||||||
lastMessage.ID = api.Msg.ID
|
lastMessage.ID = api.Msg.ID
|
||||||
chat.Read(api.Msg.ID)
|
chat.Read(api.Msg.ID)
|
||||||
@ -604,7 +613,7 @@ func handleMessage(api keybase.ChatAPI) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if api.Msg.Channel.MembersType == keybase.TEAM {
|
if api.Msg.Channel.MembersType == keybase.TEAM {
|
||||||
printToView("Chat", formatOutput(api))
|
printToView("Chat", formatOutput(api).string())
|
||||||
} else {
|
} else {
|
||||||
printToView("Chat", formatMessage(api, config.Formatting.PMFormat).string())
|
printToView("Chat", formatMessage(api, config.Formatting.PMFormat).string())
|
||||||
}
|
}
|
||||||
|
|||||||
23
types.go
23
types.go
@ -36,12 +36,14 @@ type Basics struct {
|
|||||||
|
|
||||||
// Formatting holds the 'formatting' section of the config file
|
// Formatting holds the 'formatting' section of the config file
|
||||||
type Formatting struct {
|
type Formatting struct {
|
||||||
OutputFormat string `toml:"output_format"`
|
OutputFormat string `toml:"output_format"`
|
||||||
OutputStreamFormat string `toml:"output_stream_format"`
|
OutputStreamFormat string `toml:"output_stream_format"`
|
||||||
OutputMentionFormat string `toml:"output_mention_format"`
|
OutputMentionFormat string `toml:"output_mention_format"`
|
||||||
PMFormat string `toml:"pm_format"`
|
PMFormat string `toml:"pm_format"`
|
||||||
DateFormat string `toml:"date_format"`
|
DateFormat string `toml:"date_format"`
|
||||||
TimeFormat string `toml:"time_format"`
|
TimeFormat string `toml:"time_format"`
|
||||||
|
IconFollowingUser string `toml:"icon_following_user"`
|
||||||
|
IconIndirectFollowUser string `toml:"icon_indirect_following_user"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Colors holds the 'colors' section of the config file
|
// Colors holds the 'colors' section of the config file
|
||||||
@ -75,9 +77,11 @@ type Message struct {
|
|||||||
Header Style `toml:"header"`
|
Header Style `toml:"header"`
|
||||||
Mention Style `toml:"mention"`
|
Mention Style `toml:"mention"`
|
||||||
ID Style `toml:"id"`
|
ID Style `toml:"id"`
|
||||||
|
Tags Style `toml:"tags"`
|
||||||
Time Style `toml:"time"`
|
Time Style `toml:"time"`
|
||||||
SenderDefault Style `toml:"sender_default"`
|
SenderDefault Style `toml:"sender_default"`
|
||||||
SenderDevice Style `toml:"sender_device"`
|
SenderDevice Style `toml:"sender_device"`
|
||||||
|
SenderTags Style `toml:"sender_tags"`
|
||||||
Attachment Style `toml:"attachment"`
|
Attachment Style `toml:"attachment"`
|
||||||
LinkURL Style `toml:"link_url"`
|
LinkURL Style `toml:"link_url"`
|
||||||
LinkKeybase Style `toml:"link_keybase"`
|
LinkKeybase Style `toml:"link_keybase"`
|
||||||
@ -88,7 +92,8 @@ type Message struct {
|
|||||||
|
|
||||||
// Feed holds the style information for various elements of the feed window
|
// Feed holds the style information for various elements of the feed window
|
||||||
type Feed struct {
|
type Feed struct {
|
||||||
Basic Style `toml:"basic"`
|
Basic Style `toml:"basic"`
|
||||||
Error Style `toml:"error"`
|
Error Style `toml:"error"`
|
||||||
File Style `toml:"file"`
|
File Style `toml:"file"`
|
||||||
|
Success Style `toml:"success"`
|
||||||
}
|
}
|
||||||
|
|||||||
58
userTags.go
Normal file
58
userTags.go
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var followedInSteps = make(map[string]int)
|
||||||
|
var trustTreeParent = make(map[string]string)
|
||||||
|
|
||||||
|
func clearFlagCache() {
|
||||||
|
followedInSteps = make(map[string]int)
|
||||||
|
trustTreeParent = make(map[string]string)
|
||||||
|
}
|
||||||
|
|
||||||
|
var maxDepth = 4
|
||||||
|
|
||||||
|
func generateFollowersList() {
|
||||||
|
// Does a BFS of followedInSteps
|
||||||
|
queue := []string{k.Username}
|
||||||
|
printInfo("Generating Tree of Trust...")
|
||||||
|
lastDepth := 1
|
||||||
|
for len(queue) > 0 {
|
||||||
|
head := queue[0]
|
||||||
|
queue = queue[1:]
|
||||||
|
depth := followedInSteps[head] + 1
|
||||||
|
if depth > maxDepth {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if depth > lastDepth {
|
||||||
|
printInfo(fmt.Sprintf("Trust generated at Level #%d", depth-1))
|
||||||
|
lastDepth = depth
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes, _ := k.Exec("list-following", head)
|
||||||
|
bigString := string(bytes)
|
||||||
|
following := strings.Split(bigString, "\n")
|
||||||
|
for _, user := range following {
|
||||||
|
if followedInSteps[user] == 0 && user != k.Username {
|
||||||
|
followedInSteps[user] = depth
|
||||||
|
trustTreeParent[user] = head
|
||||||
|
queue = append(queue, user)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printInfo(fmt.Sprintf("Trust-level estabilished for %d users", len(followedInSteps)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func getUserFlags(username string) StyledString {
|
||||||
|
tags := ""
|
||||||
|
followDepth := followedInSteps[username]
|
||||||
|
if followDepth == 1 {
|
||||||
|
tags += fmt.Sprintf(" %s", config.Formatting.IconFollowingUser)
|
||||||
|
} else if followDepth > 1 {
|
||||||
|
tags += fmt.Sprintf(" %s%d", config.Formatting.IconIndirectFollowUser, followDepth-1)
|
||||||
|
}
|
||||||
|
return config.Colors.Message.SenderTags.stylize(tags)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user