public GloriousDirectDemocracy(VirtualServer _server) : base(_server, "GloriousDirectDemocracy")
        {
            server.fileCommand(folder, x => System.IO.Directory.CreateDirectory(x));
            List <string> arr = server.FileSetup(folder + LUIFileName);
            string        LowestUnusedIdStr = "0";

            if (arr.Count > 0)
            {
                LowestUnusedIdStr = arr[0];
            }
            if (!ulong.TryParse(LowestUnusedIdStr, out lowestUnusedId))
            {
                lowestUnusedId = 0;
            }
            NameOfAllProposals = server.XMlDictSetup <String, ulong>(folder + MasterTableFileName);
            List <String> currentProposals = server.FileSetup(folder + CurrentProposalNamesFileName);

            Proposals     = new Dictionary <ulong, Proposal>(currentProposals.Count + 10);
            pastProposals = new Dictionary <ulong, LazyDiscLoaded <Proposal> >();
            foreach (var entry in NameOfAllProposals)
            {
                string filename = folder + entry.Value + ".prop";
                if (currentProposals.FindIndex(x => x == entry.Key) != -1)
                {
                    //currentProposal
                    try
                    {
                        /*                        string outPut = server.fileCommand(filename, x => System.IO.File.ReadAllText(x));
                         *                      var prop =  //Proposal.FromString(outPut);
                         */
                        var prop = server.fileCommand(filename, x => Funcs.XMLSetup <Proposal>(x));
                        Proposals.Add(entry.Value, prop);
                        if (prop.Started)
                        {
                            queuePropEnd(prop, entry.Value);
                        }
                    }
                    catch
                    {
                        Console.WriteLine("Unable to Get Proposal " + entry.Value + " - '" + entry.Key + "'");
                    }
                }
                else
                {
                    //pastProposal
                    pastProposals.Add(entry.Value, new LazyDiscLoaded <Proposal>(filename, y => server.fileCommand(y, x => Funcs.XMLSetup <Proposal>(x))));
                }
            }
        }
Пример #2
0
        void bork(ServerMessage e, String m)
        {
            var    split   = m.Split(" ".ToCharArray());
            string message = "Unable to comply with command. \n\n bork <mention-target> <emoticon> <on/off>";

            Console.WriteLine("Bork cmd got: " + m);
            if (split.Length == 3 || split.Length == 2)
            {
                if (Funcs.validateMentionTarget(e, split[0]))
                {
                    Emote emote;
                    //string emoji = server.toEmojiString(e, split[1]);
                    IEmote emoji = null;
                    if (Emote.TryParse(split[1], out emote))
                    {
                        emoji = emote;
                    }
                    else
                    {
                        emoji = new Emoji(split[1]);
                        server.safeSendMessage(e.Channel, split[1] + " is not a server emote, optimistically assuming it works anyway.");
                    }
                    if (emoji != null)
                    {
                        var user = Funcs.GetUserByMentionOrName(e.Server.Users, split[0]);
                        if (user == null)
                        {
                            message = "Could not find user: "******"currently borking " + emoji + " at " + split[0];
                                }
                                else
                                {
                                    message = "no such bork: " + emoji + " at " + split[0];
                                }
                            }
                            else if (split[2] == "on")
                            {
                                //                            var x = DC.ClientAPI.Send(new EmojiAddRequest(e.Channel.Id, e.Message.Id, ));
                                //                            x.Wait();
                                List <String> individualBorklist;
                                if (!borklist.TryGetValue(userId, out individualBorklist))
                                {
                                    individualBorklist = new List <string>();
                                    borklist.Add(userId, individualBorklist);
                                }
                                if (individualBorklist.Contains(emoji.ToString()) || (emote != null && individualBorklist.Find((ems) => ems.Contains(emote.Id.ToString())) != null))
                                {
                                    message = "Already doing this";
                                }
                                else
                                {
                                    individualBorklist.Add(emoji.ToString());
                                    server.XMlDictSerialization(borklistPath, borklist);
                                    message = "Understood, borking " + emoji + " at " + split[0] + " from now on";
                                }
                            }
                            else if (split[2] == "off")
                            {
                                List <String> individualBorklist;
                                if (!borklist.TryGetValue(userId, out individualBorklist))
                                {
                                    message = "I never did that in the first place";
                                }
                                else
                                {
                                    if (emote != null)
                                    {
                                        var t = individualBorklist.Find((ems) => ems.Contains(emote.Id.ToString()));
                                        if (t != null)
                                        {
                                            individualBorklist.Remove(t);
                                        }
                                    }
                                    else
                                    {
                                        individualBorklist.Remove(emoji.ToString());
                                    }
                                    if (individualBorklist.Count == 0)
                                    {
                                        borklist.Remove(userId);
                                    }
                                    server.XMlDictSerialization(borklistPath, borklist);
                                    message = "Understood, no more borking " + emoji + " at " + split[0] + " from now on";
                                }
                            }
                        }
                    }
                    else
                    {
                        message = "Invalid Emoji: " + split[1];
                    }
                }
            }
            server.safeSendMessage(e.Channel, message);
        }