Skip to content

Commit

Permalink
Merge pull request #121 from AbstractBeliefs/irc-spoiler-highlighting
Browse files Browse the repository at this point in the history
Allow colour based spoilers on IRC
  • Loading branch information
qaisjp committed Apr 17, 2021
2 parents 725266a + 93d1e5c commit 4bd3b1a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions bridge/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 == "" {
Expand Down
2 changes: 1 addition & 1 deletion bridge/irc_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 4bd3b1a

Please sign in to comment.