Skip to content

Commit

Permalink
chore: mai update | secure addtions.
Browse files Browse the repository at this point in the history
  • Loading branch information
moyoez committed Mar 13, 2024
1 parent 452d4be commit afe822d
Show file tree
Hide file tree
Showing 5 changed files with 332 additions and 195 deletions.
52 changes: 51 additions & 1 deletion compounds/toolchain/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,59 @@
package toolchain

import "strings"
import (
"github.com/FloatTech/floatbox/file"
sql "github.com/FloatTech/sqlite"
"strconv"
"strings"
"sync"
"time"
)

type AdvancedUserList struct {
UserID int64 `json:"user_id"`
}

var (
dataBaseLocater = &sql.Sqlite{}
dataBaseLocker = sync.Mutex{}
)

func init() {
dataBaseLocater.DBPath = file.BOTPATH + "hosted/advanced.db"
err := dataBaseLocater.Open(time.Hour * 24)
if err != nil {
panic(err)
}

}

// SplitCommandTo Split Command and Adjust To.
func SplitCommandTo(raw string, setCommandStopper int) (splitCommandLen int, splitInfo []string) {
rawSplit := strings.SplitN(raw, " ", setCommandStopper)
return len(rawSplit), rawSplit
}

// IsAdvancedActionUser AdvancedUserPatherHere, to ensure user can locate
func IsAdvancedActionUser(uid int64) bool {
// check user list here.
dataBaseLocker.Lock()
defer dataBaseLocker.Unlock()
var dataFinder AdvancedUserList
dataBaseLocater.Find("userlist", &dataFinder, "Where user_id is "+strconv.FormatInt(uid, 10))
if dataFinder.UserID == 0 {
return false
}
return true
}

func RemoveUserList(uid int64) {
dataBaseLocker.Lock()
defer dataBaseLocker.Unlock()
dataBaseLocater.Del("userlist", "Where user_id is "+strconv.FormatInt(uid, 10))
}

func AddtionList(userID int64) {
dataBaseLocker.Lock()
defer dataBaseLocker.Unlock()
dataBaseLocater.Insert("userlist", &AdvancedUserList{UserID: userID})
}
1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func init() {
}
// 通过代码写死的方式添加主人账号
sus = append(sus, 1292581422)

config.W = []*driver.WSClient{driver.NewWebSocketClient(*url, *token)}
config.Z = zero.Config{
NickName: append([]string{*adana}, "Lucy", "lucy", "Lucy酱"),
Expand Down
16 changes: 8 additions & 8 deletions plugin/mai/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type AliasesReturnValue struct {
// only support LXNS because => if DivingFish then need Token.

// QueryReferSong use LocalStorageData.
func QueryReferSong(Alias string, isLxnet bool) (status bool, id []int, needAcc bool) {
func QueryReferSong(Alias string, isLxnet bool) (status bool, id []int, needAcc bool, accInfoList [][]int) {
// unpackedData
getData, err := os.ReadFile(engine.DataFolder() + "alias.json")
if err != nil {
Expand All @@ -40,11 +40,11 @@ func QueryReferSong(Alias string, isLxnet bool) (status bool, id []int, needAcc
if isLxnet {
for _, listhere := range onloadList[0] {
if listhere < 10000 {
return true, []int{listhere}, false
return true, []int{listhere}, false, nil
}
}
} else {
return true, onloadList[0], false
return true, onloadList[0], false, nil
}
// query length is 2,it means this maybe same name but diff id ==> (E.G: Oshama Scramble!)
case len(onloadList) == 2:
Expand All @@ -59,22 +59,22 @@ func QueryReferSong(Alias string, isLxnet bool) (status bool, id []int, needAcc
if isLxnet {
for _, listhere := range returnIntList {
if listhere < 10000 {
return true, []int{listhere}, false
return true, []int{listhere}, false, nil
}
}
} else {
return true, returnIntList, false
return true, returnIntList, false, nil
}
}
}
}
// if query is none, means it need moreacc
return true, nil, true
return true, nil, true, onloadList
case len(onloadList) >= 3:
return true, nil, true
return true, nil, true, onloadList
}
// no found.
return false, nil, false
return false, nil, false, nil
}

// UpdateAliasPackage Use simple action to update alias.
Expand Down
Loading

0 comments on commit afe822d

Please sign in to comment.