modules/config+gacha: Make gacha rewards configurable
parent
cc9b770cf6
commit
c80fdc51cc
@ -0,0 +1,34 @@
|
|||||||
|
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
|
||||||
|
}
|
@ -1,50 +0,0 @@
|
|||||||
package gacha
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/bwmarrin/discordgo"
|
|
||||||
|
|
||||||
"PermissionGacha/modules/config"
|
|
||||||
)
|
|
||||||
|
|
||||||
type reward struct {
|
|
||||||
FriendlyName string
|
|
||||||
Reward func(s *discordgo.Session, member *discordgo.Member) (bool, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
var gachaRewards = []reward{
|
|
||||||
reward{
|
|
||||||
FriendlyName: "View Audit Log",
|
|
||||||
Reward: generateRoleReward("645856347258093568"),
|
|
||||||
},
|
|
||||||
reward{
|
|
||||||
FriendlyName: "Manage Webhook",
|
|
||||||
Reward: generateRoleReward("645856081750523914"),
|
|
||||||
},
|
|
||||||
reward{
|
|
||||||
FriendlyName: "Change Nickname",
|
|
||||||
Reward: generateRoleReward("645977231281356800"),
|
|
||||||
},
|
|
||||||
reward{
|
|
||||||
FriendlyName: "Use Voice Activity",
|
|
||||||
Reward: generateRoleReward("645880647474479115"),
|
|
||||||
},
|
|
||||||
reward{
|
|
||||||
FriendlyName: "Embed Link",
|
|
||||||
Reward: generateRoleReward("645977361254318080"),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func generateRoleReward(roleID string) func(s *discordgo.Session, member *discordgo.Member) (bool, error) {
|
|
||||||
return func(s *discordgo.Session, member *discordgo.Member) (bool, error) {
|
|
||||||
for _, v := range member.Roles {
|
|
||||||
if v == roleID {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
err := s.GuildMemberRoleAdd(config.GuildID, member.User.ID, roleID)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue