public async Task Execute(
            [Summary("The identifying name of the Taglist for which to retrieve information on.")]
            string TaglistName,
            [Summary("The Rating to filter users by, specified as a single case-insensitive character, S for Safe, Q for Questionable, and E for Explicit.")]
            char RatingSpecifier,
            [Summary("The Categories to filter users by, whitespace separated, if any.")]
            params string[] Categories
            )
        {
            Log.Application_.LogVerbose("Executing 'Taglist' command for Taglist '{0}', Rating '{1}', and {2} total Categories", TaglistName, RatingSpecifier, Categories.Length);
            Ratings?FilterByRating = await ParseRating(RatingSpecifier);

            if (FilterByRating is null)
            {
                return;
            }
            Taglist Model = await ReadTaglist(TaglistName);

            if (Model is null)
            {
                return;
            }
            string Response = RenderUsers(
                Model.FilterByUsersInterestedIn(FilterByRating.Value, Categories.ToHashSet())
                );
            await base.ReplyAsync(Response);
        }
Exemplo n.º 2
0
 protected XElement ToTaglistXML(Taglist Model)
 {
     return(new XElement(xmlns + "Taglist",
                         new XAttribute("Name", Model.Name),
                         new XAttribute("SafeArchiveChannelID", Model.ArchiveChannelIDSafe),
                         new XAttribute("QuestionableArchiveChannelID", Model.ArchiveChannelIDQuestionable),
                         new XAttribute("ExplicitArchiveChannelID", Model.ArchiveChannelIDExplicit),
                         new XElement(xmlns + "RegisteredUsers", (
                                          from U in Model.RegisteredUsers
                                          select new XElement(xmlns + "TaglistUser",
                                                              new XAttribute("Username", U.Username),
                                                              new XAttribute("UserID", U.ID),
                                                              new XAttribute("InterestedInSafe", U.AcceptsRating(Ratings.Safe)),
                                                              new XAttribute("InterestedInQuestionable", U.AcceptsRating(Ratings.Questionable)),
                                                              new XAttribute("InterestedInExplicit", U.AcceptsRating(Ratings.Explicit)),
                                                              new XElement(xmlns + "CategoryBlacklist", (
                                                                               from C in U.CategoryBlacklist
                                                                               select new XElement(xmlns + "Category",
                                                                                                   new XAttribute("Name", C)
                                                                                                   )
                                                                               ))
                                                              )
                                          ))
                         ));
 }
Exemplo n.º 3
0
        public Task Save(Taglist ToSave, Lock Lock)
        {
            Initialize();
            TaglistRepositoryLock DataFileLock = Lock as TaglistRepositoryLock;

            if (DataFileLock is null)
            {
                throw new ArgumentException("The supplied Lock was not returned by this class");
            }
            if (DataFileLock.Released)
            {
                throw new ArgumentException("The supplied Lock has been released");
            }
            try{
                XDocument DataDocument      = DataFileLock.LoadedDataDocument;
                XElement  OldTaglistElement = (
                    from TL in DataDocument.Root.Elements(xmlns + "Taglist")
                    where ToSave.Name.Equals(
                        ((string)TL.Attribute("Name")).Normalize(NormalizationForm.FormKD),
                        StringComparison.Ordinal
                        )
                    select TL
                    ).FirstOrDefault();
                if (!(OldTaglistElement is null))
                {
                    OldTaglistElement.Remove();
                }
                XElement NewTaglistElement = ToTaglistXML(ToSave);
                DataDocument.Root.Add(NewTaglistElement);
                return(XMLDataFileHandler.Save(DataDocument, SavingOptions, DataFileLock.Decorated));
            }finally{
                DataFileLock.Release();
            }
        }
        public async Task Execute(
            [Summary("The identifying name of the Taglist which the user is Registered in.")]
            string TaglistName,
            [Summary("The numeric Imgur account ID of the User Registered in the Taglist, for which to retrieve information on.")]
            int UserID
            )
        {
            Log.Application_.LogVerbose("Executing TaglistUser for user ID '{0:D}'", UserID);
            Taglist ModelTaglist = await ReadTaglist(TaglistName);

            if (ModelTaglist is null)
            {
                return;
            }
            TaglistRegisteredUser Model;

            if (!ModelTaglist.TryGetRegisteredUser(UserID, out Model))
            {
                await base.ReplyAsync(string.Format(
                                          "No Registered User in the Taglist '{1}' has the user ID '{0:D}'",
                                          UserID, ModelTaglist.Name
                                          ));

                return;
            }
            string Response = RenderUserDetails(Model);
            await base.ReplyAsync(Response);
        }
Exemplo n.º 5
0
        public async Task Save(Taglist ToSave, Lock Lock)
        {
            await Decorate.Save(ToSave, Lock);

            this.Cache = null;

            /*
             * if(!(Cache is null)){
             * this.Cache[ToSave.Name]=ToSave;
             * }
             */
        }
Exemplo n.º 6
0
        public ActionResult Tags(string tag)
        {
            Taglist t = new Taglist();

            ViewBag.count = 0;
            using (Model1 db = new Model1())
            {
                var taglist = db.tag.Where(q => q.tag == tag).Take(50).ToList();
                t.taglist       = taglist;
                ViewBag.count   = t.taglist.Count;
                ViewBag.tagname = tag;
                return(View(t));
            }
        }
        public async Task Execute(
            [Summary("The identifying name of the Taglist for which to retrieve information on.")]
            string TaglistName
            )
        {
            Log.Application_.LogVerbose("Executing 'Taglist' command for Taglist '{0}'", TaglistName);
            Taglist Model = await ReadTaglist(TaglistName);

            if (Model is null)
            {
                return;
            }
            string Response = RenderUsers(Model.RegisteredUsers);
            await base.ReplyAsync(Response);
        }
Exemplo n.º 8
0
        protected async Task MentionInterestedUsers(TagCommandParameters Command, Taglist SpecifiedTaglist)
        {
            ISet <TaglistRegisteredUser> InterestedUsers = SpecifiedTaglist.FilterByUsersInterestedIn(Command.Rating, Command.Categories);

            Log.Application_.LogVerbose("Mentioning {0} total users in response to Tag command for item '{1}'", InterestedUsers.Count, Command.ItemID);
            ISet <string> InterestedUsernames = (
                from U in InterestedUsers
                select U.Username
                ).ToHashSet();

            try{
                await Imgur.MentionUsers(Command.ItemID, Command.HostCommentID, InterestedUsernames);
            }catch (ImgurException Error) {
                Log.Application_.LogError(
                    "Error Mentioning users in Taglist '{1}' in response to the Tag command on the Imgur Gallery Item with ID '{0}'; users may have been partially Mentioned, consider re-Tagging the Gallery Item: {2}",
                    Command.ItemID, Command.TaglistName, Error.Message
                    );
                return;
            }
        }
Exemplo n.º 9
0
        protected async Task <Tuple <Taglist, Lock> > Load(string TaglistName, bool LockDataFile)
        {
            TaglistName = TaglistName.Normalize(NormalizationForm.FormKD);
            XDocument DataDocument;
            Lock      DataFileLock = null;

            if (LockDataFile)
            {
                var LoadResult = await XMLDataFileHandler.LoadFileAndLock(FileAccess.ReadWrite, FileShare.None, true);

                DataDocument = LoadResult.Item1;
                DataFileLock = LoadResult.Item2;
            }
            else
            {
                DataDocument = await XMLDataFileHandler.LoadFile(FileAccess.ReadWrite, FileShare.None, true);
            }
            bool success = false;

            try{
                Taglist Result = (
                    from TL in DataDocument.Root.Elements(xmlns + "Taglist")
                    where TaglistName.Equals(
                        ((string)TL.Attribute("Name")).Normalize(NormalizationForm.FormKD),
                        StringComparison.Ordinal
                        )
                    select FromTaglistXML(TL)
                    ).FirstOrDefault();
                if (Result is null)
                {
                    throw new EntityNotFoundException();
                }
                success = true;
                return(new Tuple <Taglist, Lock>(Result, new TaglistRepositoryLock(DataFileLock, DataDocument)));
            }finally{
                if (!success)
                {
                    DataFileLock?.Release();
                }
            }
        }
