public async Task <RuntimeResult> CreateChannelGroup(string groupName) { var configurationStep = new ConfigurationStep("What type of group is this? (🏁 checks, ❓ FAQ, 🤖 command)", Interactive, Context, ConfigurationStep.StepType.Reaction, null); var addAction = new ReactionAction(new Emoji("🏁")); addAction.Action = async(ConfigurationStep a) => { new ChannelManager().createChannelGroup(groupName, ChannelGroupType.CHECKS); await Task.CompletedTask; }; var deleteCommandChannelAction = new ReactionAction(new Emoji("❓")); deleteCommandChannelAction.Action = async(ConfigurationStep a) => { new ChannelManager().createChannelGroup(groupName, ChannelGroupType.FAQ); await Task.CompletedTask; }; var deleteCommandAction = new ReactionAction(new Emoji("🤖")); deleteCommandAction.Action = async(ConfigurationStep a) => { new ChannelManager().createChannelGroup(groupName, ChannelGroupType.COMMANDS); await Task.CompletedTask; }; configurationStep.Actions.Add(addAction); configurationStep.Actions.Add(deleteCommandChannelAction); configurationStep.Actions.Add(deleteCommandAction); await configurationStep.SetupMessage(); return(CustomResult.FromSuccess()); }
private async Task ReactionManipulated(SocketReaction reaction, ReactionAction action) { if (reaction.User.Value.IsBot) { return; } if (!_raidRepository.Contains(reaction.MessageId)) { return; } if (!_userService.UserExists(reaction.UserId) && !(await _userService.TryAddUser(reaction.UserId, (reaction.Channel as IGuildChannel)?.Guild))) { return; } var raid = _raidRepository.GetRaid(reaction.MessageId); if (!(reaction.User.Value is IGuildUser)) { return; } var aliases = _aliasService.GetActiveAliases(reaction.UserId).ToList(); if (!aliases.Any()) { return; } var aliasViewModels = _mapper.Map <List <EpgpAlias>, List <EpgpAliasViewModel> >(aliases); var role = reaction.Emote.Name.ParseRoleFromEmote(); var participant = new RaidParticipant(reaction.UserId) { Aliases = aliasViewModels, Role = role }; if (action == ReactionAction.Add) { raid.RaidObject.Participants.AddOrUpdate(participant.Id, id => participant, (id, raidParticipant) => participant); } else if (action == ReactionAction.Remove) { if (raid.RaidObject.Participants.TryGetValue(reaction.UserId, out var existingParticipant) && existingParticipant.Role == participant.Role) { raid.RaidObject.Participants.TryRemove(reaction.UserId, out _); } } var embed = CreateEmbed(raid.RaidObject, raid.ServerId); await raid.Message.ModifyAsync(opt => opt.Embed = embed); }
public static void CreateConfirmReactionMessage( ulong userId, IUserMessage message, ReactionAction onPositiveResponse, ReactionAction onNegativeResponse, bool allowMultipleReactions = false, int timeout = 300000, Action onTimeout = null ) { CreateReactionMessage( userId, message, new List <(string, ReactionAction)> { (Strings.GreenCheckEmoji, onPositiveResponse), (Strings.RedXEmoji, onNegativeResponse) },
public async Task ConfigureFAQ() { var guild = Global.Bot.GetGuild(Global.ServerID); var configurationStep = new ConfigurationStep("What do you want to do? (➕ add command, ➖ remove command in channel, ☠ delete command)", Interactive, Context, ConfigurationStep.StepType.Reaction, null); configurationStep.additionalPosts.Add("To exit react with 🆘 or type exit, depending on the type of step you are in"); var addStep = new ConfigurationStep("What kind of post do you want to add? (💌 embed, 📖 textpost, ✅ nothing further)", Interactive, Context, ConfigurationStep.StepType.Reaction, null); var aliasesStep = new ConfigurationStep("Please write the aliases you want for this command (comma separated), type 'none' for none", Interactive, Context, ConfigurationStep.StepType.Text, addStep); var channelStep = new ConfigurationStep("Which channels should the command be active in? Please mention the channels with # or type 'all' for all.", Interactive, Context, ConfigurationStep.StepType.Text, aliasesStep); var commandStep = new ConfigurationStep("What should the name of the command be?", Interactive, Context, ConfigurationStep.StepType.Text, channelStep); var textStep = new ConfigurationStep("Please post what the text of the text post should be", Interactive, Context, ConfigurationStep.StepType.Text, addStep); var embedStep = new ConfigurationStep("What do you want to configure of your embedPost? (🤖 test current embed, 🖼 set a picture, 📖 set text, 💁 decide authorship, 🎨 choose color, ✅ nothing further)", Interactive, Context, ConfigurationStep.StepType.Reaction, null); var colorStep = new ConfigurationStep("What color do you want for your embed?", Interactive, Context, ConfigurationStep.StepType.Reaction, null); var imageUrlStep = new ConfigurationStep("Please enter the url of the Image you want to set", Interactive, Context, ConfigurationStep.StepType.Text, embedStep); var embedTextStep = new ConfigurationStep("Please enter the text you want to give your embed", Interactive, Context, ConfigurationStep.StepType.Text, embedStep); var embedColorStep = new ConfigurationStep("Please choose a color you want to use for the embed", Interactive, Context, ConfigurationStep.StepType.Reaction, null); var authorStep = new ConfigurationStep("Do you want to be marked as author? (✅ yes, ❌ no)", Interactive, Context, ConfigurationStep.StepType.Reaction, null); var deletionStep = new ConfigurationStep("React to the command in the channel you want to remove (❌ go back, ◀ seek backward, ▶ seek forward)", Interactive, Context, ConfigurationStep.StepType.Reaction, null); var commandDeletionStep = new ConfigurationStep("React to the command you want to completely remove (❌ go back, ◀ seek backward, ▶ seek forward)", Interactive, Context, ConfigurationStep.StepType.Reaction, null); var chooseExistingEntryStep = new ConfigurationStep("Which post do you want to use?", Interactive, Context, ConfigurationStep.StepType.Text, addStep); var existingCommands = Global.FAQCommands.ToList(); var existingCommandChannels = new List <FAQCommandChannel>(); foreach (var comandElement in existingCommands) { if (comandElement.CommandChannels != null) { foreach (var commandChannelelement in comandElement.CommandChannels) { existingCommandChannels.Add(commandChannelelement); } } } FAQCommand command = new FAQCommand(); List <FAQCommandChannel> commandChannels = new List <FAQCommandChannel>(); List <FAQCommandChannelEntry> entries = new List <FAQCommandChannelEntry>(); var builder = new FaqCommandChannelEntryBuilder(); builder.defaultValues(); List <IPaginatable> commandChannelPaginatable = existingCommandChannels.ConvertAll(x => (IPaginatable)x); List <IPaginatable> commandPaginatable = existingCommands.ConvertAll(x => (IPaginatable)x); var deletePagination = new PaginationWithAction(deletionStep, configurationStep, commandChannelPaginatable, true, Context, Interactive); deletePagination.setup(); deletePagination.actionOnIndex = (object obj) => { var channel = obj as FAQCommandChannel; using (var db = new Database()) { db.FAQCommandChannels.Remove(channel); db.SaveChanges(); } existingCommands.Where(com => com.ID == channel.FAQCommandId).First().CommandChannels.Remove(channel); commandChannelPaginatable.Remove(obj as IPaginatable); return(deletionStep); }; var deleteCommandPagination = new PaginationWithAction(commandDeletionStep, configurationStep, commandPaginatable, true, Context, Interactive); deleteCommandPagination.setup(); deleteCommandPagination.actionOnIndex = (object obj) => { var commandToDelete = obj as FAQCommand; if (obj == null) { return(commandDeletionStep); } commandChannelPaginatable.RemoveAll(ch => (ch as FAQCommandChannel).Command.ID == commandToDelete.ID); using (var db = new Database()) { db.FAQCommands.Remove(commandToDelete); db.SaveChanges(); } existingCommands.Remove(commandToDelete); commandPaginatable.Remove(commandToDelete as IPaginatable); // if we do not remove them from the channel commands, then a the command is a null pointer return(commandDeletionStep); }; aliasesStep.TextCallback = (string text, ConfigurationStep a) => { var editingAlias = command.Aliases != null; if (text != "none") { if (editingAlias) { command.Aliases = command.Aliases + ',' + text; } else { command.Aliases = text; } } else { if (!editingAlias) { command.Aliases = ""; } } return(true); }; commandStep.TextCallback = (string text, ConfigurationStep a) => { var weGotOne = existingCommands.Where(cmd => cmd.Name == text); if (weGotOne.Any()) { command = weGotOne.First(); } else { command.Name = text; } return(true); }; imageUrlStep.TextCallback = (string text, ConfigurationStep a) => { builder = builder.withImageUrl(text); return(true); }; embedTextStep.TextCallback = (string text, ConfigurationStep a) => { builder = builder.withText(text); return(true); }; textStep.TextCallback = (string text, ConfigurationStep a) => { builder = builder.withText(text); var entry = builder.Build(); entry.IsEmbed = false; entry.Position = (uint)entries.Count(); entries.Add(entry); builder = new FaqCommandChannelEntryBuilder(); return(true); }; channelStep.TextCallback = (string text, ConfigurationStep a) => { var channelIds = Regex.Matches(text, @"(?:\<#(?<channelId>\d{18})\>)*", RegexOptions.Multiline | RegexOptions.ExplicitCapture) .OfType <Match>() .Select(mt => mt.Groups["channelId"].Value); bool channelFound = false; foreach (var channelId in channelIds) { if (channelId != string.Empty) { var channelIdLong = ulong.Parse(channelId); var channelObj = Global.FullChannels.Where(ch => ch.ChannelID == channelIdLong).DefaultIfEmpty(null).First(); if (channelObj != null) { channelFound = true; var commandChannel = new FAQCommandChannel(); commandChannel.ChannelId = channelObj.ID; commandChannel.CommandChannelEntries = new List <FAQCommandChannelEntry>(); commandChannels.Add(commandChannel); } } } if (channelFound) { a.Result = aliasesStep; } else { if (text.ToUpper().Contains("ALL")) { var channelCommands = existingCommands.Where(c => c.Name == command.Name).DefaultIfEmpty(null).First(); foreach (var channel in Global.FullChannels) { if (channelCommands != null) { var existingChannels = channelCommands.CommandChannels.Where(cch => cch.Channel?.ChannelID == channel.ChannelID); var channelAlreadyExists = existingChannels.Any(); if (channelAlreadyExists) { continue; } } var commandChannel = new FAQCommandChannel(); commandChannel.ChannelId = channel.ID; commandChannel.CommandChannelEntries = new List <FAQCommandChannelEntry>(); commandChannels.Add(commandChannel); } a.Result = aliasesStep; } else { a.Result = channelStep; } } return(true); }; chooseExistingEntryStep.TextCallback = (string text, ConfigurationStep a) => { var channelCommands = existingCommands.Where(c => c.Name == command.Name).First(); int index = 0; if (int.TryParse(text, out index)) { // it is 1 based, therefore -1 var entriesChosen = channelCommands.CommandChannels.ToList()[index - 1]; foreach (var neededEntry in entriesChosen.CommandChannelEntries) { entries.Add(neededEntry.clone()); } } else { a.Result = chooseExistingEntryStep; } return(false); }; var addAction = new ReactionAction(new Emoji("➕")); addAction.Action = async(ConfigurationStep a) => { a.Result = commandStep; await Task.CompletedTask; }; var deleteCommandChannelAction = new ReactionAction(new Emoji("➖")); deleteCommandChannelAction.Action = async(ConfigurationStep a) => { a.Result = deletionStep; await Task.CompletedTask; }; var deleteCommandAction = new ReactionAction(new Emoji("☠")); deleteCommandAction.Action = async(ConfigurationStep a) => { a.Result = commandDeletionStep; await Task.CompletedTask; }; configurationStep.Actions.Add(addAction); configurationStep.Actions.Add(deleteCommandChannelAction); configurationStep.Actions.Add(deleteCommandAction); // blue var blueChoice = new ReactionAction(new Emoji("📘")); blueChoice.Action = async(ConfigurationStep a) => { builder.withHexColor(5614830); a.Result = embedStep; await Task.CompletedTask; }; // red var redChoice = new ReactionAction(new Emoji("📕")); redChoice.Action = async(ConfigurationStep a) => { builder.withHexColor(14495300); a.Result = embedStep; await Task.CompletedTask; }; // green var greenChoice = new ReactionAction(new Emoji("📗")); greenChoice.Action = async(ConfigurationStep a) => { builder.withHexColor(7844437); a.Result = embedStep; await Task.CompletedTask; }; // yellow var yellowChoice = new ReactionAction(new Emoji("📙")); yellowChoice.Action = async(ConfigurationStep a) => { builder.withHexColor(16755763); a.Result = embedStep; await Task.CompletedTask; }; // white var whiteChoice = new ReactionAction(new Emoji("🔖")); whiteChoice.Action = async(ConfigurationStep a) => { builder.withHexColor(14805229); a.Result = embedStep; await Task.CompletedTask; }; // black var blackChoice = new ReactionAction(new Emoji("⬛")); blackChoice.Action = async(ConfigurationStep a) => { builder.withHexColor(2699059); a.Result = embedStep; await Task.CompletedTask; }; colorStep.Actions.Add(blueChoice); colorStep.Actions.Add(redChoice); colorStep.Actions.Add(greenChoice); colorStep.Actions.Add(yellowChoice); colorStep.Actions.Add(whiteChoice); colorStep.Actions.Add(blackChoice); var imageUrlAction = new ReactionAction(new Emoji("🖼")); imageUrlAction.Action = async(ConfigurationStep a) => { a.Result = imageUrlStep; await Task.CompletedTask; }; var embedTextAction = new ReactionAction(new Emoji("📖")); embedTextAction.Action = async(ConfigurationStep a) => { a.Result = embedTextStep; await Task.CompletedTask; }; var chooseColorAction = new ReactionAction(new Emoji("🎨")); chooseColorAction.Action = async(ConfigurationStep a) => { a.Result = colorStep; await Task.CompletedTask; }; var testEmbedAction = new ReactionAction(new Emoji("🤖")); testEmbedAction.Action = async(ConfigurationStep a) => { var message = await Context.Channel.SendMessageAsync(embed : OnePlusBot.Helpers.Extensions.FaqCommandEntryToBuilder(builder.Build()).Build()); a.MessagesToRemoveOnNextProgression.Add(message); a.Result = embedStep; await Task.CompletedTask; }; var authorSettingAction = new ReactionAction(new Emoji("💁")); authorSettingAction.Action = async(ConfigurationStep a) => { a.Result = authorStep; await Task.CompletedTask; }; var finishEmbedAction = new ReactionAction(new Emoji("✅")); finishEmbedAction.Action = async(ConfigurationStep a) => { a.Result = addStep; var entry = builder.Build(); entry.Position = (uint)entries.Count(); entry.IsEmbed = true; entries.Add(entry); builder = new FaqCommandChannelEntryBuilder(); await Task.CompletedTask; }; var abortEmbedAction = new ReactionAction(new Emoji("❌")); abortEmbedAction.Action = async(ConfigurationStep a) => { a.Result = addStep; await Task.CompletedTask; }; embedStep.Actions.Add(testEmbedAction); embedStep.Actions.Add(imageUrlAction); embedStep.Actions.Add(embedTextAction); embedStep.Actions.Add(chooseColorAction); embedStep.Actions.Add(authorSettingAction); embedStep.Actions.Add(finishEmbedAction); var authorAgreeAction = new ReactionAction(new Emoji("✅")); authorAgreeAction.Action = async(ConfigurationStep a) => { builder = builder.withAuthor(Context.Message.Author.Username); builder = builder.withAuthorAvatarUrl(Context.Message.Author.GetAvatarUrl()); a.Result = embedStep; await Task.CompletedTask; }; var authorDenyAction = new ReactionAction(new Emoji("❌")); authorDenyAction.Action = async(ConfigurationStep a) => { a.Result = embedStep; // TODO do not hardcode builder = builder.withAuthor("r/Oneplus"); builder = builder.withAuthorAvatarUrl("https://cdn.discordapp.com/avatars/426015562595041280/cab7dde68e8da9bcfd61842bd98e950b.png"); await Task.CompletedTask; }; authorStep.Actions.Add(authorAgreeAction); authorStep.Actions.Add(authorDenyAction); var embedAction = new ReactionAction(new Emoji("💌")); embedAction.Action = async(ConfigurationStep a) => { builder.defaultValues(); a.Result = embedStep; await Task.CompletedTask; }; var textAction = new ReactionAction(new Emoji("📖")); textAction.Action = async(ConfigurationStep a) => { a.Result = textStep; await Task.CompletedTask; }; var commandFinished = new ReactionAction(new Emoji("✅")); commandFinished.Action = async(ConfigurationStep a) => { if (entries.Count == 0) { if (command.ID != 0) { var channelCommands = existingCommands.Where(c => c.Name == command.Name).First(); if (!AreAllEntriesTheSame(channelCommands.CommandChannels.ToList())) { chooseExistingEntryStep.beforeTextPosted = (ConfigurationStep step) => { var stringBuilder = new StringBuilder(); var index = 1; foreach (var commandInChannel in channelCommands.CommandChannels) { stringBuilder.Append($"{index}: {commandInChannel.Command.Name} in {commandInChannel.Channel.Name}" + Environment.NewLine); index++; } step.additionalPosts.Clear(); step.additionalPosts.Add(stringBuilder.ToString()); return(false); }; a.Result = chooseExistingEntryStep; return; } else { var entriesToUse = channelCommands.CommandChannels.First().CommandChannelEntries; foreach (var entry in entriesToUse) { entries.Add(entry.clone()); } } } } // run this in parallel, so it doesnt block, should be fast enough in order for any additional configuration to not happen yet from the user await Task.Run(() => { foreach (var entry in entries) { foreach (var commandChannel in commandChannels) { commandChannel.CommandChannelEntries.Add(entry.clone()); } } command.CommandChannels = commandChannels; using (var db = new Database()) { if (command.ID == 0) { db.FAQCommands.Add(command); } else { db.Entry(command).State = Microsoft.EntityFrameworkCore.EntityState.Modified; foreach (var channel in command.CommandChannels) { channel.FAQCommandId = command.ID; if (channel.CommandChannelId == 0) { db.Entry(channel).State = Microsoft.EntityFrameworkCore.EntityState.Added; } foreach (var entry in channel.CommandChannelEntries) { db.Entry(entry).State = Microsoft.EntityFrameworkCore.EntityState.Added; } } } db.SaveChanges(); } command = new FAQCommand(); commandChannels = new List <FAQCommandChannel>(); entries = new List <FAQCommandChannelEntry>(); }); a.Result = configurationStep; await Task.CompletedTask; }; addStep.Actions.Add(embedAction); addStep.Actions.Add(textAction); addStep.Actions.Add(commandFinished); await configurationStep.SetupMessage(); }