Squash merge blazinglyfastcolors into main
This commit is contained in:
parent
1dfe7ca17b
commit
beb1dbc42d
2 changed files with 48 additions and 28 deletions
|
|
@ -17,6 +17,7 @@ import (
|
|||
"github.com/ayn2op/tview"
|
||||
"github.com/diamondburned/arikawa/v3/discord"
|
||||
"github.com/diamondburned/arikawa/v3/gateway"
|
||||
"github.com/diamondburned/arikawa/v3/state"
|
||||
"github.com/diamondburned/ningen/v3/discordmd"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/skratchdot/open-golang/open"
|
||||
|
|
@ -72,7 +73,7 @@ func (mt *messagesText) drawMsgs(cID discord.ChannelID) {
|
|||
|
||||
if app.cfg.Theme.MessagesText.ShowNicknames || app.cfg.Theme.MessagesText.ShowUsernameColors {
|
||||
if ch, _ := discordState.Cabinet.Channel(cID); ch.GuildID.IsValid() {
|
||||
go mt.requestGuildMembers(ch.GuildID, msgs)
|
||||
mt.requestGuildMembers(ch.GuildID, msgs)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -146,8 +147,33 @@ func (mt *messagesText) drawTimestamps(ts discord.Timestamp) {
|
|||
}
|
||||
|
||||
func (mt *messagesText) drawAuthor(msg discord.Message) {
|
||||
name := mt.authorName(msg.Author, msg.GuildID)
|
||||
fg, bg, _ := mt.authorStyle(msg.Author, msg.GuildID).Decompose()
|
||||
name := msg.Author.DisplayOrUsername()
|
||||
style := mt.cfg.Theme.MessagesText.AuthorStyle
|
||||
|
||||
if msg.GuildID.IsValid() {
|
||||
member, err := discordState.Cabinet.Member(msg.GuildID, msg.Author.ID)
|
||||
if err != nil {
|
||||
slog.Error("failed to get member from state", "guild_id", msg.GuildID, "member_id", msg.Author.ID, "err", err)
|
||||
return
|
||||
}
|
||||
|
||||
if app.cfg.Theme.MessagesText.ShowNicknames && member.Nick != "" {
|
||||
name = member.Nick
|
||||
}
|
||||
|
||||
if app.cfg.Theme.MessagesText.ShowUsernameColors {
|
||||
color, ok := state.MemberColor(member, func(id discord.RoleID) *discord.Role {
|
||||
r, _ := discordState.Cabinet.Role(msg.GuildID, id)
|
||||
return r
|
||||
})
|
||||
if ok {
|
||||
c := tcell.GetColor(color.String())
|
||||
style = config.NewStyleWrapper(tcell.StyleDefault.Foreground(c))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fg, bg, _ := style.Decompose()
|
||||
_, _ = fmt.Fprintf(mt, "[%s:%s]%s[-] ", fg.String(), bg.String(), name)
|
||||
}
|
||||
|
||||
|
|
@ -205,18 +231,6 @@ func (mt *messagesText) createReplyMsg(msg discord.Message) {
|
|||
mt.createDefaultMsg(msg)
|
||||
}
|
||||
|
||||
func (mt *messagesText) authorName(user discord.User, gID discord.GuildID) string {
|
||||
name := user.DisplayOrUsername()
|
||||
if app.cfg.Theme.MessagesText.ShowNicknames && gID.IsValid() {
|
||||
// Use guild nickname if present
|
||||
if member, _ := discordState.Cabinet.Member(gID, user.ID); member != nil && member.Nick != "" {
|
||||
name = member.Nick
|
||||
}
|
||||
}
|
||||
|
||||
return name
|
||||
}
|
||||
|
||||
func (mt *messagesText) createForwardedMsg(msg discord.Message) {
|
||||
mt.drawTimestamps(msg.Timestamp)
|
||||
mt.drawAuthor(msg)
|
||||
|
|
@ -225,18 +239,6 @@ func (mt *messagesText) createForwardedMsg(msg discord.Message) {
|
|||
fmt.Fprintf(mt, " [::d](%s)[-:-:-] ", mt.formatTimestamp(msg.MessageSnapshots[0].Message.Timestamp))
|
||||
}
|
||||
|
||||
func (mt *messagesText) authorStyle(user discord.User, gID discord.GuildID) config.StyleWrapper {
|
||||
style := mt.cfg.Theme.MessagesText.AuthorStyle
|
||||
if app.cfg.Theme.MessagesText.ShowUsernameColors && gID.IsValid() {
|
||||
// Use color from highest role in guild
|
||||
if c, ok := discordState.MemberColor(gID, user.ID); ok {
|
||||
style = config.StyleWrapper{Style: tcell.StyleDefault.Foreground(tcell.GetColor(c.String()))}
|
||||
}
|
||||
}
|
||||
|
||||
return style
|
||||
}
|
||||
|
||||
func (mt *messagesText) selectedMsg() (*discord.Message, error) {
|
||||
if !mt.selectedMessageID.IsValid() {
|
||||
return nil, errors.New("no message is currently selected")
|
||||
|
|
@ -510,7 +512,21 @@ func (mt *messagesText) reply(mention bool) {
|
|||
return
|
||||
}
|
||||
|
||||
title += mt.authorName(msg.Author, msg.GuildID)
|
||||
name := msg.Author.DisplayOrUsername()
|
||||
|
||||
if msg.GuildID.IsValid() {
|
||||
member, err := discordState.Cabinet.Member(msg.GuildID, msg.Author.ID)
|
||||
if err != nil {
|
||||
slog.Error("failed to get member from state", "guild_id", msg.GuildID, "member_id", msg.Author.ID, "err", err)
|
||||
return
|
||||
}
|
||||
|
||||
if app.cfg.Theme.MessagesText.ShowNicknames && member.Nick != "" {
|
||||
name = member.Nick
|
||||
}
|
||||
}
|
||||
|
||||
title += name
|
||||
app.messageInput.SetTitle(title)
|
||||
app.messageInput.replyMessageID = mt.selectedMessageID
|
||||
app.SetFocus(app.messageInput)
|
||||
|
|
|
|||
|
|
@ -39,6 +39,10 @@ func (aw *AlignmentWrapper) UnmarshalTOML(v any) error {
|
|||
|
||||
type StyleWrapper struct{ tcell.Style }
|
||||
|
||||
func NewStyleWrapper(style tcell.Style) StyleWrapper {
|
||||
return StyleWrapper{Style: style}
|
||||
}
|
||||
|
||||
func (sw *StyleWrapper) UnmarshalTOML(v any) error {
|
||||
m, ok := v.(map[string]any)
|
||||
if !ok {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue