public ListCollectionManager()
            {
                // Add an empty list so we can set various lists to empty
                StringListManager empty = new StringListManager();

                ListCollection.Add("empty", empty);
            }
Example #2
0
        private void RunStartupScripts()
        {
            ReadRemapList(); // BUG: This should use list manager

            MapperBanList(ChatHandler.Self, "mapperban.list");
            WhiteList(ChatHandler.Self, "whitelist.unique");
            BlockedUserList(ChatHandler.Self, "blockeduser.unique");
            accesslist("whitelist.unique");
            accesslist("blockeduser.unique");
            accesslist("mapperban.list");

#if UNRELEASED
            OpenList(ChatHandler.Self, "mapper.list"); // Open mapper list so we can get new songs filtered by our favorite mappers.
            MapperAllowList(ChatHandler.Self, "mapper.list");

            accesslist("mapper.list");

            OpenList(ChatHandler.Self, "automtt.list"); // Open mapper list so we can get new songs filtered by our favorite mappers.
            automtt = listcollection.OpenList("automtt.list");
            accesslist("automtt.list");

            string dummy = "";

            TwitchUser user = ChatHandler.Self;

            loaddecks(new ParseState(ref user, ref dummy, CmdFlags.Silent, ref dummy)); // Load our default deck collection
            // BUG: Command failure observed once, no permission to use /chatcommand. Possible cause: OurTwitchUser isn't authenticated yet.

            RunScript(ChatHandler.Self, "startup.script"); // Run startup script. This can include any bot commands.
#endif
        }
            public bool contains(ref string listname, string key, ListFlags flags = ListFlags.Unchanged)
            {
                try
                {
                    StringListManager list = OpenList(listname);
                    return(list.Contains(key));
                }
                catch (Exception ex) { Plugin.Log(ex.ToString()); } // Going to try this form, to reduce code verbosity.

                return(false);
            }
 // Add list to queue, filtered by InQueue and duplicatelist
 private string queuelist(ParseState state)
 {
     try
     {
         StringListManager list = listcollection.OpenList(state.parameter);
         foreach (var entry in list.list)
         {
             ProcessSongRequest(new ParseState(state, entry));                              // Must use copies here, since these are all threads
         }
     }
     catch (Exception ex) { Plugin.Log(ex.ToString()); } // Going to try this form, to reduce code verbosity.
     return(success);
 }
            public bool remove(ref string listname, ref string key, ListFlags flags = ListFlags.Unchanged)
            {
                try
                {
                    StringListManager list = OpenList(listname);

                    list.Removeentry(key);

                    if (!(flags.HasFlag(ListFlags.InMemory) | flags.HasFlag(ListFlags.ReadOnly)))
                    {
                        list.Writefile(listname);
                    }

                    return(false);
                }
                catch (Exception ex) { Plugin.Log(ex.ToString()); } // Going to try this form, to reduce code verbosity.

                return(false);
            }
            public bool add(ref string listname, ref string key, ListFlags flags = ListFlags.Unchanged)
            {
                try
                {
                    StringListManager list = OpenList(listname);

                    list.Add(key);


                    if (!(flags.HasFlag(ListFlags.InMemory) | flags.HasFlag(ListFlags.ReadOnly)))
                    {
                        list.Writefile(listname);
                    }
                    return(true);
                }
                catch (Exception ex) { Plugin.Log(ex.ToString()); }

                return(false);
            }
            public StringListManager ClearOldList(string request, TimeSpan delta, ListFlags flags = ListFlags.Unchanged)
            {
                string   listfilename = Path.Combine(Plugin.DataPath, request);
                TimeSpan UpdatedAge   = GetFileAgeDifference(listfilename);

                StringListManager list = OpenList(request, flags);

                if (File.Exists(listfilename) && UpdatedAge > delta) // BUG: There's probably a better way to handle this
                {
                    //RequestBot.Instance.QueueChatMessage($"Clearing old session {request}");
                    list.Clear();
                    if (!(flags.HasFlag(ListFlags.InMemory) | flags.HasFlag(ListFlags.ReadOnly)))
                    {
                        list.Writefile(request);
                    }
                }

                return(list);
            }
            public StringListManager OpenList(string request, ListFlags flags = ListFlags.Unchanged) // All lists are accessed through here, flags determine mode
            {
                StringListManager list;

                if (!ListCollection.TryGetValue(request, out list))
                {
                    list = new StringListManager();
                    ListCollection.Add(request, list);
                    if (!flags.HasFlag(ListFlags.InMemory))
                    {
                        list.Readfile(request);                                     // If in memory, we never read from disk
                    }
                }
                else
                {
                    if (flags.HasFlag(ListFlags.Uncached))
                    {
                        list.Readfile(request);                                    // If Cache is off, ALWAYS re-read file.
                    }
                }
                return(list);
            }