This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
PermissionGacha/modules/gacha/reward.go

35 lines
853 B
Go

package gacha
import (
"fmt"
"github.com/bwmarrin/discordgo"
"PermissionGacha/modules/config"
)
func rewardToUser(s *discordgo.Session, reward config.Reward, rewardee *discordgo.Member) (bool, error) {
switch reward.Type {
case "role":
return rewardRole(s, reward, rewardee)
}
return false, fmt.Errorf("gacha: rewardToUser: unknown reward type: %s", reward.Type)
}
func rewardRole(s *discordgo.Session, reward config.Reward, rewardee *discordgo.Member) (bool, error) {
roleID, found := reward.Context["id"].(string)
if !found {
return false, fmt.Errorf("gacha: rewardRole: `id` not passed to reward with type `role`")
}
for _, v := range rewardee.Roles {
if v == roleID {
return false, nil
}
}
err := s.GuildMemberRoleAdd(config.GuildID, rewardee.User.ID, roleID)
if err != nil {
return false, err
}
return true, nil
}