From 7ba8df394226bdf48d4b64c274e409ee331bf462 Mon Sep 17 00:00:00 2001 From: ilidemi Date: Thu, 7 Jul 2022 03:05:24 +0000 Subject: [PATCH] Add fishbowl tools (#64) Reducing the bus factor. Top-level directory is likely not the best place for those, open to suggestions. Co-authored-by: Ilia Demianenko Reviewed-on: https://git.handmade.network/hmn/hmn/pulls/64 Co-authored-by: ilidemi Co-committed-by: ilidemi --- fishbowl-tools/.gitignore | 1 + fishbowl-tools/.vscode/fishbowl.code-snippets | 10 +++ fishbowl-tools/steps.md | 65 ++++++++++++++++ fishbowl-tools/timestamps.go | 41 ++++++++++ fishbowl-tools/twemoji.go | 77 +++++++++++++++++++ 5 files changed, 194 insertions(+) create mode 100644 fishbowl-tools/.gitignore create mode 100644 fishbowl-tools/.vscode/fishbowl.code-snippets create mode 100644 fishbowl-tools/steps.md create mode 100644 fishbowl-tools/timestamps.go create mode 100644 fishbowl-tools/twemoji.go diff --git a/fishbowl-tools/.gitignore b/fishbowl-tools/.gitignore new file mode 100644 index 0000000..f0f1ccc --- /dev/null +++ b/fishbowl-tools/.gitignore @@ -0,0 +1 @@ +!.vscode \ No newline at end of file diff --git a/fishbowl-tools/.vscode/fishbowl.code-snippets b/fishbowl-tools/.vscode/fishbowl.code-snippets new file mode 100644 index 0000000..9d504a2 --- /dev/null +++ b/fishbowl-tools/.vscode/fishbowl.code-snippets @@ -0,0 +1,10 @@ +{ + "Resource Link": { + "prefix": [ + "hmn-link" + ], + "body": [ + "$TM_SELECTED_TEXT" + ] + } +} \ No newline at end of file diff --git a/fishbowl-tools/steps.md b/fishbowl-tools/steps.md new file mode 100644 index 0000000..78d02bf --- /dev/null +++ b/fishbowl-tools/steps.md @@ -0,0 +1,65 @@ +- [ ] Export with [DiscordChatExporter](https://github.com/Tyrrrz/DiscordChatExporter) CLI 2.34 + + ``` + DiscordChatExporter.Cli.exe export -c [thread-id] -t [token] -o [fishbowl].html --media + ``` + +- [ ] Rename `[fishbowl].html_Files` to `files`, replace links in html +- [ ] Add target="_blank" to links + + ``` + (a href="[^"]+")> + $1 target="_blank"> + ``` + +- [ ] Add JQuery to `` + + ```html + + + + ``` + +- [ ] Drag/delete noise/edit in the browser +- [ ] Save as `[fishbowl]-dragged.html` (devtools -> `` -> copy outerHTML) +- [ ] Remove JQuery, sortable classes + + ``` + ui-sortable + ui-sortable-handle + ``` + +- [ ] Check `#fishbowl-audience` for highlights +- [ ] Fix audience avatar paths if anything copied +- [ ] Fix bad pictures (composite emojis 404) +- [ ] Fix links with extra braces at the end + + ``` + href="[^"]+\)" + ``` + +- [ ] Fill in resource links with vscode snippet (select phrase, Ctrl+Shift+P -> Insert Snippet -> hmn-link, paste the url) +- [ ] Download twemojies + + ``` + go run twemoji.go [fishbowl]-dragged.html files [fishbowl]-twemojied.html + ``` + +- [ ] Fix timestamps + + ``` + go run timestamps.go [fishbowl]-twemojied.html [fishbowl]-timestamped.html + ``` + +- [ ] Create a branch off latest `hmn` master +- [ ] Create fishbowl folder under `hmn/src/templates/src/fishbowls/` +- [ ] Copy timestamped html and files, rename html +- [ ] Remove everything from html but chatlog +- [ ] Remove js, css and whitney from files +- [ ] Add content path to `fishbowl.go` +- [ ] Test locally +- [ ] Submit a pull request diff --git a/fishbowl-tools/timestamps.go b/fishbowl-tools/timestamps.go new file mode 100644 index 0000000..f02cad0 --- /dev/null +++ b/fishbowl-tools/timestamps.go @@ -0,0 +1,41 @@ +package main + +import ( + "fmt" + "os" + "regexp" +) + +func main() { + if len(os.Args) != 3 { + fmt.Println("Usage: go run timestamps.go [fishbowl].html [fishbowl]-timestamped.html") + os.Exit(1) + } + + htmlPath := os.Args[1] + htmlOutPath := os.Args[2] + + htmlBytes, err := os.ReadFile(htmlPath) + if err != nil { + panic(err) + } + + html := string(htmlBytes) + + regex, err := regexp.Compile( + "()(\\d+)-([A-Za-z]+)-(\\d+)( [^<]+)", + ) + if err != nil { + panic(err) + } + + htmlOut := regex.ReplaceAllString( + html, + "$1$3 $2, 20$4$5", + ) + + err = os.WriteFile(htmlOutPath, []byte(htmlOut), 0666) + if err != nil { + panic(err) + } +} diff --git a/fishbowl-tools/twemoji.go b/fishbowl-tools/twemoji.go new file mode 100644 index 0000000..beb1510 --- /dev/null +++ b/fishbowl-tools/twemoji.go @@ -0,0 +1,77 @@ +package main + +import ( + "fmt" + "io" + "net/http" + "os" + "path" + "strings" +) + +func main() { + if len(os.Args) != 4 { + fmt.Println("Usage: go run twemoji.go [fishbowl].html files [fishbowl]-twemojied.html") + os.Exit(1) + } + + htmlPath := os.Args[1] + filesDir := os.Args[2] + htmlOutPath := os.Args[3] + + htmlBytes, err := os.ReadFile(htmlPath) + if err != nil { + panic(err) + } + + html := string(htmlBytes) + + for { + linkStart := strings.Index(html, "https://twemoji.maxcdn.com/") + if linkStart == -1 { + break + } + + linkEnd := strings.Index(html[linkStart:], "\"") + linkStart + link := html[linkStart:linkEnd] + emojiFilenameStart := strings.LastIndex(link, "/") + 1 + emojiFilename := "twemoji_" + link[emojiFilenameStart:] + emojiPath := path.Join(filesDir, emojiFilename) + + emojiResponse, err := http.Get(link) + if err != nil { + panic(err) + } + defer emojiResponse.Body.Close() + + if emojiResponse.StatusCode > 299 { + panic("Non-200 status code: " + fmt.Sprint(emojiResponse.StatusCode)) + } + + emojiFile, err := os.Create(emojiPath) + if err != nil { + panic(err) + } + defer emojiFile.Close() + + _, err = io.Copy(emojiFile, emojiResponse.Body) + if err != nil { + panic(err) + } + + html = strings.ReplaceAll(html, link, emojiPath) + + fmt.Println(emojiFilename) + } + + html = strings.ReplaceAll( + html, + "
", + "
\n", + ) + + err = os.WriteFile(htmlOutPath, []byte(html), 0666) + if err != nil { + panic(err) + } +}