mirror of https://github.com/velour/catbase.git
topic: fix newline issue
This commit is contained in:
parent
cf5e52c2b6
commit
b59d84b301
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/velour/catbase/config"
|
||||
"github.com/velour/catbase/connectors/discord"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Topic struct {
|
||||
|
@ -24,10 +25,25 @@ func New(b bot.Bot) *Topic {
|
|||
}
|
||||
|
||||
func (p *Topic) register() {
|
||||
p.b.RegisterRegexCmd(p, bot.Message, regexp.MustCompile(`(?i)^topic (?P<topic>.+)$`), func(r bot.Request) bool {
|
||||
p.b.RegisterRegexCmd(p, bot.Message, regexp.MustCompile(`(?i)^topic$`), func(r bot.Request) bool {
|
||||
switch conn := r.Conn.(type) {
|
||||
case *discord.Discord:
|
||||
err := conn.SetTopic(r.Msg.Channel, r.Values["topic"])
|
||||
topic, err := conn.Topic(r.Msg.Channel)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("couldn't get topic")
|
||||
return false
|
||||
}
|
||||
p.b.Send(conn, bot.Message, r.Msg.Channel, fmt.Sprintf("Topic: %s", topic))
|
||||
return true
|
||||
|
||||
}
|
||||
return false
|
||||
})
|
||||
p.b.RegisterRegexCmd(p, bot.Message, regexp.MustCompile(`(?i)^topic (?P<topic>.*)`), func(r bot.Request) bool {
|
||||
topic := strings.TrimPrefix(r.Msg.Body, "topic ")
|
||||
switch conn := r.Conn.(type) {
|
||||
case *discord.Discord:
|
||||
err := conn.SetTopic(r.Msg.Channel, topic)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("couldn't set topic")
|
||||
return false
|
||||
|
@ -43,18 +59,4 @@ func (p *Topic) register() {
|
|||
}
|
||||
return false
|
||||
})
|
||||
p.b.RegisterRegexCmd(p, bot.Message, regexp.MustCompile(`(?i)^topic$`), func(r bot.Request) bool {
|
||||
switch conn := r.Conn.(type) {
|
||||
case *discord.Discord:
|
||||
topic, err := conn.Topic(r.Msg.Channel)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("couldn't get topic")
|
||||
return false
|
||||
}
|
||||
p.b.Send(conn, bot.Message, r.Msg.Channel, fmt.Sprintf("Topic: %s", topic))
|
||||
return true
|
||||
|
||||
}
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue