2020-05-20 07:13:12 +00:00
|
|
|
package mock
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
2020-06-03 23:13:06 +00:00
|
|
|
"strings"
|
2020-05-20 07:13:12 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/Pallinder/go-randomdata"
|
|
|
|
"github.com/diamondburned/cchat"
|
|
|
|
"github.com/diamondburned/cchat/text"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Message struct {
|
|
|
|
id uint32
|
|
|
|
time time.Time
|
|
|
|
author string
|
|
|
|
content string
|
|
|
|
nonce string
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2020-06-03 23:13:06 +00:00
|
|
|
_ cchat.MessageCreate = (*Message)(nil)
|
|
|
|
_ cchat.MessageUpdate = (*Message)(nil)
|
|
|
|
_ cchat.MessageDelete = (*Message)(nil)
|
|
|
|
_ cchat.MessageNonce = (*Message)(nil)
|
|
|
|
_ cchat.MessageMentioned = (*Message)(nil)
|
2020-05-20 07:13:12 +00:00
|
|
|
)
|
|
|
|
|
2020-06-03 23:13:06 +00:00
|
|
|
func newEmptyMessage(id uint32, author string) Message {
|
|
|
|
return Message{
|
|
|
|
id: id,
|
|
|
|
author: author,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newRandomMessage(id uint32, author string) Message {
|
|
|
|
return Message{
|
|
|
|
id: id,
|
|
|
|
time: time.Now(),
|
|
|
|
author: author,
|
|
|
|
content: randomdata.Paragraph(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-20 07:13:12 +00:00
|
|
|
func echoMessage(sendable cchat.SendableMessage, id uint32, author string) Message {
|
|
|
|
var echo = Message{
|
|
|
|
id: id,
|
|
|
|
time: time.Now(),
|
|
|
|
author: author,
|
|
|
|
content: sendable.Content(),
|
|
|
|
}
|
|
|
|
if noncer, ok := sendable.(cchat.MessageNonce); ok {
|
|
|
|
echo.nonce = noncer.Nonce()
|
|
|
|
}
|
|
|
|
return echo
|
|
|
|
}
|
|
|
|
|
|
|
|
func randomMessage(id uint32) Message {
|
|
|
|
var now = time.Now()
|
|
|
|
return Message{
|
|
|
|
id: id,
|
|
|
|
time: now,
|
|
|
|
author: randomdata.SillyName(),
|
|
|
|
content: randomdata.Paragraph(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m Message) ID() string {
|
|
|
|
return strconv.Itoa(int(m.id))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m Message) Time() time.Time {
|
|
|
|
return m.time
|
|
|
|
}
|
|
|
|
|
2020-06-03 23:13:06 +00:00
|
|
|
func (m Message) Author() cchat.MessageAuthor {
|
|
|
|
return Author{name: m.author}
|
2020-05-20 07:13:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m Message) Content() text.Rich {
|
|
|
|
return text.Rich{Content: m.content}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m Message) Nonce() string {
|
|
|
|
return m.nonce
|
|
|
|
}
|
2020-06-03 23:13:06 +00:00
|
|
|
|
|
|
|
// Mentioned is true when the message content contains the author's name.
|
|
|
|
func (m Message) Mentioned() bool {
|
|
|
|
// hack
|
|
|
|
return strings.Contains(m.content, m.author)
|
|
|
|
}
|
|
|
|
|
|
|
|
type Author struct {
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ cchat.MessageAuthor = (*Author)(nil)
|
|
|
|
|
|
|
|
func (a Author) ID() string {
|
|
|
|
return a.name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a Author) Name() text.Rich {
|
|
|
|
return text.Rich{Content: a.name}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a Author) Avatar() string {
|
|
|
|
return "https://gist.github.com/diamondburned/945744c2b5ce0aa0581c9267a4e5cf24/raw/598069da673093aaca4cd4aa0ede1a0e324e9a3a/astolfo_selfie.png"
|
|
|
|
}
|