Esempio n. 1
0
 public void SetUserData(UserData data)
 {
     _userData = data;
 }
Esempio n. 2
0
        private void ReadDataFromFile()
        {
            if (File.Exists($"{_settings.ServerRootPath}/botdata.json"))
            {
                string json = File.ReadAllText($"{_settings.ServerRootPath}/botdata.json");
                _botData = JsonConvert.DeserializeObject <BotData>(json);
            }
            else
            {
                _botData = new BotData();
            }

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

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

                Task.Run(
                    async() =>
                {
                    while (_client.ConnectionState != ConnectionState.Connected || _client.LoginState != LoginState.LoggedIn)
                    {
                        await Task.Delay(100, _token);
                    }
                    await Task.Delay(10000, _token);
                    //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(g => g.Id == _settings.guildId);
                            SocketGuildUser sgu = guild.GetUser(userID.Key);
                            if (sgu == null)
                            {
                                continue;
                            }

                            IGuildUser user = sgu as IGuildUser;

                            IRole mutedRole = user.Guild.GetRole(_settings.MutedRoleId);
                            //Make sure they have the muted role
                            if (!user.RoleIds.Contains(_settings.MutedRoleId))
                            {
                                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);
                            }, _token);
                        }
                    }
                }, _token);
            }
            else
            {
                _userData = new UserData();
            }

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

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

            if (File.Exists($"{_settings.ServerRootPath}/feeds.json"))
            {
                string json = File.ReadAllText($"{_settings.ServerRootPath}/feeds.json");
                _feedData = JsonConvert.DeserializeObject <FeedData>(json);
            }
            else
            {
                _feedData = new FeedData();
            }
        }