package main import ( "fmt" "os" "time" "github.com/alexflint/go-arg" "github.com/bwmarrin/discordgo" "github.com/sirupsen/logrus" ) type UserRole struct { Rank int CurrentRole string } // Global var (I know, and i don't care) var api string = "https://preprod.42ctf.org/api/bot/discord?token=" + os.Getenv("AUTH_TOKEN") var guild string var rolesID map[string]string var Users map[string]*UserRole var args struct { Guild string `arg:"-g,required,env:GUILD_ID"` Top1 string `arg:"env:TOP_1"` Top10 string `arg:"env:TOP_10"` Top50 string `arg:"env:TOP_50"` Wait int `default:"2" help:"Minutes between run"` Force bool DryRun bool } func main() { fmt.Println(len(os.Args), os.Args) arg.MustParse(&args) guild = args.Guild rolesID = make(map[string]string) rolesID["top1"] = args.Top1 rolesID["top10"] = args.Top10 rolesID["top50"] = args.Top50 discord, err := discordgo.New("Bot " + os.Getenv("DISCORD_TOKEN")) if err != nil { logrus.Fatal(err.Error()) } if err := populateUserRole(discord); err != nil { logrus.Fatal(err.Error()) } if args.DryRun { logrus.Warn("Running in Dry Run mode") } if args.Force { logrus.Warn("Force update of all users") forceUpdate(discord, args.DryRun) } for { logrus.Info("Start update") updateUserRole(discord, args.DryRun) logrus.Info("End update, sleep for 2 minutes") time.Sleep(time.Duration(args.Wait) * time.Minute) } }