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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user