modules/config: Move roles and token into config file

master
Luther Wen Xu 2019-12-13 18:07:39 +07:00
parent c73d28cc79
commit 801f9f8d6f
Signed by: chanbakjsd
GPG Key ID: B7D77E3E9D102B70
6 changed files with 12 additions and 27 deletions

2
.gitignore vendored

@ -1,4 +1,2 @@
token.txt
roles.txt
bot.db
config.json

@ -2,10 +2,8 @@ package main
import (
"fmt"
"io/ioutil"
"os"
"os/signal"
"strings"
"syscall"
"github.com/bwmarrin/discordgo"
@ -13,14 +11,13 @@ import (
"PermissionGacha/db"
"PermissionGacha/modules/active"
"PermissionGacha/modules/commands"
"PermissionGacha/modules/config"
"PermissionGacha/modules/level"
"PermissionGacha/modules/starboard"
)
func main() {
token, _ := ioutil.ReadFile("token.txt")
dg, err := discordgo.New(strings.TrimSpace(string(token)))
dg, err := discordgo.New(config.BotToken)
if err != nil {
fmt.Println("Error creating Discord session:", err)
return

@ -11,6 +11,8 @@ type config struct {
GuildID string `json:"guildID"`
PrestigeRequirement int `json:"prestigeFactor"`
StarChannel string `json:"starChannel"`
BotToken string `json:"token"`
LevelRoles []string `json:"roles"`
}
type activeNerf struct {
@ -36,6 +38,8 @@ func init() {
GuildID = output.GuildID
PrestigeRequirement = output.PrestigeRequirement
StarChannel = output.StarChannel
BotToken = output.BotToken
LevelRoles = output.LevelRoles
}
//Exposed Variables
@ -47,3 +51,5 @@ var CommandPrefix string
var GuildID string
var PrestigeRequirement int
var StarChannel string
var BotToken string
var LevelRoles []string

@ -9,7 +9,7 @@ import (
func GiveLevelRoles(s *discordgo.Session, discordID string, oldLevel, newLevel int) {
for i := oldLevel + 1; i <= newLevel; i++ {
s.GuildMemberRoleAdd(config.GuildID, discordID, rolesFromLevel[i-1])
s.GuildMemberRoleAdd(config.GuildID, discordID, config.LevelRoles[i-1])
}
}
@ -20,7 +20,7 @@ func RemoveAllLevelRoles(s *discordgo.Session, discordID string) {
return
}
for _, v := range member.Roles {
for _, w := range rolesFromLevel {
for _, w := range config.LevelRoles {
if v == w {
s.GuildMemberRoleRemove(config.GuildID, discordID, v)
break

@ -15,9 +15,9 @@ func GetOldLevel(s *discordgo.Session, id string) (int, error) {
}
foundLevel := 0
levelSearchLoop:
for i := len(rolesFromLevel); i > 0; i-- {
for i := len(config.LevelRoles); i > 0; i-- {
for _, v := range member.Roles {
if rolesFromLevel[i-1] == v {
if config.LevelRoles[i-1] == v {
foundLevel = i
break levelSearchLoop
}

@ -1,16 +0,0 @@
package roles
import (
"io/ioutil"
"strings"
)
var rolesFromLevel []string
func init() {
listOfRoles, _ := ioutil.ReadFile("roles.txt")
rolesFromLevel = strings.Split(string(listOfRoles), "\n")
for k, v := range rolesFromLevel {
rolesFromLevel[k] = strings.TrimSpace(v)
}
}