コード例 #1
0
ファイル: InviteManager.cs プロジェクト: wkwestfa/EmeraldBot
    /// <summary>
    /// Invites have two integer values: validUses and invalidUses.
    /// This function determines which one of those values should be incremented.
    /// </summary>
    private static void CalculateValidInvite(SocketGuildUser newUser)
    {
        foreach (var discordInvite in discordInvites)                                                                    // Cycle through discord invites
        {
            foreach (var invite in Constants.invites)                                                                    // For each discord invite, we also need to cycle through our custom invites to determine the correct one.
            {
                if (invite.inviteId == discordInvite.Id && (invite.validUses + invite.invalidUses) < discordInvite.Uses) // if the id's are the same and the uses are less than the Discord Uses, then we know this is the invite!
                {
                    if (!existingUser)                                                                                   // Now we check to make sure the user has never been on the server before, and then...
                    {
                        Bot.GetUser(discordInvite.Inviter.ToString()).inviteCount += 1;                                  // We can finally add an invite to the person who invited them!
                        invite.validUses += 1;
                        Bot.AddRewards(Bot.GetUser(discordInvite.Inviter.ToString()));                                   // We must add rewards to the user who invited the new member.

                        Console.WriteLine($"{newUser.Username} joined for the first time!  Invited by {invite.username.Split('#')[0]}. {invite.username.Split('#')[0]} has invited {Bot.GetUser(discordInvite.Inviter.ToString()).inviteCount} new members in total!");
                        break;
                    }
                    else                         // But if the user has already been to the server before, then...
                    {
                        invite.invalidUses += 1; // We know it is not a proper invite.
                        break;
                    }
                }
                else if (invite.inviteId == discordInvite.Id)
                {
                    break;
                }
            }
        }
    }