Пример #1
0
        protected override void OnMessage(WebSocketSharp.MessageEventArgs e)
        {
            JObject obj = JsonConvert.DeserializeObject <JObject>(e.Data);

            switch (obj.GetValue("op").ToObject <ReconOpcode>())
            {
            case ReconOpcode.StartRecon:
                Task.Run(() =>
                {
                    if (obj.GetValue("guild_id").ToString() == "")
                    {
                        SocketServer.Broadcast("/recon", new ReconRequest(_id, ReconOpcode.NoId)); return;
                    }
                    var req = obj.ToObject <StartReconRequest>();

                    int bots           = 0;
                    DiscordGuild guild = null;

                    foreach (var bot in Server.Bots)
                    {
                        try
                        {
                            if (bot.SocketClient)
                            {
                                if (guild == null)
                                {
                                    guild = bot.Client.GetGuild(req.GuildId);

                                    bots++;
                                }
                                else
                                {
                                    if (bot.Guilds.Where(g => g.Id == req.GuildId).Count() > 0)
                                    {
                                        bots++;
                                    }
                                }
                            }
                            else
                            {
                                guild = bot.Client.GetGuild(req.GuildId);

                                bots++;
                            }
                        }
                        catch { }
                    }


                    if (guild == null)
                    {
                        SocketServer.Broadcast("/recon", new ReconRequest(_id, ReconOpcode.ReconFailed));

                        return;
                    }


                    ServerRecon recon = new ServerRecon(_id)
                    {
                        Name              = guild.Name,
                        Description       = guild.Description ?? "No description",
                        Region            = guild.Region,
                        VerificationLevel = guild.VerificationLevel.ToString(),
                        VanityInvite      = guild.VanityInvite ?? "None",
                        BotsInGuild       = $"{bots}/{Server.Bots.Count}"
                    };

                    foreach (var role in guild.Roles.Where(r => r.Mentionable))
                    {
                        recon.Roles.Add(new NameId(role.Name, role.Id));
                    }

                    foreach (var emoji in guild.Emojis.Distinct())
                    {
                        recon.Emojis.Add(new NameId(emoji.Name, emoji.Id.Value));
                    }

                    SocketServer.Broadcast("/recon", recon);
                });
                break;
            }
        }
Пример #2
0
        public async void StartAsync()
        {
            await Task.Run(() =>
            {
                if (Server.Bots.Count == 0)
                {
                    SocketServer.Broadcast("/checker", new CheckerErrorRequest("notokens"));
                    Finished = true;
                    return;
                }

                SocketServer.Broadcast("/checker", new CheckerStartedRequest());
                List <RaidBotClient> uncheckedClients = new List <RaidBotClient>(Server.Bots);
                foreach (var client in new List <RaidBotClient>(uncheckedClients))
                {
                    BotCheckedRequest req = new BotCheckedRequest(client);

                    try
                    {
                        client.Client.JoinGuild("a");
                    }
                    catch (DiscordHttpException e)
                    {
                        if (e.Code == DiscordError.UnknownInvite || e.Code == DiscordError.MaximumGuilds)
                        {
                            req.Valid = true;
                        }
                        else
                        {
                            if (e.Code == DiscordError.AccountUnverified)
                            {
                                File.AppendAllText(_checkDir + "/Locked.txt", client.Client.Token + "\n");
                            }
                            else
                            {
                                File.AppendAllText(_checkDir + "/Invalid.txt", client.Client.Token + "\n");
                            }
                        }
                    }
                    catch (JsonReaderException)
                    {
                        SocketServer.Broadcast("/checker", new CheckerErrorRequest("ratelimit"));

                        List <string> uncheckedTokens = new List <string>();
                        foreach (var acc in uncheckedClients)
                        {
                            uncheckedTokens.Add(acc.Client.Token);
                        }

                        File.WriteAllText(_checkDir + "/Unchecked.txt", string.Join("\n", uncheckedTokens));
                        Finished = true;
                        break;
                    }

                    uncheckedClients.Remove(client);

                    if (req.Valid)
                    {
                        File.AppendAllText(_checkDir + "/Valid.txt", client.Client.Token + "\n");

                        Progress.Valid++;
                    }
                    else
                    {
                        Server.Bots.Remove(client);
                        SocketServer.Broadcast("/list", new ListRequest(ListAction.Remove, client));
                        Progress.Invalid++;
                    }

                    req.Progress = Progress;

                    SocketServer.Broadcast("/checker", req);
                }

                SocketServer.Broadcast("/checker", new CheckerRequest(CheckerOpcode.Done));

                Finished = true;
            });
        }