diff --git a/util/discord.go b/util/discord.go index bd36c97..70e51f7 100644 --- a/util/discord.go +++ b/util/discord.go @@ -2,28 +2,10 @@ package util import ( "encoding/json" - "regexp" "github.com/ayntgl/discordgo" ) -var ( - boldRegex = regexp.MustCompile(`(?m)\*\*(.*?)\*\*`) - italicRegex = regexp.MustCompile(`(?m)\*(.*?)\*`) - underlineRegex = regexp.MustCompile(`(?m)__(.*?)__`) - strikeThroughRegex = regexp.MustCompile(`(?m)~~(.*?)~~`) -) - -func ParseMarkdown(md string) string { - var res string - res = boldRegex.ReplaceAllString(md, "[::b]$1[::-]") - res = italicRegex.ReplaceAllString(res, "[::i]$1[::-]") - res = underlineRegex.ReplaceAllString(res, "[::u]$1[::-]") - res = strikeThroughRegex.ReplaceAllString(res, "[::s]$1[::-]") - - return res -} - func FindMessageByID(ms []*discordgo.Message, mID string) (int, *discordgo.Message) { for i, m := range ms { if m.ID == mID { @@ -34,20 +16,6 @@ func FindMessageByID(ms []*discordgo.Message, mID string) (int, *discordgo.Messa return -1, nil } -func ChannelIsUnread(s *discordgo.State, c *discordgo.Channel) bool { - if c.LastMessageID == "" { - return false - } - - for _, rs := range s.ReadState { - if c.ID == rs.ID { - return c.LastMessageID != rs.LastMessageID - } - } - - return false -} - func HasPermission(s *discordgo.State, cID string, p int64) bool { perm, err := s.UserChannelPermissions(s.User.ID, cID) if err != nil { diff --git a/util/ui.go b/util/ui.go index 66adb65..f3b801c 100644 --- a/util/ui.go +++ b/util/ui.go @@ -1,11 +1,29 @@ package util import ( + "regexp" "strings" "github.com/ayntgl/discordgo" ) +var ( + boldRegex = regexp.MustCompile(`(?m)\*\*(.*?)\*\*`) + italicRegex = regexp.MustCompile(`(?m)\*(.*?)\*`) + underlineRegex = regexp.MustCompile(`(?m)__(.*?)__`) + strikeThroughRegex = regexp.MustCompile(`(?m)~~(.*?)~~`) +) + +func ParseMarkdown(md string) string { + var res string + res = boldRegex.ReplaceAllString(md, "[::b]$1[::-]") + res = italicRegex.ReplaceAllString(res, "[::i]$1[::-]") + res = underlineRegex.ReplaceAllString(res, "[::u]$1[::-]") + res = strikeThroughRegex.ReplaceAllString(res, "[::s]$1[::-]") + + return res +} + func ChannelToString(c *discordgo.Channel) string { var repr string if c.Name != "" { diff --git a/util/discord_test.go b/util/ui_test.go similarity index 100% rename from util/discord_test.go rename to util/ui_test.go