| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- package ui
- 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 != "" {
- repr = "#" + c.Name
- } else if len(c.Recipients) == 1 {
- rp := c.Recipients[0]
- repr = rp.Username + "#" + rp.Discriminator
- } else {
- rps := make([]string, len(c.Recipients))
- for i, r := range c.Recipients {
- rps[i] = r.Username + "#" + r.Discriminator
- }
- repr = strings.Join(rps, ", ")
- }
- return repr
- }
|