skulduggery.go (view raw)
1//
2// Copyright (c) 2019 Ted Unangst <tedu@tedunangst.com>
3//
4// Permission to use, copy, modify, and distribute this software for any
5// purpose with or without fee is hereby granted, provided that the above
6// copyright notice and this permission notice appear in all copies.
7//
8// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
16package main
17
18import (
19 "regexp"
20
21 "github.com/mattn/go-runewidth"
22)
23
24// these lists are mostly (?) accurate
25var bigboldshitz = "๐๐๐๐๐๐
๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐"
26var lilboldshitz = "๐๐๐๐๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ"
27var moeboldshitz = "๐๐๐๐๐๐๐๐๐๐๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ"
28var morboldshitz = "๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ๐๐๐๐๐๐
๐๐"
29var biggothshitz = "๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ๐๐๐๐๐๐
"
30var lilgothshitz = "๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐"
31var moegothshitz = "๐๐
๐ฎ๐๐๐๐๐ณโ๐๐๐๐๐๐๐๐โ๐๐๐๐๐๐๐๐
"
32var morgothshitz = "๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท"
33var bigitalshitz = "๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ๐๐"
34var lilitalshitz = "๐๐๐๐
๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐"
35var moeitalshitz = "๐ผ๐ฝ๐พ๐ฟ๐๐๐๐๐๐
๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐"
36var moritalshitz = "๐๐๐๐๐๐๐๐๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ"
37var bigbangshitz = "๐ธ๐นโ๐ป๐ผ๐ฝ๐พโ๐๐๐๐๐โ๐โโโ๐๐๐๐๐๐๐โค"
38var lilbangshitz = "๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ"
39var bigwideshitz = "๏ผก๏ผข๏ผฃ๏ผค๏ผฅ๏ผฆ๏ผง๏ผจ๏ผฉ๏ผช๏ผซ๏ผฌ๏ผญ๏ผฎ๏ผฏ๏ผฐ๏ผฑ๏ผฒ๏ผณ๏ผด๏ผต๏ผถ๏ผท๏ผธ๏ผน๏ผบ"
40var lilwideshitz = "๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ
๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ"
41var bigblokshitz = "๐
ฐ๐
ฑ๐
ฒ๐
ณ๐
ด๐
ต๐
ถ๐
ท๐
ธ๐
น๐
บ๐
ป๐
ผ๐
ฝ๐
พ๐
ฟ๐๐๐๐๐๐
๐๐๐๐"
42var evenmoeshitz = "๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ๐๐๐๐๐๐
๐๐๐๐๐๐๐๐"
43var evenmorshitz = "๐ถ๐ท๐ธ๐น๐๐ป๐ฐ๐ฝ๐พ๐ฟ๐๐๐๐๐ธ๐
๐๐๐๐๐๐๐๐๐๐"
44
45var re_alltheshitz = regexp.MustCompile(`([` +
46 bigboldshitz + lilboldshitz +
47 moeboldshitz + morboldshitz +
48 biggothshitz + lilgothshitz +
49 moegothshitz + morgothshitz +
50 bigitalshitz + lilitalshitz +
51 moeitalshitz + moritalshitz +
52 bigbangshitz + lilbangshitz +
53 bigwideshitz + lilwideshitz +
54 evenmoeshitz + evenmorshitz +
55 bigblokshitz +
56 "][ '\ufe0f]?){3,}")
57
58var allUppers = []string{bigboldshitz, moeboldshitz, biggothshitz, bigwideshitz, moegothshitz, bigitalshitz, moeitalshitz, bigbangshitz, bigblokshitz, evenmoeshitz}
59var allLowers = []string{lilboldshitz, morboldshitz, lilgothshitz, lilwideshitz, morgothshitz, lilitalshitz, moritalshitz, lilbangshitz, evenmorshitz}
60
61var re_moredumb = regexp.MustCompile("[\U0001f44f\U0001f6a8\U000026a0]\ufe0f?")
62
63// this may not be especially fast
64func unpucker(s string) string {
65 fixer := func(r string) string {
66 x := make([]byte, len(r))
67 xi := 0
68 loop1:
69 for _, c := range r {
70 xi++
71 if c == ' ' || c == '\'' {
72 x[xi] = byte(c)
73 continue
74 }
75 for _, set := range allUppers {
76 i := 0
77 for _, rr := range set {
78 if rr == c {
79 x[xi] = byte('A' + i)
80 continue loop1
81 }
82 i++
83 }
84 }
85 for _, set := range allLowers {
86 i := 0
87 for _, rr := range set {
88 if rr == c {
89 x[xi] = byte('a' + i)
90 continue loop1
91 }
92 i++
93 }
94 }
95 x[xi] = '.'
96 }
97 return string(x)
98 }
99 s = re_alltheshitz.ReplaceAllStringFunc(s, fixer)
100
101 s = re_moredumb.ReplaceAllString(s, ".")
102
103 zw := false
104 for _, c := range s {
105 if runewidth.RuneWidth(c) == 0 {
106 zw = true
107 break
108 }
109 }
110 if zw {
111 x := make([]byte, 0, len(s))
112 zw = false
113 for _, c := range s {
114 if runewidth.RuneWidth(c) == 0 {
115 if zw {
116 continue
117 }
118 zw = true
119 } else {
120 zw = false
121 }
122 q := string(c)
123 x = append(x, []byte(q)...)
124 }
125 return string(x)
126 }
127 return s
128}