mirror of
https://github.com/elyby/chrly.git
synced 2025-05-31 14:11:51 +05:30
Проект разбит на более мелкие части
This commit is contained in:
48
lib/tools/tools.go
Normal file
48
lib/tools/tools.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
"crypto/md5"
|
||||
"strconv"
|
||||
"encoding/hex"
|
||||
"elyby/minecraft-skinsystem/lib/structures"
|
||||
"elyby/minecraft-skinsystem/lib/services"
|
||||
"encoding/json"
|
||||
"log"
|
||||
)
|
||||
|
||||
func ParseUsername(username string) string {
|
||||
const suffix = ".png"
|
||||
if strings.HasSuffix(username, suffix) {
|
||||
username = strings.TrimSuffix(username, suffix)
|
||||
}
|
||||
|
||||
return username
|
||||
}
|
||||
|
||||
func BuildNonElyTexturesHash(username string) string {
|
||||
n := time.Now()
|
||||
hour := time.Date(n.Year(), n.Month(), n.Day(), n.Hour(), 0, 0, 0, time.UTC).Unix()
|
||||
hasher := md5.New()
|
||||
hasher.Write([]byte("non-ely-" + strconv.FormatInt(hour, 10) + "-" + username))
|
||||
|
||||
return hex.EncodeToString(hasher.Sum(nil))
|
||||
}
|
||||
|
||||
func FindRecord(username string) (structures.SkinItem, error) {
|
||||
var record structures.SkinItem;
|
||||
result, err := services.Redis.Cmd("GET", BuildKey(username)).Str();
|
||||
if (err == nil) {
|
||||
decodeErr := json.Unmarshal([]byte(result), &record)
|
||||
if (decodeErr != nil) {
|
||||
log.Println("Cannot decode record data")
|
||||
}
|
||||
}
|
||||
|
||||
return record, err
|
||||
}
|
||||
|
||||
func BuildKey(username string) string {
|
||||
return "username:" + strings.ToLower(username)
|
||||
}
|
Reference in New Issue
Block a user