/// <summary> /// Runs every time a new user joins the server. /// </summary> public static async Task NewUserJoined(SocketGuildUser newUser) { // Discord API doesn't make our jobs easy, so we have to grab the data from the API and then convert it into a list that was can manipulate ourselves, hence the two lines below. var rawDiscordInvites = await channel.GetInvitesAsync(); discordInvites = new List <RestInviteMetadata>(rawDiscordInvites); CalculateNewInvites(); if (Bot.GetUser(newUser.ToString()) == null) // If the user has never been to the server before, then... { Bot.AddUser(newUser); // Add them to our user list. existingUser = false; } else // Otherwise, if the user HAS joined the server in the past, then... { existingUser = true; // We make sure our code is aware of that as we will need to know later. Console.WriteLine($"{newUser.Username} joined the server, but they have been here in the past."); } CalculateValidInvite(newUser); Bot.UpdateUsersFile(); Bot.UpdateInvitesFile(); }
/// <summary> /// Only runs if the proper files have not been created (user) and creates the files for us. /// </summary> public static async Task Init() { var rawInvites = await channel.GetInvitesAsync(); foreach (var user in channel.Users) { Bot.AddUser(user); } foreach (var invite in rawInvites) { Bot.AddInvite(invite); } foreach (var user in Constants.users) { var userInvites = Constants.invites.FindAll(x => x.username == user.username); if (userInvites.Count > 0) { foreach (var invite in userInvites) { user.inviteCount += invite.validUses; } } // Add rewards to users string[] lines = File.ReadAllLines(@"Data/MinecraftRewards.txt"); foreach (string line in lines) { var rewardLevel = line.Split(',')[0]; var reward = line.Split(',')[1]; if (user.inviteCount >= Convert.ToInt16(rewardLevel)) { user.minecraftRewards.Add(reward); } } } Bot.UpdateInvitesFile(); Bot.UpdateUsersFile(); }