-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: mai update | secure addtions.
- Loading branch information
moyoez
committed
Mar 13, 2024
1 parent
452d4be
commit afe822d
Showing
5 changed files
with
332 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.