Esempio n. 1
0
 public static void UpdateList(ListAction action, RaidBotClient bot)
 {
     UpdateList(action, new List <RaidBotClient>()
     {
         bot
     });
 }
Esempio n. 2
0
        private void Client_OnLoggedIn(DiscordSocketClient client, LoginEventArgs args)
        {
            RaidBotClient raidClient = Accounts.First(acc => acc.Client.User.Id == client.User.Id);

            raidClient.Guilds        = args.Guilds.Cast <DiscordGuild>().ToList();
            raidClient.Relationships = args.Relationships.ToList();
        }
Esempio n. 3
0
        protected override void OnMessage(WebSocketSharp.MessageEventArgs e)
        {
            JObject obj = JsonConvert.DeserializeObject <JObject>(e.Data);

            switch (obj.GetValue("op").ToObject <ListOpcode>())
            {
            case ListOpcode.Token:
                TokenRequest  tokenReq = obj.ToObject <TokenRequest>();
                DiscordClient client   = Server.Bots.First(c => c.Client.User.Id == tokenReq.Id);
                tokenReq.Token = client.Token;
                tokenReq.At    = client.User.ToString();

                Send(tokenReq);
                break;

            case ListOpcode.BotModify:
                ModRequest modReq = obj.ToObject <ModRequest>();

                if (modReq.SetAll)
                {
                    foreach (var bot in new List <RaidBotClient>(Server.Bots))
                    {
                        ModifyUser(bot, modReq);
                    }
                }
                else
                {
                    RaidBotClient bot = Server.Bots.First(c => c.Client.User.Id == modReq.Id);

                    ModResponse resp = new ModResponse {
                        At = bot.Client.User.ToString()
                    };
                    resp.Success = ModifyUser(bot, modReq);

                    Send(resp);
                }
                break;

            case ListOpcode.BotInfo:
                BotInfoRequest infoReq = JsonConvert.DeserializeObject <BotInfoRequest>(e.Data);

                SocketServer.Broadcast("/list",
                                       BotInfo.FromClient(Server.Bots.First(b => b.Client.User.Id == infoReq.Id), infoReq.GetGuildsAndFriends));
                break;
            }
        }
