Skip to content

Commit

Permalink
chore: Upgrade to TELEGRAMV7 API
Browse files Browse the repository at this point in the history
  • Loading branch information
MoYoez committed Mar 11, 2024
1 parent 8cb13fd commit e2a086e
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 94 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "telegram-bot-api"]
path = telegram-bot-api
url = [email protected]:OvyFlash/telegram-bot-api.git
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,6 @@ replace modernc.org/sqlite => github.com/fumiama/sqlite3 v1.20.0-with-win386

replace github.com/remyoudompheng/bigfft => github.com/fumiama/bigfft v0.0.0-20211011143303-6e0bfa3c836b

replace github.com/fumiama/ReiBot => github.com/MoYoez/ReiBot v0.0.0-20240223162232-5c2ab46deccd
replace github.com/fumiama/ReiBot => github.com/MoYoez/ReiBot v0.0.0-20240311142840-76873b41aa4a

replace github.com/go-telegram-bot-api/telegram-bot-api/v5 => ./telegram-bot-api/
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b h1:tvciXWq2nuvTbFeJG
github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs=
github.com/FloatTech/zbpctrl v1.5.3-0.20230130095145-714ad318cd52 h1:BrStRXeosWh8L0iA/EjPd8w6xNexDkqki39ITZko/9Q=
github.com/FloatTech/zbpctrl v1.5.3-0.20230130095145-714ad318cd52/go.mod h1:qqMLUwR7tKpqnAqsgI7aZbn0hbs2FEVF4ylMXqIpBdY=
github.com/MoYoez/ReiBot v0.0.0-20240223162232-5c2ab46deccd h1:Od/aS1u2T17NFCoCveBFGCTbQEZTBqNV3omnTJF/0dY=
github.com/MoYoez/ReiBot v0.0.0-20240223162232-5c2ab46deccd/go.mod h1:+QH0VtJBX7SEHriFNmJldFJCcBqM51Abkt/PaMFw8FI=
github.com/MoYoez/ReiBot v0.0.0-20240311142840-76873b41aa4a h1:hVdKlkVTX2ta8BFo2xcH7wBuQVsVzzRNKUbZklyaeNI=
github.com/MoYoez/ReiBot v0.0.0-20240311142840-76873b41aa4a/go.mod h1:d8YGk5jIN2VyMMnMJg6edBt7I7yDhpTXSUELGuLxCCQ=
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e h1:wR3MXQ3VbUlPKOOUwLOYgh/QaJThBTYtsl673O3lqSA=
github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e/go.mod h1:vD7Ra3Q9onRtojoY5sMCLQ7JBgjUsrXDnDKyFxqpf9w=
Expand Down Expand Up @@ -53,8 +53,6 @@ github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 h1:wG8n/XJQ07TmjbITcGiUaOtXxdrINDz1b0J1w0SzqDc=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
Expand Down
19 changes: 19 additions & 0 deletions plugin/blocker/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package blocker

import (
ctrl "github.com/FloatTech/zbpctrl"
rei "github.com/fumiama/ReiBot"
)

var (
engine = rei.Register("blocker", &ctrl.Options[*rei.Ctx]{
DisableOnDefault: true,
Help: "block",
})
)

func init() {
engine.OnMessage().SetBlock(true).Handle(func(ctx *rei.Ctx) {

})
}
6 changes: 2 additions & 4 deletions plugin/mai/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ func init() {
return
}
// token is valid, get data.
// getIntID, _ := strconv.ParseInt(getMaiID.Userid, 10, 64)
// getFullData := GetMusicList(getIntID, 0, 600)
getFullData, err := web.GetData("https://maihook.lemonkoi.one/api/getMusicList?userid=" + getMaiID.Userid)
var unmashellData UserMusicListStruct

Check failure on line 158 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / lint

