@@ -2,7 +2,9 @@ package main
2
2
3
3
import (
4
4
"os"
5
+ "regexp"
5
6
"sort"
7
+ "strconv"
6
8
"strings"
7
9
8
10
"github.com/disgoorg/disgo/discord"
@@ -69,6 +71,7 @@ func (t *Transcript) AddMessage(m discord.Message) {
69
71
name = t .nameOverride [m .Author .ID .String ()].(string )
70
72
} else {
71
73
name = m .Author .Username
74
+ t .nameOverride [m .Author .ID .String ()] = name
72
75
}
73
76
74
77
// create a new block
@@ -233,6 +236,7 @@ func (t *Transcript) SaveTranscript() {
233
236
234
237
// preprocess message to handle newlines
235
238
content := strings .ReplaceAll (m .Content , "\n " , "\n > " )
239
+ content = t .replaceMentions (content )
236
240
237
241
writeToFile (f , "> " + content )
238
242
writeToFile (f , "" )
@@ -259,3 +263,25 @@ func writeToFile(file *os.File, content string) {
259
263
log .Panic (err )
260
264
}
261
265
}
266
+
267
+ func (t * Transcript ) replaceMentions (content string ) string {
268
+ outerPart := regexp .MustCompile ("<@!*&*|>" )
269
+
270
+ return regexp .MustCompile ("<@!*&*[0-9]+>" ).ReplaceAllStringFunc (content , func (s string ) string {
271
+ idStr := outerPart .ReplaceAllString (s , "" )
272
+
273
+ idNum , err := strconv .ParseUint (idStr , 10 , 64 )
274
+ if err != nil {
275
+ eris .Wrap (err , "failed to parse id" )
276
+ log .Panic (err )
277
+ }
278
+
279
+ id := snowflake .ID (idNum )
280
+
281
+ if val , ok := t .nameOverride [id .String ()].(string ); ok {
282
+ return "@" + val
283
+ } else {
284
+ return s
285
+ }
286
+ })
287
+ }
0 commit comments