Skip to content

Commit

Permalink
fix: waifu plugin not work | score panic err
Browse files Browse the repository at this point in the history
  • Loading branch information
MoYoez committed Nov 22, 2023
1 parent 42c42a0 commit 225b966
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
8 changes: 6 additions & 2 deletions plugin/score/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ func init() {
return
}
siEventUserName := toolchain.GetNickNameFromUsername(ctx.Message.From.UserName)
siTargetUserName := toolchain.GetNickNameFromUsername(getEntitiy[1])
siTargetUserName := toolchain.GetNickNameFromUsername(getEntitiy[0])
ctx.SendPlainMessage(true, "转账成功了哦~\n", siEventUserName, " 变化为 ", siEventUser.Coins, " - ", modifyCoins, "= ", siEventUser.Coins-modifyCoins, "\n", siTargetUserName, " 变化为: ", siTargetUser.Coins, " + ", modifyCoins, "= ", siTargetUser.Coins+modifyCoins)
_ = coins.InsertUserCoins(sdb, siEventUser.UID, siEventUser.Coins-modifyCoins)
_ = coins.InsertUserCoins(sdb, siTargetUser.UID, siTargetUser.Coins+modifyCoins)
Expand All @@ -461,7 +461,11 @@ func init() {

})
engine.OnMessageCommand("coinstaus").SetBlock(true).Handle(func(ctx *rei.Ctx) {
_, getCodeRaw := toolchain.SplitCommandTo(ctx.Message.Text, 2)
getLength, getCodeRaw := toolchain.SplitCommandTo(ctx.Message.Text, 2)
if getLength < 2 {
ctx.SendPlainMessage(true, "缺少指令 , 应当为 /command (disable|禁用|enable|启用)")
return
}
getCode := getCodeRaw[1]
if getCode != "禁用" && getCode != "disable" && getCode != "enable" && getCode != "启用" {
ctx.SendPlainMessage(true, "指令错误 , 应当为 /command (disable|禁用|enable|启用)")
Expand Down
34 changes: 10 additions & 24 deletions plugin/wife/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package wife

import (
"bytes"
"fmt"
"image/png"
"math/rand"
"regexp"
"strconv"
"time"

Expand All @@ -16,33 +18,14 @@ import (
ctrl "github.com/FloatTech/zbpctrl"
rei "github.com/fumiama/ReiBot"
tgba "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/wdvxdr1123/ZeroBot/extension/rate"
)

var (
MessageTickerLimiter = rate.NewManager[int64](time.Minute*1, 2)
engine = rei.Register("wife", &ctrl.Options[*rei.Ctx]{
engine = rei.Register("wife", &ctrl.Options[*rei.Ctx]{
DisableOnDefault: false,
Help: "Hi NekoPachi!",
PrivateDataFolder: "wife",
}).ApplySingle(ReverseSingle)

ReverseSingle = rei.NewSingle(
rei.WithKeyFn(func(ctx *rei.Ctx) int64 {
switch msg := ctx.Value.(type) {
case *tgba.Message:
return msg.From.ID
case *tgba.CallbackQuery:
return msg.From.ID
}
return 0
}), rei.WithPostFn[int64](func(ctx *rei.Ctx) {
if !MessageTickerLimiter.Load(ctx.Message.Chat.ID).Acquire() {
return
}
_, _ = ctx.SendPlainMessage(false, "正在操作哦~")
}),
)
})
)

/*
Expand Down Expand Up @@ -162,6 +145,7 @@ func init() {
// command patterns
// marry @user
// in telegram, we should consider user more.
fmt.Print("")
getEntities := toolchain.ListEntitiesMention(ctx)
uid := ctx.Message.From.ID
if len(getEntities) == 0 {
Expand Down Expand Up @@ -233,7 +217,7 @@ func init() {
}
ResuitTheReferUserAndMakeIt(ctx, dict, fiancee, uid)
})
engine.OnMessageCommand("waifu").SetBlock(true).Handle(func(ctx *rei.Ctx) {
engine.OnMessageCommand("wife").SetBlock(true).Handle(func(ctx *rei.Ctx) {
/*
Work:
- Check the User Status, if the user is 1 or 0 || 10 ,then pause and do this handler.
Expand All @@ -245,6 +229,7 @@ func init() {
/*
TODO: HIDE MODE TYPE 6
*/
fmt.Print("start")
uid := ctx.Message.From.ID
gid := ctx.Message.Chat.ID
// Check if Disabled this group.
Expand Down Expand Up @@ -467,10 +452,11 @@ func init() {
ctx.SendPlainMessage(true, "本群貌似还没有人结婚来着(")
return
}
emojiRegex := regexp.MustCompile(`[\x{1F600}-\x{1F64F}|[\x{1F300}-\x{1F5FF}]|[\x{1F680}-\x{1F6FF}]|[\x{1F700}-\x{1F77F}]|[\x{1F780}-\x{1F7FF}]|[\x{1F800}-\x{1F8FF}]|[\x{1F900}-\x{1F9FF}]|[\x{1FA00}-\x{1FA6F}]|[\x{1FA70}-\x{1FAFF}]|[\x{1FB00}-\x{1FBFF}]|[\x{1F170}-\x{1F251}]|[\x{1F300}-\x{1F5FF}]|[\x{1F600}-\x{1F64F}]|[\x{1FC00}-\x{1FCFF}]|[\x{1F004}-\x{1F0CF}]|[\x{1F170}-\x{1F251}]]+`)
for i := 0; i < num; i++ {
getUserInt64, _ := strconv.ParseInt(getList[i][0], 10, 64)
getTargetInt64, _ := strconv.ParseInt(getList[i][1], 10, 64)
RawMsg += strconv.FormatInt(int64(i+1), 10) + ". " + toolchain.GetNickNameFromUserid(ctx, getUserInt64) + "( " + getList[i][0] + " )" + " --> " + toolchain.GetNickNameFromUserid(ctx, getTargetInt64) + "( " + getList[i][1] + " )" + "\n"
RawMsg += strconv.FormatInt(int64(i+1), 10) + ". " + emojiRegex.ReplaceAllString(toolchain.GetNickNameFromUserid(ctx, getUserInt64), "") + "( " + getList[i][0] + " )" + " --> " + emojiRegex.ReplaceAllString(toolchain.GetNickNameFromUserid(ctx, getTargetInt64), "") + "( " + getList[i][1] + " )" + "\n"
}
headerMsg := "群老婆列表~ For Group( " + strconv.FormatInt(gid, 10) + " )" + " [ " + ctx.Message.Chat.Title + " ]\n\n"
base64Font, err := text.RenderText(headerMsg+RawMsg+"\n\n Tips: 此列表将会在 23:00 PM (GMT+8) 重置", transform.ReturnLucyMainDataIndex("Font")+"regular-bold.ttf", 1920, 45)
Expand All @@ -480,7 +466,7 @@ func init() {
ctx.SendPlainMessage(true, "ERR: ", err)
return
}
ctx.Caller.Send(tgba.NewChatPhoto(gid, tgba.FileReader{Name: "waifu_" + strconv.FormatInt(gid, 10), Reader: bytes.NewReader(buf.Bytes())}))
ctx.SendPhoto(tgba.FileReader{Name: "waifu_" + strconv.FormatInt(gid, 10), Reader: bytes.NewReader(buf.Bytes())}, true, "")
})
engine.OnMessageCommand("waifuwish").SetBlock(true).Handle(func(ctx *rei.Ctx) {
getEntities := toolchain.ListEntitiesMention(ctx)
Expand Down
11 changes: 10 additions & 1 deletion plugin/wife/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"crypto/md5"
"encoding/hex"
"fmt"
"io"
"math/rand"
"net/http"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -131,7 +133,14 @@ func ReplyMeantMode(header string, referTarget int64, statusCodeToPerson int64,
aheader := msg + "\n今天你的群" + replyTarget + "是\n"
formatAvatar := GenerateUserImageLink(ctx, referTarget)
formatReply := "[ " + toolchain.GetNickNameFromUserid(ctx, referTarget) + " ] " + "( " + strconv.FormatInt(referTarget, 10) + " ) 哦w~"
ctx.SendPhoto(tgba.FileURL(formatAvatar), true, (aheader + formatReply))
datas, _ := http.Get(formatAvatar)
// avatar
// aheader+formatReply
data, err := io.ReadAll(datas.Body)
if err != nil {
panic(err)
}
ctx.SendPhoto(tgba.FileBytes{Bytes: data, Name: "IMAGE.png"}, true, aheader+formatReply)
}

// GenerateMD5 Generate MD5
Expand Down

0 comments on commit 225b966

Please sign in to comment.