protected void SetValue(Item i, string value) { if (i == null) { return; } using (new EditContext(i)) { i["Value"] = value; } CleanupList.Add(i); }
/// <summary> /// Initializes a new instance of the <see cref="CSharpContinuation"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="parentFeature">The parent feature.</param> /// <param name="source">The Easly node from which the C# node is created.</param> protected CSharpContinuation(ICSharpContext context, ICSharpFeature parentFeature, IContinuation source) : base(source) { ParentFeature = parentFeature; Instructions = CSharpScope.Create(context, parentFeature, (IScope)source.Instructions); foreach (IInstruction Instruction in source.CleanupList) { ICSharpInstruction NewInstruction = CSharpInstruction.Create(context, parentFeature, Instruction); CleanupList.Add(NewInstruction); } }
protected Item BuildExtranetPages(SiteInfo siteItem, IEnumerable <Language> selectedLangs) { LangCur = 1; LangTotal = selectedLangs.Count(); Item extranetFolder = null; foreach (Language targetLang in selectedLangs) { using (new LanguageSwitcher(targetLang)) { //get content and media branch and branch ancestor info BranchItem extranetBranch = MasterDB.GetItem(InputData.Get <string>(Constants.Keys.ExtranetBranch)); //if adding multiple languages, determines if this is the first language added or not bool firstRun = (LangCur == 1); if (firstRun) // if adding multiple languages you only want to do this once //status { BuildJob.Status.Messages.Add(string.Format("Building {0} content from branch.", targetLang.CultureInfo.DisplayName)); Item HomeItem = MasterDB.GetItem(string.Format("{0}{1}", siteItem.RootPath, siteItem.StartItem)); extranetFolder = HomeItem.Add("extranet", extranetBranch); CleanupList.Add(extranetFolder); // Register website for cleanup if creation fails. } else { // All content items including website item IEnumerable <Item> contentItems = new Item[] { extranetFolder }.Concat(extranetFolder.Axes.GetDescendants()); //add new version for language and update referential links ItemCur = 1; ItemTotal = contentItems.Count(); foreach (Item newItem in contentItems) { BuildJob.Status.Messages.Add(string.Format("Language {0} of {1}<br/>Item {2} of {3}", LangCur, LangTotal, ItemCur, ItemTotal)); //create a version of the current language for all the content under website Item langVersion = MasterDB.GetItem(newItem.ID, targetLang); langVersion = langVersion.Versions.AddVersion(); ItemCur++; } } } LangCur++; } return(extranetFolder); }
protected Item ConfigureLoginPage(Item extranetFolder, Item newParent, string sitename) { Item loginPage = extranetFolder.Paths.GetSubItem("login"); loginPage.MoveTo(newParent); //update permissions string s = loginPage[FieldIDs.Security]; if (!string.IsNullOrEmpty(s)) { ReplaceSecurity(loginPage, "BranchTemplate", sitename); } CleanupList.Add(loginPage); return(loginPage); }
public async override Task ProcessMessage(SocketUserMessage input) { //Add the user's message to be cleaned up after this poll is completed. CleanupList.Add(input); string Message = input.Content.Trim(); string rawMsg = input.Content.Trim().ToLowerInvariant(); if (rawMsg == "stop" || rawMsg == "cancel") { await SendAsync("Setup aborted."); await this.Bot.CloseDialog(this); return; } else if (rawMsg == "back" || rawMsg == "go back") { //If the user said back, return to the previous step. await PreviousStep(); return; } //Parse out the differant options we will need. bool Skip = rawMsg == "skip"; bool?Bool = rawMsg.ParseBool(); SocketTextChannel CH = input.MentionedChannels.OfType <SocketTextChannel>().FirstOrDefault(); SocketRole ROLE = input.MentionedRoles.FirstOrDefault(); //ToDo - Submitted a issue for dehumanizer, to see if this "logic" can be offloaded to their library. const string msg_BoolParseFailed = "I did not reconize that message. You may say yes, no, true, false, y or n.\r\n"; string msg_ChannelExpected = $"I expected a channel. Please tag the channel like this: {this.Channel.Mention}\r\n"; string msg_RoleExpected = $"I expected a role. Please tag the role like this:\r\n {this.Guild.CurrentUser.Roles.FirstOrDefault(o => o.IsMentionable)?.Mention ?? "@MyRole"}"; switch (CurrentStep) { case SetupStep.Initial: await NextStep(); break; case SetupStep.WarBot_Prefix: if (Skip) { Config.Prefix = "bot,"; } else { Config.Prefix = Message; } await NextStep($"My prefix has been set to '{Config.Prefix}'"); break; case SetupStep.User_Left_Channel: if (Skip) { Config.SetGuildChannel(Core.WarBotChannelType.USER_LEFT, null); await SkipStep("I will not send notifications when a user leaves."); } else if (CH != null) { Config.SetGuildChannel(Core.WarBotChannelType.USER_LEFT, CH); await NextStep($"User leave notifications will go to {CH.Mention}"); } else { await SendAsync(msg_ChannelExpected); } break; case SetupStep.User_Left_Message: if (Skip) { Config[Setting_Key.USER_LEFT].Set(true, null); await SkipStep("I will send a default message."); } else { Config[Setting_Key.USER_LEFT].Set(true, Message); await NextStep("When users leave the server, this message will be sent:\r" + $"\n{Message}\r" + $"\nIn channel {Config.GetGuildChannel(WarBotChannelType.USER_LEFT).Mention}"); } break; case SetupStep.User_Join_Channel: if (Skip) { Config.SetGuildChannel(Core.WarBotChannelType.USER_JOIN, null); Config[Setting_Key.USER_JOIN].Enabled = false; await SkipStep("I will not send new user greetings."); } else if (CH != null) { Config.SetGuildChannel(Core.WarBotChannelType.USER_JOIN, CH); await NextStep($"New user greetings will go to {CH.Mention}"); } else { await SendAsync(msg_ChannelExpected); } break; case SetupStep.User_Join_Message: if (Skip) { Config[Setting_Key.USER_JOIN].Set(true, null); await SkipStep("I will send a default message."); } else { Config[Setting_Key.USER_JOIN].Set(true, Message); await NextStep("New users joining the server will receive this message:\r" + $"\n{User.Mention}, {Message}\r" + $"\nIn channel {Config.GetGuildChannel(WarBotChannelType.USER_JOIN).Mention}"); } break; case SetupStep.Channel_Updates: if (Skip) { Config.SetGuildChannel(Core.WarBotChannelType.WARBOT_UPDATES, null); Config[Setting_Key.WARBOT_UPDATES].Enabled = false; await SkipStep("I will not send notifications when I am updated."); } else if (CH != null) { Config.SetGuildChannel(Core.WarBotChannelType.WARBOT_UPDATES, CH); Config[Setting_Key.WARBOT_UPDATES].Enabled = true; await NextStep($"My update notifications will be sent to {CH.Mention}."); } else { await SendAsync(msg_ChannelExpected); } break; case SetupStep.Channel_Officers: if (Skip) { Config.SetGuildChannel(Core.WarBotChannelType.CH_Officers, null); await SkipStep("I will not send any officer related messages or errors."); } else if (CH != null) { Config.SetGuildChannel(Core.WarBotChannelType.CH_Officers, CH); await NextStep($"My officer-related messages and errors will be sent to {CH.Mention}."); } else { await SendAsync(msg_ChannelExpected); } break; case SetupStep.WAR_Channel: if (Skip || Bool == false) { Config.SetGuildChannel(Core.WarBotChannelType.WAR, null); Config[Setting_Key.WAR_PREP_STARTED].Enabled = false; Config[Setting_Key.WAR_PREP_ENDING].Enabled = false; Config[Setting_Key.WAR_STARTED].Enabled = false; await SkipStep("I will not send any type of announcements for hustle castle clan wars.\r" + "\nYou may enable this feature later if you wish."); } else if (CH != null) { Config.SetGuildChannel(Core.WarBotChannelType.WAR, CH); await NextStep($"My war announcements will be sent to {CH.Mention}."); } else { await SendAsync(msg_ChannelExpected); } break; case SetupStep.WAR_SendPrepStarted: if (Bool == true) { await NextStep(); } else if (Bool == false || Skip) { Config[Setting_Key.WAR_PREP_STARTED].Set(false, null); await SkipStep("I will not send notifications when war prep starts."); } else { await SendAsync(msg_BoolParseFailed); } break; case SetupStep.WAR_PrepStartedMessage: if (Skip) { Config[Setting_Key.WAR_PREP_STARTED].Set(true, null); await SkipStep("I will use my default notification when war prep starts."); } else { Config[Setting_Key.WAR_PREP_STARTED].Set(true, Message); await NextStep("The war prep started message has been set to:\r" + $"\n{Message}"); } break; //War prep ending case SetupStep.WAR_SendPrepEnding: if (Bool == true) { await NextStep(); } else if (Bool == false || Skip) { Config[Setting_Key.WAR_PREP_ENDING].Set(false, null); await SkipStep("I will not send notifications for war prep ending."); } //Failed to parse a boolean. else { await SendAsync(msg_BoolParseFailed); } break; case SetupStep.WAR_PrepEndingMessage: if (Skip) { Config[Setting_Key.WAR_PREP_ENDING].Set(true, null); await NextStep("I will use my default notification when war prep is ending."); } else { Config[Setting_Key.WAR_PREP_ENDING].Set(true, Message); await NextStep("The war prep ending message has been set to:\r" + $"\n{Message}"); } break; //War Started case SetupStep.WAR_SendWarStarted: if (Bool == true) { await NextStep(); } else if (Bool == false || Skip) { Config[Setting_Key.WAR_STARTED].Set(false, null); await SkipStep("I will not send a notification when clan wars start."); } else { await SendAsync(msg_BoolParseFailed); } break; case SetupStep.WAR_WarStartedMessage: if (Skip) { Config[Setting_Key.WAR_STARTED].Set(true, null); await SkipStep("I will use my default notification after war has started."); } else { Config[Setting_Key.WAR_STARTED].Set(true, Message); await NextStep("The war started message has been set to:\r" + $"\n{Message}"); } break; //Enable specific wars case SetupStep.Enable_Specific_Wars: if (Bool == true) { await NextStep(); } else if (Bool == false || Skip) { Config[Setting_Key.WAR_1].Enable(); Config[Setting_Key.WAR_2].Enable(); Config[Setting_Key.WAR_3].Enable(); Config[Setting_Key.WAR_4].Enable(); await SkipStep("I will send notifications for all 4 war cycles."); } else { await SendAsync(msg_BoolParseFailed); } break; case SetupStep.WAR_1_Enabled: if (Bool == true) { Config[Setting_Key.WAR_1].Enable(); await NextStep("I will notify for war 1."); } else if (Bool == false || Skip) { Config[Setting_Key.WAR_1].Disable(); await SkipStep("I will not notify for war 1."); } else { await SendAsync(msg_BoolParseFailed); } break; case SetupStep.WAR_2_Enabled: if (Bool == true) { Config[Setting_Key.WAR_2].Enable(); await NextStep("I will notify for war 2."); } else if (Bool == false || Skip) { Config[Setting_Key.WAR_2].Disable(); await SkipStep("I will not notify for war 2."); } else { await SendAsync(msg_BoolParseFailed); } break; case SetupStep.WAR_3_Enabled: if (Bool == true) { Config[Setting_Key.WAR_3].Enable(); await NextStep("I will notify for war 3."); } else if (Bool == false || Skip) { Config[Setting_Key.WAR_3].Disable(); await SkipStep("I will not notify for war 3."); } else { await SendAsync(msg_BoolParseFailed); } break; case SetupStep.WAR_4_Enabled: if (Bool == true) { Config[Setting_Key.WAR_4].Enable(); await NextStep("I will notify for war 4."); } else if (Bool == false || Skip) { Config[Setting_Key.WAR_4].Disable(); await SkipStep("I will not notify for war 4."); } else { await SendAsync(msg_BoolParseFailed); } break; case SetupStep.Should_Set_Roles: if (Bool == true) { await NextStep(); } else if (Bool == false || Skip) { this.Config.ClearAllRoles(); await SkipStep("I will not perform any role-based management or tagging."); } else { await SendAsync(msg_BoolParseFailed); } break; case SetupStep.WAR_Clear_Channel: if (Bool == true) { this.Config[Setting_Key.CLEAR_WAR_CHANNEL_ON_WAR_START].Enable(); var warch = this.Config.GetGuildChannel(WarBotChannelType.WAR); await NextStep($"I will automatically purge all non-pinned messages from {warch.Mention} when the preperation peroid starts."); } else if (Bool == false || Skip) { this.Config[Setting_Key.CLEAR_WAR_CHANNEL_ON_WAR_START].Disable(); await SkipStep("I will not automatically empty the war channel."); } else { await SendAsync(msg_BoolParseFailed); } break; case SetupStep.Portal_Channel: if (Skip || Bool == false) { Config.SetGuildChannel(WarBotChannelType.PORTAL, null); Config[Setting_Key.PORTAL_STARTED].Disable(); await SkipStep("I will not send portal notifications.\r" + "\nYou may enable this feature later if you wish."); } else if (CH != null) { Config.SetGuildChannel(WarBotChannelType.PORTAL, CH); await NextStep($"My portal notifications will be sent to {CH.Mention}."); } else { await SendAsync(msg_ChannelExpected); } break; case SetupStep.Portal_Started_Message: if (Skip) { Config[Setting_Key.PORTAL_STARTED].Set(true, null); await SkipStep("I will use my default notification when the portal opens."); } else { Config[Setting_Key.PORTAL_STARTED].Set(true, Message); await NextStep("The war started message has been set to:\r" + $"\n{Message}"); } break; //All of these steps share the same logic. case SetupStep.Role_Guest: case SetupStep.Role_Member: case SetupStep.Role_Officer: case SetupStep.Role_Leader: case SetupStep.Role_ServerAdmin: var role = GetRoleFromStep(CurrentStep); if (Skip) { Config.SetGuildRole(role, null); await SkipStep(); } else if (ROLE != null) { Config.SetGuildRole(role, ROLE); await NextStep($"Role {role.ToString()} has been assigned to discord role {(ROLE.IsMentionable ? ROLE.Mention : ROLE.Name)}"); } else { await SendAsync(msg_RoleExpected); } break; case SetupStep.Set_Website: if (Skip) { Config.Website = null; await SkipStep("No website will be configured."); } else { Config.Website = Message; await NextStep("The website message has been set to:\r" + $"\n{Message}"); } break; case SetupStep.Set_Loot: if (Skip) { Config.Loot = null; await SkipStep("No loot message will be configured."); } else { Config.Loot = Message; await NextStep("The Loot message has been set to:\r" + $"\n{Message}"); } break; default: throw new Exception("Unhandled case."); } }
public override async Task ProcessMessage(SocketUserMessage input) { var msg = input.Content; var cmd = input.Content.Trim().ToLowerInvariant(); //Delete this message after the dialog is over. CleanupList.Add(input); if (string.IsNullOrEmpty(msg)) { return; } if (cmd.Equals("stop") || cmd.Equals("cancel")) { await startStep(State.CANCELLED); return; } else if (currState == State.GET_QUESTION) { this.Poll = new Poll(Channel, msg); await SendAsync($"The topic has been set to:\r\n**{msg}**"); await startStep(State.GET_OPTIONS); } else if (currState != State.GET_OPTIONS) { throw new Exception("This shouldn't be possible? Something broke. Current State " + currState.ToString()); } else if ((cmd.Equals("remove") || cmd.Equals("undo"))) { //Cleanup the message. if (Poll.Options.Any()) { Poll.Options.Remove(Poll.Options.Last()); await SendAsync($"Item Removed."); return; } else { await SendAsync("There were no questions in the list."); } } else if (cmd.Equals("done")) { if (Poll.Options.Count == 0) { await SendAsync("You have not added any options to the poll. Please provide an option."); } else if (Poll.Options.Count < 2) { await SendAsync("You have not added enough options to the poll. You must provide at least two options."); } else { await startStep(State.DONE); } } else //Add new option. { if (Poll.Options.Count >= Emotes.Length) { await SendAsync($"You may only add up to {Emotes.Length} options."); } else { //Get a list of emotes which are currently used. var usedEmotes = Poll.Options.Select(o => o.Emote); //Find the first emote, which is not currently in use. var nextReaction = this.Emotes.FirstOrDefault(o => !usedEmotes.Contains(o)); Poll.Options.Add(new PollOption(msg, nextReaction)); return; } } }