undefined: UserMusicListStruct (typecheck)
json.Unmarshal(getFullData, &unmashellData)
Expand Down Expand Up @@ -735,7 +733,7 @@ func MaimaiRenderBase(ctx *rei.Ctx, israw bool) {
if israw {
getDocumentType := &tgba.DocumentConfig{
BaseFile: tgba.BaseFile{BaseChat: tgba.BaseChat{
ChatID: ctx.Message.Chat.ID,
ChatConfig: tgba.ChatConfig{ChatID: ctx.Message.Chat.ID},
},
File: tgba.FilePath(engine.DataFolder() + "save/" + "LXNS_" + strconv.Itoa(int(getUserID)) + ".png")},
Caption: "",
Expand Down Expand Up @@ -765,7 +763,7 @@ func MaimaiRenderBase(ctx *rei.Ctx, israw bool) {
if israw {
getDocumentType := &tgba.DocumentConfig{
BaseFile: tgba.BaseFile{BaseChat: tgba.BaseChat{
ChatID: ctx.Message.Chat.ID,
ChatConfig: tgba.ChatConfig{ChatID: ctx.Message.Chat.ID},
},
File: tgba.FilePath(engine.DataFolder() + "save/" + strconv.Itoa(int(getUserID)) + ".png")},
Caption: "",
Expand Down
2 changes: 1 addition & 1 deletion plugin/slash/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func init() {
if getReply == "" {
return
}
ctx.Caller.Send(&tgba.MessageConfig{BaseChat: tgba.BaseChat{ChatID: ctx.Message.Chat.ID}, Text: getReply, ParseMode: "MarkdownV2", DisableWebPagePreview: true})
ctx.Caller.Send(&tgba.MessageConfig{BaseChat: tgba.BaseChat{ChatConfig: tgba.ChatConfig{ChatID: ctx.Message.Chat.ID}}, Text: getReply, ParseMode: "MarkdownV2", LinkPreviewOptions: tgba.LinkPreviewOptions{IsDisabled: true}})
})

}
Expand Down
2 changes: 1 addition & 1 deletion plugin/stickers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func init() {
if err != nil {
return
}
ctx.Caller.Request(tgba.StickerConfig{BaseFile: tgba.BaseFile{BaseChat: tgba.BaseChat{ChatID: ctx.Message.Chat.ID}, File: tgba.FileID(getStickerPack.Stickers[rand.Intn(len(getStickerPack.Stickers))].FileID)}})
ctx.Caller.Request(tgba.StickerConfig{BaseFile: tgba.BaseFile{BaseChat: tgba.BaseChat{ChatConfig: tgba.ChatConfig{ChatID: ctx.Message.Chat.ID}}, File: tgba.FileID(getStickerPack.Stickers[rand.Intn(len(getStickerPack.Stickers))].FileID)}})
}

})
Expand Down
4 changes: 2 additions & 2 deletions plugin/tools/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"strings"
"time"

ctrl "github.com/FloatTech/zbpctrl"
"github.com/MoYoez/Lucy_reibot/utils/toolchain"
"github.com/MoYoez/Lucy_reibot/utils/userpackage"
ctrl "github.com/FloatTech/zbpctrl"
rei "github.com/fumiama/ReiBot"
tgba "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/shirou/gopsutil/cpu"
Expand All @@ -36,7 +36,7 @@ func init() {
} else {
gid = ctx.Message.Chat.ID
}
_, _ = ctx.Caller.Send(&tgba.LeaveChatConfig{ChatID: gid})
_, _ = ctx.Caller.Send(&tgba.LeaveChatConfig{ChatConfig: tgba.ChatConfig{ChatID: gid}})
})
engine.OnMessageCommand("status").SetBlock(true).Handle(func(ctx *rei.Ctx) {
ctx.SendPlainMessage(false, "* Hosted On Azure JP Cloud.\n",
Expand Down
144 changes: 72 additions & 72 deletions plugin/tracemoe/moe.go
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
// Package tracemoe 搜番
package tracemoe

import (
"fmt"
"strconv"

rei "github.com/fumiama/ReiBot"
tgba "github.com/go-telegram-bot-api/telegram-bot-api/v5"

trmoe "github.com/fumiama/gotracemoe"

"github.com/FloatTech/floatbox/binary"
ctrl "github.com/FloatTech/zbpctrl"
)

var (
moe = trmoe.NewMoe("")
)

func init() { // 插件主体
engine := rei.Register("tracemoe", &ctrl.Options[*rei.Ctx]{
DisableOnDefault: false,
Help: "tracemoe\n- 搜番 | 搜索番剧[图片]",
})
// 以图搜图
engine.OnMessageCommand("tracemoe", rei.MustProvidePhoto("请发送一张图片", "获取图片失败!")).SetBlock(true).
Handle(func(ctx *rei.Ctx) {
// 开始搜索图片
_, _ = ctx.SendPlainMessage(false, "少女祈祷中...")
ps := ctx.State["photos"].([]tgba.PhotoSize)
pic := ps[len(ps)-1]
picu, err := ctx.Caller.GetFileDirectURL(pic.FileID)
if err != nil {
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
return
}
if result, err := moe.Search(picu, true, true); err != nil {
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
} else if len(result.Result) > 0 {
r := result.Result[0]
hint := "我有把握是这个!"
if r.Similarity < 80 {
hint = "大概是这个?"
}
mf := int(r.From / 60)
mt := int(r.To / 60)
sf := r.From - float32(mf*60)
st := r.To - float32(mt*60)
_, _ = ctx.Caller.Send(&tgba.PhotoConfig{
BaseFile: tgba.BaseFile{
BaseChat: tgba.BaseChat{
ChatID: ctx.Message.Chat.ID,
ReplyToMessageID: ctx.Event.Value.(*tgba.Message).MessageID,
},
File: tgba.FileURL(r.Image),
},
Caption: binary.BytesToString(binary.NewWriterF(func(m *binary.Writer) {
m.WriteString(hint)
_ = m.WriteByte('\n')
m.WriteString("番剧名: ")
m.WriteString(r.Anilist.Title.Native)
_ = m.WriteByte('\n')
m.WriteString("话数: ")
m.WriteString(strconv.Itoa(r.Episode))
_ = m.WriteByte('\n')
m.WriteString(fmt.Sprint("时间:", mf, ":", sf, "-", mt, ":", st))
})),
})
}
})
}
// Package tracemoe 搜番
package tracemoe

import (
"fmt"
"strconv"

rei "github.com/fumiama/ReiBot"
tgba "github.com/go-telegram-bot-api/telegram-bot-api/v5"

trmoe "github.com/fumiama/gotracemoe"

"github.com/FloatTech/floatbox/binary"
ctrl "github.com/FloatTech/zbpctrl"
)

var (
moe = trmoe.NewMoe("")
)

func init() { // 插件主体
engine := rei.Register("tracemoe", &ctrl.Options[*rei.Ctx]{
DisableOnDefault: false,
Help: "tracemoe\n- 搜番 | 搜索番剧[图片]",
})
// 以图搜图
engine.OnMessageCommand("tracemoe", rei.MustProvidePhoto("请发送一张图片", "获取图片失败!")).SetBlock(true).
Handle(func(ctx *rei.Ctx) {
// 开始搜索图片
_, _ = ctx.SendPlainMessage(false, "少女祈祷中...")
ps := ctx.State["photos"].([]tgba.PhotoSize)
pic := ps[len(ps)-1]
picu, err := ctx.Caller.GetFileDirectURL(pic.FileID)
if err != nil {
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
return
}
if result, err := moe.Search(picu, true, true); err != nil {
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
} else if len(result.Result) > 0 {
r := result.Result[0]
hint := "我有把握是这个!"
if r.Similarity < 80 {
hint = "大概是这个?"
}
mf := int(r.From / 60)
mt := int(r.To / 60)
sf := r.From - float32(mf*60)
st := r.To - float32(mt*60)
_, _ = ctx.Caller.Send(&tgba.PhotoConfig{
BaseFile: tgba.BaseFile{
BaseChat: tgba.BaseChat{
ChatConfig: tgba.ChatConfig{ChatID: ctx.Message.Chat.ID},
ReplyParameters: tgba.ReplyParameters{MessageID: ctx.Event.Value.(*tgba.Message).MessageID},
},
File: tgba.FileURL(r.Image),
},
Caption: binary.BytesToString(binary.NewWriterF(func(m *binary.Writer) {
m.WriteString(hint)
_ = m.WriteByte('\n')
m.WriteString("番剧名: ")
m.WriteString(r.Anilist.Title.Native)
_ = m.WriteByte('\n')
m.WriteString("话数: ")
m.WriteString(strconv.Itoa(r.Episode))
_ = m.WriteByte('\n')
m.WriteString(fmt.Sprint("时间:", mf, ":", sf, "-", mt, ":", st))
})),
})
}
})
}
8 changes: 4 additions & 4 deletions plugin/wife/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
"strings"
"time"

"github.com/MoYoez/Lucy_reibot/utils/toolchain"
"github.com/MoYoez/Lucy_reibot/utils/userlist"
fcext "github.com/FloatTech/floatbox/ctxext"
sql "github.com/FloatTech/sqlite"
"github.com/MoYoez/Lucy_reibot/utils/toolchain"
"github.com/MoYoez/Lucy_reibot/utils/userlist"
rei "github.com/fumiama/ReiBot"
tgba "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/wdvxdr1123/ZeroBot/extension/rate"
Expand Down Expand Up @@ -157,15 +157,15 @@ func ReplyMeantMode(header string, referTarget int64, statusCodeToPerson int64,
if err != nil {
ctx.Caller.Send(&tgba.MessageConfig{
BaseChat: tgba.BaseChat{
ChatID: ctx.Message.Chat.ID,
ChatConfig: tgba.ChatConfig{ChatID: ctx.Message.Chat.ID},
},
Text: aheader,
ParseMode: tgba.ModeMarkdownV2,
})
return
}
data, _ := io.ReadAll(datas.Body)
ctx.Caller.Send(&tgba.PhotoConfig{BaseFile: tgba.BaseFile{BaseChat: tgba.BaseChat{ChatID: ctx.Message.Chat.ID}, File: tgba.FileBytes{Bytes: data, Name: "IMAGE.png"}}, Caption: aheader, ParseMode: tgba.ModeMarkdownV2})
ctx.Caller.Send(&tgba.PhotoConfig{BaseFile: tgba.BaseFile{BaseChat: tgba.BaseChat{ChatConfig: tgba.ChatConfig{ChatID: ctx.Message.Chat.ID}}, File: tgba.FileBytes{Bytes: data, Name: "IMAGE.png"}}, Caption: aheader, ParseMode: tgba.ModeMarkdownV2})
}

// GenerateMD5 Generate MD5
Expand Down
1 change: 1 addition & 0 deletions telegram-bot-api
Submodule telegram-bot-api added at eced2e
10 changes: 5 additions & 5 deletions utils/toolchain/toolchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ func GetBotIsAdminInThisGroup(ctx *rei.Ctx) bool {
getSelfMember, err := ctx.Caller.GetChatMember(
tgba.GetChatMemberConfig{
ChatConfigWithUser: tgba.ChatConfigWithUser{
ChatID: ctx.Message.Chat.ID,
UserID: ctx.Caller.Self.ID,
ChatConfig: tgba.ChatConfig{ChatID: ctx.Message.Chat.ID},
UserID: ctx.Caller.Self.ID,
},
},
)
Expand Down Expand Up @@ -284,8 +284,8 @@ func CheckIfthisUserInThisGroup(userID int64, ctx *rei.Ctx) bool {
getResult, err := ctx.Caller.GetChatMember(
tgba.GetChatMemberConfig{
ChatConfigWithUser: tgba.ChatConfigWithUser{
ChatID: group,
UserID: userID,
ChatConfig: tgba.ChatConfig{ChatID: group},
UserID: userID,
},
},
)
Expand Down Expand Up @@ -336,7 +336,7 @@ func GetUserNickNameByIDInGroup(ctx *rei.Ctx, id int64) string {
if !CheckIfthisUserInThisGroup(id, ctx) {
return ""
}
chatPrefer, err := ctx.Caller.GetChatMember(tgba.GetChatMemberConfig{ChatConfigWithUser: tgba.ChatConfigWithUser{ChatID: ctx.Message.Chat.ID, UserID: id}})
chatPrefer, err := ctx.Caller.GetChatMember(tgba.GetChatMemberConfig{ChatConfigWithUser: tgba.ChatConfigWithUser{ChatConfig: tgba.ChatConfig{ChatID: ctx.Message.Chat.ID}, UserID: id}})
if err != nil {
panic(err)
}
Expand Down

0 comments on commit e2a086e

Please sign in to comment.