コード例 #1
0
 async Task removedThing(VotableThing thing)
 {
     if (thing.FetchedAt.ToUniversalTime() < applicationStart.AddSeconds(5))
     {
         return;
     }
     if (thing is Post)
     {
         Post post = thing as Post;
         if (!(post.LinkFlairText is null) && FlairConfig.ContainsKey(post.LinkFlairText))
         {
             String userfile = "";
             using (StreamReader sr = new StreamReader(new FileStream($"data//user//{post.AuthorName}.json", FileMode.OpenOrCreate))){
                 userfile = sr.ReadToEnd();
             }
             User user;
             if (userfile.Equals(""))
             {
                 user = new User();
             }
             else
             {
                 user = JsonConvert.DeserializeObject <User>(userfile);
                 //Calculate Monday of Week (UTC)
                 var cal = System.Globalization.DateTimeFormatInfo.CurrentInfo.Calendar;
                 var d1  = user.lastEdit.Date.AddDays(-1 * ((int)cal.GetDayOfWeek(user.lastEdit) - 1));
                 var d2  = post.CreatedUTC.Date.AddDays(-1 * ((int)cal.GetDayOfWeek(post.CreatedUTC) - 1));
                 if (d1 != d2) //Diffrent Week
                 {
                     return;
                 }
             }
             if (!user.FlairCount.ContainsKey(post.LinkFlairText))
             {
                 user.FlairCount.Add(post.LinkFlairText, 0);
                 return; //flair not yet accounted for with this User
             }
             else
             {
                 user.FlairCount[post.LinkFlairText] -= 1;
                 if (user.FlairCount[post.LinkFlairText] < 0) //wtf?
                 {
                     user.FlairCount[post.LinkFlairText] = 0;
                 }
             }
             using (StreamWriter sw = new StreamWriter(new FileStream($"data//user//{post.AuthorName}.json", FileMode.OpenOrCreate))){
                 sw.Write(JsonConvert.SerializeObject(user));
             }
         }
     }
 }
コード例 #2
0
        public static string GetBotLinks(VotableThing relatedThing = null)
        {
            List <string> botLinks = new List <string>();

            if (relatedThing != null)
            {
                string encodedLink = WebUtility.HtmlEncode(RedditHelper.GetFullLink(relatedThing.Permalink));
                botLinks.Add(Markdown.Link("Feedback", "https://docs.google.com/forms/d/e/1FAIpQLSchgbXwXMylhtbA8kXFycZenSKpCMZjmYWMZcqREl_OlCm4Ew/viewform?usp=pp_url&entry.266808192=" + encodedLink));
            }
            else
            {
                botLinks.Add(Markdown.Link("Feedback", "https://docs.google.com/forms/d/e/1FAIpQLSchgbXwXMylhtbA8kXFycZenSKpCMZjmYWMZcqREl_OlCm4Ew/viewform?usp=pp_url"));
            }

            botLinks.Add(Markdown.Link("FAQ", "https://github.com/derekantrican/MountainProject/wiki/Bot-FAQ"));
            botLinks.Add(Markdown.Link("Syntax", "https://github.com/derekantrican/MountainProject/wiki/Bot-Syntax"));
            botLinks.Add(Markdown.Link("GitHub", "https://github.com/derekantrican/MountainProject"));
            botLinks.Add(Markdown.Link("Donate", "https://www.paypal.me/derekantrican"));

            return(string.Join(" | ", botLinks));
        }