about summary refs log tree commit diff
path: root/fun
diff options
context:
space:
mode:
authoreta <eta@theta.eu.org>2020-06-15T16·59+0100
committereta <eta@theta.eu.org>2020-06-16T13·29+0000
commit4c22cf316933613215e83f70a6bb2c556d42e02c (patch)
tree9acd34f84ad63ea236de253f8cfae65ce3151059 /fun
parent70731b9ee0408a923964fb948f920f91bdf16ec3 (diff)
feat(clbot): insert Unicode ZWS to avoid pinging users r/992
Change-Id: I732bf6daa01f5b2099c4f4cbdd21a2ceedc79cb1
Reviewed-on: https://cl.tvl.fyi/c/depot/+/385
Reviewed-by: q3k <q3k@q3k.org>
Reviewed-by: lukegb <lukegb@tvl.fyi>
Diffstat (limited to 'fun')
-rw-r--r--fun/clbot/clbot.go16
1 files changed, 12 insertions, 4 deletions
diff --git a/fun/clbot/clbot.go b/fun/clbot/clbot.go
index b7bfa0d961..222ce07788 100644
--- a/fun/clbot/clbot.go
+++ b/fun/clbot/clbot.go
@@ -63,7 +63,9 @@ func callOnShutdown(f func()) {
 	shutdownFuncs = append(shutdownFuncs, f)
 }
 
-const ignoreBotChar = "\xe2\x80\x8b"
+// Unicode U+200B zero-width-space, to avoid triggering other bots
+// or highlighting people on IRC.
+const zeroWidthSpace = "\u200b"
 
 func runIRC(ctx context.Context, ircCfg irc.ClientConfig, sendMsg <-chan string) {
 	bo := backoffutil.NewDefaultBackOff()
@@ -100,7 +102,7 @@ func runIRC(ctx context.Context, ircCfg irc.ClientConfig, sendMsg <-chan string)
 						return
 					case msg := <-sendMsg:
 						log.Infof("sending message %q to %v", msg, *ircChannel)
-						ircClient.Writef("PRIVMSG %s :%s%s", *ircChannel, ignoreBotChar, msg)
+						ircClient.Writef("PRIVMSG %s :%s%s", *ircChannel, zeroWidthSpace, msg)
 					}
 				}
 			}()
@@ -132,6 +134,12 @@ func username(p gerritevents.PatchSet) string {
 	return "UNKNOWN USER"
 }
 
+// noping inserts a Unicode zero-width space between the first and rest characters of `user`
+// in an effort to avoid pinging that user on IRC.
+func noping(user string) string {
+	return fmt.Sprintf("%s%s%s", user[0], zeroWidthSpace, user[1:])
+}
+
 func patchSetURL(c gerritevents.Change, p gerritevents.PatchSet) string {
 	return fmt.Sprintf("https://cl.tvl.fyi/%d", c.Number)
 }
@@ -190,12 +198,12 @@ func main() {
 				if e.Change.Project != "depot" || e.Change.Branch != "master" || e.PatchSet.Number != 1 {
 					continue
 				}
-				parsedMsg = fmt.Sprintf("CL/%d: %q proposed by %s - %s", e.Change.Number, e.Change.Subject, username(e.PatchSet), patchSetURL(e.Change, e.PatchSet))
+				parsedMsg = fmt.Sprintf("CL/%d: %q proposed by %s - %s", e.Change.Number, e.Change.Subject, noping(username(e.PatchSet)), patchSetURL(e.Change, e.PatchSet))
 			case *gerritevents.ChangeMerged:
 				if e.Change.Project != "depot" || e.Change.Branch != "master" {
 					continue
 				}
-				parsedMsg = fmt.Sprintf("CL/%d: %q submitted by %s - %s", e.Change.Number, e.Change.Subject, username(e.PatchSet), patchSetURL(e.Change, e.PatchSet))
+				parsedMsg = fmt.Sprintf("CL/%d: %q submitted by %s - %s", e.Change.Number, e.Change.Subject, noping(username(e.PatchSet)), patchSetURL(e.Change, e.PatchSet))
 			}
 			if parsedMsg != "" {
 				sendMsgChan <- parsedMsg