HIMBOT RETURNS
This commit is contained in:
@ -22,15 +22,6 @@ func BalanceGetCommand(s *discordgo.Session, i *discordgo.InteractionCreate) (st
|
||||
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) {
|
||||
entries, err := lib.GetLeaderboard(i.GuildID, 10)
|
||||
if err != nil {
|
||||
@ -51,48 +42,48 @@ func LeaderboardCommand(s *discordgo.Session, i *discordgo.InteractionCreate) (s
|
||||
}
|
||||
|
||||
func BalanceSendCommand(s *discordgo.Session, i *discordgo.InteractionCreate) (string, error) {
|
||||
options := i.ApplicationCommandData().Options
|
||||
|
||||
// Discord handles the user mention/tag and provides the correct user ID
|
||||
var recipientID string
|
||||
var amount int
|
||||
|
||||
for _, opt := range options {
|
||||
switch opt.Name {
|
||||
case "user":
|
||||
recipientID = opt.UserValue(nil).ID
|
||||
case "amount":
|
||||
amount = int(opt.IntValue())
|
||||
}
|
||||
}
|
||||
|
||||
// Validate amount
|
||||
if amount <= 0 {
|
||||
return "", fmt.Errorf("amount must be positive")
|
||||
}
|
||||
|
||||
// Get sender's info
|
||||
sender, err := lib.GetUser(i)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to get sender info: %w", err)
|
||||
}
|
||||
|
||||
// Don't allow sending to self
|
||||
if sender.ID == recipientID {
|
||||
return "", fmt.Errorf("you cannot send himbucks to yourself")
|
||||
}
|
||||
|
||||
// Get recipient's info
|
||||
recipient, err := s.User(recipientID)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to get recipient info: %w", err)
|
||||
}
|
||||
|
||||
// Send the himbucks
|
||||
err = lib.SendBalance(sender.ID, recipientID, i.GuildID, amount)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to send himbucks: %w", err)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("💸 Successfully sent %d Himbucks to %s! 💸", amount, recipient.Username), nil
|
||||
options := i.ApplicationCommandData().Options
|
||||
|
||||
// Discord handles the user mention/tag and provides the correct user ID
|
||||
var recipientID string
|
||||
var amount int
|
||||
|
||||
for _, opt := range options {
|
||||
switch opt.Name {
|
||||
case "user":
|
||||
recipientID = opt.UserValue(nil).ID
|
||||
case "amount":
|
||||
amount = int(opt.IntValue())
|
||||
}
|
||||
}
|
||||
|
||||
// Validate amount
|
||||
if amount <= 0 {
|
||||
return "", fmt.Errorf("amount must be positive")
|
||||
}
|
||||
|
||||
// Get sender's info
|
||||
sender, err := lib.GetUser(i)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to get sender info: %w", err)
|
||||
}
|
||||
|
||||
// Don't allow sending to self
|
||||
if sender.ID == recipientID {
|
||||
return "", fmt.Errorf("you cannot send himbucks to yourself")
|
||||
}
|
||||
|
||||
// Get recipient's info
|
||||
recipient, err := s.User(recipientID)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to get recipient info: %w", err)
|
||||
}
|
||||
|
||||
// Send the himbucks
|
||||
err = lib.SendBalance(sender.ID, recipientID, i.GuildID, amount)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to send himbucks: %w", err)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("💸 Successfully sent %d Himbucks to %s! 💸", amount, recipient.Username), nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user