/// <summary> Initializes a new instance of the DiscordClient class. </summary> public DiscordClient(DiscordConfig config = null) { Config = config ?? new DiscordConfig(); Config.Lock(); State = (int)ConnectionState.Disconnected; Status = UserStatus.Online; //Logging Log = new LogManager(this); Logger = Log.CreateLogger("Discord"); //Async _taskManager = new TaskManager(Cleanup); _connectionLock = new AsyncLock(); _disconnectedEvent = new ManualResetEvent(true); _connectedEvent = new ManualResetEventSlim(false); CancelToken = new CancellationToken(true); //Cache _servers = new ConcurrentDictionary<ulong, Server>(); _channels = new ConcurrentDictionary<ulong, Channel>(); _privateChannels = new ConcurrentDictionary<ulong, Channel>(); //Serialization _serializer = new JsonSerializer(); _serializer.DateTimeZoneHandling = DateTimeZoneHandling.Utc; #if TEST_RESPONSES _serializer.CheckAdditionalContent = true; _serializer.MissingMemberHandling = MissingMemberHandling.Error; #else _serializer.Error += (s, e) => { e.ErrorContext.Handled = true; Logger.Error("Serialization Failed", e.ErrorContext.Error); }; #endif //Networking ClientAPI = new RestClient(Config, DiscordConfig.ClientAPIUrl, Log.CreateLogger("ClientAPI")); StatusAPI = new RestClient(Config, DiscordConfig.StatusAPIUrl, Log.CreateLogger("StatusAPI")); GatewaySocket = new GatewaySocket(this, _serializer, Log.CreateLogger("Gateway")); GatewaySocket.Connected += (s, e) => { if (State == ConnectionState.Connecting) EndConnect(); }; GatewaySocket.Disconnected += (s, e) => OnDisconnected(e.WasUnexpected, e.Exception); GatewaySocket.ReceivedDispatch += (s, e) => OnReceivedEvent(e); if (Config.UseMessageQueue) MessageQueue = new MessageQueue(this, Log.CreateLogger("MessageQueue")); //Extensibility Services = new ServiceManager(this); //Import/Export //_messageImporter = new JsonSerializer(); //_messageImporter.ContractResolver = new Message.ImportResolver(); }
Task IQueuedAction.Do(MessageQueue queue) => queue.Edit(_msg, _text);
Task IQueuedAction.Do(MessageQueue queue) => queue.Delete(_msg);
Task IQueuedAction.Do(MessageQueue queue) => queue.Send(_msg);