Exemplo n.º 1
0
        public async Task <RuntimeResult> StartAmending(string name)
        {
            if (name.Contains("-"))
            {
                return(new BotResult($"Name contains illegal charactor: `-`"));
            }
            if (Group != null)
            {
                return(new BotResult($"You are already amending a bill, you must abandon or complete that Group first."));
            }
            if (!Service.Laws.TryGetValue(name, out var act))
            {
                return(new BotResult("Could not find a bill by that name"));
            }
            var content = JsonConvert.SerializeObject(act, new BotUserConverter());

            Act          = JsonConvert.DeserializeObject <Act>(content, new BotUserConverter()); // easiest way to clone everything
            Act.PathName = $"amend-{name}-{Context.User.Id}";
            Group        = new AmendmentGroup()
            {
                Author       = Context.BotUser,
                Contributors = new BotUser[] { },
                Draft        = true,
                Id           = Act.AmendmentReferences.Count + 1,
                Date         = DateTime.Now
            };
            Act.AmendmentReferences[Group.Id] = Group;
            await ReplyAsync("Amendment started");

            return(new BotResult());
        }
Exemplo n.º 2
0
        public async Task <RuntimeResult> ContinueAmendment(string name)
        {
            if (Group != null)
            {
                return(new BotResult("You are already amending something"));
            }
            name = $"amend-{name}-{Context.User.Id}";
            if (!Service.Laws.TryGetValue(name, out var act))
            {
                return(new BotResult("Could not find a bill by that name"));
            }
            var highestId = act.AmendmentReferences.Keys.OrderByDescending(x => x).FirstOrDefault();

            if (!act.AmendmentReferences.TryGetValue(highestId, out var group))
            {
                return(new BotResult($"Could not find the the latest amendment for this bill"));
            }
            if (!group.Draft)
            {
                return(new BotResult("This amendment has been finished"));
            }
            if (group.Author.Id != Context.User.Id)
            {
                return(new BotResult("You did not author this amendment"));
            }
            Act   = act;
            Group = group;
            await ReplyAsync($"Continued amendment {group.Id} for {Act.ShortTitle}");

            return(new BotResult());
        }
Exemplo n.º 3
0
        protected override void BeforeExecute(CommandInfo command)
        {
            if (!saves.ContainsKey(Context.User.Id))
            {
                saves[Context.User.Id] = new SaveInfo();
            }
            var info = saves[Context.User.Id];

            Act   = info.act;
            Group = info.group;
        }
Exemplo n.º 4
0
        public async Task <RuntimeResult> ApproveAmmendment(string name, int id)
        {
            if (!Service.Laws.TryGetValue(name, out var act))
            {
                return(new BotResult("Could not find a bill by that name"));
            }
            if (!act.AmendmentReferences.TryGetValue(id, out var group))
            {
                return(new BotResult($"There no amendment group matches that id"));
            }
            if (!group.Draft)
            {
                return(new BotResult("That amendment has already been approved"));
            }
            var properName = name.Split('-')[1]; // "amend-[name]-id"

            if (!Service.Laws.TryGetValue(properName, out var original))
            {
                return(new BotResult("Could not find original bill that this amends"));
            }
            group.Draft = false;
            group.Date  = DateTime.Now;
            int oldId = group.Id;

            group.Id = original.AmendmentReferences.Count + 1; // may have changed since last.
            original.AmendmentReferences[group.Id] = group;
            foreach (var section in act.Children)
            {
                var oSection = original.Children.FirstOrDefault(x => x.Number == section.Number && x.Group == section.Group);
                foreach (var sectionAmendment in section.TextAmendments.Where(x => x.GroupId == oldId))
                {
                    sectionAmendment.GroupId   = group.Id;
                    sectionAmendment.AmendsAct = original;
                    oSection.TextAmendments.Add(sectionAmendment);
                }

                foreach (var paragraph in section.Children)
                {
                    var oParagraph = oSection.Children.FirstOrDefault(x => x.Number == paragraph.Number);
                    foreach (var paragraphAmendment in paragraph.TextAmendments.Where(x => x.GroupId == oldId))
                    {
                        paragraphAmendment.GroupId   = group.Id;
                        paragraphAmendment.AmendsAct = original;
                        oParagraph.TextAmendments.Add(paragraphAmendment);
                    }

                    foreach (var clause in paragraph.Children)
                    {
                        var oClause = oParagraph.Children.FirstOrDefault(x => x.Number == clause.Number);
                        foreach (var clauseAmendment in clause.TextAmendments.Where(x => x.GroupId == oldId))
                        {
                            clauseAmendment.GroupId   = group.Id;
                            clauseAmendment.AmendsAct = original;
                            oClause.TextAmendments.Add(clauseAmendment);
                        }
                    }
                }
            }
            Service.SaveAct(original);
            Service.RemoveAct(act);
            Act   = null;
            Group = null;
            await ReplyAsync("Amendment applied, should be visible at: " + original.URL);

            return(new BotResult());
        }