private async Task <string?> WaitForFinishingMoveAsync(LocalizationService lcs) { if (this.Winner is null) { return(null); } string fstr = lcs.GetString(this.Channel.GuildId, "fmt-game-duel-f", Emojis.DuelSwords, this.Winner.Mention, Emojis.DuelSwords); DiscordMessage msg = await this.Channel.EmbedAsync(fstr); InteractivityResult <DiscordMessage> mctx = await this.Interactivity.WaitForMessageAsync( m => m.Channel == this.Channel && m.Author == this.Winner, TimeSpan.FromSeconds(15) ); if (mctx.TimedOut || string.IsNullOrWhiteSpace(mctx.Result.Content)) { return(null); } try { await msg.DeleteAsync(); await mctx.Result.DeleteAsync(); } catch (Exception e) when(e is UnauthorizedException or NotFoundException) { // No permissions to delete the messages } return(mctx.Result.Content.Trim()); } }
public static async Task <string> GetMention(CommandContext ctx, string mention, string message = "Please send a valid mention.") { await ctx.RespondAsync($"{mention} isn't a valid tag! {message}"); InteractivityResult <DiscordMessage> mes = await GetMessageWithMention(ctx); if (mes.Result.Content.ToLower() == "cancel") { await ctx.RespondAsync("Command Cancelled."); return(ctx.Message.Author.Id.ToString()); } else { mention = mes.Result.Content; if (!IsMention(mention)) { return(await GetMention(ctx, mention, message)); } else { return(mention); } } }
public async Task ConfigReset(CommandContext ctx) { InteractivityExtension interactivity = ctx.Client.GetInteractivity(); DiscordMessage msg = await ctx.RespondAsync( "Please type out \"yes\" to confirm. All configuration for your server will be reset!"); InteractivityResult <DiscordMessage> tmp = await interactivity.WaitForMessageAsync(s => s.Author == ctx.Message.Author, new TimeSpan(0, 0, 30)); if (!tmp.TimedOut || tmp.Result.Content != "yes") { string path; foreach ((ulong key, DiscordChannel _) in ctx.Guild.Channels) { ConfigManager.GetXml(key.ToString(), ConfigManager.Channel, out path); File.Delete(path); } ConfigManager.GetXml(ctx.Guild.Id.ToString(), ConfigManager.Guild, out path); File.Delete(path); await msg.ModifyAsync("Deleted."); } else { await msg.ModifyAsync("Cancelled."); } }
public async Task RandomCatSpam(CommandContext ctx, [Description("period of cat posting. [number][d/h/m/s]")] TimeSpan period) { InteractivityExtension interactivity = ctx.Client.GetInteractivity(); await ctx.RespondAsync(":cat: Cats will appear here every" + $"{(period.Days != 0 ? $" {period.Days} day(s)" : "")}" + $"{(period.Hours != 0 ? $" {period.Hours} hour(s)" : "")}" + $"{(period.Minutes != 0 ? $" {period.Minutes} minute(s)" : "")}" + $"{(period.Seconds != 0 ? $" {period.Seconds} second(s)" : "")}.\n" + "Enter `stop cats` to stop it."); while (true) { await RandomCat(ctx); InteractivityResult <DiscordMessage> stopmsg = await interactivity.WaitForMessageAsync(xm => xm.ChannelId.Equals(ctx.Message.ChannelId) && xm.Content == "stop cats", period); if (stopmsg.TimedOut) { continue; } await ctx.RespondAsync("Cat spam ends here."); break; } }
public async Task QuickType(CommandContext ctx, [Description("Bytes to generate. One byte equals two characters")] int bytes, [Description("Time before exiting")] TimeSpan time) { if (ctx.Channel.Get(ConfigManager.Enabled) .And(ctx.Channel.GetMethodEnabled())) { await ctx.TriggerTypingAsync(); if (time > new TimeSpan(0, 1, 0)) { throw new ArgumentOutOfRangeException("Please choose a smaller time"); } InteractivityExtension interactivity = ctx.Client.GetInteractivity(); byte[] codeBytes = new byte[bytes]; Program.Rnd.NextBytes(codeBytes); string code = BitConverter.ToString(codeBytes).ToLower().Replace("-", ""); await ctx.RespondAsync($"The first one to type the following code gets a reward: {code.Emotify()}"); InteractivityResult <DiscordMessage> msg = await interactivity.WaitForMessageAsync(xm => xm.Content.Contains(code), time); if (msg.TimedOut) { await ctx.RespondAsync("Nobody? Really?"); } else { await ctx.RespondAsync($"And the winner is: {msg.Result.Author.Mention}"); } } }
public static async Task <bool> WaitForBoolReplyAsync(this InteractivityExtension interactivity, ulong cid, ulong uid, SharedData shared = null) { if (!(shared is null)) { shared.AddPendingResponse(cid, uid); } bool response = false; InteractivityResult <DiscordMessage> mctx = await interactivity.WaitForMessageAsync(m => { if (m.ChannelId != cid || m.Author.Id != uid) { return(false); } bool?b = CustomBoolConverter.TryConvert(m.Content); response = b ?? false; return(b.HasValue); }); if (!(shared is null) && !shared.TryRemovePendingResponse(cid, uid)) { throw new ConcurrentOperationException("Failed to remove user from waiting list. Something went wrong!"); } return(response); }
public static async Task <Reaction> AddAndWaitForYesNoReaction(this InteractivityExtension interactivity, DiscordMessage msg, DiscordUser user) { DiscordClient client = interactivity.Client; await msg.CreateReactionAsync(DiscordEmoji.FromName(client, ":regional_indicator_y:")); await msg.CreateReactionAsync(DiscordEmoji.FromName(client, ":regional_indicator_n:")); InteractivityResult <MessageReactionAddEventArgs> interactivityResult = await interactivity.WaitForReactionAsync(msg, user); if (interactivityResult.TimedOut || interactivityResult.Result.Emoji.Equals(DiscordEmoji.FromName(client, ":regional_indicator_n:"))) { DiscordMessage snark = await interactivityResult.Result.Channel.SendMessageAsync($"{user.Mention}, well then why did you get my attention! Thanks for wasting my time. Let me clean up now. :triumph:"); await Task.Delay(5000); await interactivityResult.Result.Channel.DeleteMessagesAsync(new List <DiscordMessage> { msg, snark }); return(interactivityResult.TimedOut ? Reaction.None : Reaction.No); } await msg.DeleteAllReactionsAsync(); return(Reaction.Yes); }
private async Task QueryAndPrintInfoAsync(CommandContext ctx, DatabaseSwatServer server) { SwatServerInfo info = await SwatServerInfo.QueryIPAsync(server.IP, server.QueryPort); if (info is null) { await this.InformFailureAsync(ctx, "No reply from server."); return; } DiscordMessage msg = await ctx.RespondAsync(embed : info.ToDiscordEmbed(this.ModuleColor)); await msg.CreateReactionAsync(StaticDiscordEmoji.Information); await Task.Delay(250); InteractivityResult <MessageReactionAddEventArgs> rctx = await ctx.Client.GetInteractivity().WaitForEventArgsAsync <MessageReactionAddEventArgs>(e => e.Message == msg && e.Emoji == StaticDiscordEmoji.Information); if (!rctx.TimedOut) { SwatServerInfo completeInfo = await SwatServerInfo.QueryIPAsync(server.IP, server.QueryPort, complete : true); if (completeInfo is null) { await this.InformFailureAsync(ctx, "No reply from server."); return; } await msg.ModifyAsync(embed : completeInfo.ToDiscordEmbed(this.ModuleColor)); } }
// Takes turns to wait for the player and ai to make a move. public async Task MakeMove(DiscordMessage embed) { if (GameActive) { InteractivityResult <MessageReactionAddEventArgs> reactionResultp1 = await InteractivityResult(p1.Id, embed); ActivePlayer = ai.Name; await RemoveChoice(embed, reactionResultp1.Result.Emoji); await UpdateField(grid.GameGrid, embed, reactionResultp1.Result.Emoji, p1.PlayerEmoji, 1); if (Turn >= 2) { CheckWinCondition(p1.Name, grid.GameGrid); } } if (GameActive) { await Task.Delay(1000); ActivePlayer = p1.Name; DiscordEmoji aiMove = ConvertAiMove(); await RemoveChoice(embed, aiMove); await UpdateField(grid.GameGrid, embed, aiMove, ai.AiEmoji, 2); if (Turn >= 2) { CheckWinCondition(ai.Name, grid.GameGrid); } } }
public async Task AddGuildEvent(CommandContext context) { DiscordMessage msg = await context.RespondAsync($":wave: Hi, {context.User.Mention}! You wanted to create a new event?"); await msg.CreateReactionAsync(DiscordEmoji.FromName(context.Client, ":regional_indicator_y:")); await msg.CreateReactionAsync(DiscordEmoji.FromName(context.Client, ":regional_indicator_n:")); InteractivityExtension interactivity = context.Client.GetInteractivity(); InteractivityResult <MessageReactionAddEventArgs> interactivityResult = await interactivity.WaitForReactionAsync(msg, context.User); if (interactivityResult.TimedOut || !interactivityResult.Result.Emoji.Equals(DiscordEmoji.FromName(context.Client, ":regional_indicator_y:"))) { DiscordMessage snark = await context.RespondAsync("Well, thanks for wasting my time. Have a good day."); await Task.Delay(5000); await context.Channel.DeleteMessagesAsync(new List <DiscordMessage> { msg, snark, context.Message }); return; } await context.Message.DeleteAsync(); await msg.DeleteAllReactionsAsync(); await this.AddGuildEventInteractive(context, interactivity, msg); }
public static async Task <bool?> WaitForConfirmation(this InteractivityExtension interactivity, TimeSpan?timeoutoverride = null) { string[] positive = new string[] { "yes", "y", "yeah", "✅", "✔", }; string[] negative = new string[] { "no", "n", "nope", "❌", "✖", "❎" }; InteractivityResult <DiscordMessage> interactivityResult = await interactivity.WaitForMessageAsync(msg => positive.Any(w => msg.Content.ToLower().Contains(w)) || negative.Any(w => msg.Content.ToLower().Contains(w)), timeoutoverride); return(positive.Any(w => interactivityResult.Result.Content.ToLower().Contains(w)) ? true : negative.Any(w => interactivityResult.Result.Content.ToLower().Contains(w)) ? false : (bool?)null); }
private async Task VerifyTransactionAsync( CommandContext ctx, GlobalUserModel sender, GlobalUserModel receiver, uint amount) { // 'Complicated async logic here' // InteractivityExtension interactivity = ctx.Client.GetInteractivity(); int authKey = new Random().Next(1000, 10000); await ctx.RespondAsync("Just verifying you want to send money to this person. " + $"Could you type `{authKey}` to confirm? (Ignoring this will cancel, " + "since Velvet can't be bothered to write that logic right now.)"); InteractivityResult <DiscordMessage> message = await interactivity.WaitForMessageAsync(m => m.Author == ctx.User && m.Content == authKey.ToString(), TimeSpan.FromMinutes(3)); if (message.TimedOut) { await ctx.RespondAsync("Timed out :("); } else { DiscordMember member = await ctx.Guild.GetMemberAsync(receiver.Id); DiscordEmbedBuilder embed = new DiscordEmbedBuilder() .WithThumbnail(ctx.User.AvatarUrl) .WithDescription($"Successfully donated {amount} dollars to {member.Mention}! " + $"Feel free to do `{ctx.Prefix}cash` to ensure you've received the funds.") .WithColor(DiscordColor.PhthaloGreen); sender.Cash -= (int)amount; receiver.Cash += (int)amount; await ctx.RespondAsync(embed : embed); } }
private async Task <string> WaitForFinishingMoveAsync() { DiscordMessage msg = await this.Channel.EmbedAsync($"{StaticDiscordEmoji.DuelSwords} {this.Winner.Mention}, FINISH HIM! {StaticDiscordEmoji.DuelSwords}"); InteractivityResult <DiscordMessage> mctx = await this.Interactivity.WaitForMessageAsync( m => m.ChannelId == this.Channel.Id && m.Author.Id == this.Winner.Id, TimeSpan.FromSeconds(15) ); if (mctx.TimedOut || string.IsNullOrWhiteSpace(mctx.Result.Content)) { return(null); } try { await msg.DeleteAsync(); await mctx.Result.DeleteAsync(); } catch (Exception e) when(e is UnauthorizedException || e is NotFoundException) { // No permissions to delete the messages } return(mctx.Result.Content.Trim()); }
private static async Task <int> GetMaximumNumberOfSuggestions(CommandContext context, InteractivityExtension interactivity) { await context.Channel.SendMessageAsync("How many suggestions do you want pulled to vote on? (3-10)"); int?maximumNumberOfSuggestions = null; while (maximumNumberOfSuggestions == null) { InteractivityResult <DiscordMessage> getMaxNumSuggestions = await interactivity.WaitForMessageAsync(m => m.ChannelId == context.Channel.Id && m.Author.Id == context.Member.Id); if (getMaxNumSuggestions.TimedOut) { throw new UserTimeoutException("movie night creation"); } if (int.TryParse(getMaxNumSuggestions.Result.Content, out int maxNumSuggestions) && maxNumSuggestions <= 10 && maxNumSuggestions >= 3) { maximumNumberOfSuggestions = maxNumSuggestions; } else { await context.Channel.SendMessageAsync("Invalid Input. Please try again."); } } return(maximumNumberOfSuggestions.Value); }
private void setPage(InteractivityResult <DSharpPlus.EventArgs.MessageReactionAddEventArgs> messageResult) { if (messageResult.TimedOut) { page = ShopPage.TimedOut; return; } switch (messageResult.Result.Emoji.GetDiscordName()) { case ":crossed_swords:": page = ShopPage.Armory; break; case ":shield:": page = ShopPage.Buffs; break; case ":star:": page = ShopPage.Flair; break; case ":moneybag:": page = ShopPage.StoreFront; break; } }
/// <summary> /// Update the interactivity reaction message, and then send a new result /// message to the original channel that the command was sent from. /// </summary> /// <param name="reactionMessage"></param> /// <param name="reactionEvent"></param> public async Task Result(ReactionMessage reactionMessage, InteractivityResult <MessageReactionAddEventArgs> reactionEvent) { DateTime timestamp = DateTime.UtcNow; string resultText = "Denied"; var emoji = new ConfirmOrDenyEmojiModel(_ctx); var embedBuilder = new DiscordEmbedBuilder() .WithTimestamp(timestamp) .WithColor(DiscordColor.Red); if (reactionEvent.Result.Emoji == emoji.Confirmed) { resultText = "Confirmed"; embedBuilder.Color = DiscordColor.Green; } string username = reactionEvent.Result.User?.Username ?? "<unknown username>"; string footerText = $"{reactionEvent.Result.Emoji} {resultText} by {username}"; embedBuilder.WithFooter(footerText); if (_ctx.Channel.Id != reactionMessage.Channel?.Id) { await SendResultsToUserDefinedChannel(embedBuilder, resultText).ConfigureAwait(false); } embedBuilder.AddField("Jump Link", $"[Original Message]({_ctx.Message.JumpLink})"); await reactionMessage.DeleteAllReactions().ConfigureAwait(false); await reactionMessage.Update(embedBuilder).ConfigureAwait(false); }
private static async Task <DayOfWeek> GetMovieStartDayOfWeek(CommandContext context, InteractivityExtension interactivity) { await context.Channel.SendMessageAsync("What day of the week would you like to show the movie? (respond with the full day name or the three letter abbreviation)"); DayOfWeek?movieStartDayOfWeek = null; while (movieStartDayOfWeek == null) { InteractivityResult <DiscordMessage> getDayOfWeekResult = await interactivity.WaitForMessageAsync(m => m.ChannelId == context.Channel.Id && m.Author.Id == context.Member.Id); if (getDayOfWeekResult.TimedOut) { throw new UserTimeoutException("movie night creation"); } movieStartDayOfWeek = ParseDayOfWeek(getDayOfWeekResult.Result.Content); if (movieStartDayOfWeek == null) { await context.Channel.SendMessageAsync("Invalid input. Please try again."); } } return(movieStartDayOfWeek.Value); }
// Waits for the player1 to make a move - after it will wait for player 2 public async Task MakeMove(DiscordMessage embed) { if (GameActive) { InteractivityResult <MessageReactionAddEventArgs> reactionResultp1 = await InteractivityResult(p1.Id, embed); ActivePlayer = p2.Name; await RemoveChoice(embed, reactionResultp1.Result.Emoji); await UpdateField(grid.GameGrid, embed, reactionResultp1.Result.Emoji, p1.PlayerEmoji, 1); if (Turn >= 2) { CheckWinCondition(p1.Name, grid.GameGrid); } } if (GameActive) { InteractivityResult <MessageReactionAddEventArgs> reactionResultp2 = await InteractivityResult(p2.Id, embed); ActivePlayer = p1.Name; await RemoveChoice(embed, reactionResultp2.Result.Emoji); await UpdateField(grid.GameGrid, embed, reactionResultp2.Result.Emoji, p2.PlayerEmoji, 2); if (Turn >= 2) { CheckWinCondition(p2.Name, grid.GameGrid); } } }
private static async Task <TimeSpan> GetMovieStartTimeOfDay(CommandContext context, InteractivityExtension interactivity) { await context.Channel.SendMessageAsync("What time would you like to show the movie? (respond with the time in 24h format. Ex: 13:20 for 1:20 pm)"); TimeSpan?movieStartTimeOfDay = null; while (movieStartTimeOfDay == null) { InteractivityResult <DiscordMessage> getTimeResult = await interactivity.WaitForMessageAsync(m => m.ChannelId == context.Channel.Id && m.Author.Id == context.Member.Id); if (getTimeResult.TimedOut) { throw new UserTimeoutException("movie night creation"); } if (!TimeSpan.TryParseExact(getTimeResult.Result.Content, @"hh\:mm", null, out TimeSpan parsedTimeSpan)) { await context.Channel.SendMessageAsync("Invalid input. Please try again."); } else if (parsedTimeSpan.TotalHours >= 0 && parsedTimeSpan.TotalHours < 24) { movieStartTimeOfDay = parsedTimeSpan; } else { await context.Channel.SendMessageAsync("You must provide a time within 00:00-23:59."); } } return(movieStartTimeOfDay.Value); }
private static async Task <(int, int)> GetDaysAndHours(CommandContext context, InteractivityExtension interactivity) { int?voteEndDays = null; int?voteEndHours = null; while (voteEndDays == null || voteEndHours == null) { InteractivityResult <DiscordMessage> getVoteEnd = await interactivity.WaitForMessageAsync(m => m.ChannelId == context.Channel.Id && m.Author.Id == context.Member.Id); if (getVoteEnd.TimedOut) { throw new UserTimeoutException("movie night creation"); } if (!TimeSpan.TryParseExact(getVoteEnd.Result.Content, @"d\d%h\h", null, out TimeSpan parsedTimeSpan)) { await context.Channel.SendMessageAsync("Invalid input. Please try again."); } else if (parsedTimeSpan.TotalDays >= 0 && parsedTimeSpan.TotalDays < 7) { voteEndDays = parsedTimeSpan.Days; voteEndHours = parsedTimeSpan.Hours; } else { await context.Channel.SendMessageAsync("You must provide a time within 0d0h-6d23h."); } } return(voteEndDays.Value, voteEndHours.Value); }
private static async Task <OmdbParentalRating> GetMaxParentalRating(CommandContext context, InteractivityExtension interactivity) { await context.Channel.SendMessageAsync("What is the maximum parental rating you want included in the movie night?"); OmdbParentalRating?maxParentalRating = null; while (maxParentalRating == null) { InteractivityResult <DiscordMessage> getParentalRating = await interactivity.WaitForMessageAsync(m => m.ChannelId == context.Channel.Id && m.Author.Id == context.Member.Id); if (getParentalRating.TimedOut) { throw new UserTimeoutException("movie night creation"); } try { maxParentalRating = getParentalRating.Result.Content.ToOmdbParentalRating(); } catch (JsonException) { } if (maxParentalRating == null) { await context.Channel.SendMessageAsync("Invalid Input. Please try again with an MPA Parental Rating. If you are sure that the rating exists, please contact the developer."); } } return(maxParentalRating.Value); }
public static async Task <DiscordChannel?> WaitForChannelMentionAsync(this InteractivityExtension interactivity, DiscordChannel channel, DiscordUser user) { InteractivityResult <DiscordMessage> mctx = await interactivity.WaitForMessageAsync( m => m.Channel == channel && m.Author == user && m.MentionedChannels.Count == 1 ); return(mctx.TimedOut ? null : mctx.Result.MentionedChannels.FirstOrDefault() ?? null); }
public override async Task RunAsync() { var questions = new Queue <string>(_countries.Keys.Shuffle()); int timeouts = 0; for (int i = 1; i < this.NumberOfQuestions; i++) { string question = questions.Dequeue(); await this.Channel.TriggerTypingAsync(); await this.Channel.SendFileAsync("flag.png", new FileStream(question, FileMode.Open), content : $"Question #{Formatter.Bold(i.ToString())}:"); bool timeout = true; var answerRegex = new Regex($@"\b{_countries[question]}\b", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase); InteractivityResult <DiscordMessage> mctx = await this.Interactivity.WaitForMessageAsync( xm => { if (xm.ChannelId != this.Channel.Id || xm.Author.IsBot) { return(false); } timeout = false; return(answerRegex.IsMatch(xm.Content)); }, TimeSpan.FromSeconds(10) ); if (mctx.TimedOut) { if (timeout) { timeouts++; } else { timeouts = 0; } if (timeouts == 3) { this.IsTimeoutReached = true; return; } await this.Channel.SendMessageAsync($"Time is out! The correct answer was: {Formatter.Bold(_countries[question])}"); } else { await this.Channel.SendMessageAsync($"GG {mctx.Result.Author.Mention}, you got it right!"); this.Results.AddOrUpdate(mctx.Result.Author, u => 1, (u, v) => v + 1); } await Task.Delay(TimeSpan.FromSeconds(2)); } }
public static async Task <int?> WaitForOptionReplyAsync(this InteractivityExtension interactivity, DiscordChannel channel, DiscordUser user, int max, int min = 0) { int index = 0; InteractivityResult <DiscordMessage> mctx = await interactivity.WaitForMessageAsync( m => m.Channel == channel && m.Author == user && int.TryParse(m.Content, out index) && index < max && index >= min ); return(mctx.TimedOut ? null : index); }
public static int CheckInteractivity(InteractivityResult <MessageReactionAddEventArgs> interactivity) { int number; var reaction = interactivity.Result.Emoji; Console.WriteLine(GetEmoji.FromOneToFiveDiscordEmojies[0]); number = GetEmoji.FromOneToFiveDiscordEmojies.IndexOf(reaction); return(number); }
/// <summary> /// Handles timout, and updates specified variable if successful /// </summary> /// <param name="context">Interactivity Results</param> /// <param name="variable">Variable that should be updated so long as the response doesn't timeout</param> protected void ReplyHandlerAction(InteractivityResult <DiscordMessage> context, ref string variable) { if (context.TimedOut) { throw new StopWizardException(GetType().Name); } variable = context.Result.Content; }
public async Task PrefixSuccess(CommandContext ctx, [DSharpPlus.CommandsNext.Attributes.Description("The operation to be executed [add/list/del] ")] string operation) { switch (operation.ToLowerInvariant()) { case "add": var msg = await ctx.RespondAsync(embed : EmbedBase.InputEmbed("Prefix to be added")); InteractivityResult <DiscordMessage> response = await ctx.Message.GetNextMessageAsync(); var prefix = response.Result.Content; if (Program.Config.Prefixes.Contains(prefix.ToLowerInvariant())) { await msg.ModifyAsync(embed : EmbedBase.OutputEmbed($"This prefix is already added.")); } else { Program.Config.Prefixes.Add(prefix.ToLowerInvariant()); File.WriteAllText(Directory.GetCurrentDirectory() + "/Config.json", JsonConvert.SerializeObject(Program.Config, Formatting.Indented)); await msg.ModifyAsync(embed : EmbedBase.OutputEmbed($"Prefix added without errors.")); } break; case "del": var msg2 = await ctx.RespondAsync(embed : EmbedBase.InputEmbed("Prefix to be removed")); InteractivityResult <DiscordMessage> response2 = await ctx.Message.GetNextMessageAsync(); var prefix2 = response2.Result.Content; if (!Program.Config.Prefixes.Contains(prefix2.ToLowerInvariant())) { await msg2.ModifyAsync(embed : EmbedBase.OutputEmbed($"This prefix doesn't exists.")); } else { Program.Config.Prefixes.Remove(prefix2.ToLowerInvariant()); File.WriteAllText(Directory.GetCurrentDirectory() + "/Config.json", JsonConvert.SerializeObject(Program.Config, Formatting.Indented)); await msg2.ModifyAsync(embed : EmbedBase.OutputEmbed($"Prefix removed without errors.")); } break; case "list": await ctx.RespondAsync(embed : EmbedBase.OrderedListEmbed(Program.Config.Prefixes, "Prefixes")); break; default: var embed = EmbedBase.CommandHelpEmbed(ctx.Command); await ctx.RespondAsync(embed : embed); break; } }
public static async Task <bool> WaitForBoolReplyAsync(this InteractivityExtension interactivity, DiscordChannel channel, DiscordUser user) { var conv = new BoolConverter(); bool response = false; InteractivityResult <DiscordMessage> mctx = await interactivity.WaitForMessageAsync( m => m.Channel == channel && m.Author == user && conv.TryConvert(m.Content, out response) ); return(!mctx.TimedOut && response); }
private async Task SetupPrefixAsync(GuildConfig gcfg, CommandContext ctx, DiscordChannel channel) { if (await ctx.WaitForBoolReplyAsync("q-setup-prefix", channel: channel, reply: false)) { await channel.LocalizedEmbedAsync(this.Localization, "q-setup-prefix-new", GuildConfig.PrefixLimit); InteractivityResult <DiscordMessage> mctx = await channel.GetNextMessageAsync(ctx.User, m => m.Content.Length <= GuildConfig.PrefixLimit); gcfg.Prefix = mctx.TimedOut ? throw new CommandFailedException(ctx, "str-timeout") : mctx.Result.Content; } }
protected override async Task CloseMessageAsync(IUserMessage message, InteractivityResult <TValue> result) { if (result.IsCancelled && CancelledPage != null) { await message.ModifyAsync(x => { x.Content = CancelledPage.Text; x.Embed = CancelledPage.Embed; }); } if (result.IsTimeouted && TimeoutedPage != null) { await message.ModifyAsync(x => { x.Content = TimeoutedPage.Text; x.Embed = TimeoutedPage.Embed; }); } }