|
|
|
@ -18,6 +18,7 @@ import (
|
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
"github.com/bwmarrin/discordgo" |
|
|
|
|
"github.com/ryanuber/columnize" |
|
|
|
|
"github.com/unixvoid/glogger" |
|
|
|
|
"gopkg.in/gcfg.v1" |
|
|
|
|
"gopkg.in/redis.v5" |
|
|
|
@ -181,6 +182,8 @@ func staticCommandHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|
|
|
|
advancedHelpMsg(s, m) |
|
|
|
|
case "rng": |
|
|
|
|
rngHandler(s, m, redisClient) |
|
|
|
|
case "shop": |
|
|
|
|
shopHandler(s, m, redisClient) |
|
|
|
|
case "dubs": |
|
|
|
|
dubsHandler(s, m, redisClient) |
|
|
|
|
case "lunch": |
|
|
|
@ -297,6 +300,148 @@ func rngHandler(s *discordgo.Session, m *discordgo.MessageCreate, redisClient *r
|
|
|
|
|
s.ChannelMessageSend(m.ChannelID, rngMsg) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func shopHandler(s *discordgo.Session, m *discordgo.MessageCreate, redisClient *redis.Client) { |
|
|
|
|
// item settings
|
|
|
|
|
minCommon := 4 |
|
|
|
|
maxCommon := 6 |
|
|
|
|
minUncommon := 2 |
|
|
|
|
maxUncommon := 4 |
|
|
|
|
minRare := 1 |
|
|
|
|
maxRare := 3 |
|
|
|
|
minVeryRare := 0 |
|
|
|
|
maxVeryRare := 2 |
|
|
|
|
|
|
|
|
|
// initialize item table
|
|
|
|
|
var itemTable []string |
|
|
|
|
itemTable = append(itemTable, "Name | Rarity | Price | Type") |
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// commons:
|
|
|
|
|
//
|
|
|
|
|
// get common amount (rand.Intn(max - min) + min
|
|
|
|
|
rand.Seed(time.Now().UnixNano()) |
|
|
|
|
commons := rand.Intn(maxCommon-minCommon) + minCommon |
|
|
|
|
for n := 0; n < commons; n++ { |
|
|
|
|
// grab random item
|
|
|
|
|
command, err := loreQuery("index:dnd:common", redisClient) |
|
|
|
|
if err != nil { |
|
|
|
|
glogger.Error.Println(err) |
|
|
|
|
} |
|
|
|
|
// if the array is empty, exit early
|
|
|
|
|
if len(command) <= 0 { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
// pull random item
|
|
|
|
|
rand.Seed(time.Now().UnixNano()) |
|
|
|
|
rngItem := fmt.Sprint(command[rand.Intn(len(command))]) |
|
|
|
|
|
|
|
|
|
// get item details for shop message
|
|
|
|
|
rngItemName, _ := redisClient.HGet(rngItem, "name").Result() |
|
|
|
|
rngItemRarity, _ := redisClient.HGet(rngItem, "rarity").Result() |
|
|
|
|
rngItemPrice, _ := redisClient.HGet(rngItem, "price").Result() |
|
|
|
|
rngItemType, _ := redisClient.HGet(rngItem, "type").Result() |
|
|
|
|
|
|
|
|
|
// put together message
|
|
|
|
|
itemTable = append(itemTable, fmt.Sprintf("%s | %s | %s | %s", rngItemName, rngItemRarity, rngItemPrice, rngItemType)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// uncommons:
|
|
|
|
|
//
|
|
|
|
|
// get uncommon amount (rand.Intn(max - min) + min
|
|
|
|
|
rand.Seed(time.Now().UnixNano()) |
|
|
|
|
uncommons := rand.Intn(maxUncommon-minUncommon) + minUncommon |
|
|
|
|
for n := 0; n < uncommons; n++ { |
|
|
|
|
// grab random item
|
|
|
|
|
command, err := loreQuery("index:dnd:uncommon", redisClient) |
|
|
|
|
if err != nil { |
|
|
|
|
glogger.Error.Println(err) |
|
|
|
|
} |
|
|
|
|
// if the array is empty, exit early
|
|
|
|
|
if len(command) <= 0 { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
// pull random item
|
|
|
|
|
rand.Seed(time.Now().UnixNano()) |
|
|
|
|
rngItem := fmt.Sprint(command[rand.Intn(len(command))]) |
|
|
|
|
|
|
|
|
|
// get item details for shop message
|
|
|
|
|
rngItemName, _ := redisClient.HGet(rngItem, "name").Result() |
|
|
|
|
rngItemRarity, _ := redisClient.HGet(rngItem, "rarity").Result() |
|
|
|
|
rngItemPrice, _ := redisClient.HGet(rngItem, "price").Result() |
|
|
|
|
rngItemType, _ := redisClient.HGet(rngItem, "type").Result() |
|
|
|
|
|
|
|
|
|
// put together message
|
|
|
|
|
itemTable = append(itemTable, fmt.Sprintf("%s | %s | %s | %s", rngItemName, rngItemRarity, rngItemPrice, rngItemType)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// rare:
|
|
|
|
|
//
|
|
|
|
|
// get rare amount (rand.Intn(max - min) + min
|
|
|
|
|
rand.Seed(time.Now().UnixNano()) |
|
|
|
|
rare := rand.Intn(maxRare-minRare) + minRare |
|
|
|
|
for n := 0; n < rare; n++ { |
|
|
|
|
// grab random item
|
|
|
|
|
command, err := loreQuery("index:dnd:rare", redisClient) |
|
|
|
|
if err != nil { |
|
|
|
|
glogger.Error.Println(err) |
|
|
|
|
} |
|
|
|
|
// if the array is empty, exit early
|
|
|
|
|
if len(command) <= 0 { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
// pull random item
|
|
|
|
|
rand.Seed(time.Now().UnixNano()) |
|
|
|
|
rngItem := fmt.Sprint(command[rand.Intn(len(command))]) |
|
|
|
|
|
|
|
|
|
// get item details for shop message
|
|
|
|
|
rngItemName, _ := redisClient.HGet(rngItem, "name").Result() |
|
|
|
|
rngItemRarity, _ := redisClient.HGet(rngItem, "rarity").Result() |
|
|
|
|
rngItemPrice, _ := redisClient.HGet(rngItem, "price").Result() |
|
|
|
|
rngItemType, _ := redisClient.HGet(rngItem, "type").Result() |
|
|
|
|
|
|
|
|
|
// put together message
|
|
|
|
|
itemTable = append(itemTable, fmt.Sprintf("%s | %s | %s | %s", rngItemName, rngItemRarity, rngItemPrice, rngItemType)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// very rare:
|
|
|
|
|
//
|
|
|
|
|
// get very rare amount (rand.Intn(max - min) + min
|
|
|
|
|
rand.Seed(time.Now().UnixNano()) |
|
|
|
|
veryRare := rand.Intn(maxVeryRare-minVeryRare) + minVeryRare |
|
|
|
|
for n := 0; n < veryRare; n++ { |
|
|
|
|
// grab random item
|
|
|
|
|
command, err := loreQuery("index:dnd:very_rare", redisClient) |
|
|
|
|
if err != nil { |
|
|
|
|
glogger.Error.Println(err) |
|
|
|
|
} |
|
|
|
|
// if the array is empty, exit early
|
|
|
|
|
if len(command) <= 0 { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
// pull random item
|
|
|
|
|
rand.Seed(time.Now().UnixNano()) |
|
|
|
|
rngItem := fmt.Sprint(command[rand.Intn(len(command))]) |
|
|
|
|
|
|
|
|
|
// get item details for shop message
|
|
|
|
|
rngItemName, _ := redisClient.HGet(rngItem, "name").Result() |
|
|
|
|
rngItemRarity, _ := redisClient.HGet(rngItem, "rarity").Result() |
|
|
|
|
rngItemPrice, _ := redisClient.HGet(rngItem, "price").Result() |
|
|
|
|
rngItemType, _ := redisClient.HGet(rngItem, "type").Result() |
|
|
|
|
|
|
|
|
|
// put together message
|
|
|
|
|
itemTable = append(itemTable, fmt.Sprintf("%s | %s | %s | %s", rngItemName, rngItemRarity, rngItemPrice, rngItemType)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// put together formatted discord message
|
|
|
|
|
bigMsg := "```\n" |
|
|
|
|
bigMsg = bigMsg + columnize.SimpleFormat(itemTable) |
|
|
|
|
bigMsg = bigMsg + "\n```" |
|
|
|
|
s.ChannelMessageSend(m.ChannelID, bigMsg) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func dubsHandler(s *discordgo.Session, m *discordgo.MessageCreate, redisClient *redis.Client) { |
|
|
|
|
// aka index:command:added
|
|
|
|
|
newType := fmt.Sprintf("index:dubs") |
|
|
|
|