/// <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> Max time (in milliseconds) to wait for an API request to complete. </summary>
public int APITimeout { get { return _apiTimeout; } set { SetValue(ref _apiTimeout, value); } }
private int _apiTimeout = 10000;
/// <summary> The proxy to user for API and WebSocket connections. </summary>
public string ProxyUrl { get { return _proxyUrl; } set { SetValue(ref _proxyUrl, value); } }
private string _proxyUrl = null;
/// <summary> The credentials to use for this proxy. </summary>
public NetworkCredential ProxyCredentials { get { return _proxyCredentials; } set { SetValue(ref _proxyCredentials, value); } }
/// <summary> Returns the configuration object used to make this client. Note that this object cannot be edited directly - to change the configuration of this client, use the DiscordClient(DiscordClientConfig config) constructor. </summary>
/// <summary> Returns the configuration object used to make this client. Note that this object cannot be edited directly - to change the configuration of this client, use the DiscordClient(DiscordClientConfig config) constructor. </summary>
public DiscordClientConfig Config => _config;
private readonly DiscordClientConfig _config;
public DiscordConfig Config => _config;
private readonly DiscordConfig _config;
/// <summary> Returns the current connection state of this client. </summary>
/// <summary> Returns the current connection state of this client. </summary>
public DiscordClientState State => (DiscordClientState)_state;
public DiscordClientState State => (DiscordClientState)_state;
@@ -110,9 +110,9 @@ namespace Discord
}
}
/// <summary> Initializes a new instance of the DiscordClient class. </summary>
/// <summary> Initializes a new instance of the DiscordClient class. </summary>
public DiscordClient(DiscordClientConfig config = null)
public DiscordClient(DiscordConfig config = null)
{
{
_config = config ?? new DiscordClientConfig();
_config = config ?? new DiscordConfig();
_config.Lock();
_config.Lock();
_rand = new Random();
_rand = new Random();
@@ -133,7 +133,7 @@ namespace Discord
_cacheLock = new object();
_cacheLock = new object();
_channels = new Channels(this, _cacheLock);
_channels = new Channels(this, _cacheLock);
_users = new Users(this, _cacheLock);
_users = new Users(this, _cacheLock);
_messages = new Messages(this, _cacheLock, Config.MessageCacheLength > 0);
_messages = new Messages(this, _cacheLock, Config.MessageCacheSize > 0);
_roles = new Roles(this, _cacheLock);
_roles = new Roles(this, _cacheLock);
_servers = new Servers(this, _cacheLock);
_servers = new Servers(this, _cacheLock);
_globalUsers = new GlobalUsers(this, _cacheLock);
_globalUsers = new GlobalUsers(this, _cacheLock);
@@ -259,7 +259,8 @@ namespace Discord
private DataWebSocket CreateWebSocket()
private DataWebSocket CreateWebSocket()
{
{
var socket = new DataWebSocket(this, _log.CreateLogger("WebSocket"));
var socket = new DataWebSocket(_config, _log.CreateLogger("WebSocket"));
var settings = new JsonSerializerSettings();
socket.Connected += (s, e) =>
socket.Connected += (s, e) =>
{
{
if (_state == (int)DiscordClientState.Connecting)
if (_state == (int)DiscordClientState.Connecting)
@@ -290,7 +291,6 @@ namespace Discord
try
try
{
{
var response = await _api.Login(email, password)
var response = await _api.Login(email, password)
.Timeout(_config.APITimeout)
.ConfigureAwait(false);
.ConfigureAwait(false);
token = response.Token;
token = response.Token;
if (_config.LogLevel >= LogSeverity.Verbose)
if (_config.LogLevel >= LogSeverity.Verbose)
@@ -311,7 +311,7 @@ namespace Discord
await Disconnect().ConfigureAwait(false);
await Disconnect().ConfigureAwait(false);
_api.Token = token;
_api.Token = token;
var gatewayResponse = await _api.Gateway().Timeout(_config.APITimeout).ConfigureAwait(false);
var gatewayResponse = await _api.Gateway().ConfigureAwait(false);
public class DiscordClientConfig : DiscordAPIClientConfig
{
/// <summary> Max time in milliseconds to wait for DiscordClient to connect and initialize. </summary>
public int ConnectionTimeout { get { return _connectionTimeout; } set { SetValue(ref _connectionTimeout, value); } }
private int _connectionTimeout = 30000;
/// <summary> Gets or sets the time (in milliseconds) to wait after an unexpected disconnect before reconnecting. </summary>
public int ReconnectDelay { get { return _reconnectDelay; } set { SetValue(ref _reconnectDelay, value); } }
private int _reconnectDelay = 1000;
/// <summary> Gets or sets the time (in milliseconds) to wait after an reconnect fails before retrying. </summary>
public int FailedReconnectDelay { get { return _failedReconnectDelay; } set { SetValue(ref _failedReconnectDelay, value); } }
private int _failedReconnectDelay = 10000;
/// <summary> Gets or sets the time (in milliseconds) to wait when the websocket's message queue is empty before checking again. </summary>
public int WebSocketInterval { get { return _webSocketInterval; } set { SetValue(ref _webSocketInterval, value); } }
private int _webSocketInterval = 100;
/// <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 MessageCacheLength { get { return _messageCacheLength; } set { SetValue(ref _messageCacheLength, value); } }
private int _messageCacheLength = 100;
//Experimental Features
/// <summary> (Experimental) Instructs Discord to not send send information about offline users, for servers with more than 50 users. </summary>
public bool UseLargeThreshold { get { return _useLargeThreshold; } set { SetValue(ref _useLargeThreshold, value); } }
private bool _useLargeThreshold = false;
//Experimental Features
/// <summary> (Experimental) 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>
public bool UseMessageQueue { get { return _useMessageQueue; } set { SetValue(ref _useMessageQueue, value); } }
private bool _useMessageQueue = false;
/// <summary> Gets or sets the time (in milliseconds) to wait when the message queue is empty before checking again. </summary>
public int MessageQueueInterval { get { return _messageQueueInterval; } set { SetValue(ref _messageQueueInterval, value); } }
private int _messageQueueInterval = 100;
/// <summary> (Experimental) 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;
/// <summary> (Experimental) Acknowledges all incoming messages so that they appear read. </summary>
public bool AckMessages { get { return _ackMessages; } set { SetValue(ref _ackMessages, value); } }
private bool _ackMessages = false;
public new DiscordClientConfig Clone()
{
var config = MemberwiseClone() as DiscordClientConfig;
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.