コード例 #1
0
        public async Task LookupAsync(string accountName)
        {
            var counts       = new Dictionary <int, int>();
            var discordUsers = await manager.GetDiscordUsers();

            foreach (var discordUser in discordUsers)
            {
                var dbUser = await manager.GetDatabaseUser(discordUser.Id);

                if (dbUser == null)
                {
                    continue;
                }

                try
                {
                    var verifier = VerifyService.Create(dbUser.AccountID, dbUser.APIKey, manager, discordUser, strings);

                    await verifier.LoadAccount();

                    if (verifier.AccountName == accountName)
                    {
                        Console.WriteLine($"Account {accountName} found, Discord Name: {discordUser.Nickname ?? discordUser.Username}");
                        return;
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine($"Could not load information for user {discordUser.Username} ({dbUser.APIKey})");
                }
            }

            Console.WriteLine($"Account {accountName} not found");
        }
コード例 #2
0
        public async Task GetStatistics()
        {
            try
            {
                Console.WriteLine("Calculating Statistics");

                var counts       = new Dictionary <int, int>();
                var discordUsers = await manager.GetDiscordUsers();

                foreach (var discordUser in discordUsers)
                {
                    var dbUser = await manager.GetDatabaseUser(discordUser.Id);

                    if (dbUser == null)
                    {
                        continue;
                    }
                    try
                    {
                        var verifier = VerifyService.Create(dbUser.AccountID, dbUser.APIKey, manager, discordUser, strings);

                        await verifier.LoadAccount();

                        if (!counts.ContainsKey(verifier.World))
                        {
                            counts.Add(verifier.World, 0);
                        }

                        counts[verifier.World] = counts[verifier.World] + 1;
                    }
                    catch (Exception)
                    {
                        Console.WriteLine($"Could not load information for user {discordUser.Username} ({dbUser.APIKey})");
                    }
                }

                foreach (var value in counts)
                {
                    Console.WriteLine($"World [{value.Key}]: {value.Value}");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Exception: {ex.Message}");
            }
        }
コード例 #3
0
        public async Task Process(IMessage e)
        {
            try
            {
                Console.WriteLine($"Message: {e.Content}");

                Console.WriteLine($"Begin verification for {e.Author.Username}");
                await e.Channel.SendMessageAsync("Starting Verification Process...");

                if (e.Author.Status == UserStatus.Invisible)
                {
                    await e.Channel.SendMessageAsync("You cannot be set to invisible while Verifying. Please change your discord status to Online");

                    return;
                }

                var request = await VerifyService.CreateFromRequestMessage(e, manager, this.strings);

                if (request == null)
                {
                    return;
                }

                await request.Validate(false);

                if (!request.IsValid)
                {
                    return;
                }

                await manager.VerifyUser(request.Requestor.Id, request.Account.Id, request.APIKey);

                await e.Channel.SendMessageAsync(this.strings.EndMessage);

                Console.WriteLine($"{e.Author.Username} Verified.");
            }
            catch (Exception ex)            {
                await e.Channel.SendMessageAsync(this.strings.ErrorMessage);

                Console.WriteLine($"Error: {ex.ToString()}");
            }
        }
コード例 #4
0
        private async Task CheckUsers()
        {
            Console.WriteLine("Reverification process beginning");

            var discordUsers = await manager.GetDiscordUsers();

            var verifiedNonBotUsers = discordUsers.Where(u => !(u.IsBot || !manager.IsUserVerified(u)));

            foreach (var discordUser in verifiedNonBotUsers)
            {
                Console.WriteLine($"Verifying user {discordUser.Nickname ?? discordUser.Username}");

                var dbUser = await manager.GetDatabaseUser(discordUser.Id);

                if (dbUser == null)
                {
                    try
                    {
                        if (discordUser.GuildPermissions.Administrator)
                        {
                            continue;
                        }

                        await manager.UnverifyUser(discordUser, dbUser);

                        continue;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Error while checking user {discordUser.Nickname ?? discordUser.Username}: {ex.Message}");
                    }
                }

                var attempts = 0;
                while (attempts < 3)
                {
                    try
                    {
                        var verifier = VerifyService.Create(dbUser.AccountID, dbUser.APIKey, manager, discordUser, strings);
                        await verifier.Validate(true);

                        if (verifier.IsValid)
                        {
                            Console.WriteLine($"User {discordUser.Nickname ?? discordUser.Username} is still valid");
                        }
                        else
                        {
                            await manager.UnverifyUser(discordUser, dbUser);
                        }

                        break;
                    }
                    catch (Exception)
                    {
                        Console.WriteLine($"Error reverifying user {discordUser.Nickname ?? discordUser.Username} ({discordUser.Id})");
                        //Console.WriteLine($"Error: {ex}");
                        attempts++;
                    }
                }
            }

            Console.WriteLine("Reverification process complete");
        }