2020-10-05 03:45:34 +00:00
|
|
|
package mention
|
|
|
|
|
|
|
|
import (
|
2020-12-20 05:44:26 +00:00
|
|
|
"github.com/diamondburned/arikawa/v2/discord"
|
2020-10-05 03:45:34 +00:00
|
|
|
"github.com/diamondburned/cchat-discord/internal/segments/renderer"
|
|
|
|
"github.com/diamondburned/cchat/text"
|
2021-01-06 02:40:01 +00:00
|
|
|
"github.com/diamondburned/ningen/v2"
|
|
|
|
"github.com/diamondburned/ningen/v2/md"
|
2020-10-05 03:45:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Channel struct {
|
|
|
|
discord.Channel
|
|
|
|
}
|
|
|
|
|
2021-01-06 02:40:01 +00:00
|
|
|
func NewChannelFromID(s *ningen.State, chID discord.ChannelID) *Channel {
|
|
|
|
ch, err := s.Channel(chID)
|
|
|
|
if err != nil {
|
|
|
|
return &Channel{
|
|
|
|
Channel: discord.Channel{ID: chID, Name: "unknown channel"},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Channel{
|
|
|
|
Channel: *ch,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-05 03:45:34 +00:00
|
|
|
func NewChannel(ch discord.Channel) *Channel {
|
|
|
|
return &Channel{
|
|
|
|
Channel: ch,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ch *Channel) MentionInfo() text.Rich {
|
|
|
|
var topic = ch.Topic
|
|
|
|
if ch.NSFW {
|
|
|
|
topic = "(NSFW)\n" + topic
|
|
|
|
}
|
|
|
|
|
|
|
|
if topic == "" {
|
|
|
|
return text.Rich{}
|
|
|
|
}
|
|
|
|
|
2021-01-06 02:40:01 +00:00
|
|
|
bytes := []byte(topic)
|
|
|
|
|
|
|
|
r := renderer.New(bytes)
|
|
|
|
r.Walk(md.Parse(bytes))
|
|
|
|
|
|
|
|
return text.Rich{
|
|
|
|
Content: r.String(),
|
|
|
|
Segments: r.Segments,
|
|
|
|
}
|
2020-10-05 03:45:34 +00:00
|
|
|
}
|