private void SaveData() { CasinoData data = new CasinoData() { LotteryCashPool = _lotteryCashPool, SlotMachineCashPool = _slotMachineCashPool }; _updateService.SetCasinoData(data); }
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)) { 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(); } }
public void SetCasinoData(CasinoData data) { _casinoData = data; }