Exemplo n.º 10
0
        private bool CheckTaglistChannel(Taglist Check, ulong ChannelID, string ChannelTypeName, bool ShouldBeNSFW = false)
        {
            if (!Discord.TextChannelExists(ChannelID, out string ChannelName, out bool NSFW))
            {
                Log.Bootstrap_.LogError(
                    "The '{1}' Channel for the Taglist '{0}' (the Channel specified by the ID {2:D}), does not exist in the Guild",
                    Check.Name, ChannelTypeName, ChannelID
                    );
                return(false);
            }

            /*
             * ??? Possible Discord API bug; the Discord API doesn't seem to correctly identify NSFW Channels
             * if(ShouldBeNSFW && !NSFW){
             * Log.Bootstrap_.LogWarning(
             * "The '{1}' Channel for the Taglist '{0}' (Channel '{3}', #{2:D}) is not marked as NSFW",
             * Check.Name,ChannelTypeName,ChannelID,ChannelName
             * );
             * }
             */
            return(true);
        }
Exemplo n.º 11
0
 protected async Task ArchiveTaggedItem(TagCommandParameters Command, GalleryItem ToArchive, Taglist SpecifiedTaglist)
 {
     Log.Application_.LogVerbose("Archiving item '{0}' to relevant Archive Channel for Taglist '{1}'", ToArchive.ID, SpecifiedTaglist.Name);
     try{
         await Discord.PostGalleryItemDetails(
             SpecifiedTaglist.ArchiveChannelIDForRating(Command.Rating),
             ToArchive
             );
     }catch (DiscordException Error) {
         Log.Application_.LogError(
             "Error archiving Imgur Gallery Item with ID '{0}' to the relevant Archive channel for Taglist '{1}': {2}",
             ToArchive.ID, SpecifiedTaglist.Name, Error.Message
             );
     }
 }
Exemplo n.º 12
0
    public void ReadLines(Scene s)
    {
        if (s.Index >= s.Lines.Count)
        {
            return;
        }
        var line = s.GetCurrentLine();
        var text = "";
        var list = new List <string>();

        list.AddRange(_taglist);
        var fade_list = new List <string>();

        fade_list.AddRange(_fadetag);
        var _tagFactory = new Taglist();

        if (line.Contains("#"))
        {
            while (true)
            {
                if (!line.Contains("#"))
                {
                    break;
                }
                line = line.Replace("#", "");
                foreach (string tag in list)
                {
                    if (line.Contains(tag))
                    {
                        _tagFactory.CreateTag(tag).Do(_sc, line, s);
                    }
                }
                s.GoNextLine();
                if (s.IsFinished())
                {
                    break;
                }
                line = s.GetCurrentLine();
            }
        }
        if (line.Contains("*"))
        {
            line = line.Replace("*", "");
            foreach (string tag in fade_list)
            {
                if (line.Contains(tag))
                {
                    _tagFactory.CreateTag(tag).Do(_sc, line, s);
                }
            }
            s.GoNextLine();
            line = s.GetCurrentLine();
        }

        if (line.Contains('{'))
        {
            line = line.Replace("{", "");
            while (true)
            {
                if (line.Contains('}'))
                {
                    line  = line.Replace("}", "");
                    text += line;
                    s.GoNextLine();
                    break;
                }
                else
                {
                    text += line;
                }
                s.GoNextLine();
                if (s.IsFinished())
                {
                    break;
                }
                line = s.GetCurrentLine();
            }
            if (!string.IsNullOrEmpty(text))
            {
                _sc.SetText(text);
            }
        }
    }
