Store AppName/Url/Version in DiscordConfig, generate config for AudioClient
This commit is contained in:
@@ -70,7 +70,6 @@ namespace Discord.Audio
|
||||
public AudioClient(DiscordClient client, Server server, int id)
|
||||
{
|
||||
Id = id;
|
||||
_config = client.Config;
|
||||
Service = client.GetService<AudioService>();
|
||||
Config = Service.Config;
|
||||
Serializer = client.Serializer;
|
||||
@@ -87,6 +86,25 @@ namespace Discord.Audio
|
||||
//Networking
|
||||
if (Config.EnableMultiserver)
|
||||
{
|
||||
//TODO: We can remove this hack when official API launches
|
||||
var baseConfig = client.Config;
|
||||
var builder = new DiscordConfigBuilder
|
||||
{
|
||||
AppName = baseConfig.AppName,
|
||||
AppUrl = baseConfig.AppUrl,
|
||||
AppVersion = baseConfig.AppVersion,
|
||||
CacheToken = baseConfig.CacheDir != null,
|
||||
ConnectionTimeout = baseConfig.ConnectionTimeout,
|
||||
EnablePreUpdateEvents = false,
|
||||
FailedReconnectDelay = baseConfig.FailedReconnectDelay,
|
||||
LargeThreshold = 1,
|
||||
LogLevel = baseConfig.LogLevel,
|
||||
MessageCacheSize = 0,
|
||||
ReconnectDelay = baseConfig.ReconnectDelay,
|
||||
UsePermissionsCache = false
|
||||
};
|
||||
_config = builder.Build();
|
||||
|
||||
ClientAPI = new JsonRestClient(_config, DiscordConfig.ClientAPIUrl, client.Log.CreateLogger($"ClientAPI #{id}"));
|
||||
GatewaySocket = new GatewaySocket(_config, client.Serializer, client.Log.CreateLogger($"Gateway #{id}"));
|
||||
GatewaySocket.Connected += (s, e) =>
|
||||
@@ -96,7 +114,10 @@ namespace Discord.Audio
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
_config = client.Config;
|
||||
GatewaySocket = client.GatewaySocket;
|
||||
}
|
||||
GatewaySocket.ReceivedDispatch += (s, e) => OnReceivedEvent(e);
|
||||
VoiceSocket = new VoiceSocket(_config, Config, client.Serializer, client.Log.CreateLogger($"Voice #{id}"));
|
||||
VoiceSocket.Server = server;
|
||||
|
||||
@@ -34,10 +34,18 @@ namespace Discord
|
||||
public bool CacheToken { get; set; } = true;
|
||||
/// <summary> Gets or sets the number of messages per channel that should be kept in cache. Setting this to zero disables the message cache entirely. </summary>
|
||||
public int MessageCacheSize { get; set; } = 100;
|
||||
/// <summary> Gets or sets whether the permissions cache should be used. This makes operations such as User.GetPermissions(Channel), User.ServerPermissions and Channel.Members </summary>
|
||||
/// <summary>
|
||||
/// Gets or sets whether the permissions cache should be used.
|
||||
/// This makes operations such as User.GetPermissions(Channel), User.ServerPermissions, Channel.GetUser, and Channel.Members much faster while increasing memory usage.
|
||||
/// </summary>
|
||||
public bool UsePermissionsCache { get; set; } = true;
|
||||
/// <summary> Gets or sets whether the a copy of a model is generated on an update event to allow a user to check which properties changed. </summary>
|
||||
/// <summary> Gets or sets whether the a copy of a model is generated on an update event to allow you to check which properties changed. </summary>
|
||||
public bool EnablePreUpdateEvents { get; set; } = true;
|
||||
/// <summary>
|
||||
/// Gets or sets the max number of users a server may have for offline users to be included in the READY packet. Max is 250.
|
||||
/// Decreasing this may reduce CPU usage while increasing login time and network usage.
|
||||
/// </summary>
|
||||
public int LargeThreshold { get; set; } = 250;
|
||||
|
||||
//Events
|
||||
|
||||
@@ -65,22 +73,32 @@ namespace Discord
|
||||
|
||||
public LogSeverity LogLevel { get; }
|
||||
|
||||
public string AppName { get; }
|
||||
public string AppUrl { get; }
|
||||
public string AppVersion { get; }
|
||||
public string UserAgent { get; }
|
||||
public string CacheDir { get; }
|
||||
|
||||
public int ConnectionTimeout { get; }
|
||||
public int ReconnectDelay { get; }
|
||||
public int FailedReconnectDelay { get; }
|
||||
|
||||
public int LargeThreshold { get; } = 250;
|
||||
public int LargeThreshold { get; }
|
||||
public int MessageCacheSize { get; }
|
||||
public bool UsePermissionsCache { get; }
|
||||
public bool EnablePreUpdateEvents { get; }
|
||||
|
||||
public string UserAgent { get; }
|
||||
public string CacheDir { get; }
|
||||
|
||||
internal DiscordConfig(DiscordConfigBuilder builder)
|
||||
{
|
||||
LogLevel = builder.LogLevel;
|
||||
|
||||
AppName = builder.AppName;
|
||||
AppUrl = builder.AppUrl;
|
||||
AppVersion = builder.AppVersion;
|
||||
UserAgent = GetUserAgent(builder);
|
||||
CacheDir = GetCacheDir(builder);
|
||||
|
||||
ConnectionTimeout = builder.ConnectionTimeout;
|
||||
ReconnectDelay = builder.ReconnectDelay;
|
||||
FailedReconnectDelay = builder.FailedReconnectDelay;
|
||||
@@ -88,12 +106,9 @@ namespace Discord
|
||||
MessageCacheSize = builder.MessageCacheSize;
|
||||
UsePermissionsCache = builder.UsePermissionsCache;
|
||||
EnablePreUpdateEvents = builder.EnablePreUpdateEvents;
|
||||
|
||||
UserAgent = GetUserAgent(builder);
|
||||
CacheDir = GetCacheDir(builder);
|
||||
}
|
||||
|
||||
private string GetUserAgent(DiscordConfigBuilder builder)
|
||||
private static string GetUserAgent(DiscordConfigBuilder builder)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (!string.IsNullOrEmpty(builder.AppName))
|
||||
@@ -115,7 +130,7 @@ namespace Discord
|
||||
sb.Append($"DiscordBot ({LibUrl}, v{LibVersion})");
|
||||
return sb.ToString();
|
||||
}
|
||||
private string GetCacheDir(DiscordConfigBuilder builder)
|
||||
private static string GetCacheDir(DiscordConfigBuilder builder)
|
||||
{
|
||||
if (builder.CacheToken)
|
||||
return Path.Combine(Path.GetTempPath(), builder.AppName ?? "Discord.Net");
|
||||
|
||||
Reference in New Issue
Block a user