This commit is contained in:
@@ -87,3 +87,61 @@ func BalanceSendCommand(s *discordgo.Session, i *discordgo.InteractionCreate) (s
|
||||
|
||||
return fmt.Sprintf("💸 Successfully sent %d Himbucks to %s! 💸", amount, recipient.Username), nil
|
||||
}
|
||||
|
||||
func GiveCommand(s *discordgo.Session, i *discordgo.InteractionCreate) (string, error) {
|
||||
if !isAdmin(i.Member.User.ID) {
|
||||
s.InteractionResponseDelete(i.Interaction)
|
||||
|
||||
s.FollowupMessageCreate(i.Interaction, true, &discordgo.WebhookParams{
|
||||
Content: "You do not have permission to use this command.",
|
||||
Flags: discordgo.MessageFlagsEphemeral,
|
||||
})
|
||||
|
||||
return "", nil
|
||||
}
|
||||
|
||||
options := i.ApplicationCommandData().Options
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
recipient, err := s.User(recipientID)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to get recipient info: %w", err)
|
||||
}
|
||||
|
||||
_, err = lib.GetOrCreateUserWithGuild(recipientID, recipient.Username, i.GuildID)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to initialize recipient profile: %w", err)
|
||||
}
|
||||
|
||||
err = lib.GiveHimbucks(recipientID, i.GuildID, amount)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to give himbucks: %w", err)
|
||||
}
|
||||
|
||||
action := "given to"
|
||||
if amount < 0 {
|
||||
action = "taken from"
|
||||
amount = -amount
|
||||
}
|
||||
|
||||
return fmt.Sprintf("✅ Successfully %s %s %d Himbucks.", action, recipient.Username, amount), nil
|
||||
}
|
||||
|
||||
func isAdmin(userID string) bool {
|
||||
for _, adminID := range lib.AppConfig.AdminIDs {
|
||||
if userID == adminID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
59
command/shop.go
Normal file
59
command/shop.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"himbot/lib"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
func ShopCommand(s *discordgo.Session, i *discordgo.InteractionCreate) (string, error) {
|
||||
options := i.ApplicationCommandData().Options
|
||||
|
||||
if len(options) == 0 {
|
||||
return "Welcome to the Himbucks Shop! Use `/shop buy` to purchase items.", nil
|
||||
}
|
||||
|
||||
if options[0].Name == "buy" {
|
||||
subOptions := options[0].Options
|
||||
if len(subOptions) == 0 {
|
||||
return "Please specify an item to buy.", nil
|
||||
}
|
||||
|
||||
item := subOptions[0].StringValue()
|
||||
user, err := lib.GetUser(i)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
switch item {
|
||||
case "pizza":
|
||||
cost, newBalance, err := lib.BuyPizza(user.ID, i.GuildID)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("❌ %s", err.Error()), nil
|
||||
}
|
||||
return fmt.Sprintf("Here is your pizza, %s!\n**Cost:** %d himbucks\n**Remaining Balance:** %d himbucks\n```\n%s\n```", user.Username, cost, newBalance, getPizzaArt()), nil
|
||||
|
||||
case "multiplier":
|
||||
newMult, cost, newBalance, err := lib.BuyMultiplier(user.ID, i.GuildID)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("❌ %s", err.Error()), nil
|
||||
}
|
||||
return fmt.Sprintf("Multiplier upgraded!\nYou spent **%d** himbucks.\nYour new earning multiplier is **%.1fx**!\n**Remaining Balance:** %d himbucks", cost, newMult, newBalance), nil
|
||||
|
||||
default:
|
||||
return fmt.Sprintf("Unknown item: %s", item), nil
|
||||
}
|
||||
}
|
||||
|
||||
return "Unknown subcommand.", nil
|
||||
}
|
||||
|
||||
func getPizzaArt() string {
|
||||
return `
|
||||
// ""--.._
|
||||
|| (_) _ "-._
|
||||
|| _ (_) '-.
|
||||
|| (_) __..-'
|
||||
\__..--"`
|
||||
}
|
||||
Reference in New Issue
Block a user