Exemplo n.º 13
0
        public async Task RunDebug()
        {
            /*
             * Imgur.ImgurCommandParser Parser=new Imgur.ImgurCommandParser();
             * Parser.ProcessCommands(new ModelsImpl.Comment(){
             * CommentText="~@Tagaroo tag taglist-name s category1 category2 category3.@Tagaroo tag\n",
             * Id=0
             * },this);
             */
            /*
             * ICollection<string> Results=Imgur.ImgurInterfacer.ChunkConcatenate(
             * new List<string>(){"22","1","4444","666666","7777777","333","22","55555"},
             * string.Empty," ",6
             * );
             * foreach(string Result in Results){
             * Console.WriteLine(Result);
             * Console.WriteLine();
             * }
             */
            /*
             * IReadOnlyDictionary<string,Taglist> Results=await new DataAccess.TaglistRepository(@"DataAccess\Taglists.xml",false).LoadAll();
             * foreach(Taglist Result in Results.Values){
             * Console.WriteLine("Taglist: {0}",Result.Name);
             * foreach(TaglistRegisteredUser User in Result.RegisteredUsers){
             * Console.WriteLine("{0}; Ratings - {1}; Category blacklist - {2}",User.Username,User.AcceptedRatings,string.Join(", ",User.CategoryBlacklist));
             * }
             * Console.WriteLine();
             * }
             */
            /*
             * ICollection<string> Results=await new CoreProcess(
             * null,new DataAccess.TaglistRepository(@"DataAccess\Taglists.xml",true),new Settings()
             * ).ProcessTagCommand(new Tag(
             * 0,string.Empty,"TheTaglist",Ratings.Safe,new List<string>(){"A"}
             * ));
             * foreach(string Result in Results){
             * Console.WriteLine(Result);
             * }
             */
            /*
             * DataAccess.SettingsRepository Repository=new DataAccess.SettingsRepository(@"DataAccess\Settings.xml");
             * Settings Model=await Repository.LoadSettings();
             * await Repository.SaveNewImgurUserAuthorizationToken("A","R");
             * Model.CommenterUsernames.Add("Added");
             * Model.PullCommentsFrequency=TimeSpan.FromSeconds(172799);
             * Model.RequestThreshholdPullCommentsPerUser=byte.MinValue;
             * Model.CommentsProcessedUpToInclusive=DateTimeOffset.UtcNow.ToOffset(TimeSpan.FromHours(1));
             * await Repository.SaveWritableSettings(Model);
             */
            /*
             * DataAccess.SettingsRepository RepositorySettings=new DataAccess.SettingsRepositoryMain(@"Settings.xml");
             * DataAccess.TaglistRepository RepositoryTaglist=new DataAccess.TaglistRepositoryMain(@"Taglists.xml",true);
             * Settings ModelSettings=await RepositorySettings.LoadSettings();
             * var ModelTaglists=await RepositoryTaglist.LoadAll();
             * ApplicationConfiguration ModelConfiguration=await RepositorySettings.LoadConfiguration();
             */
            DataAccess.TaglistRepository RepositoryTaglist = new DataAccess.TaglistRepositoryMain(@"Taglists.xml");
            RepositoryTaglist.Initialize();
            var ModelAndLock = await RepositoryTaglist.LoadAndLock("SampleTaglist");

            Taglist Model = ModelAndLock.Item1;

            DataAccess.Lock Lock = ModelAndLock.Item2;
            Model.UnRegisterUser("All");
            Model.UnRegisterUser(56);
            Model.RegisterUser(new TaglistRegisteredUser("None", 56, TaglistRegisteredUser.RatingFlags.None, new List <string>(0)));
            Model.RegisterUser(new TaglistRegisteredUser("New Many", 255, TaglistRegisteredUser.RatingFlags.Safe | TaglistRegisteredUser.RatingFlags.Questionable | TaglistRegisteredUser.RatingFlags.Explicit, new List <string> {
                "Category A", "Category B", "Category C"
            }));
            try{
                Model.RegisterUser(new TaglistRegisteredUser("Explicit", 257, TaglistRegisteredUser.RatingFlags.Explicit, new List <string>(0)));
            }catch (AlreadyExistsException) {
            }
            Model.RegisterUser(new TaglistRegisteredUser("Safe", 59, TaglistRegisteredUser.RatingFlags.Safe, new List <string> {
                "NotSafe"
            }));
            await RepositoryTaglist.Save(Model, Lock);
        }