public async Task DisplayAsync() { var embed = BuildEmbed(); var message = await Context.Channel.SendMessageAsync(embed : embed).ConfigureAwait(false); Message = message; Interactive.AddReactionCallback(message, this); // Reactions take a while to add, don't wait for them _ = Task.Run(async() => { await message.AddReactionAsync(options.First); await message.AddReactionAsync(options.Back); await message.AddReactionAsync(options.Stop); await message.AddReactionAsync(options.Next); await message.AddReactionAsync(options.Last); }); if (Timeout != null) { _ = Task.Delay(Timeout.Value).ContinueWith(_ => { Interactive.RemoveReactionCallback(message); Message.DeleteAsync(); }); } }
public async Task DisplayAsync() { var guid = BlackJackService.CreateImage(Context.User.Id); var embedBuilder = new EmbedBuilder() .WithSuccessColor() .WithImageUrl($"attachment://board{guid}.png") .WithDescription(BlackJackService.GetScoreFromMatch(Context.User.Id)) .WithFooter("React with the action you want to perform. (timeout = 30 seconds)"); var message = await InteractiveBase.SendFileAsync($"BlackJack/board{guid}.png", embed : embedBuilder); Message = message; Interactive.AddReactionCallback(message, this); // Reactions take a while to add, don't wait for them await Task.Run(async() => { await message.AddReactionAsync(_options.HitEmote); await message.AddReactionAsync(_options.StandEmote); }); if (Timeout != null) { await Task.Delay(Timeout.Value).ContinueWith(async _ => { //BlackJackService.RemovePlayerFromMatch(Context.User.Id); Interactive.RemoveReactionCallback(message); if (!_userClicked) { await Message.DeleteAsync(); } }); } }
public async Task DisplayAsync() { var embed = BuildEmbed(); Message = await Context.Channel.SendMessageAsync(_pager.Content, embed : embed); Interactive.AddReactionCallback(Message, this); // Reactions take a while to add, don't wait for them _ = Executor.ExecuteAsync(async() => { if (!_pager.Pages.IsEmpty()) { await Message.AddReactionAsync(_pager.Options.First); await Message.AddReactionAsync(_pager.Options.Back); await Message.AddReactionAsync(_pager.Options.Next); await Message.AddReactionAsync(_pager.Options.Last); var manageMessages = Context.Channel is IGuildChannel guildChannel && (Context.User as IGuildUser).GetPermissions(guildChannel).ManageMessages; if (_pager.Options.JumpDisplayOptions == JumpDisplayOptions.Always || (_pager.Options.JumpDisplayOptions == JumpDisplayOptions.WithManageMessages && manageMessages)) { await Message.AddReactionAsync(_pager.Options.Jump); } } await Message.AddReactionAsync(_pager.Options.Stop); if (_pager.Options.DisplayInformationIcon) { await Message.AddReactionAsync(_pager.Options.Info); } }); }
public async Task DisplayAsync() { var embed = BuildEmbed(); var message = await Context.Channel.SendMessageAsync(_pager.Content, embed : embed).ConfigureAwait(false); Message = message; Interactive.AddReactionCallback(message, this); // Reactions take a while to add, don't wait for them _ = Task.Run(async() => { await message.AddReactionAsync(options.First); await message.AddReactionAsync(options.Back); await message.AddReactionAsync(options.Next); await message.AddReactionAsync(options.Last); var manageMessages = (Context.Channel is IGuildChannel guildChannel) ? (Context.User as IGuildUser).GetPermissions(guildChannel).ManageMessages : false; }); if (Timeout.HasValue && Timeout.Value != null) { _ = Task.Delay(Timeout.Value).ContinueWith(_ => { Interactive.RemoveReactionCallback(message); _ = Message.DeleteAsync(); }); } }
/// <summary> /// The display async. /// </summary> /// <param name="reactionList"> /// The reactions. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> public async Task DisplayAsync(ReactionList reactionList) { var embed = BuildEmbed(); var message = await Context.Channel.SendMessageAsync(pager.Content, embed : embed).ConfigureAwait(false); Message = message; Interactive.AddReactionCallback(message, this); // reactionList take a while to add, don't wait for them _ = Task.Run(async() => { if (reactionList.First) { await message.AddReactionAsync(options.First); } if (reactionList.Backward) { await message.AddReactionAsync(options.Back); } if (reactionList.Forward) { await message.AddReactionAsync(options.Next); } if (reactionList.Last) { await message.AddReactionAsync(options.Last); } var manageMessages = Context.Channel is IGuildChannel guildChannel && (Context.User as IGuildUser).GetPermissions(guildChannel).ManageMessages; if (reactionList.Jump) { if (options.JumpDisplayOptions == JumpDisplayOptions.Always || (options.JumpDisplayOptions == JumpDisplayOptions.WithManageMessages && manageMessages)) { await message.AddReactionAsync(options.Jump); } } if (reactionList.Trash) { await message.AddReactionAsync(options.Stop); } if (reactionList.Info) { if (options.DisplayInformationIcon) { await message.AddReactionAsync(options.Info); } } }); if (Timeout.HasValue) { DisplayTimeout(message, Message); } }
public async Task DisplayAsync() { Rest.RestUserMessage message; if (_pager.ForceSendAsEmbed || _pager.Pages.ElementAt(page - 1).GetType() == typeof(EmbedBuilder) || _pager.Pages.ElementAt(page - 1).GetType() == typeof(Embed)) { var embed = BuildEmbed(); message = await Context.Channel.SendMessageAsync(_pager.Content, embed : embed).ConfigureAwait(false); } else { try { var content = Convert.ToString(_pager.Pages.ElementAt(page - 1)); message = await Context.Channel.SendMessageAsync(content).ConfigureAwait(false); } catch (Exception) { var embed = BuildEmbed(); message = await Context.Channel.SendMessageAsync(_pager.Content, embed : embed).ConfigureAwait(false); } } Message = message; Interactive.AddReactionCallback(message, this); // Reactions take a while to add, don't wait for them _ = Task.Run(async() => { await message.AddReactionAsync(options.First); await message.AddReactionAsync(options.Back); await message.AddReactionAsync(options.Next); await message.AddReactionAsync(options.Last); var manageMessages = (Context.Channel is IGuildChannel guildChannel) ? (Context.User as IGuildUser).GetPermissions(guildChannel).ManageMessages : false; if (options.JumpDisplayOptions == JumpDisplayOptions.Always || (options.JumpDisplayOptions == JumpDisplayOptions.WithManageMessages && manageMessages)) { await message.AddReactionAsync(options.Jump); } await message.AddReactionAsync(options.Stop); if (options.DisplayInformationIcon) { await message.AddReactionAsync(options.Info); } }); // TODO: (Next major version) timeouts need to be handled at the service-level! if (Timeout.HasValue && Timeout.Value != null) { _ = Task.Delay(Timeout.Value).ContinueWith(_ => { Interactive.RemoveReactionCallback(message); _ = Message.DeleteAsync(); }); } }
public async Task DisplayAsync() { var embed = BuildEmbed(); var message = await Context.Channel.SendMessageAsync(_pager.Content, embed : embed).ConfigureAwait(false); Message = message; Interactive.AddReactionCallback(message, this); // Reactions take a while to add, don't wait for them _ = Task.Run(async() => { if (options.First != null) { await message.AddReactionAsync(options.First); } if (options.Back != null) { await message.AddReactionAsync(options.Back); } if (options.Next != null) { await message.AddReactionAsync(options.Next); } if (options.Last != null) { await message.AddReactionAsync(options.Last); } var manageMessages = (Context.Channel is IGuildChannel guildChannel) ? (Context.User as IGuildUser).GetPermissions(guildChannel).ManageMessages : false; if ((options.JumpDisplayOptions == JumpDisplayOptions.Always || (options.JumpDisplayOptions == JumpDisplayOptions.WithManageMessages && manageMessages)) && options.Jump != null) { await message.AddReactionAsync(options.Jump); } if (options.Stop != null) { await message.AddReactionAsync(options.Stop); } if (options.DisplayInformationIcon) { await message.AddReactionAsync(options.Info); } }); // TODO: (Next major version) timeouts need to be handled at the service-level! if (Timeout.HasValue && Timeout.Value != null) { _ = Task.Delay(Timeout.Value).ContinueWith(_ => { Interactive.RemoveReactionCallback(message); _ = Message.DeleteAsync(); }); } }
public async Task DisplayAsync() { var embed = BuildEmbed(); IUserMessage message; if (_isDeferred) { message = await Context.Interaction.FollowupAsync(_pager.Content, embed : embed).ConfigureAwait(false); } else { await Context.Interaction.RespondAsync(_pager.Content, embed : embed).ConfigureAwait(false); message = await Context.Interaction.GetOriginalResponseAsync().ConfigureAwait(false); } Message = message; Interactive.AddReactionCallback(message, this); // Reactions take a while to add, don't wait for them _ = Task.Run(async() => { await message.AddReactionAsync(Options.First); await message.AddReactionAsync(Options.Back); await message.AddReactionAsync(Options.Next); await message.AddReactionAsync(Options.Last); var manageMessages = (Context.Channel is IGuildChannel guildChannel) && (Context.User as IGuildUser).GetPermissions(guildChannel).ManageMessages; if (Options.JumpDisplayOptions == JumpDisplayOptions.Always || (Options.JumpDisplayOptions == JumpDisplayOptions.WithManageMessages && manageMessages)) { await message.AddReactionAsync(Options.Jump); } await message.AddReactionAsync(Options.Stop); if (Options.DisplayInformationIcon) { await message.AddReactionAsync(Options.Info); } }); // TODO: (Next major version) timeouts need to be handled at the service-level! if (Timeout.HasValue && Timeout.Value != null) { _ = Task.Delay(Timeout.Value).ContinueWith(_ => { Interactive.RemoveReactionCallback(message); Context.Interaction.DeleteOriginalResponseAsync(); //_ = Message.DeleteAsync(); }); } }
public async Task EmojiOption(IUserMessage message, EmojiResponse response, TimeSpan timespan, params Emoji[] emojis) { foreach (Emoji emoji in emojis) { await message.AddReactionAsync(emoji); } await Task.Run(async() => { Interactive.AddReactionCallback(message, response); await Task.Delay(timespan); Interactive.RemoveReactionCallback(message); }); }
public async Task DisplayAsync() { var embed = BuildEmbed(); var message = await Context.Channel.SendMessageAsync(_pager.Content, embed : embed).ConfigureAwait(false); Message = message; Interactive.AddReactionCallback(message, this); // Reactions take a while to add, don't wait for them await Task.Run(async() => { await message.AddReactionAsync(_options.First); await message.AddReactionAsync(_options.Back); await message.AddReactionAsync(_options.Next); await message.AddReactionAsync(_options.Last); var manageMessages = (Context.Channel is IGuildChannel guildChannel) ? (Context.User as IGuildUser).GetPermissions(guildChannel).ManageMessages : false; if (_options.JumpDisplayOptions == JumpDisplayOptions.Always || (_options.JumpDisplayOptions == JumpDisplayOptions.WithManageMessages && manageMessages)) { await message.AddReactionAsync(_options.Jump); } await message.AddReactionAsync(_options.Stop); if (_options.DisplayInformationIcon) { await message.AddReactionAsync(_options.Info); } }); if (Timeout.HasValue) { await Task.Delay(Timeout.Value).ContinueWith(async _ => { Interactive.RemoveReactionCallback(message); await Message.DeleteAsync(); }); } }
public async Task FindPokemon([Remainder] string Name) { //Get the pokemon collection var pkm = Database.GetCollection <Pokemon>("Pokemon"); var moves = Database.GetCollection <Move>("Moves"); var abs = Database.GetCollection <Ability>("Abilities"); results = pkm .IncludeAll() .Find(x => x.DexName.ToLower().Contains(Name.ToLower())); if (results.Count() == 0) { await ReplyAsync(Context.User.Mention + ", No pokemon was found with that name."); return; } if (results.Count() > 20) { await ReplyAsync(Context.User.Mention + " Too many results! Narrow your search a bit."); } if (results.Count() == 1) { await ReplyAsync(Context.User.Mention + ", Pokemon found!", false, PokemonEntry(results.First())); return; } var n = new Emoji("▶"); var p = new Emoji("◀"); var msg = await ReplyAsync("Searching the pokedex..."); await msg.AddReactionAsync(p); //Add Previous button await msg.AddReactionAsync(n); //Add Next button Interactive.AddReactionCallback(msg, new InlineReactionCallback(Interactive, Context, new ReactionCallbackData(Context.User.Mention + ", Here are the results of your search! This pokedex result will be interactable for 5 minutes.", PokemonEntry(results.ElementAt(index)), false, false, TimeSpan.FromMinutes(5)) .WithCallback(p, (c, r) => GoBack(r, c, msg)) .WithCallback(n, (c, r) => Advance(r, c, msg)) )); }
public async Task DisplayAsync() { var embed = BuildEmbed(); var message = await Context.Channel.SendMessageAsync(_pager.MessageText, embed : embed).ConfigureAwait(false); Message = message; Interactive.AddReactionCallback(message, this); // Reactions take a while to add, don't wait for them _ = Task.Run(async() => { if (_pager.PageCount > 4) { await message.AddReactionAsync(options.First); } await message.AddReactionAsync(options.Back); await message.AddReactionAsync(options.Next); if (_pager.PageCount > 4) { await message.AddReactionAsync(options.Last); } if (_pager.PageCount > 4) { await message.AddReactionAsync(options.Jump); } }); // TODO: (Next major version) timeouts need to be handled at the service-level! if (Timeout.HasValue) { _ = Task.Delay(Timeout.Value).ContinueWith(_ => { Interactive.RemoveReactionCallback(message); message.RemoveAllReactionsAsync(); }); } }
public async Task DisplayAsync() { var message = await Context.Channel.SendMessageAsync(embed : _dialogue.Embed).ConfigureAwait(false); Message = message; Interactive.AddReactionCallback(message, this); // Reactions take a while to add, don't wait for them _ = Task.Run(async() => { foreach (var emote in _dialogue.Options) { await message.AddReactionAsync(emote.Key); } }); if (Timeout.HasValue) { _ = Task.Delay(Timeout.Value).ContinueWith(_ => { Interactive.RemoveReactionCallback(message); switch (_dialogue.OnTimeout) { case TimeoutOptions.Delete: message.DeleteAsync(); break; case TimeoutOptions.RemoveReactions: message.RemoveAllReactionsAsync(); break; default: break; } }); } }
/// <summary> /// Sends or edits the message, the reactions. /// </summary> /// <param name="reactionList"> /// The reactions. /// </param> /// <param name="oldMessage"> /// The old message to edit. /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> public async Task DisplayAsync(ReactionList reactionList, IUserMessage oldMessage) { var embed = BuildEmbed(); if (oldMessage == null) { Message = await Context.Channel.SendMessageAsync(pager.Content, embed : embed).ConfigureAwait(false); } else { // TODO: A better way to update the reactions //await OnStopAsync(oldMessage, ActionOnTimeout.DeleteReactions); Interactive.RemoveReactionCallback(oldMessage); await oldMessage.ModifyAsync(x => { x.Content = null; x.Embed = embed; }).ConfigureAwait(false); Message = (IUserMessage)await Context.Channel.GetMessageAsync(oldMessage.Id).ConfigureAwait(false); } //this.Message = Message; if (pages == 1) { return; } Interactive.AddReactionCallback(Message, this); // reactionList take a while to add, don't wait for them _ = Task.Run(async() => { if (reactionList.First) { await Message.AddReactionAsync(Options.First); } if (reactionList.Backward) { await Message.AddReactionAsync(Options.Back); } if (reactionList.Forward) { await Message.AddReactionAsync(Options.Next); } if (reactionList.Last) { await Message.AddReactionAsync(Options.Last); } bool manageMessages = Context.Channel is IGuildChannel guildChannel && (Context.User as IGuildUser).GetPermissions(guildChannel).ManageMessages; if (reactionList.Jump) { if (Options.JumpDisplayOptions == JumpDisplayOptions.Always || (Options.JumpDisplayOptions == JumpDisplayOptions.WithManageMessages && manageMessages)) { await Message.AddReactionAsync(Options.Jump); } } if (reactionList.Stop) { await Message.AddReactionAsync(Options.Stop); } if (reactionList.Info) { await Message.AddReactionAsync(Options.Info); } }); if (Timeout.HasValue) { _ = Task.Delay(Timeout.Value) .ContinueWith(_ => OnStopAsync(Message, Options.ActionOnTimeout).ConfigureAwait(false)) .ConfigureAwait(false); } }
public async Task DisplayAsync(ReactionList reactionList) { var embed = BuildEmbed(); RestUserMessage message; if (embed is string) { message = await Context.Channel.SendMessageAsync(embed as string).ConfigureAwait(false); } else if (embed is Embed) { message = await Context.Channel.SendMessageAsync(_pager.Content, embed : embed as Embed).ConfigureAwait(false); } else { return; } Message = message; Interactive.AddReactionCallback(message, this); _ = Task.Run(async() => { if (reactionList.First) { await message.AddReactionAsync(Options.First); } if (reactionList.Backward) { await message.AddReactionAsync(Options.Back); } if (reactionList.Forward) { await message.AddReactionAsync(Options.Next); } if (reactionList.Last) { await message.AddReactionAsync(Options.Last); } var manageMessages = Context.Channel is IGuildChannel guildChannel && (Context.User as IGuildUser).GetPermissions(guildChannel).ManageMessages; if (reactionList.Jump && Options.JumpDisplayOptions == JumpDisplayOptions.Always || Options.JumpDisplayOptions == JumpDisplayOptions.WithManageMessages && manageMessages) { await message.AddReactionAsync(Options.Jump); } if (reactionList.Trash) { await message.AddReactionAsync(Options.Stop); } if (reactionList.Info && Options.DisplayInformationIcon) { await message.AddReactionAsync(Options.Info); } }); if (Timeout.HasValue) { DisplayTimeout(message, Message); } }
public async Task SetupMessage() { PostedMessages = new Collection <IMessage>(); Interactive.ClearReactionCallbacks(); if (this.beforeTextPosted != null) { this.beforeTextPosted(this); } if (additionalPosts.Count > 0) { var additionalPostsString = new StringBuilder(); foreach (var text in additionalPosts) { additionalPostsString.Append(text + Environment.NewLine); } var value = additionalPostsString.ToString(); if (value != string.Empty) { var message = await Context.Channel.SendMessageAsync(value); PostedMessages.Add(message); } } this.Message = await Context.Channel.SendMessageAsync(description); PostedMessages.Add(this.Message); if (type == StepType.Reaction) { var emotes = new Collection <IEmote>(); foreach (var action in Actions) { emotes.Add(action.Emote); } await Message.AddReactionsAsync(emotes.ToArray()); Interactive.AddReactionCallback(this.Message, this); } else { var response = await Interactive.NextMessageAsync(Context, true, true, TimeSpan.FromMinutes(2)); Result = response.Content; await response.DeleteAsync(); await RemoveMessagesOnNextProgression(); reactBasedOnResult(); } if (Timeout.HasValue && Timeout.Value != null) { _ = Task.Delay(Timeout.Value).ContinueWith(async _ => { if (Message != null) { Interactive.RemoveReactionCallback(Message); } foreach (var message in PostedMessages) { await message.DeleteAsync(); } }); } }
/// <summary> /// Sends the paginated message with the provided reaction list. /// </summary> /// <param name="reactionList"> /// The reactions to add. /// </param> /// <param name="oldMessage"> /// An old message to reuse. /// </param> /// <returns> /// A task representing the asynchronous operation. /// </returns> internal async Task DisplayAsync(ReactionList reactionList, IUserMessage oldMessage) { var embed = BuildEmbed(); if (oldMessage == null) { Message = await Context.Channel.SendMessageAsync(_pager.Text, embed : embed).ConfigureAwait(false); } else { // Remove the old message callback Interactive.RemoveReactionCallback(oldMessage); if (oldMessage.Reactions.Count > 0) { // There's still reactions (that means the bot doesn't have ManageMessages perms) await oldMessage.DeleteAsync(); Message = await Context.Channel.SendMessageAsync(_pager.Text, embed : embed).ConfigureAwait(false); } else { await oldMessage.ModifyAsync(x => { x.Content = _pager.Text; x.Embed = embed; }).ConfigureAwait(false); Message = oldMessage; } } if (_pages <= 1) { return; } Interactive.AddReactionCallback(Message, this); // reactionList take a while to add, don't wait for them _ = Task.Run(async() => { if (reactionList.First) { await Message.AddReactionAsync(_pager.Options.First).ConfigureAwait(false); } if (reactionList.Backward) { await Message.AddReactionAsync(_pager.Options.Back).ConfigureAwait(false); } if (reactionList.Forward) { await Message.AddReactionAsync(_pager.Options.Next).ConfigureAwait(false); } if (reactionList.Last) { await Message.AddReactionAsync(_pager.Options.Last).ConfigureAwait(false); } if (reactionList.Jump) { await Message.AddReactionAsync(_pager.Options.Jump).ConfigureAwait(false); } if (reactionList.Stop) { await Message.AddReactionAsync(_pager.Options.Stop).ConfigureAwait(false); } if (reactionList.Info) { await Message.AddReactionAsync(_pager.Options.Info).ConfigureAwait(false); } if (Timeout.HasValue) { await Task.Delay(Timeout.Value).ConfigureAwait(false); await OnStopAsync(Message, _pager.Options.ActionOnTimeout).ConfigureAwait(false); } }); }