public async Task <Message> SendPaginatedMessageAsync(EspeonContext context, PaginatedMessage pager) { var callback = new PaginatedMessageCallback(this, context, pager); await callback.DisplayAsync().ConfigureAwait(false); return(callback.Message); }
private async Task MainAsync() { var manager = new LogManager(LogSeverity.Verbose); var client = new WumpusBotClient(restRateLimiter: new DefaultRateLimiter(), logManager: manager) { Authorization = new AuthenticationHeaderValue("Bot", Environment.GetEnvironmentVariable("Espeon")), }; manager.Output += message => Console.WriteLine(message); var commands = new CommandServiceBuilder <EspeonContext>() .AddPipeline((ctx, next) => { if (ctx.Context.Message.StartsWith("!")) { ctx.PrefixLength = 1; } return(next.Invoke()); }) .AddCommandParser <DefaultCommandParser>() .AddModule <Commands>() .BuildCommandService(); var services = new ServiceCollection() .AddSingleton <InteractiveService>() .AddSingleton(client) .AddSingleton(commands) .BuildServiceProvider(); _ = Task.Run(async() => { await client.RunAsync(); }); try { client.Gateway.MessageCreate += async message => { if (message.Author.Bot.IsSpecified) { return; } if (!message.Content.StartsWith(new Utf8String("!"))) { return; } var channel = await client.Rest.GetChannelAsync(message.ChannelId); var context = new EspeonContext(client.Rest, message, channel, commands); await commands.ExecuteAsync(context, services); }; } catch (Exception e) { Console.WriteLine(e); } await Task.Delay(-1); }
public PaginatedMessageCallback(InteractiveService interactive, EspeonContext sourceContext, PaginatedMessage pager, ICriterion <Emoji> criterion = null) { _interactive = interactive; Context = sourceContext; Criterion = criterion ?? new EmptyCriterion <Emoji>(); _pager = pager; _pages = _pager.Pages.Count(); }
public async Task <bool> JudgeAsync(EspeonContext sourceContext, T parameter) { foreach (var criterion in _critiera) { var result = await criterion.JudgeAsync(sourceContext, parameter).ConfigureAwait(false); if (!result) { return(false); } } return(true); }
public Task <bool> JudgeAsync(EspeonContext sourceContext, T parameter) => Task.FromResult(true);
public Task <bool> JudgeAsync(EspeonContext sourceContext, Message parameter) { bool ok = int.TryParse(parameter.Content.ToString(), out _); return(Task.FromResult(ok)); }
public Task <bool> JudgeAsync(EspeonContext sourceContext, Emoji parameter) { bool ok = parameter.User.Value.Id == sourceContext.User.Id; return(Task.FromResult(ok)); }