private Task executeAsyncMode(IDMCommandContext context, IGuildCommandContext guildContext, object parsedArgs) { switch (ExecutionMethod) { case HandledContexts.None: return(context.Channel.SendEmbedAsync("INTERNAL ERROR", true)); case HandledContexts.DMOnly: AsyncCommandContainer.NewAsyncCommand(Execute, context, parsedArgs); break; case HandledContexts.GuildOnly: AsyncCommandContainer.NewAsyncCommand(ExecuteGuild, guildContext, parsedArgs); break; case HandledContexts.Both: if (context.IsGuildContext) { AsyncCommandContainer.NewAsyncCommand(ExecuteGuild, guildContext, parsedArgs); } else { AsyncCommandContainer.NewAsyncCommand(Execute, context, parsedArgs); } break; } return(Task.CompletedTask); }
internal static void AddCommandContainer(AsyncCommandContainer container) { lock (queueLock) { asyncCommandQueue.Enqueue(container); } }
private static void NewAsyncCommand(AsyncDelegate task, IDMCommandContext context) { AsyncCommandContainer container = new AsyncCommandContainer(task, context); container.typingState = context.Channel.EnterTypingState(); AsyncCommandHandler.AddCommandContainer(container); }
private async void AsyncCommandHandlerLoop() { while (true) { lock (asyncCommandQueue) { if (asyncCommandQueue.Count > 0) { commandContainer = asyncCommandQueue.Dequeue(); } } if (commandContainer != null) { await commandContainer.Execute(); commandContainer = null; } else { Thread.Sleep(sleep); } } }