package main import ( "crypto/rand" "fmt" "github.com/bwmarrin/discordgo" ) const ( viewAuditLogRole = "645856347258093568" manageWebhookRole = "645856081750523914" changeNicknameRole = "645977231281356800" embedLinkRole = "645977361254318080" voiceActivityRole = "645977361254318080" ) func checkForGachaEligibility(dg *discordgo.Session, discordID, intendedLevel string) { member, err := dg.GuildMember(guildID, discordID) if err != nil { logError(dg, "checkForGachaEligibility", "getGuildMember", discordID) return } found := false for _, v := range member.Roles { if v == intendedLevel { found = true break } } if found { return } if intendedLevel != rolesFromLevel[0] { rollGacha(dg, member) } err = dg.GuildMemberRoleAdd(guildID, discordID, intendedLevel) if err != nil { logError(dg, "checkForGachaEligibility", "guildMemberRoleAdd", err) } } func rollGacha(dg *discordgo.Session, member *discordgo.Member) { lookUpAndGive := func(friendlyName, role string) { found := false for _, v := range member.Roles { if v == role { found = true break } } channel, err := dg.UserChannelCreate(member.User.ID) if found { rewardShard(dg, member.User.ID) if err == nil { dg.ChannelMessageSend( channel.ID, fmt.Sprintf( "**GACHA > ** You got __%s__! However, it was a duplicate so you got a shard instead.", friendlyName, ), ) } } else { dg.GuildMemberRoleAdd(guildID, member.User.ID, role) dg.ChannelMessageSend( channel.ID, fmt.Sprintf("**GACHA > ** You got __%s__!", friendlyName), ) } } gachaRandomness := make([]byte, 1) rand.Read(gachaRandomness) switch gachaRandomness[0] % 5 { case 0: lookUpAndGive("View Audit Log", viewAuditLogRole) case 1: lookUpAndGive("Manage Webhook", manageWebhookRole) case 2: lookUpAndGive("Change Nickname", changeNicknameRole) case 3: lookUpAndGive("Embed Link", embedLinkRole) case 4: lookUpAndGive("Use Voice Activity", voiceActivityRole) } }