Skip to content

Commit

Permalink
Merge branch 'FloatTech:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiang-Red authored Jul 22, 2022
2 parents e22fb3c + ceb3df5 commit 03b9e28
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,14 @@ print("run[CQ:image,file="+j["img"]+"]")

- [x] 藏尾诗[xxx]

</details>
<details>
<summary>英文字符翻转</summary>

`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/char_reverser"`

- [x] 翻转 [英文字符串]

</details>
<details>
<summary>选择困难症帮手</summary>
Expand Down
2 changes: 1 addition & 1 deletion kanban/banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
var (
info = [...]string{
"* OneBot + ZeroBot + Golang",
"* Version 1.5.0-beta4 - 2022-07-13 12:24:13 +0800 CST",
"* Version 1.5.0-beta5 - 2022-07-22 15:39:17 +0800 CST",
"* Copyright © 2020 - 2022 FloatTech. All Rights Reserved.",
"* Project: https://github.com/FloatTech/ZeroBot-Plugin",
}
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import (
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/bilibili" // b站相关
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/book_review" // 哀伤雪刃吧推书记录
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/cangtoushi" // 藏头诗
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/char_reverser" // 英文字符翻转
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/choose" // 选择困难症帮手
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/chouxianghua" // 说抽象话
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/coser" // 三次元小姐姐
Expand Down
111 changes: 111 additions & 0 deletions plugin/char_reverser/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Package charreverser 英文字符反转
package charreverser

import (
"regexp"
"strings"

ctrl "github.com/FloatTech/zbpctrl"
"github.com/FloatTech/zbputils/control"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
)

const commandRegex = `[A-z]{1}([A-z]|\s)+[A-z]{1}` // 命令正则表达式

var (
charMap = map[rune]rune{
'a': 'ɐ',
'b': 'q',
'c': 'ɔ',
'd': 'p',
'e': 'ǝ',
'f': 'ɟ',
'g': 'ƃ',
'h': 'ɥ',
'i': 'ᴉ',
'j': 'ɾ',
'k': 'ʞ',
'l': 'l',
'm': 'ɯ',
'n': 'u',
'o': 'o',
'p': 'd',
'q': 'b',
'r': 'ɹ',
's': 's',
't': 'ʇ',
'u': 'n',
'v': 'ʌ',
'w': 'ʍ',
'x': 'x',
'y': 'ʎ',
'z': 'z',
'A': '∀',
'B': 'ᗺ',
'C': 'Ɔ',
'D': 'ᗡ',
'E': 'Ǝ',
'F': 'Ⅎ',
'G': '⅁',
'H': 'H',
'I': 'I',
'J': 'ſ',
'K': 'ʞ',
'L': '˥',
'M': 'W',
'N': 'N',
'O': 'O',
'P': 'Ԁ',
'Q': 'Ò',
'R': 'ᴚ',
'S': 'S',
'T': '⏊',
'U': '∩',
'V': 'Λ',
'W': 'M',
'X': 'X',
'Y': '⅄',
'Z': 'Z',
}

compiledRegex = regexp.MustCompile(commandRegex)
)

func init() {
// 初始化engine
engine := control.Register(
"charreverser",
&ctrl.Options[*zero.Ctx]{
DisableOnDefault: false,
Help: "字符翻转\n -翻转 <英文字符串>",
},
)
// 处理字符翻转指令
engine.OnRegex(`翻转( )+[A-z]{1}([A-z]|\s)+[A-z]{1}`).SetBlock(true).Handle(
func(ctx *zero.Ctx) {
// 获取需要翻转的字符串
results := compiledRegex.FindAllString(ctx.MessageString(), -1)
str := results[0]

// 将字符顺序翻转
var tempBuilder strings.Builder
for i := len(str) - 1; i >= 0; i-- {
tempBuilder.WriteByte(str[i])
}

// 翻转字符字形
var reversedStrBuilder strings.Builder
for _, char := range tempBuilder.String() {
if char != ' ' {
reversedStrBuilder.WriteRune(charMap[char])
} else {
reversedStrBuilder.WriteRune(' ')
}
}

// 发送翻转后的字符串
ctx.SendChain(message.Text(reversedStrBuilder.String()))
},
)
}

0 comments on commit 03b9e28

Please sign in to comment.