From 2f08b672e18a309507ccae442b929f3a84a1c3b0 Mon Sep 17 00:00:00 2001 From: Gareth Pulham Date: Thu, 15 Apr 2021 22:48:00 +0100 Subject: [PATCH 1/2] Add black-on-black colouring for discord spoilers --- bridge/discord.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bridge/discord.go b/bridge/discord.go index 9debefc..950cd15 100644 --- a/bridge/discord.go +++ b/bridge/discord.go @@ -89,6 +89,10 @@ func userToMention(u *discordgo.User) (mention string) { return } +// For spoiler colouring: +var spoilerPattern = regexp.MustCompile(`\|\|(.*?)\|\|`) +var colorCode = string(rune(3)) + func (d *discordBot) publishMessage(s *discordgo.Session, m *discordgo.Message, wasEdit bool) { // Fix crash if these fields don't exist if m.Author == nil || s.State.User == nil { @@ -148,6 +152,10 @@ func (d *discordBot) publishMessage(s *discordgo.Session, m *discordgo.Message, content = "[edit] " + content } + if strings.Count(content, "||") >= 2 { + content = spoilerPattern.ReplaceAllString(content, colorCode+"1,1$1"+colorCode) + } + pmTarget := "" // Blank guild means that it's a PM if m.GuildID == "" { From 93d1e5c4fd050d6fa7a8d39afc30c0c3cb304d78 Mon Sep 17 00:00:00 2001 From: Gareth Pulham Date: Thu, 15 Apr 2021 23:33:31 +0100 Subject: [PATCH 2/2] Enable IRC->Discord spoilers The code for this is already there in irc/format/markdown.go, it was just blocked on account of the colours being stripped off early. --- bridge/irc_listener.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridge/irc_listener.go b/bridge/irc_listener.go index 329cfa9..13cbbb6 100644 --- a/bridge/irc_listener.go +++ b/bridge/irc_listener.go @@ -262,7 +262,7 @@ func (i *ircListener) OnPrivateMessage(e *irc.Event) { msg = "_" + msg + "_" } - msg = ircf.BlocksToMarkdown(ircf.Parse(ircf.StripColor(msg))) + msg = ircf.BlocksToMarkdown(ircf.Parse(msg)) go func(e *irc.Event) { i.bridge.discordMessagesChan <- IRCMessage{