mirror of
https://github.com/Xevion/r2park.git
synced 2025-12-06 03:16:05 -06:00
docs, provide genuine existence return for GetCode getter func
This commit is contained in:
@@ -204,9 +204,9 @@ func RegisterCommandHandler(session *discordgo.Session, interaction *discordgo.I
|
|||||||
if !guestCodeProvided && guestCodeCondition == GuestCodeNotRequired {
|
if !guestCodeProvided && guestCodeCondition == GuestCodeNotRequired {
|
||||||
// A guest code could be stored, so check for it.
|
// A guest code could be stored, so check for it.
|
||||||
log.WithField("location", locationId).Debug("No guest code provided for location, but one is not required. Checking for stored code.")
|
log.WithField("location", locationId).Debug("No guest code provided for location, but one is not required. Checking for stored code.")
|
||||||
code = GetCode(int64(locationId), int(userId))
|
code, ok := GetCode(int64(locationId), int(userId))
|
||||||
|
|
||||||
if code == "" {
|
if !ok {
|
||||||
// No code was stored, error out.
|
// No code was stored, error out.
|
||||||
HandleError(session, interaction, nil, ":x: This location requires a guest code.")
|
HandleError(session, interaction, nil, ":x: This location requires a guest code.")
|
||||||
return
|
return
|
||||||
|
|||||||
10
data.go
10
data.go
@@ -2,6 +2,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/go-redis/redis"
|
||||||
)
|
)
|
||||||
|
|
||||||
// LocationExists checks if a location identifier is valid (as known by the cache).
|
// LocationExists checks if a location identifier is valid (as known by the cache).
|
||||||
@@ -11,6 +13,7 @@ func LocationExists(location int64) bool {
|
|||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StoreCode stores a guest code for a given location and member ID.
|
||||||
func StoreCode(code string, location int64, member_id int) bool {
|
func StoreCode(code string, location int64, member_id int) bool {
|
||||||
key := fmt.Sprintf("code:%d:%d", location, member_id)
|
key := fmt.Sprintf("code:%d:%d", location, member_id)
|
||||||
already_set := db.Exists(key).Val() == 1
|
already_set := db.Exists(key).Val() == 1
|
||||||
@@ -19,11 +22,14 @@ func StoreCode(code string, location int64, member_id int) bool {
|
|||||||
return already_set
|
return already_set
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCode(location int64, member_id int) string {
|
// GetCode returns the guest code for a given location and member ID.
|
||||||
|
func GetCode(location int64, member_id int) (string, bool) {
|
||||||
key := fmt.Sprintf("code:%d:%d", location, member_id)
|
key := fmt.Sprintf("code:%d:%d", location, member_id)
|
||||||
return db.Get(key).Val()
|
result := db.Get(key)
|
||||||
|
return result.Val(), result.Err() == redis.Nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RemoveCode removes a guest code for a given location and member ID.
|
||||||
func RemoveCode(location int64, member_id int) {
|
func RemoveCode(location int64, member_id int) {
|
||||||
key := fmt.Sprintf("code:%d:%d", location, member_id)
|
key := fmt.Sprintf("code:%d:%d", location, member_id)
|
||||||
db.Del(key)
|
db.Del(key)
|
||||||
|
|||||||
Reference in New Issue
Block a user