diff --git a/data.go b/data.go new file mode 100644 index 0000000..7caca77 --- /dev/null +++ b/data.go @@ -0,0 +1,17 @@ +package main + +import ( + "fmt" +) + +func StoreCode(code string, location int64, member_id int) bool { + key := fmt.Sprintf("code:%d:%d", location, member_id) + + val_exists := db.Exists(key).Val() + db.Set(key, code, 0) + val := db.Get(code).Val() + + fmt.Println(val, val_exists) + + return false +} diff --git a/go.mod b/go.mod index 78c65bd..78e0b1f 100644 --- a/go.mod +++ b/go.mod @@ -6,8 +6,12 @@ require ( github.com/PuerkitoBio/goquery v1.8.1 // indirect github.com/andybalholm/cascadia v1.3.1 // indirect github.com/bwmarrin/discordgo v0.27.1 // indirect + github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect + github.com/go-redis/redis v6.15.9+incompatible // indirect github.com/gorilla/websocket v1.4.2 // indirect github.com/joho/godotenv v1.5.1 // indirect + github.com/redis/go-redis/v9 v9.3.0 // indirect golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect golang.org/x/net v0.7.0 // indirect golang.org/x/sys v0.5.0 // indirect diff --git a/go.sum b/go.sum index 9da07b4..37ef949 100644 --- a/go.sum +++ b/go.sum @@ -4,10 +4,20 @@ github.com/andybalholm/cascadia v1.3.1 h1:nhxRkql1kdYCc8Snf7D5/D3spOX+dBgjA6u8x0 github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA= github.com/bwmarrin/discordgo v0.27.1 h1:ib9AIc/dom1E/fSIulrBwnez0CToJE113ZGt4HoliGY= github.com/bwmarrin/discordgo v0.27.1/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY= +github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= +github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= +github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg= +github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +github.com/redis/go-redis v6.15.9+incompatible h1:F+tnlesQSl3h9V8DdmtcYFdvkHLhbb7AgcLW6UJxnC4= +github.com/redis/go-redis v6.15.9+incompatible/go.mod h1:ic6dLmR0d9rkHSzaa0Ab3QVRZcjopJ9hSSPCrecj/+s= +github.com/redis/go-redis/v9 v9.3.0 h1:RiVDjmig62jIWp7Kk4XVLs0hzV6pI3PyTnnL0cnn0u0= +github.com/redis/go-redis/v9 v9.3.0/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b h1:7mWr3k41Qtv8XlltBkDkl8LoP3mpSgBW8BUoxtEdbXg= diff --git a/main.go b/main.go index 7fb420a..d494c44 100644 --- a/main.go +++ b/main.go @@ -6,15 +6,18 @@ import ( "os/signal" "github.com/bwmarrin/discordgo" + "github.com/go-redis/redis" "github.com/joho/godotenv" ) var ( session *discordgo.Session - commandDefinitions = []*discordgo.ApplicationCommand{RegisterCommandDefinition} + commandDefinitions = []*discordgo.ApplicationCommand{RegisterCommandDefinition, CodeCommandDefinition} commandHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate){ "register": RegisterCommandHandler, + "code": CodeCommandHandler, } + db *redis.Client ) func main() { @@ -23,7 +26,19 @@ func main() { log.Fatal("Error loading .env file") } - session, err := discordgo.New("Bot " + os.Getenv("BOT_TOKEN")) + opt := &redis.Options{ + Addr: os.Getenv("REDIS_HOST"), + Password: os.Getenv("REDIS_PASSWORD"), + } + db = redis.NewClient(opt) + + ping_result, err := db.Ping().Result() + if err != nil { + log.Fatal(err) + } + log.Printf("Redis connection established (%s).", ping_result) + + session, err = discordgo.New("Bot " + os.Getenv("BOT_TOKEN")) if err != nil { log.Fatalf("Invalid bot parameters: %v", err) }