Make colored names optional and disabled by default
MODIFY
internal/config/config.go
internal/config/config.go
@@ -37,6 +37,7 @@ const (
var (
currentConfig = Config{
Times: HourMinuteAndSeconds,
+ UseRandomUserColors: false,
ShowUserContainer: true,
ShowChatHeader: true,
ShowFrame: false,
@@ -59,6 +60,9 @@ type Config struct {
//Times decides on the time format (none, short and long).
Times int
+ //UseRandomUserColors decides wether the users get assigned a random color
+ //out of a pool for the current session.
+ UseRandomUserColors bool
//FocusChannelAfterGuildSelection will cause the widget focus to move over
//to the channel tree after selecting a guild.

MODIFY
internal/discordgoplus/users.go
internal/discordgoplus/users.go
@@ -22,7 +22,6 @@ var (
"red",
"lime",
"yellow",
- "blue",
"fuchsia",
"aqua",
}
@@ -32,34 +31,20 @@ var (
lastRandomNumber int64 = -1
)
-// GetUserName returns a name for the user.
-// Names will be escaped and bots will get the "[BOT]" prefix and a blue color.
-func GetUserName(user *discordgo.User) string {
- color := GetUserColor(user.ID)
- var nameToUse string
+// GetUserColor gets the users color for this session. If no color can be found
+// a new color will be a generated and cached.
+func GetUserColor(user *discordgo.User) string {
if user.Bot {
- nameToUse = "[blue]" + botPrefix
- } else {
- if color != "" {
- nameToUse = nameToUse + "[" + color + "]"
- }
+ return "blue"
}
- nameToUse = nameToUse + tview.Escape(user.Username)
-
- return nameToUse
-}
-
-// GetUserColor gets the users color for this session. If no color can be found
-// a new color will be a generated and cached.
-func GetUserColor(userID string) string {
- color, ok := userColorCache[userID]
+ color, ok := userColorCache[user.ID]
if ok {
return color
}
newColor := getRandomColorString()
- userColorCache[userID] = newColor
+ userColorCache[user.ID] = newColor
return newColor
}
@@ -79,9 +64,9 @@ func getRandomColorString() string {
return colors[numberInt64]
}
-// GetMemberName returns a name for the member using his nickname if available.
-// Names will be escaped and bots get a special "[BOT]" prefix and a blue
-// color.
+// GetMemberName returns the name to use for representing this user. This is
+// either the username or the nickname. In case the member is a bot, the bot
+// prefix will be prepended.
func GetMemberName(member *discordgo.Member) string {
var discordName string
if member.Nick != "" {
@@ -91,10 +76,22 @@ func GetMemberName(member *discordgo.Member) string {
}
if member.User.Bot {
- return "[blue]" + botPrefix + discordName
+ return botPrefix + discordName
+ }
+
+ return discordName
+}
+
+// GetUserName returns the users username, prepending the bot prefix in case he
+// is a bot.
+func GetUserName(user *discordgo.User) string {
+ discordName := tview.Escape(user.Username)
+
+ if user.Bot {
+ return botPrefix + discordName
}
- return "[" + GetUserColor(member.User.ID) + "]" + discordName
+ return discordName
}
// SortUserRoles sorts an array of roleIDs according to the guilds roles.

MODIFY
internal/ui/chatview.go
internal/ui/chatview.go
@@ -483,7 +483,13 @@ func (chatView *ChatView) formatMessage(message *discordgo.Message) string {
messageAuthor = discordgoplus.GetUserName(message.Author)
}
- return fmt.Sprintf("[silver]%s [::b]%s[::-] [white]%s[\"\"][\"\"]", timeCellText, messageAuthor, messageText)
+ if config.GetConfig().UseRandomUserColors {
+ messageAuthor = "[" + discordgoplus.GetUserColor(message.Author) + "]" + messageAuthor
+ } else {
+ messageAuthor = "[green]" + messageAuthor
+ }
+
+ return fmt.Sprintf("[gray]%s %s [white]%s[\"\"][\"\"]", timeCellText, messageAuthor, messageText)
}
func parseBoldAndUnderline(messageText string) string {

MODIFY
internal/ui/usertree.go
internal/ui/usertree.go
@@ -142,6 +142,9 @@ func (userTree *UserTree) loadGuildRoles(guildID string) ([]*discordgo.Role, err
// already part of the tree, in that case the nodes name is updated.
func (userTree *UserTree) AddOrUpdateMember(member *discordgo.Member) {
nameToUse := discordgoplus.GetMemberName(member)
+ if config.GetConfig().UseRandomUserColors {
+ nameToUse = "[" + discordgoplus.GetUserColor(member.User) + "]" + nameToUse
+ }
userNode, contains := userTree.userNodes[member.User.ID]
if contains && userNode != nil {
@@ -169,6 +172,9 @@ func (userTree *UserTree) AddOrUpdateMember(member *discordgo.Member) {
// in that case the users node gets updated.
func (userTree *UserTree) AddOrUpdateUser(user *discordgo.User) {
nameToUse := discordgoplus.GetUserName(user)
+ if config.GetConfig().UseRandomUserColors {
+ nameToUse = "[" + discordgoplus.GetUserColor(user) + "]" + nameToUse
+ }
userNode, contains := userTree.userNodes[user.ID]
if contains && userNode != nil {

Make colored names optional and disabled by default