Fix
This commit is contained in:
parent
46c24134d5
commit
ce580e77fd
3 changed files with 27 additions and 8 deletions
|
@ -22,6 +22,15 @@ func BalanceCommand(s *discordgo.Session, i *discordgo.InteractionCreate) (strin
|
||||||
return fmt.Sprintf("💸 You have %d himbucks! 💸", balance), nil
|
return fmt.Sprintf("💸 You have %d himbucks! 💸", balance), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BalanceSyncCommand(s *discordgo.Session, i *discordgo.InteractionCreate) (string, error) {
|
||||||
|
syncError := lib.SyncBalance()
|
||||||
|
if syncError != nil {
|
||||||
|
return "", syncError
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("💸 Force-Synchronized Himbucks! 💸"), nil
|
||||||
|
}
|
||||||
|
|
||||||
func LeaderboardCommand(s *discordgo.Session, i *discordgo.InteractionCreate) (string, error) {
|
func LeaderboardCommand(s *discordgo.Session, i *discordgo.InteractionCreate) (string, error) {
|
||||||
entries, err := lib.GetLeaderboard(i.GuildID, 10)
|
entries, err := lib.GetLeaderboard(i.GuildID, 10)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -114,12 +114,6 @@ func ProcessMessage(s *discordgo.Session, m *discordgo.MessageCreate) error {
|
||||||
func GetBalance(discordID, guildID string) (int, error) {
|
func GetBalance(discordID, guildID string) (int, error) {
|
||||||
var balance int
|
var balance int
|
||||||
|
|
||||||
_, syncError := DBConnector.Sync()
|
|
||||||
|
|
||||||
if syncError != nil {
|
|
||||||
fmt.Println("Error syncing database:", syncError)
|
|
||||||
}
|
|
||||||
|
|
||||||
queryError := DBClient.QueryRow(`
|
queryError := DBClient.QueryRow(`
|
||||||
SELECT h.balance
|
SELECT h.balance
|
||||||
FROM himbucks h
|
FROM himbucks h
|
||||||
|
@ -135,6 +129,17 @@ func GetBalance(discordID, guildID string) (int, error) {
|
||||||
return balance, nil
|
return balance, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SyncBalance() error {
|
||||||
|
_, syncError := DBConnector.Sync()
|
||||||
|
|
||||||
|
if syncError != nil {
|
||||||
|
fmt.Println("Error syncing database:", syncError)
|
||||||
|
return syncError
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func GetLeaderboard(guildID string, limit int) ([]HimbucksEntry, error) {
|
func GetLeaderboard(guildID string, limit int) ([]HimbucksEntry, error) {
|
||||||
rows, err := DBClient.Query(`
|
rows, err := DBClient.Query(`
|
||||||
SELECT u.username, h.balance, h.message_count
|
SELECT u.username, h.balance, h.message_count
|
||||||
|
|
9
main.go
9
main.go
|
@ -44,13 +44,17 @@ var (
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "balance",
|
Name: "himbucks",
|
||||||
Description: "Check your himbucks balance",
|
Description: "Check your himbucks balance",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "leaderboard",
|
Name: "himboard",
|
||||||
Description: "View the himbucks leaderboard",
|
Description: "View the himbucks leaderboard",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "syncbucks",
|
||||||
|
Description: "Sync your himbucks balance with the database",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
commandHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate){
|
commandHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate){
|
||||||
|
@ -59,6 +63,7 @@ var (
|
||||||
"markov": lib.HandleCommand("markov", 30*time.Second, command.MarkovCommand),
|
"markov": lib.HandleCommand("markov", 30*time.Second, command.MarkovCommand),
|
||||||
"balance": lib.HandleCommand("balance", 5*time.Second, command.BalanceCommand),
|
"balance": lib.HandleCommand("balance", 5*time.Second, command.BalanceCommand),
|
||||||
"leaderboard": lib.HandleCommand("leaderboard", 5*time.Second, command.LeaderboardCommand),
|
"leaderboard": lib.HandleCommand("leaderboard", 5*time.Second, command.LeaderboardCommand),
|
||||||
|
"syncbucks": lib.HandleCommand("syncbucks", 1800*time.Second, command.BalanceSyncCommand),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue