Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 internal static void AddCommandContainer(AsyncCommandContainer container)
 {
     lock (queueLock)
     {
         asyncCommandQueue.Enqueue(container);
     }
 }
Esempio n. 3
0
        private static void NewAsyncCommand(AsyncDelegate task, IDMCommandContext context)
        {
            AsyncCommandContainer container = new AsyncCommandContainer(task, context);

            container.typingState = context.Channel.EnterTypingState();
            AsyncCommandHandler.AddCommandContainer(container);
        }
Esempio n. 4
0
        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);
                }
            }
        }