mirror of
https://github.com/diamondburned/cchat-discord.git
synced 2025-01-23 18:56:39 +00:00
Minor tweaks and bug fixes regarding typing and embeds
This commit is contained in:
parent
508f355b96
commit
5ec2584509
18
channel.go
18
channel.go
|
@ -24,16 +24,10 @@ func chGuildCheck(chType discord.ChannelType) bool {
|
|||
}
|
||||
|
||||
func filterAccessible(s *Session, chs []discord.Channel) []discord.Channel {
|
||||
u, err := s.Me()
|
||||
if err != nil {
|
||||
// Shouldn't happen.
|
||||
return chs
|
||||
}
|
||||
|
||||
filtered := chs[:0]
|
||||
|
||||
for _, ch := range chs {
|
||||
p, err := s.Permissions(ch.ID, u.ID)
|
||||
p, err := s.Permissions(ch.ID, s.userID)
|
||||
// Treat error as non-fatal and add the channel anyway.
|
||||
if err != nil || p.Has(discord.PermissionViewChannel) {
|
||||
filtered = append(filtered, ch)
|
||||
|
@ -460,18 +454,20 @@ func (ch *Channel) Typing() error {
|
|||
return ch.session.Typing(ch.id)
|
||||
}
|
||||
|
||||
// TypingTimeout returns 8 seconds.
|
||||
// TypingTimeout returns 10 seconds.
|
||||
func (ch *Channel) TypingTimeout() time.Duration {
|
||||
return 8 * time.Second
|
||||
return 10 * time.Second
|
||||
}
|
||||
|
||||
func (ch *Channel) TypingSubscribe(ti cchat.TypingIndicator) (func(), error) {
|
||||
return ch.session.AddHandler(func(t *gateway.TypingStartEvent) {
|
||||
if t.ChannelID == ch.id {
|
||||
// Ignore channel mismatch or if the typing event is ours.
|
||||
if t.ChannelID != ch.id || t.UserID == ch.session.userID {
|
||||
return
|
||||
}
|
||||
if typer, err := NewTyper(ch.session.Store, t); err == nil {
|
||||
ti.AddTyper(typer)
|
||||
}
|
||||
}
|
||||
}), nil
|
||||
}
|
||||
|
||||
|
|
|
@ -14,16 +14,22 @@ import (
|
|||
|
||||
var imageExts = []string{".jpg", ".jpeg", ".png", ".webp", ".gif"}
|
||||
|
||||
func (r *TextRenderer) writeEmbedSep(embedColor discord.Color) {
|
||||
if start, end := r.writeString("---"); embedColor > 0 {
|
||||
r.append(NewColoredSegment(start, end, embedColor.Uint32()))
|
||||
}
|
||||
}
|
||||
|
||||
func (r *TextRenderer) renderEmbeds(embeds []discord.Embed, m *discord.Message, s state.Store) {
|
||||
for _, embed := range embeds {
|
||||
r.startBlock()
|
||||
r.buf.WriteString("---")
|
||||
r.writeEmbedSep(embed.Color)
|
||||
r.ensureBreak()
|
||||
|
||||
r.renderEmbed(embed, m, s)
|
||||
|
||||
r.ensureBreak()
|
||||
r.buf.WriteString("---") // render prepends newline already
|
||||
r.writeEmbedSep(embed.Color) // render prepends newline already
|
||||
r.endBlock()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue