public async Task PrivateControlsMessageInit() { var existingControlsMessage = DateTextChannel.GetMessageAsync(PrivateControlsMessageId); var answers = new Answer[] { new Answer(LikeEmoji, e => { _ = ApplyPrivateReactionsAsync(e.User, LikeEmoji).ConfigureAwait(false); }), new Answer(CancelLikeEmoji, e => { _ = ApplyPrivateReactionsAsync(e.User, CancelLikeEmoji).ConfigureAwait(false); }), new Answer(DisLikeEmoji, e => { _ = ApplyPrivateReactionsAsync(e.User, DisLikeEmoji).ConfigureAwait(false); }), new Answer(TimeEmoji, e => { _ = ApplyPrivateReactionsAsync(e.User, TimeEmoji).ConfigureAwait(false); }) }; Task.WaitAny(new Task[] { existingControlsMessage, Task.Delay(5000) }); PrivateControlsMessage = await DialogFramework.CreateQuestion(DateTextChannel, PrivateMessageBody, answers, existingMessage : !existingControlsMessage.IsFaulted?existingControlsMessage.Result : null, behavior : MessageBehavior.Permanent, deleteAnswer : true, deleteAnswerTimeout : TimeSpan.Zero).ConfigureAwait(false); PrivateControlsMessageId = PrivateControlsMessage.Id; }
private async Task SetCategory(CommandContext ctx, string categoryType) { string info = ""; if (categoryType == "Date Category") { info = "creating new voice lobbies and returning activity members back from secret rooms"; } else if (categoryType == "Secret Category") { info = "creating new secret rooms for dates"; } else { return; } var config = DateBot.Instance.GetGuild(ctx.Guild.Id) as GuildConfig; DiscordChannel cat = null; await DialogFramework.CreateQuestion(ctx.Channel, $"Paste {categoryType} Id, it will be used for {info}.", message => { ulong.TryParse(message, out var id); ctx.Guild.Channels.TryGetValue(id, out cat); return(cat != null && cat.IsCategory); }, e => { if (categoryType == "Date Category") { config.DateCategoryId = cat.Id; _ = SetMainTextChannelAsync(ctx, config); } else if (categoryType == "Secret Category") { config.DateSecretCategoryId = cat.Id; _ = MainMenu(ctx); } return(Task.CompletedTask); }, ctx.User.Id, deleteAnswer : true, deleteAnswerTimeout : TimeSpan.Zero, wrongAnswer : "I'm looking for a ulong Id of a category"); async Task SetMainTextChannelAsync(CommandContext ctx, GuildConfig config) { DiscordChannel channel = null; await DialogFramework.CreateQuestion(ctx.Channel, "Paste main text channel Id, where will happen all interaction with date activity.", message => { ulong.TryParse(message, out var id); return(ctx.Guild.Channels.TryGetValue(id, out channel)); }, e => { config.DateTextChannelId = channel.Id; return(Task.CompletedTask); }, UserId : ctx.User.Id, deleteAnswer : true, deleteAnswerTimeout : TimeSpan.Zero, wrongAnswer : "Doesn't look like it's a channel Id").ConfigureAwait(false); _ = MainMenu(ctx); } }
public async Task PostHere(CommandContext ctx, [RemainingText] string text) { await DialogFramework.CreateQuestion(ctx.Channel, text, new Answer[] { new Answer(EmojiProvider.One, async e => { await DialogFramework.QuickVolatileMessage(ctx.Channel, "thx", TimeSpan.FromSeconds(1)).ConfigureAwait(false); }) }, behavior : MessageBehavior.Permanent, deleteAnswer : true, deleteAnswerTimeout : TimeSpan.Zero); }
private async Task SetMessage(CommandContext ctx, string messageType) { string info = ""; if (messageType == "Welcome") { info = "setting gender, and age preferences"; } else if (messageType == "Controls") { info = "conrolls during a date, setting likes or adding time"; } else { return; } var config = DateBot.Instance.GetGuild(ctx.Guild.Id) as GuildConfig; ctx.Guild.Channels.TryGetValue(config.DateTextChannelId, out var channel); await DialogFramework.CreateQuestion(ctx.Channel, $"Set {messageType} message content, it will be used for {info}", s => true, async e => { //TODO Check regex to have only numbers? if (ulong.TryParse(e.Message.Content, out var id)) { var message = await channel.GetMessageAsync(id); if (message == null) { //Error message not found _ = DialogFramework.QuickVolatileMessage(ctx.Channel, "This Seemed to be a message Id, but it wasn't found"); } else { if (messageType == "Welcome") { config.WelcomeMessageId = id; } else if (messageType == "Controls") { config.PrivateControlsMessageId = id; } } } else { if (messageType == "Welcome") { config.WelcomeMessageBody = e.Message.Content; } else if (messageType == "Controls") { config.PrivateMessageBody = e.Message.Content; } } }, ctx.User.Id, deleteAnswer : true, deleteAnswerTimeout : TimeSpan.Zero, wrongAnswer : "Enter a message body, or paste existing messages Id"); _ = MainMenu(ctx); }
public async Task Question(CommandContext ctx, [RemainingText] string text) { await ctx.Message.DeleteAsync().ConfigureAwait(false); await DialogFramework.CreateQuestion(ctx.Channel, text, result => true, async e => { var q = await e.Question.Channel.GetMessageAsync(e.Question.Id); await q.ModifyAsync(q.Content + Environment.NewLine + e.Message.Content).ConfigureAwait(false); }, ctx.User.Id, MessageBehavior.Permanent, deleteAnswer : true, deleteAnswerTimeout : TimeSpan.Zero, waitForMultipleAnswers : true); }
private async Task SetTimeout(CommandContext ctx) { var config = DateBot.Instance.GetGuild(ctx.Guild.Id) as GuildConfig; float time = default; await DialogFramework.CreateQuestion(ctx.Channel, $"Set timeout in minutes in form of `2,5` for 2 and a half minutes", message => { return(float.TryParse(message, out time)); }, e => { config.SecretRoomTime = (int)(time * 60000f); return(Task.CompletedTask); }, ctx.User.Id, deleteAnswer : true, deleteAnswerTimeout : TimeSpan.Zero, wrongAnswer : "This isn't a float value"); _ = MainMenu(ctx); }
/// <summary> /// Gets or creates welcome message and refreshes reaction emojis /// </summary> /// <returns></returns> public async Task WelcomeMessageInit() { var existingWelcomeMessage = DateTextChannel.GetMessageAsync(WelcomeMessageId); //TODO Would be nice to have an override for one action with many emojis, passing emoji in for simplicity var answers = new Answer[2 + OptionEmojis.Count()]; answers[0] = new Answer(MaleEmoji, e => { //TODO doesn't add those that are not yet in activity UserState uState = AddOrGetUserState(e.User); uState.Gender = GenderEnum.Male; uState.AgeOptions = 0; }); answers[1] = new Answer(FemaleEmoji, e => { UserState uState = AddOrGetUserState(e.User); uState.Gender = GenderEnum.Female; uState.AgeOptions = 0; }); for (int i = 2; i < answers.Length; i++) { var index = i; answers[index] = new Answer(OptionEmojis[index - 2], e => { UserState uState = AddOrGetUserState(e.User); var option = 1 << (index - 2); if (uState.Gender == GenderEnum.Female) { uState.AgeOptions ^= option; //toggle age group } else { uState.AgeOptions = option; } }); } Task.WaitAny(new Task[] { existingWelcomeMessage, Task.Delay(5000) }); WelcomeMessage = await DialogFramework.CreateQuestion(DateTextChannel, WelcomeMessageBody, answers, existingMessage : !existingWelcomeMessage.IsFaulted?existingWelcomeMessage.Result : null, behavior : MessageBehavior.Permanent, deleteAnswer : true, deleteAnswerTimeout : TimeSpan.Zero); WelcomeMessageId = WelcomeMessage.Id; }
private async Task MainMenu(CommandContext ctx) { await DialogFramework.CreateQuestion(ctx.Channel, $"Choose what you want to set:\n" + $"{EmojiProvider.Rose} to set Date Category\n" + $"{EmojiProvider.Detective} to set Secret Category\n" + $"{EmojiProvider.Handsahke} to set Welcome message\n" + $"{EmojiProvider.ControlKnobs} to set Controls message\n" + $"{EmojiProvider.WhiteHeartInRed} to set Emojis\n" + $"{EmojiProvider.Timer} to set timeout length\n" + $"{EmojiProvider.ArrowsClockwise} to apply changes (reinit bot on this guild)\n" + $"{EmojiProvider.CrossOnGreen} to quit this dialog", new Answer[] { new Answer(EmojiProvider.Rose, e => { _ = SetCategory(ctx, "Date Category"); }), new Answer(EmojiProvider.Detective, e => { _ = SetCategory(ctx, "Secret Category"); }), new Answer(EmojiProvider.Handsahke, e => { _ = SetMessage(ctx, "Welcome"); }), new Answer(EmojiProvider.ControlKnobs, e => { _ = SetMessage(ctx, "Controls"); }), new Answer(EmojiProvider.WhiteHeartInRed, e => { _ = SetEmoji(ctx); }), new Answer(EmojiProvider.Timer, e => { _ = SetTimeout(ctx); }), new Answer(EmojiProvider.ArrowsClockwise, e => { var gt = DateBot.Instance.GetGuild(ctx.Guild.Id); _ = gt.Initialize(ctx.Guild); }), new Answer(EmojiProvider.CrossOnGreen, e => { DialogFramework.QuickVolatileMessage(ctx.Channel, "Thank you for interaction, bye."); }) }, ctx.User.Id, deleteAnswer : true, deleteAnswerTimeout : TimeSpan.Zero, timeoutMessage : "Thank you for interaction, bye.").ConfigureAwait(false); }
public async Task Config(CommandContext ctx) { await ctx.Message.DeleteAsync().ConfigureAwait(false); var isNew = !DummyBot.Instance.GuildRegistered(ctx.Guild.Id); if (isNew) { var newGuildTask = new GuildTask() { GuildId = ctx.Guild.Id }; DummyBot.Instance.AddGuild(newGuildTask); await DummyBot.Instance.SaveStates().ConfigureAwait(false); } await MainMenu().ConfigureAwait(false); //Ask what to set up // Voice Channel to connect // Channel>Message id's to set random reaction async Task MainMenu() { //Menu message await DialogFramework.CreateQuestion(ctx.Channel, $"What we should set up?" + Environment.NewLine + $"{EmojiProvider.One} Voice channel to connect to " + Environment.NewLine + $"{EmojiProvider.Two} Message id to react to", new Answer[] { new Answer(EmojiProvider.One, new string[] { "one", "voice", "channel" }, async e => { await SetVoiceChannel().ConfigureAwait(false); }), new Answer(EmojiProvider.Two, new string[] { "two", "message", "react" }, async e => { await SetMessageChannel().ConfigureAwait(false); }) }, ctx.User.Id, timeoutBeforeDelete : TimeSpan.Zero, deleteAnswer : true).ConfigureAwait(false); } //Continue configuring or quit? async Task Continue() { //ask await DialogFramework.CreateQuestion(ctx.Channel, "Would you go over?", new Answer[] { new Answer(EmojiProvider.CheckMarkOnGreen, new string[] { "yes", "sure", "go" }, async e => { await MainMenu().ConfigureAwait(false); }), new Answer(EmojiProvider.CrossOnGreen, new string[] { "no", "stop", "done" }, async e => { await DialogFramework.QuickVolatileMessage(ctx.Channel, "Thank you. We are done here. Have a nice day.").ConfigureAwait(false); }) }, ctx.User.Id, timeoutBeforeDelete : TimeSpan.Zero, deleteAnswer : true).ConfigureAwait(false); } //Setvoice channel async Task SetVoiceChannel() { //Message DiscordChannel channel = null; await DialogFramework.CreateQuestion(ctx.Channel, $"Enter channel name, to connect to.", message => { channel = ctx.Guild.Channels.FirstOrDefault(c => c.Value.Name.Contains(message)).Value; return(channel != null); }, async e => { var gt = DummyBot.Instance.GetGuild(ctx.Guild.Id); gt.ConnectToVoiceName = channel.Name; gt.ConnectToVoice = channel; //Apply changes in task await DummyBot.Instance.GetGuild(ctx.Guild.Id).Initialize().ConfigureAwait(false); //Continue to next step await Continue().ConfigureAwait(false); }, ctx.User.Id, timeoutBeforeDelete : TimeSpan.Zero, deleteAnswer : true, wrongAnswer : "Couldn't find that channel. Try again.").ConfigureAwait(false); } //Set channel id to react on a message async Task SetMessageChannel() { DiscordChannel channel = null; await DialogFramework.CreateQuestion(ctx.Channel, #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously $"Paste Channel Id, where to set random reaction.", message => { if (ulong.TryParse(message, out var id)) { channel = ctx.Guild.GetChannel(id); } return(channel != null); }, async e => { #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously var gt = DummyBot.Instance.GetGuild(ctx.Guild.Id); gt.SetRandomReactionOnChannelId = channel.Id; gt.SetRandomReactionOnChannel = channel; //Continue to next step await SetMessage().ConfigureAwait(false); }, ctx.User.Id, timeoutBeforeDelete : TimeSpan.Zero, deleteAnswer : true, wrongAnswer : "Couldn't find that channel. Try again.").ConfigureAwait(false); } //Set message id to react to async Task SetMessage() { GuildTask gt = null; DiscordMessage msg = null; await DialogFramework.CreateQuestion(ctx.Channel, $"Paste Message Id, where to set random reaction.", message => { ulong.TryParse(message, out var id); gt = DummyBot.Instance.GetGuild(ctx.Guild.Id); msg = gt.SetRandomReactionOnChannel.GetMessageAsync(id).Result; return(msg != null); }, async e => { gt.SetRandomReactionOnMessageId = msg.Id; gt.SetRandomReactionOnMessage = msg; //Apply changes in task _ = DummyBot.Instance.GetGuild(ctx.Guild.Id).Initialize(); //Continue to next step await Continue().ConfigureAwait(false); }, ctx.User.Id, timeoutBeforeDelete : TimeSpan.Zero, deleteAnswer : true, wrongAnswer : "Couldn't find that message. Try again.").ConfigureAwait(false); } }
private async Task SetEmoji(CommandContext ctx) { var gt = DateBot.Instance.GetGuild(ctx.Guild.Id); await DialogFramework.CreateQuestion(ctx.Channel, $"Choose what Emoji to set\n" + $"{EmojiProvider.MaleSign} to set emoji for selecting male gender. Currently it is set to {gt.MaleEmojiId}\n" + $"{EmojiProvider.FemaleSign} to set emoji for selecting male gender. Currently it is set to {gt.FemaleEmojiId}\n" + $"{EmojiProvider.QuestionMark} to set emojs for age options. Keep spaces inbetween. Currently it is set to {string.Join(" ", gt.OptionEmojiIds)}\n" + $"{EmojiProvider.Heart} to set emojs for Like. Currently it is set to {gt.LikeEmojiId}\n" + $"{EmojiProvider.HeartBlack} to set emojs for canceling Like. Currently it is set to {gt.CancelLikeEmojiId}\n" + $"{EmojiProvider.HeartBroken} to set emojs for canceling Like. Currently it is set to {gt.DisLikeEmojiId}\n" + $"{EmojiProvider.Timer} to set emojs for canceling Like. Currently it is set to {gt.TimeEmojiId}\n" + $"{EmojiProvider.CrossOnGreen} to go back.", new Answer[] { new Answer(EmojiProvider.MaleSign, async e => await Set("Male").ConfigureAwait(false)), new Answer(EmojiProvider.FemaleSign, async e => await Set("Female").ConfigureAwait(false)), new Answer(EmojiProvider.QuestionMark, async e => await Set("Options").ConfigureAwait(false)), new Answer(EmojiProvider.Heart, async e => await Set("Like").ConfigureAwait(false)), new Answer(EmojiProvider.HeartBlack, async e => await Set("Cancel Like").ConfigureAwait(false)), new Answer(EmojiProvider.HeartBroken, async e => await Set("Dislike").ConfigureAwait(false)), new Answer(EmojiProvider.Timer, async e => await Set("Time").ConfigureAwait(false)), new Answer(EmojiProvider.CrossOnGreen, async e => await MainMenu(ctx).ConfigureAwait(false)) }, ctx.User.Id); async Task Set(string emojiType) { var message = $"Enter an emoji for {emojiType}"; if (emojiType == "Options") { message = $"Enter an emoji sequence for age options. Keep spaces inbetween."; } await DialogFramework.CreateQuestion(ctx.Channel, message, message => { //Seems like we get unicode here from message.Content, not name. Had some problems with it if (emojiType == "Options") { var split = message.Split(' ', System.StringSplitOptions.RemoveEmptyEntries); return(split.All(m => DiscordEmoji.FromUnicode(DateBot.Instance.Client, m) != null)); } else { return(DiscordEmoji.FromUnicode(DateBot.Instance.Client, message) is DiscordEmoji); } }, e => { switch (emojiType) { case "Male": gt.MaleEmojiId = DiscordEmoji.FromUnicode(DateBot.Instance.Client, e.Message.Content).GetDiscordName(); break; case "Female": gt.FemaleEmojiId = DiscordEmoji.FromUnicode(DateBot.Instance.Client, e.Message.Content).GetDiscordName(); break; case "Like": gt.LikeEmojiId = DiscordEmoji.FromUnicode(DateBot.Instance.Client, e.Message.Content).GetDiscordName(); break; case "Cancel Like": gt.CancelLikeEmojiId = DiscordEmoji.FromUnicode(DateBot.Instance.Client, e.Message.Content).GetDiscordName(); break; case "Dislike": gt.DisLikeEmojiId = DiscordEmoji.FromUnicode(DateBot.Instance.Client, e.Message.Content).GetDiscordName(); break; case "Time": gt.TimeEmojiId = DiscordEmoji.FromUnicode(DateBot.Instance.Client, e.Message.Content).GetDiscordName(); break; case "Options": gt.OptionEmojiIds = e.Message.Content.Split(' ', System.StringSplitOptions.RemoveEmptyEntries). Select(u => DiscordEmoji.FromUnicode(DateBot.Instance.Client, u).GetDiscordName()).ToList(); break; default: break; } //Return back to the Emoji menu _ = SetEmoji(ctx); return(Task.CompletedTask); }, ctx.User.Id, deleteAnswer : true, deleteAnswerTimeout : TimeSpan.Zero, wrongAnswer : "This isn't looking right."); } }