Esempio n. 4
0
        private static bool ModifyUser(RaidBotClient client, ModRequest req)
        {
            try
            {
                if (client.Client.User.Hypesquad != req.Hypesquad)
                {
                    client.Client.User.SetHypesquad(req.Hypesquad);
                }

                if (req.Avatar != null)
                {
                    client.Client.User.ChangeProfile(new UserProfileUpdate()
                    {
                        Avatar = req.Avatar
                    });
                }

                if (!client.SocketClient)
                {
                    client.Client.User.Update();
                }

                if (req.Status != "Unset")
                {
                    UserStatus status = (UserStatus)Enum.Parse(typeof(UserStatus), req.Status.Replace(" ", ""), true);

                    ((DiscordSocketClient)client.Client).SetStatus(status);
                }

                UpdateList(ListAction.Update, client);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 5
0
        public static BasicBotInfo FromClient(RaidBotClient client)
        {
            BasicBotInfo bot = new BasicBotInfo()
            {
                At        = client.Client.User.ToString(),
                Id        = client.Client.User.Id.ToString(),
                Hypesquad = client.Client.User.Hypesquad.ToString()
            };

            if (client.Client.User.TwoFactorAuth)
            {
                bot.Verification = "Phone verified";
            }
            else if (client.Client.User.EmailVerified)
            {
                bot.Verification = "Email verified";
            }
            else
            {
                bot.Verification = "None or locked";
            }

            return(bot);
        }
Esempio n. 6
0
 public BotCheckedRequest(RaidBotClient client) : base(CheckerOpcode.BotChecked)
 {
     Bot      = BasicBotInfo.FromClient(client);
     Progress = new CheckerProgress();
 }
Esempio n. 7
0
        public static BotInfo FromClient(RaidBotClient bot, bool getGuildsAndFriends)
        {
            BotInfo info = new BotInfo
            {
                At       = bot.Client.User.ToString(),
                Id       = bot.Client.User.Id.ToString(),
                AvatarId = bot.Client.User.Avatar.Url.Replace($"https://cdn.discordapp.com/avatars/{bot.Client.User.Id}/", ""),
                Gateway  = bot.SocketClient
            };

            if (bot.Client.User.TwoFactorAuth)
            {
                info.Verification = "Phone verified";
            }
            else if (bot.Client.User.EmailVerified)
            {
                info.Verification = "Email verified";
            }
            else
            {
                info.Verification = "None or locked";
            }

            foreach (Enum value in Enum.GetValues(typeof(DiscordBadge)))
            {
                if (value.ToString() == "LocalUser" || value.ToString() == "None")
                {
                    continue;
                }

                if (bot.Client.User.Badges.HasFlag(value))
                {
                    info.Badges.Add(value.ToString());
                }
            }

            if (bot.Client.User.Nitro != DiscordNitroType.None)
            {
                info.Badges.Add("Nitro");
            }

            if (getGuildsAndFriends)
            {
                info.Guilds  = new List <GuildInfo>();
                info.Friends = new List <FriendInfo>();

                if (bot.SocketClient)
                {
                    foreach (var guild in bot.Guilds)
                    {
                        info.Guilds.Add(new GuildInfo(guild));
                    }
                }
                else
                {
                    foreach (var guild in bot.Client.GetGuilds())
                    {
                        info.Guilds.Add(new GuildInfo(guild));
                    }
                }

                foreach (var relationship in bot.SocketClient ? bot.Relationships : bot.Client.GetRelationships())
                {
                    if (relationship.Type == RelationshipType.Friends)
                    {
                        info.Friends.Add(new FriendInfo(relationship));
                    }
                }
            }

            return(info);
        }
Esempio n. 8
0
 public ListRequest(ListAction action, RaidBotClient bot)
     : this(action, new List <RaidBotClient>() { bot })
 {
 }
Esempio n. 9
0
        public async void LoadAsync()
        {
            if (!File.Exists("Config.json"))
            {
                File.WriteAllText("Config.json", JsonConvert.SerializeObject(new Config()));
            }

            if (!File.Exists("Tokens.txt"))
            {
                File.Create("Tokens.txt").Close();
            }

            try
            {
                _config = JsonConvert.DeserializeObject <Config>(File.ReadAllText("Config.json"));
            }
            catch
            {
                _config = new Config();
            }

            await Task.Run(() =>
            {
                BotListEndpoint.UpdateList(ListAction.Remove, Accounts);
                Accounts.Clear();
                Server.ServerStatus = "Loading bots";
                _tokensLoading      = true;


                string[] tokens = File.Exists("Tokens.txt")
                                        ? File.ReadAllLines("Tokens.txt") : new string[] { };

                foreach (var token in tokens.Distinct())
                {
                    if (string.IsNullOrWhiteSpace(token))
                    {
                        continue;
                    }

                    try
                    {
                        RaidBotClient client = null;

                        if (Accounts.Count <= _config.GatewayCap && _config.EnableGateway)
                        {
                            DiscordSocketClient sClient = new DiscordSocketClient();
                            sClient.OnLoggedIn         += Client_OnLoggedIn;
                            sClient.Login(token);
                            client = new RaidBotClient(sClient);
                        }
                        else
                        {
                            client = new RaidBotClient(new DiscordClient(token));
                        }

                        Accounts.Add(client);
                        BotListEndpoint.UpdateList(ListAction.Add, client);
                    }
                    catch (DiscordHttpException) { }
                    catch (Exception e)
                    {
                        Console.WriteLine($"Unknown error when loading account:\n{e}");
                    }
                }


                var bruh = Accounts.GroupBy(bot => bot.Client.User.Id);
                List <RaidBotClient> removedAccounts = new List <RaidBotClient>();
                foreach (var ok in bruh)
                {
                    removedAccounts.AddRange(ok.ToList().Skip(1));
                }

                Accounts = bruh.Select(group => group.First()).ToList();


                if (removedAccounts.Count > 0)
                {
                    foreach (var bot in new List <RaidBotClient>(removedAccounts))
                    {
                        if (Accounts.Contains(bot))
                        {
                            removedAccounts.RemoveAt(removedAccounts.IndexOf(bot));
                        }
                    }

                    BotListEndpoint.UpdateList(ListAction.Remove, removedAccounts);
                }


                if (Accounts.Count < tokens.Length)
                {
                    StringBuilder builder = new StringBuilder();
                    foreach (var bot in Accounts)
                    {
                        builder.AppendLine(bot.Client.Token);
                    }

                    File.WriteAllText("Tokens-valid.txt", builder.ToString());
                }


                Server.ServerStatus = "Ready";
                _tokensLoading      = false;

                if (!_reloaderRunning)
                {
                    StartAutoReloaderAsync();
                }
            });
        }