diff --git a/api.go b/api.go index 141c951..f42f715 100644 --- a/api.go +++ b/api.go @@ -2048,7 +2048,7 @@ func (app *appContext) TelegramAddUser(gc *gin.Context) { // @Summary Sets whether to notify a user through telegram or not. // @Produce json -// @Param telegramNotifyDTO body telegramNotifyDTO true "User's Jellyfin ID and whether or not to notify then through Telegram." +// @Param SetContactMethodDTO body SetContactMethodsDTO true "User's Jellyfin ID and whether or not to notify then through Telegram." // @Success 200 {object} boolResponse // @Success 400 {object} boolResponse // @Success 500 {object} boolResponse diff --git a/discord.go b/discord.go index 4f49354..4c44931 100644 --- a/discord.go +++ b/discord.go @@ -41,6 +41,7 @@ func newDiscordDaemon(app *appContext) (*DiscordDaemon, error) { for _, user := range app.storage.discord { dd.users[user.ID] = user } + return dd, nil } @@ -91,13 +92,6 @@ func (d *DiscordDaemon) run() { return } -func (d *DiscordDaemon) Shutdown() { - d.Stopped = true - d.ShutdownChannel <- "Down" - <-d.ShutdownChannel - close(d.ShutdownChannel) -} - func (d *DiscordDaemon) messageHandler(s *dg.Session, m *dg.MessageCreate) { if m.GuildID != "" && d.channelName != "" { if d.channelID == "" { @@ -235,16 +229,7 @@ func (d *DiscordDaemon) Send(message *Message, channelID ...string) error { msg := "" var embeds []*dg.MessageEmbed if message.Markdown != "" { - var links []Link - msg, links = StripAltText(message.Markdown, true) - embeds = make([]*dg.MessageEmbed, len(links)) - for i := range links { - embeds[i] = &dg.MessageEmbed{ - URL: links[i].URL, - Title: links[i].Alt, - Type: dg.EmbedTypeLink, - } - } + msg, embeds = StripAltText(message.Markdown, true) } else { msg = message.Text } diff --git a/stripmd.go b/stripmd.go index 2a5ea4d..caed8ea 100644 --- a/stripmd.go +++ b/stripmd.go @@ -3,6 +3,7 @@ package main import ( "strings" + dg "github.com/bwmarrin/discordgo" stripmd "github.com/writeas/go-strip-markdown" ) @@ -13,22 +14,32 @@ type Link struct { // StripAltText removes Markdown alt text from links and images and replaces them with just the URL. // Currently uses the deepest alt text when links/images are nested. // If links = true, links are completely removed, and a list of URLs and their alt text is also returned. -func StripAltText(md string, links bool) (string, []Link) { +func StripAltText(md string, links bool) (string, []*dg.MessageEmbed) { altTextStart := -1 // Start of alt text (between '[' & ']') URLStart := -1 // Start of url (between '(' & ')') URLEnd := -1 previousURLEnd := -2 out := "" - embeds := []Link{} + embeds := []*dg.MessageEmbed{} for i := range md { if altTextStart != -1 && URLStart != -1 && md[i] == ')' { URLEnd = i - 1 out += md[previousURLEnd+2 : altTextStart-1] if links { - embeds = append(embeds, Link{ - URL: md[URLStart : URLEnd+1], - Alt: md[altTextStart : URLStart-2], - }) + embed := &dg.MessageEmbed{ + Type: dg.EmbedTypeLink, + Title: md[altTextStart : URLStart-2], + } + if md[altTextStart-1] == '!' { + embed.Title = md[altTextStart+1 : URLStart-2] + embed.Type = dg.EmbedTypeImage + embed.Image = &dg.MessageEmbedImage{ + URL: md[URLStart : URLEnd+1], + } + } else { + embed.URL = md[URLStart : URLEnd+1] + } + embeds = append(embeds, embed) } else { out += md[URLStart : URLEnd+1] }