mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 22:00:11 +08:00
fix: emojimix logical error
This commit is contained in:
parent
8f20487a15
commit
69394377d0
@ -247,7 +247,7 @@ zerobot [-h] [-t token] [-u url] [-n nickname] [-p prefix] [-d|w] [-g 监听地
|
|||||||
- [x] 讲个笑话[@xxx] | 讲个笑话[qq号]
|
- [x] 讲个笑话[@xxx] | 讲个笑话[qq号]
|
||||||
- **抽象话** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_chouxianghua"`
|
- **抽象话** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_chouxianghua"`
|
||||||
- [x] 抽象翻译[xxx]
|
- [x] 抽象翻译[xxx]
|
||||||
- **抽象话** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_emojimix"`
|
- **合成emoji** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_emojimix"`
|
||||||
- [x] [emoji][emoji]
|
- [x] [emoji][emoji]
|
||||||
- **绝绝子** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_juejuezi"`
|
- **绝绝子** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_juejuezi"`
|
||||||
- [x] 喝奶茶绝绝子 | 绝绝子吃饭
|
- [x] 喝奶茶绝绝子 | 绝绝子吃饭
|
||||||
|
|||||||
@ -9,10 +9,13 @@ import (
|
|||||||
"github.com/FloatTech/zbputils/control"
|
"github.com/FloatTech/zbputils/control"
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
"github.com/FloatTech/zbputils/control/order"
|
||||||
"github.com/FloatTech/zbputils/ctxext"
|
"github.com/FloatTech/zbputils/ctxext"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const bed = "https://www.gstatic.com/android/keyboard/emojikitchen/%d/u%x/u%x_u%x.png"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
control.Register("emojimix", order.AcquirePrio(), &control.Options{
|
control.Register("emojimix", order.AcquirePrio(), &control.Options{
|
||||||
DisableOnDefault: false,
|
DisableOnDefault: false,
|
||||||
@ -20,39 +23,34 @@ func init() {
|
|||||||
"- [emoji][emoji]",
|
"- [emoji][emoji]",
|
||||||
}).OnMessage(match).SetBlock(true).Limit(ctxext.LimitByUser).
|
}).OnMessage(match).SetBlock(true).Limit(ctxext.LimitByUser).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
r1 := ctx.State["emojimix_e1"].(rune)
|
r := ctx.State["emojimix"].([]rune)
|
||||||
r2 := ctx.State["emojimix_e2"].(rune)
|
logrus.Debugln("[emojimix] match:", r)
|
||||||
u1 := fmt.Sprintf("https://www.gstatic.com/android/keyboard/emojikitchen/%d/u%x/u%x_u%x.png", emojis[r1], r1, r1, r2)
|
r1, r2 := r[0], r[1]
|
||||||
u2 := fmt.Sprintf("https://www.gstatic.com/android/keyboard/emojikitchen/%d/u%x/u%x_u%x.png", emojis[r2], r2, r2, r1)
|
u1 := fmt.Sprintf(bed, emojis[r1], r1, r1, r2)
|
||||||
client := &http.Client{}
|
u2 := fmt.Sprintf(bed, emojis[r2], r2, r2, r1)
|
||||||
resp1, err := client.Head(u1)
|
logrus.Debugln("[emojimix] u1:", u1)
|
||||||
if err == nil && resp1.StatusCode == http.StatusOK {
|
logrus.Debugln("[emojimix] u2:", u2)
|
||||||
ctx.SendChain(message.Image(u1))
|
resp1, err := http.Head(u1)
|
||||||
|
if err == nil {
|
||||||
resp1.Body.Close()
|
resp1.Body.Close()
|
||||||
return
|
if resp1.StatusCode == http.StatusOK {
|
||||||
|
ctx.SendChain(message.Image(u1))
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
resp2, err := client.Head(u2)
|
resp2, err := http.Head(u2)
|
||||||
if err == nil && resp2.StatusCode == http.StatusOK {
|
if err == nil {
|
||||||
ctx.SendChain(message.Image(u2))
|
|
||||||
resp2.Body.Close()
|
resp2.Body.Close()
|
||||||
return
|
if resp2.StatusCode == http.StatusOK {
|
||||||
|
ctx.SendChain(message.Image(u2))
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func match(ctx *zero.Ctx) bool {
|
func match(ctx *zero.Ctx) bool {
|
||||||
r := []rune(ctx.Event.RawMessage)
|
logrus.Debugln("[emojimix] msg:", ctx.Event.Message)
|
||||||
if len(r) == 2 {
|
|
||||||
if _, ok := emojis[r[0]]; !ok {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if _, ok := emojis[r[1]]; !ok {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
ctx.State["emojimix_e1"] = r[0]
|
|
||||||
ctx.State["emojimix_e2"] = r[1]
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
if len(ctx.Event.Message) == 2 {
|
if len(ctx.Event.Message) == 2 {
|
||||||
r1 := face2emoji(ctx.Event.Message[0])
|
r1 := face2emoji(ctx.Event.Message[0])
|
||||||
if _, ok := emojis[r1]; !ok {
|
if _, ok := emojis[r1]; !ok {
|
||||||
@ -62,8 +60,20 @@ func match(ctx *zero.Ctx) bool {
|
|||||||
if _, ok := emojis[r2]; !ok {
|
if _, ok := emojis[r2]; !ok {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
ctx.State["emojimix_e1"] = r1
|
ctx.State["emojimix"] = []rune{r1, r2}
|
||||||
ctx.State["emojimix_e2"] = r2
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
r := []rune(ctx.Event.RawMessage)
|
||||||
|
logrus.Debugln("[emojimix] raw msg:", ctx.Event.RawMessage)
|
||||||
|
if len(r) == 2 {
|
||||||
|
if _, ok := emojis[r[0]]; !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if _, ok := emojis[r[1]]; !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
ctx.State["emojimix"] = r
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user