Пример #1
0
        private void SaveData()
        {
            CasinoData data = new CasinoData()
            {
                LotteryCashPool = _lotteryCashPool, SlotMachineCashPool = _slotMachineCashPool
            };

            _updateService.SetCasinoData(data);
        }
Пример #2
0
 public void SetCasinoData(CasinoData data)
 {
     _casinoData = data;
 }
Пример #3
0
        private void ReadDataFromFile()
        {
            if (File.Exists($"{Settings.GetServerRootPath()}/botdata.json"))
            {
                string json = File.ReadAllText($"{Settings.GetServerRootPath()}/botdata.json");
                _botData = JsonConvert.DeserializeObject <BotData>(json);
            }
            else
            {
                _botData = new BotData();
            }

            if (File.Exists($"{Settings.GetServerRootPath()}/animedata.json"))
            {
                string json = File.ReadAllText($"{Settings.GetServerRootPath()}/animedata.json");
                _animeData = JsonConvert.DeserializeObject <AnimeData>(json);
            }
            else
            {
                _animeData = new AnimeData();
            }

            if (File.Exists($"{Settings.GetServerRootPath()}/userdata.json"))
            {
                string json = File.ReadAllText($"{Settings.GetServerRootPath()}/userdata.json");
                _userData = JsonConvert.DeserializeObject <UserData>(json);

                Task.Run(
                    async() =>
                {
                    while (_client.ConnectionState != ConnectionState.Connected || _client.LoginState != LoginState.LoggedIn)
                    {
                        await Task.Delay(100);
                    }
                    await Task.Delay(1000);
                    //Check if there are users still muted
                    foreach (var userID in _userData.MutedUsers)
                    {
                        if (_userData.MutedUsers.HasUser(userID.Key, evenIfCooldownNowOver: true))
                        {
                            SocketGuild guild   = _client.Guilds.First();
                            SocketGuildUser sgu = guild.GetUser(userID.Key);
                            if (sgu == null)
                            {
                                continue;
                            }

                            IGuildUser user = sgu as IGuildUser;

                            IRole mutedRole = Settings.GetMutedRole(user.Guild);
                            //Make sure they have the muted role
                            if (!user.RoleIds.Contains(mutedRole.Id))
                            {
                                await user.AddRoleAsync(mutedRole);
                            }

                            //Setup delay to remove role when time is up.
                            Task.Run(async() =>
                            {
                                await _userData.MutedUsers.AwaitCooldown(user.Id);
                                await user.RemoveRoleAsync(mutedRole);
                            });
                        }
                    }
                });
            }
            else
            {
                _userData = new UserData();
            }

            if (File.Exists($"{Settings.GetServerRootPath()}/casinodata.json"))
            {
                string json = File.ReadAllText($"{Settings.GetServerRootPath()}/casinodata.json");
                _casinoData = JsonConvert.DeserializeObject <CasinoData>(json);
            }
            else
            {
                _casinoData = new CasinoData();
            }

            if (File.Exists($"{Settings.GetServerRootPath()}/FAQs.json"))
            {
                string json = File.ReadAllText($"{Settings.GetServerRootPath()}/FAQs.json");
                _faqData = JsonConvert.DeserializeObject <List <FaqData> >(json);
            }
            else
            {
                _faqData = new List <FaqData>();
            }
        }