-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #493 from CSUSTers/dev
Merge `dev` branch
- Loading branch information
Showing
18 changed files
with
369 additions
and
451 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,136 +1,61 @@ | ||
package base | ||
|
||
import ( | ||
"regexp" | ||
"strings" | ||
|
||
"bytes" | ||
"csust-got/entities" | ||
"math/rand/v2" | ||
"regexp" | ||
|
||
. "gopkg.in/telebot.v3" | ||
) | ||
|
||
var ( | ||
// change 'y' to 'i' if end with this. | ||
yEndTable = [...]string{"ty", "ly", "fy", "py", "dy", "by"} | ||
|
||
// hugeXer regex | ||
hugeRegex = regexp.MustCompile(`^(huge)+.+(er)+$`) | ||
hooPrePatt = regexp.MustCompile(`(?i)^h[o0]*`) | ||
hooSufPatt = regexp.MustCompile(`(?i)[o0]*$`) | ||
hooRunes = []rune("o0O") | ||
) | ||
|
||
// HugeEncoder encode 'xxx' to 'hugexxxer'. | ||
func HugeEncoder(ctx Context) error { | ||
arg, ok := parseHugeArgs(ctx) | ||
if !ok { | ||
return ctx.Reply(arg, ModeMarkdownV2) | ||
// HooEncoder encode 'XXX' to 'hooXXXoo'. | ||
func HooEncoder(ctx Context) error { | ||
_, s, err := entities.CommandTakeArgs(ctx.Message(), 0) | ||
if err != nil { | ||
return ctx.Reply("h0oOo") | ||
} | ||
|
||
// encode | ||
arg = hooEncode(arg) | ||
|
||
return ctx.Reply(arg, ModeMarkdownV2) | ||
s = hooEncode(s) | ||
return ctx.Reply(s) | ||
} | ||
|
||
// HugeDecoder decode 'hugehugehugexxxererer' to 'hugexxxer'. | ||
func HugeDecoder(ctx Context) error { | ||
arg, ok := parseHugeArgs(ctx) | ||
if !ok { | ||
return ctx.Reply(arg, ModeMarkdownV2) | ||
} | ||
|
||
// decode | ||
arg = hooDecode(arg) | ||
|
||
return ctx.Reply(arg, ModeMarkdownV2) | ||
} | ||
|
||
func parseHugeArgs(ctx Context) (arg string, ok bool) { | ||
if ctx.Message().ReplyTo != nil { | ||
arg = ctx.Message().ReplyTo.Text | ||
} | ||
|
||
command := entities.FromMessage(ctx.Message()) | ||
|
||
if command.Argc() > 0 { | ||
arg = command.ArgAllInOneFrom(0) | ||
} | ||
|
||
arg = strings.TrimSpace(arg) | ||
func hooEncode(s string) string { | ||
matches1 := hooPrePatt.FindStringIndex(s) | ||
matches2 := hooSufPatt.FindStringIndex(s) | ||
|
||
// no args | ||
if arg == "" { | ||
return "HUGEFIVER", false | ||
i1, i2 := 0, len(s) | ||
if matches1 != nil { | ||
i1 = matches1[1] | ||
} | ||
|
||
// tldr | ||
if len(arg) > 128 { | ||
return "hugeTLDRer", false | ||
if matches2 != nil { | ||
i2 = matches2[0] | ||
} | ||
|
||
return arg, true | ||
} | ||
bs := bytes.NewBufferString("h") | ||
|
||
func hooEncode(arg string) string { | ||
if arg == "" { | ||
return "HUGEFIVER" | ||
} | ||
// add 'huge' to prefix | ||
if !strings.HasPrefix(arg, "huge") { | ||
if arg[0] != 'e' { | ||
arg = "e" + arg | ||
} | ||
arg = "hug" + arg | ||
} | ||
// add 'er' to suffix | ||
if !strings.HasSuffix(arg, "er") { | ||
arg = encodeParseEnd(arg) | ||
// only add 'r' if $arg end with 'e' | ||
if arg[len(arg)-1] != 'e' { | ||
arg += "e" | ||
if i1 >= i2-1 { | ||
for range 4 { | ||
bs.WriteRune(hooRunes[rand.N(len(hooRunes))]) | ||
} | ||
arg += "r" | ||
} | ||
// if we get 'huger' after encode, we <fork> him. | ||
if arg == "huger" { | ||
arg = "hugeF**Ker" | ||
return bs.String() | ||
} | ||
|
||
return arg | ||
} | ||
|
||
// encodeParseEnd change 'y' to 'i' if end with $yEndTable | ||
func encodeParseEnd(arg string) string { | ||
for _, v := range yEndTable { | ||
if strings.HasSuffix(arg, v) { | ||
arg = arg[0:len(arg)-1] + "i" | ||
break | ||
} | ||
} | ||
return arg | ||
} | ||
|
||
func hooDecode(arg string) string { | ||
if !hugeRegex.MatchString(arg) { | ||
return "hugeFAKEr" | ||
for range 2 { | ||
bs.WriteRune(hooRunes[rand.N(len(hooRunes))]) | ||
} | ||
|
||
// find first 'huge' and last 'er' | ||
huge := strings.Index(arg, "huge") | ||
er := strings.LastIndex(arg, "er") | ||
bs.WriteString(s[i1:i2]) | ||
|
||
// find end of first consecutive 'huge' and start of last consecutive 'er' | ||
var hugeEnd, erStart int | ||
for hugeEnd = huge; hugeEnd+4 < len(arg); hugeEnd += 4 { | ||
if arg[hugeEnd:hugeEnd+4] != "huge" { | ||
break | ||
} | ||
} | ||
for erStart = er; erStart-2 >= 0; erStart -= 2 { | ||
if arg[erStart-2:erStart] != "er" { | ||
break | ||
} | ||
for range 2 { | ||
bs.WriteRune(hooRunes[rand.N(len(hooRunes))]) | ||
} | ||
|
||
// decode | ||
arg = arg[0:huge+4] + arg[hugeEnd:erStart] + arg[er:] | ||
return arg | ||
return bs.String() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.