public IAsyncResultFunc <TContext> Invoke(Option <IAsyncResultFunc <TContext> > nextAsyncActionOption) { var asyncActions = new List <IAsyncResultFunc <TContext> >(); foreach (var asyncActionBuilderAction in asyncActionBuilderActions) { var asyncActionBuilder = AsyncFuncBuilder <TContext> .Create(); asyncActionBuilderAction.Invoke(asyncActionBuilder); asyncActions.Add(asyncActionBuilder.Build()); } var enumeratingAsyncAction = factory.Create(asyncActions); return(nextAsyncActionOption.TryGetValue(out var nextAsyncAction) ? Actions.Enumerator.Enumerator <TContext> .Create(enumeratingAsyncAction, nextAsyncAction) : enumeratingAsyncAction); }
public IAsyncResultFunc <TInput> Invoke(Option <IAsyncResultFunc <TInput> > nextAsyncActionOption) { var asyncActionBuilder = AsyncFuncBuilder <TOutput> .Create(); configuration.Invoke(asyncActionBuilder); var command = asyncActionBuilder.Build(); var asyncContextSwitchDecorator = new AsyncResultFunc <TInput, TOutput>(asyncAbortableParser, command); if (nextAsyncActionOption.TryGetValue(out var nextAsyncAction)) { return(Actions.Enumerator.Enumerator <TInput> .Create(asyncContextSwitchDecorator, nextAsyncAction)); } return(asyncContextSwitchDecorator); }
public static async Task Main() { var discordSocketClient = new DiscordSocketClient( new DiscordSocketConfig { AlwaysDownloadUsers = true, LogLevel = LogSeverity.Verbose, DefaultRetryMode = RetryMode.AlwaysRetry }); discordSocketClient.Log += message => { Console.WriteLine(message); return(Task.CompletedTask); }; await discordSocketClient.LoginAsync(TokenType.Bot, "TOKEN").ConfigureAwait(false); await discordSocketClient.StartAsync().ConfigureAwait(false); var discordContextFactory = new DiscordContextFactory(discordSocketClient); var asyncFuncBuilder = AsyncFuncBuilder <DiscordContext> .Create(); discordSocketClient.Ready += () => { var autoBuilderFactory = new AutoBuilderFactory(TypeParserDictionaryFactory.CreateDefault()); asyncFuncBuilder .WithCondition(context => !context.User.IsBot) .WithCondition(context => !context.IsPrivateChannel) .WithPrefix( new MentionPrefix(discordSocketClient.CurrentUser), root => root.WithGroup( new StringPrefix("misc"), new List <Action <AsyncFuncBuilder <PrefixNormalizedDiscordContext> > > { echo => echo.WithPrefix( new StringPrefix("echo"), command => command.WithAdapter( autoBuilderFactory.Create() .Build <PrefixNormalizedDiscordContext, EchoContext>( input => input.PrefixNormalizedMessage), CreateEchoConfiguration())), reverse => reverse.WithPrefix( new StringPrefix("reverse"), command => command.WithAdapter( new ReverseTypeParser(), CreateReverseConfiguration())) }, fallback => fallback.WithAsyncFunc( async context => { await context.DiscordContext.Channel.SendMessageAsync( "Sorry, I don't know that command!") .ConfigureAwait(false); }))); var asyncAction = asyncFuncBuilder.Build(); discordSocketClient.MessageReceived += async message => { if (message is IUserMessage userMessage) { var result = await asyncAction.InvokeAsync( discordContextFactory.Create(userMessage), CancellationToken.None) .ConfigureAwait(false); } }; return(Task.CompletedTask); }; await Task.Delay(-1).ConfigureAwait(false); }