Skip to content
This repository has been archived by the owner on Feb 8, 2025. It is now read-only.

Commit

Permalink
feat: add maimai unlocker
Browse files Browse the repository at this point in the history
  • Loading branch information
MoYoez committed Dec 24, 2023
1 parent 1c5c6dd commit 56589cc
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
4 changes: 4 additions & 0 deletions plugin/mai/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 关于此文档缺少依赖库说明


此部分对华立的 Request Hook 库 删除了 Push || 所以此 项目中不存在 Hook 依赖。
25 changes: 25 additions & 0 deletions plugin/mai/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,31 @@ func init() {
return
}
BindUserToMaimai(ctx, getSplitStringList[2])
case getSplitStringList[1] == "userbind":
if getSplitLength < 3 {
ctx.SendPlainMessage(true, "参数提供不足, /mai userbind <maiTempID> ")
return
}
getID, _ := toolchain.GetChatUserInfoID(ctx)
userID := GetUserMaiUserid(getSplitStringList[2])

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

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, 386)

undefined: GetUserMaiUserid

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

View workflow job for this annotation

GitHub Actions / lint

undefined: GetUserMaiUserid

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

View workflow job for this annotation

GitHub Actions / lint

undefined: GetUserMaiUserid

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

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, amd64)

undefined: GetUserMaiUserid

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

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, arm)

undefined: GetUserMaiUserid

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

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, arm64)

undefined: GetUserMaiUserid

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

View workflow job for this annotation

GitHub Actions / Build binary CI (windows, 386)

undefined: GetUserMaiUserid

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

View workflow job for this annotation

GitHub Actions / Build binary CI (windows, amd64)

undefined: GetUserMaiUserid
if userID == -1 {
ctx.SendPlainMessage(true, "ID 无效或者是过期 ,请使用新的ID或者再次尝试")
return
}
FormatUserIDDatabase(getID, strconv.FormatInt(userID, 10)).BindUserIDDataBase()
case getSplitStringList[1] == "unlock":
getID, _ := toolchain.GetChatUserInfoID(ctx)
getMaiID := GetUserIDFromDatabase(getID)
if getMaiID.Userid == "" {
ctx.SendPlainMessage(true, "没有绑定~ 绑定方式: /mai userbind <maiTempID>")
return
}
getCode := FastUnlockerMai15mins(getMaiID.Userid)

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

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, 386)

undefined: FastUnlockerMai15mins

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

View workflow job for this annotation

GitHub Actions / lint

undefined: FastUnlockerMai15mins

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

View workflow job for this annotation

GitHub Actions / lint

undefined: FastUnlockerMai15mins

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

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, amd64)

undefined: FastUnlockerMai15mins

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

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, arm)

undefined: FastUnlockerMai15mins

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

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, arm64)

undefined: FastUnlockerMai15mins

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

View workflow job for this annotation

GitHub Actions / Build binary CI (windows, 386)

undefined: FastUnlockerMai15mins

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

View workflow job for this annotation

GitHub Actions / Build binary CI (windows, amd64)

undefined: FastUnlockerMai15mins
if getCode == 200 {
ctx.SendPlainMessage(true, "发信成功,如果未生效请重新尝试")
} else {
ctx.SendPlainMessage(true, "发信失败,如果未生效请重新尝试")
}
case getSplitStringList[1] == "plate":
if getSplitLength < 3 {
ctx.SendPlainMessage(true, "参数提供不足")
Expand Down
33 changes: 32 additions & 1 deletion plugin/mai/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ type DataHostSQL struct {
Background string `db:"bg"` // bg
}

// UserIDToQQ TIPS: Onebot path, actually it refers to Telegram Userid.

type UserIDToQQ struct {
QQ int64 `db:"user_qq"` // qq nums
Userid string `db:"user_id"` // user_id
}

var (
maiDatabase = &sql.Sqlite{}
maiLocker = sync.Mutex{}
Expand All @@ -33,12 +40,36 @@ func FormatUserDataBase(tgid int64, plate string, bg string, username string) *D
return &DataHostSQL{TelegramId: tgid, Plate: plate, Background: bg, Username: username}
}

func FormatUserIDDatabase(qq int64, userid string) *UserIDToQQ {
return &UserIDToQQ{QQ: qq, Userid: userid}
}

func InitDataBase() error {
maiLocker.Lock()
defer maiLocker.Unlock()
return maiDatabase.Create("userinfo", &DataHostSQL{})
maiDatabase.Create("userinfo", &DataHostSQL{})
maiDatabase.Create("useridinfo", &UserIDToQQ{})
return nil
}

// GetUserIDFromDatabase Params: user qq id ==> user maimai id.
func GetUserIDFromDatabase(userID int64) UserIDToQQ {
maiLocker.Lock()
defer maiLocker.Unlock()
var infosql UserIDToQQ
userIDStr := strconv.FormatInt(userID, 10)
_ = maiDatabase.Find("useridinfo", &infosql, "where user_qq is "+userIDStr)
return infosql
}

func (info *UserIDToQQ) BindUserIDDataBase() error {
maiLocker.Lock()
defer maiLocker.Unlock()
return maiDatabase.Insert("useridinfo", info)
}

// maimai origin render base.

// GetUserPlateInfoFromDatabase Get plate data
func GetUserPlateInfoFromDatabase(userID int64) string {
maiLocker.Lock()
Expand Down

0 comments on commit 56589cc

Please sign in to comment.