feat: upgrade to new version go-mc
This commit is contained in:
@@ -1,52 +1,53 @@
|
||||
package mc
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"tg-mc/models"
|
||||
"time"
|
||||
)
|
||||
// import (
|
||||
// "sync"
|
||||
// "tg-mc/models"
|
||||
// "time"
|
||||
// )
|
||||
|
||||
type Auth interface {
|
||||
IsAuthed(u models.User, expireMode bool) bool
|
||||
Auth(u models.User)
|
||||
Reject(u models.User)
|
||||
}
|
||||
// type Auth interface {
|
||||
// IsAuthed(u models.User, expireMode bool) bool
|
||||
// Auth(u models.User)
|
||||
// Reject(u models.User)
|
||||
// }
|
||||
|
||||
type Authcator struct {
|
||||
UserMap *sync.Map
|
||||
}
|
||||
// type Authcator struct {
|
||||
// UserMap *sync.Map
|
||||
// }
|
||||
|
||||
var authcator *Authcator
|
||||
// var authcator *Authcator
|
||||
|
||||
func GetAuthcator() Auth {
|
||||
if authcator == nil {
|
||||
authcator = &Authcator{
|
||||
UserMap: &sync.Map{},
|
||||
}
|
||||
}
|
||||
return authcator
|
||||
}
|
||||
// func GetAuthcator() Auth {
|
||||
// if authcator == nil {
|
||||
// authcator = &Authcator{
|
||||
// UserMap: &sync.Map{},
|
||||
// }
|
||||
// }
|
||||
// return authcator
|
||||
// }
|
||||
|
||||
func (a *Authcator) IsAuthed(u models.User, expireMode bool) bool {
|
||||
// if u.MCName != "VaalaCat" {
|
||||
// return true
|
||||
// }
|
||||
if approveTime, ok := a.UserMap.Load(u.MCName); ok {
|
||||
if !expireMode {
|
||||
return true
|
||||
} else if time.Since(approveTime.(time.Time)) < 30*time.Second {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
// func (a *Authcator) IsAuthed(u models.User, expireMode bool) bool {
|
||||
// return true
|
||||
// // if u.MCName != "VaalaCat" {
|
||||
// // return true
|
||||
// // }
|
||||
// if approveTime, ok := a.UserMap.Load(u.MCName); ok {
|
||||
// if !expireMode {
|
||||
// return true
|
||||
// } else if time.Since(approveTime.(time.Time)) < 30*time.Second {
|
||||
// return true
|
||||
// } else {
|
||||
// return false
|
||||
// }
|
||||
// }
|
||||
// return false
|
||||
// }
|
||||
|
||||
func (a *Authcator) Auth(u models.User) {
|
||||
a.UserMap.Store(u.MCName, time.Now())
|
||||
}
|
||||
// func (a *Authcator) Auth(u models.User) {
|
||||
// a.UserMap.Store(u.MCName, time.Now())
|
||||
// }
|
||||
|
||||
func (a *Authcator) Reject(u models.User) {
|
||||
a.UserMap.Delete(u.MCName)
|
||||
}
|
||||
// func (a *Authcator) Reject(u models.User) {
|
||||
// a.UserMap.Delete(u.MCName)
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user