From 3dcdd159f632a147086388ad34fe921be83a06b1 Mon Sep 17 00:00:00 2001 From: RogueException Date: Sat, 5 Dec 2015 18:54:03 -0400 Subject: [PATCH] Added missing file --- src/Discord.Net/DiscordConfig.cs | 90 ++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/Discord.Net/DiscordConfig.cs diff --git a/src/Discord.Net/DiscordConfig.cs b/src/Discord.Net/DiscordConfig.cs new file mode 100644 index 000000000..a3fcf4c5b --- /dev/null +++ b/src/Discord.Net/DiscordConfig.cs @@ -0,0 +1,90 @@ +using System; + +namespace Discord +{ + public enum LogSeverity : byte + { + Error = 1, + Warning = 2, + Info = 3, + Verbose = 4, + Debug = 5 + } + + public abstract class BaseConfig + where T : BaseConfig + { + protected bool _isLocked; + protected internal void Lock() { _isLocked = true; } + protected void SetValue(ref U storage, U value) + { + if (_isLocked) + throw new InvalidOperationException("Unable to modify a discord client's configuration after it has been created."); + storage = value; + } + + public T Clone() + { + var config = MemberwiseClone() as T; + config._isLocked = false; + return config; + } + } + + public class DiscordConfig : BaseConfig + { + //Global + + /// 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. + public LogSeverity LogLevel { get { return _logLevel; } set { SetValue(ref _logLevel, value); } } + private LogSeverity _logLevel = LogSeverity.Info; + /// User Agent string to use when connecting to Discord. + 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 + + /// Max time (in milliseconds) to wait for an API request to complete. + public int RestTimeout { get { return _restTimeout; } set { SetValue(ref _restTimeout, value); } } + private int _restTimeout = 10000; + + /// 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. + public bool UseMessageQueue { get { return _useMessageQueue; } set { SetValue(ref _useMessageQueue, value); } } + private bool _useMessageQueue = false; + /// Gets or sets the time (in milliseconds) to wait when the message queue is empty before checking again. + public int MessageQueueInterval { get { return _messageQueueInterval; } set { SetValue(ref _messageQueueInterval, value); } } + private int _messageQueueInterval = 100; + + //WebSocket + + /// Gets or sets the time (in milliseconds) to wait for the websocket to connect and initialize. + public int ConnectionTimeout { get { return _connectionTimeout; } set { SetValue(ref _connectionTimeout, value); } } + private int _connectionTimeout = 30000; + /// Gets or sets the time (in milliseconds) to wait after an unexpected disconnect before reconnecting. + public int ReconnectDelay { get { return _reconnectDelay; } set { SetValue(ref _reconnectDelay, value); } } + private int _reconnectDelay = 1000; + /// Gets or sets the time (in milliseconds) to wait after an reconnect fails before retrying. + public int FailedReconnectDelay { get { return _failedReconnectDelay; } set { SetValue(ref _failedReconnectDelay, value); } } + private int _failedReconnectDelay = 10000; + + /// Gets or sets the time (in milliseconds) to wait when the websocket's message queue is empty before checking again. + public int WebSocketInterval { get { return _webSocketInterval; } set { SetValue(ref _webSocketInterval, value); } } + private int _webSocketInterval = 100; + + /// Instructs Discord to not send send information about offline users, for servers with more than 50 users. + public bool UseLargeThreshold { get { return _useLargeThreshold; } set { SetValue(ref _useLargeThreshold, value); } } + private bool _useLargeThreshold = false; + /// Acknowledges all incoming messages so that they appear read. + public bool AckMessages { get { return _ackMessages; } set { SetValue(ref _ackMessages, value); } } + private bool _ackMessages = false; + + //Cache + + /// Gets or sets the number of messages per channel that should be kept in cache. Setting this to zero disables the message cache entirely. + public int MessageCacheSize { get { return _messageCacheSize; } set { SetValue(ref _messageCacheSize, value); } } + private int _messageCacheSize = 100; + /// Maintains the LastActivity property for users, showing when they last made an action (sent message, joined server, typed, etc). + public bool TrackActivity { get { return _trackActivity; } set { SetValue(ref _trackActivity, value); } } + private bool _trackActivity = true; + } +}