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
24var bigboldshitz = "๐๐๐๐๐๐
๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐"
25var lilboldshitz = "๐๐๐๐๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ"
26var moeboldshitz = "๐๐๐๐๐๐๐๐๐๐๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ"
27var morboldshitz = "๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ๐๐๐๐๐๐
๐๐"
28var biggothshitz = "๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ๐๐๐๐๐๐
"
29var lilgothshitz = "๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐"
30var moegothshitz = "๐๐
๐ฎ๐๐๐๐๐ณโ๐๐๐๐๐๐๐๐โ๐๐๐๐๐๐๐๐
"
31var morgothshitz = "๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท"
32var bigitalshitz = "๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ๐๐"
33var lilitalshitz = "๐๐๐๐
๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐"
34var moeitalshitz = "๐ผ๐ฝ๐พ๐ฟ๐๐๐๐๐๐
๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐"
35var moritalshitz = "๐๐๐๐๐๐๐๐๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ"
36var bigbangshitz = "๐ธ๐นโ๐ป๐ผ๐ฝ๐พโ๐๐๐๐๐โ๐โโโ๐๐๐๐๐๐๐โค"
37var lilbangshitz = "๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ"
38var bigwideshitz = "๏ผก๏ผข๏ผฃ๏ผค๏ผฅ๏ผฆ๏ผง๏ผจ๏ผฉ๏ผช๏ผซ๏ผฌ๏ผญ๏ผฎ๏ผฏ๏ผฐ๏ผฑ๏ผฒ๏ผณ๏ผด๏ผต๏ผถ๏ผท๏ผธ๏ผน๏ผบ"
39var lilwideshitz = "๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ
๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ๏ฝ"
40var bigblokshitz = "๐
ฐ๐
ฑ๐
ฒ๐
ณ๐
ด๐
ต๐
ถ๐
ท๐
ธ๐
น๐
บ๐
ป๐
ผ๐
ฝ๐
พ๐
ฟ๐๐๐๐๐๐
๐๐๐๐"
41
42var re_alltheshitz = regexp.MustCompile(`([` +
43 bigboldshitz + lilboldshitz +
44 moeboldshitz + morboldshitz +
45 biggothshitz + lilgothshitz +
46 moegothshitz + morgothshitz +
47 bigitalshitz + lilitalshitz +
48 moeitalshitz + moritalshitz +
49 bigbangshitz + lilbangshitz +
50 bigwideshitz + lilwideshitz +
51 bigblokshitz +
52 "][ '\ufe0f]?){3,}")
53
54var allUppers = []string{bigboldshitz, moeboldshitz, biggothshitz, bigwideshitz, moegothshitz, bigitalshitz, moeitalshitz, bigbangshitz, bigblokshitz}
55var allLowers = []string{lilboldshitz, morboldshitz, lilgothshitz, lilwideshitz, morgothshitz, lilitalshitz, moritalshitz, lilbangshitz}
56
57var re_moredumb = regexp.MustCompile("[\U0001f44f\U0001f6a8\U000026a0]\ufe0f?")
58
59// this may not be especially fast
60func unpucker(s string) string {
61 fixer := func(r string) string {
62 x := make([]byte, len(r))
63 xi := 0
64 loop1:
65 for _, c := range r {
66 xi++
67 if c == ' ' || c == '\'' {
68 x[xi] = byte(c)
69 continue
70 }
71 for _, set := range allUppers {
72 i := 0
73 for _, rr := range set {
74 if rr == c {
75 x[xi] = byte('A' + i)
76 continue loop1
77 }
78 i++
79 }
80 }
81 for _, set := range allLowers {
82 i := 0
83 for _, rr := range set {
84 if rr == c {
85 x[xi] = byte('a' + i)
86 continue loop1
87 }
88 i++
89 }
90 }
91 x[xi] = '.'
92 }
93 return string(x)
94 }
95 s = re_alltheshitz.ReplaceAllStringFunc(s, fixer)
96
97 s = re_moredumb.ReplaceAllString(s, ".")
98
99 zw := false
100 for _, c := range s {
101 if runewidth.RuneWidth(c) == 0 {
102 zw = true
103 break
104 }
105 }
106 if zw {
107 x := make([]byte, 0, len(s))
108 zw = false
109 for _, c := range s {
110 if runewidth.RuneWidth(c) == 0 {
111 if zw {
112 continue
113 }
114 zw = true
115 } else {
116 zw = false
117 }
118 q := string(c)
119 x = append(x, []byte(q)...)
120 }
121 return string(x)
122 }
123 return s
124}