public CommandOptions GetCommandOptions(string commandString) { if (this.CachedCommandOptions != null && this.CachedCommandOptions.CommandId == commandString) { return(this.CachedCommandOptions); } return(this.CachedCommandOptions = ServerContext.Create(this.DbConnectionString).CommandOptions.FirstOrDefault(c => c.ServerId == this.Id && c.CommandId == commandString)); }
public void LoadConfig(string dbConnectionString) { ServerContext dbContext = ServerContext.Create(dbConnectionString); this.IgnoredChannels = dbContext.Channels.Where(c => c.ServerId == this.Id && c.Ignored).Select(c => c.ChannelId).ToList(); this.TemporaryChannels = dbContext.Channels.Where(c => c.ServerId == this.Id && c.Temporary).Select(c => c.ChannelId).ToList(); this.MutedChannels = dbContext.Channels.Where(c => c.ServerId == this.Id && c.MutedUntil > DateTime.MinValue).Select(c => c.ChannelId).ToList(); ReloadConfig(dbConnectionString); }
public List <CommandChannelOptions> GetCommandChannelOptions(string commandString) { CommandChannelOptions tmp; if (this.CachedCommandChannelOptions != null && (tmp = this.CachedCommandChannelOptions.FirstOrDefault()) != null && tmp.CommandId == commandString) { return(this.CachedCommandChannelOptions); } return(this.CachedCommandChannelOptions = ServerContext.Create(this.DbConnectionString).CommandChannelOptions.Where(c => c.ServerId == this.Id && c.CommandId == commandString)?.ToList()); }
public void ReloadConfig(string dbConnectionString) { this.DbConnectionString = dbConnectionString; ServerContext dbContext = ServerContext.Create(dbConnectionString); this.Config = dbContext.ServerConfigurations.FirstOrDefault(c => c.ServerId == this.Id); if (this.Config == null) { this.Config = new ServerConfig() { ServerId = this.Id, Name = this.Guild.Name }; dbContext.ServerConfigurations.Add(this.Config); dbContext.SaveChanges(); } this.CustomCommands?.Clear(); this.CustomAliases?.Clear(); this.Roles?.Clear(); this.CustomCommands = dbContext.CustomCommands.Where(c => c.ServerId == this.Id).ToDictionary(c => c.CommandId); this.CustomAliases = dbContext.CustomAliases.Where(c => c.ServerId == this.Id).ToDictionary(c => c.Alias); this.Roles = dbContext.Roles.Where(c => c.ServerId == this.Id).ToDictionary(c => c.RoleId); List <ChannelConfig> channels = dbContext.Channels.Where(c => c.ServerId == this.Id).ToList(); this.IgnoredChannels = channels.Where(c => c.Ignored).Select(c => c.ChannelId).ToList(); this.TemporaryChannels = channels.Where(c => c.Temporary).Select(c => c.ChannelId).ToList(); this.MutedChannels = channels.Where(c => c.MutedUntil > DateTime.MinValue).Select(c => c.ChannelId).ToList(); dbContext.Dispose(); SocketRole role; if (this.Config.MuteRoleId != 0 && (role = this.Guild.GetRole(this.Config.MuteRoleId)) != null) { foreach (SocketTextChannel channel in this.Guild.TextChannels) { if (this.Config.MuteIgnoreChannelId == channel.Id) { continue; } try{ channel.AddPermissionOverwriteAsync(role, new OverwritePermissions(sendMessages: PermValue.Deny)).GetAwaiter().GetResult(); } catch (Exception) { } } } }
public CommandOptions GetCommandOptions(string commandString) { if (this.CustomAliases.ContainsKey(commandString)) { commandString = this.CustomAliases[commandString].CommandId; } if (this.CachedCommandOptions != null && this.CachedCommandOptions.CommandId == commandString) { return(this.CachedCommandOptions); } ServerContext dbContext = ServerContext.Create(this.DbConnectionString); this.CachedCommandOptions = dbContext.CommandOptions.FirstOrDefault(c => c.ServerId == this.Id && c.CommandId == commandString); dbContext.Dispose(); return(this.CachedCommandOptions); }
public void ReloadConfig(string dbConnectionString) { this.DbConnectionString = dbConnectionString; ServerContext dbContext = ServerContext.Create(dbConnectionString); this.Config = dbContext.ServerConfigurations.FirstOrDefault(c => c.ServerId == this.Id); if (this.Config == null) { this.Config = new ServerConfig() { ServerId = this.Id, Name = this.Guild.Name }; dbContext.ServerConfigurations.Add(this.Config); } this.CustomCommands?.Clear(); this.CustomAliases?.Clear(); this.Roles?.Clear(); this.CustomCommands = dbContext.CustomCommands.Where(c => c.ServerId == this.Id).ToDictionary(c => c.CommandId); this.CustomAliases = dbContext.CustomAliases.Where(c => c.ServerId == this.Id).ToDictionary(c => c.Alias); this.Roles = dbContext.Roles.Where(c => c.ServerId == this.Id).ToDictionary(c => c.RoleId); }