Browse Source

Added AppName and AppVersion optional fields to DiscordConfig. UserAgent is now readonly.

tags/docs-0.9
RogueException 9 years ago
parent
commit
39b3667ce4
2 changed files with 37 additions and 7 deletions
  1. +36
    -6
      src/Discord.Net/DiscordConfig.cs
  2. +1
    -1
      src/Discord.Net/Net/Rest/SharpRestEngine.cs

+ 36
- 6
src/Discord.Net/DiscordConfig.cs View File

@@ -1,4 +1,5 @@
using System;
using System.Text;

namespace Discord
{
@@ -38,14 +39,38 @@ namespace Discord
/// <summary> Specifies the minimum log level severity that will be sent to the LogMessage event. Warning: setting this to debug will really hurt performance but should help investigate any internal issues. </summary>
public LogSeverity LogLevel { get { return _logLevel; } set { SetValue(ref _logLevel, value); } }
private LogSeverity _logLevel = LogSeverity.Info;
/// <summary> User Agent string to use when connecting to Discord. </summary>
public string UserAgent { get { return _userAgent; } set { SetValue(ref _userAgent, value); } }
private string _userAgent = $"Discord.Net/{DiscordClient.Version} (https://github.com/RogueException/Discord.Net)";

//Rest
/// <summary> Name of your application. </summary>
public string AppName { get { return _appName; } set { SetValue(ref _appName, value); UpdateUserAgent(); } }
private string _appName = null;
/// <summary> Version of your application. </summary>
public string AppVersion { get { return _appVersion; } set { SetValue(ref _appVersion, value); UpdateUserAgent(); } }
private string _appVersion = null;

/// <summary> Max time (in milliseconds) to wait for an API request to complete. </summary>
public int RestTimeout { get { return _restTimeout; } set { SetValue(ref _restTimeout, value); } }
/// <summary> User Agent string to use when connecting to Discord. </summary>
public string UserAgent { get { return _userAgent; } }
private string _userAgent;
private void UpdateUserAgent()
{
StringBuilder builder = new StringBuilder();
if (!string.IsNullOrEmpty(_appName))
{
builder.Append(_appName);
if (!string.IsNullOrEmpty(_appVersion))
{
builder.Append('/');
builder.Append(_appVersion);
}
builder.Append(' ');
}
builder.Append($"DiscordBot (https://github.com/RogueException/Discord.Net, v{DiscordClient.Version})");
_userAgent = builder.ToString();
}

//Rest

/// <summary> Max time (in milliseconds) to wait for an API request to complete. </summary>
public int RestTimeout { get { return _restTimeout; } set { SetValue(ref _restTimeout, value); } }
private int _restTimeout = 10000;

/// <summary> Enables or disables the internal message queue. This will allow SendMessage to return immediately and handle messages internally. Messages will set the IsQueued and HasFailed properties to show their progress. </summary>
@@ -89,5 +114,10 @@ namespace Discord
/// <summary> Maintains the LastActivity property for users, showing when they last made an action (sent message, joined server, typed, etc). </summary>
public bool TrackActivity { get { return _trackActivity; } set { SetValue(ref _trackActivity, value); } }
private bool _trackActivity = true;

public DiscordConfig()
{
UpdateUserAgent();
}
}
}

+ 1
- 1
src/Discord.Net/Net/Rest/SharpRestEngine.cs View File

@@ -22,7 +22,7 @@ namespace Discord.Net.Rest
PreAuthenticate = false,
ReadWriteTimeout = _config.RestTimeout,
UserAgent = config.UserAgent
};
};
/*if (_config.ProxyUrl != null)
_client.Proxy = new WebProxy(_config.ProxyUrl, true, new string[0], _config.ProxyCredentials);
else*/


Loading…
Cancel
Save