Пример #1
0
        internal async Task <Boolean> CheckShouldBanAsync(ModeratableThing thing, IEnumerable <String> bannedGroups)
        {
            if (IsUnbannable(thing))
            {
                return(false);
            }

            // flair bypass only applies to authors that can have flair
            if (thing is VotableThing votableThing)
            {
                if (!String.IsNullOrWhiteSpace(votableThing.AuthorFlairCssClass) &&
                    ignoreAuthorCssClasses.Any(cssClass => votableThing.AuthorFlairCssClass.Contains(cssClass)))
                {
                    return(false);
                }
            }
            if (UserLookup is CacheableBackedBotDatabase cacheable)
            {
                if (cacheable.IsStale)
                {
                    IncrementStatisticIfExists("requestRate");
                }
            }
            IEnumerable <String> groupNames = (await UserLookup.GetGroupsForUserAsync(thing.AuthorName)).Select(group => group.Name);

            return(groupNames.Any(groupName => bannedGroups.Contains(groupName)));
        }
Пример #2
0
        public void OnNext(ModAction value)
        {
            if (value.ModeratorName == "AutoModerator" && value.Details.ToLower().Contains("spez_that"))
            {
                bool   isPost = value.TargetThingFullname.StartsWith("t3_");
                string reason = value.Details.Substring(value.Details.ToLower().IndexOf("spez_that") + 10);
                subTweeter.SendTweet(sub.Name, (isPost ? "post" : "comment"), value.TargetAuthorName, reason, (isPost ? value.TargetTitle : value.TargetBody), value.TargetThingPermalink);
            }
            else if (value.Action == ModActionType.Distinguish && value.TargetThingFullname.StartsWith("t1_") && value.TargetBody.ToLower().Contains("spez_that"))
            {
                var              modcomment = (ModeratableThing)value.GetTargetThing().Result;
                string           reason     = "";
                ModeratableThing thing      = null;
                if (modcomment.Kind == "t4")
                {
                    var pm = (PrivateMessage)modcomment;
                    thing  = pm.GetParent() as ModeratableThing;
                    reason = pm.Body.Substring(pm.Body.ToLower().IndexOf("spez_that") + 10);
                }
                else
                {
                    var c = (Comment)modcomment;
                    thing = new Reddit(sub.WebAgent, false).GetThingByFullnameAsync(c.ParentId).Result as ModeratableThing;
                    c.RemoveAsync().Wait();
                    reason = c.Body.Substring(c.Body.ToLower().IndexOf("spez_that") + 10);
                }
                string type    = "thing";
                string message = "";
                string url     = "";
                switch (thing.Kind)
                {
                case "t3":
                    type    = "post";
                    message = ((Post)thing).Title;
                    url     = ((Post)thing).Permalink.ToString();
                    break;

                case "t1":
                    type    = "comment";
                    message = ((Comment)thing).Body;
                    url     = ((Comment)thing).Permalink.ToString();
                    break;

                case "t4":
                    type    = "message";
                    message = ((PrivateMessage)thing).Body;
                    url     = "";
                    break;
                }
                if (!string.IsNullOrWhiteSpace(url) && !url.ToLower().StartsWith("https://reddit.com/"))
                {
                    url = "https://reddit.com" + (url.StartsWith("/") ? "" : "/") + url;
                }
                subTweeter.SendTweet(sub.Name, type, thing.AuthorName, reason, message, url);
            }
        }
Пример #3
0
        public override async Task <Message> HandleMessage(Message msg)
        {
            MessageContext context = new MessageContext(msg, this);
            string         fname   = Smart.Format(Fullname, context);
            string         reason  = Smart.Format(Reason, context);

            try
            {
                await ModeratableThing.ReportAsync(Agent, fname, ModeratableThing.ReportType.Other, reason);
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"{ex.GetType().Name} thrown when removing thing: {ex.Message}");
            }

            return(msg);
        }
Пример #4
0
 /// <summary>
 /// Checks whether this user is ineligible to be banned. The only case where
 /// this currently returns <see langword="true" /> is when the <paramref name="thing"/>
 /// or its <see cref="ModeratableThing.AuthorName"/> is <see langword="null"/>, whitespace,
 /// or equal to <see cref="DeletedUserName"/>.
 /// </summary>
 /// <param name="thing">The comment to test for the ability to ban</param>
 /// <returns>A value determining whether the user is not bannable on Reddit.</returns>
 public static Boolean IsUnbannable(ModeratableThing thing) => String.IsNullOrWhiteSpace(thing?.AuthorName) || thing?.AuthorName == DeletedUserName;