| 17 | const bed = "https://www.gstatic.com/android/keyboard/emojikitchen/%d/u%x/u%x_u%x.png" |
| 18 | |
| 19 | func init() { |
| 20 | control.AutoRegister(&ctrl.Options[*zero.Ctx]{ |
| 21 | DisableOnDefault: false, |
| 22 | Brief: "合成emoji", |
| 23 | Help: "- [emoji][emoji]", |
| 24 | }).OnMessage(match).SetBlock(true).Limit(ctxext.LimitByUser). |
| 25 | Handle(func(ctx *zero.Ctx) { |
| 26 | r := ctx.State["emojimix"].([]rune) |
| 27 | logrus.Debugln("[emojimix] match:", r) |
| 28 | r1, r2 := r[0], r[1] |
| 29 | u1 := fmt.Sprintf(bed, emojis[r1], r1, r1, r2) |
| 30 | u2 := fmt.Sprintf(bed, emojis[r2], r2, r2, r1) |
| 31 | logrus.Debugln("[emojimix] u1:", u1) |
| 32 | logrus.Debugln("[emojimix] u2:", u2) |
| 33 | resp1, err := http.Head(u1) |
| 34 | if err == nil { |
| 35 | resp1.Body.Close() |
| 36 | if resp1.StatusCode == http.StatusOK { |
| 37 | ctx.SendChain(message.Image(u1)) |
| 38 | return |
| 39 | } |
| 40 | } |
| 41 | resp2, err := http.Head(u2) |
| 42 | if err == nil { |
| 43 | resp2.Body.Close() |
| 44 | if resp2.StatusCode == http.StatusOK { |
| 45 | ctx.SendChain(message.Image(u2)) |
| 46 | return |
| 47 | } |
| 48 | } |
| 49 | }) |
| 50 | } |
| 51 | |
| 52 | func match(ctx *zero.Ctx) bool { |
| 53 | logrus.Debugln("[emojimix] msg:", ctx.Event.Message) |