Compare commits

..

3 Commits

Author SHA1 Message Date
FoxxMD
381976d6af feat(modlog): Implement normalizing raw modlog data
Refactor ModAction to use data from either mod notes or modlog
2022-10-03 11:31:35 -04:00
FoxxMD
3faf4ca3dc fix: Fix wiki location usage when getting from subreddit resources 2022-09-28 10:34:48 -04:00
FoxxMD
2f35b82d5e feat(history): Log failure results for easier rule tuning 2022-09-28 10:25:26 -04:00
7 changed files with 184 additions and 23 deletions

View File

@@ -40,7 +40,7 @@
// for this to pass the Author of the Submission must not have the flair "Supreme Memer" and have the name "user1" or "user2"
{
"flairText": ["Supreme Memer"],
"name": ["user1","user2"]
"names": ["user1","user2"]
},
{
// for this to pass the Author of the Submission must not have the flair "Decent Memer"

View File

@@ -30,7 +30,7 @@ runs:
# for this to pass the Author of the Submission must not have the flair "Supreme Memer" and have the name "user1" or "user2"
- flairText:
- Supreme Memer
name:
names:
- user1
- user2
# for this to pass the Author of the Submission must not have the flair "Decent Memer"

View File

@@ -395,3 +395,82 @@ export interface RuleResultsTemplateData {
export interface GenericContentTemplateData extends BaseTemplateData, Partial<RuleResultsTemplateData>, Partial<ActionResultsTemplateData> {
item?: (SubmissionTemplateData | CommentTemplateData)
}
export type ModerationActionType =
'banuser'
| 'unbanuser'
| 'spamlink'
| 'removelink'
| 'approvelink'
| 'spamcomment'
| 'removecomment'
| 'approvecomment'
| 'addmoderator'
| 'showcomment'
| 'invitemoderator'
| 'uninvitemoderator'
| 'acceptmoderatorinvite'
| 'removemoderator'
| 'addcontributor'
| 'removecontributor'
| 'editsettings'
| 'editflair'
| 'distinguish'
| 'marknsfw'
| 'wikibanned'
| 'wikicontributor'
| 'wikiunbanned'
| 'wikipagelisted'
| 'removewikicontributor'
| 'wikirevise'
| 'wikipermlevel'
| 'ignorereports'
| 'unignorereports'
| 'setpermissions'
| 'setsuggestedsort'
| 'sticky'
| 'unsticky'
| 'setcontestmode'
| 'unsetcontestmode'
| 'lock'
| 'unlock'
| 'muteuser'
| 'unmuteuser'
| 'createrule'
| 'editrule'
| 'reorderrules'
| 'deleterule'
| 'spoiler'
| 'unspoiler'
| 'modmail_enrollment'
| 'community_styling'
| 'community_widgets'
| 'markoriginalcontent'
| 'collections'
| 'events'
| 'hidden_award'
| 'add_community_topics'
| 'remove_community_topics'
| 'create_scheduled_post'
| 'edit_scheduled_post'
| 'delete_scheduled_post'
| 'submit_scheduled_post'
| 'edit_post_requirements'
| 'invitesubscriber'
| 'submit_content_rating_survey'
| 'adjust_post_crowd_control_level'
| 'enable_post_crowd_control_filter'
| 'disable_post_crowd_control_filter'
| 'deleteoverriddenclassification'
| 'overrideclassification'
| 'reordermoderators'
| 'snoozereports'
| 'unsnoozereports'
| 'addnote'
| 'deletenote'
| 'addremovalreason'
| 'createremovalreason'
| 'updateremovalreason'
| 'deleteremovalreason';
export const moderatorActionTypes = ['banuser', 'unbanuser', 'spamlink', 'removelink', 'approvelink', 'spamcomment', 'removecomment', 'approvecomment', 'addmoderator', 'showcomment', 'invitemoderator', 'uninvitemoderator', 'acceptmoderatorinvite', 'removemoderator', 'addcontributor', 'removecontributor', 'editsettings', 'editflair', 'distinguish', 'marknsfw', 'wikibanned', 'wikicontributor', 'wikiunbanned', 'wikipagelisted', 'removewikicontributor', 'wikirevise', 'wikipermlevel', 'ignorereports', 'unignorereports', 'setpermissions', 'setsuggestedsort', 'sticky', 'unsticky', 'setcontestmode', 'unsetcontestmode', 'lock', 'unlock', 'muteuser', 'unmuteuser', 'createrule', 'editrule', 'reorderrules', 'deleterule', 'spoiler', 'unspoiler', 'modmail_enrollment', 'community_styling', 'community_widgets', 'markoriginalcontent', 'collections', 'events', 'hidden_award', 'add_community_topics', 'remove_community_topics', 'create_scheduled_post', 'edit_scheduled_post', 'delete_scheduled_post', 'submit_scheduled_post', 'edit_post_requirements', 'invitesubscriber', 'submit_content_rating_survey', 'adjust_post_crowd_control_level', 'enable_post_crowd_control_filter', 'disable_post_crowd_control_filter', 'deleteoverriddenclassification', 'overrideclassification', 'reordermoderators', 'snoozereports', 'unsnoozereports', 'addnote', 'deletenote', 'addremovalreason', 'createremovalreason', 'updateremovalreason', 'deleteremovalreason'];

View File

@@ -300,6 +300,12 @@ export class HistoryRule extends Rule {
this.logger.verbose(`${PASS} ${resultData.result}`);
return Promise.resolve([true, this.getResult(true, resultData)]);
} else {
// log failures for easier debugging
for(const res of criteriaResults) {
const resultData = this.generateResultDataFromCriteria(res);
this.logger.verbose(`${FAIL} ${resultData.result}`);
}
}
return Promise.resolve([false, this.getResult(false, {result: failCriteriaResult})]);

View File

@@ -1,39 +1,111 @@
import {Submission, RedditUser, Comment, Subreddit, PrivateMessage} from "snoowrap/dist/objects"
import {generateSnoowrapEntityFromRedditThing, parseRedditFullname} from "../../util"
import Snoowrap from "snoowrap";
import {ModerationActionType} from "../../Common/Infrastructure/Atomic";
//import {ExtendedSnoowrap} from "../../Utils/SnoowrapClients";
export interface ModActionRaw {
action?: string | null
action?: ModerationActionType | null
reddit_id?: string | null
details?: string | null
description?: string | null
}
export interface ModActionRawNormalized extends ModActionRaw {
createdBy?: RedditUser | Subreddit
subreddit: Subreddit
}
export interface ModLogRaw {
id: string
mod_id36: string // wtf
mod: string // name of moderator that performed the action
target_fullname: string // ThingID IE t3_wuywlr
target_author: string
details: string // flair_edit
action: ModerationActionType
description: string
target_body: string
subreddit_name_prefixed: string
subreddit: Subreddit // proxy object
created_utc: number
}
export class ModAction {
action?: string
action?: ModerationActionType
actedOn?: RedditUser | Submission | Comment | Subreddit | PrivateMessage
details?: string
description?: string
createdBy?: RedditUser | Subreddit
subreddit?: Subreddit
constructor(data: ModActionRaw | undefined, client: Snoowrap) {
const {
action,
reddit_id,
details,
description
} = data || {};
this.action = action !== null ? action : undefined;
this.details = details !== null ? details : undefined;
this.description = description !== null ? description : undefined;
constructor(data: ModActionRawNormalized | ModLogRaw | undefined, client: Snoowrap, subreddit?: Subreddit) {
if(data !== undefined) {
const {
action,
details,
description
} = data || {};
if (reddit_id !== null && reddit_id !== undefined) {
const thing = parseRedditFullname(reddit_id);
if (thing !== undefined) {
this.actedOn = generateSnoowrapEntityFromRedditThing(thing, client);
if(subreddit !== undefined) {
this.subreddit = subreddit;
}
if(asModActionRaw(data)) {
const {
reddit_id,
createdBy,
subreddit: subFromData
} = data as ModActionRawNormalized || {};
this.createdBy = createdBy;
if(this.subreddit === undefined) {
this.subreddit = subFromData;
}
if (reddit_id !== null && reddit_id !== undefined) {
const thing = parseRedditFullname(reddit_id);
if (thing !== undefined) {
this.actedOn = generateSnoowrapEntityFromRedditThing(thing, client);
}
}
} else {
const {
target_fullname,
target_author,
mod,
mod_id36,
subreddit: subFromData
} = data || {};
if (target_fullname !== null && target_fullname !== undefined) {
const thing = parseRedditFullname(target_fullname);
if (thing !== undefined) {
this.actedOn = generateSnoowrapEntityFromRedditThing(thing, client);
if (this.actedOn instanceof RedditUser) {
this.actedOn.name = target_author;
}
}
}
const author = parseRedditFullname(`t2_${mod_id36}`);
if(author !== undefined) {
this.createdBy = generateSnoowrapEntityFromRedditThing(author, client) as RedditUser;
if (this.createdBy instanceof RedditUser) {
this.createdBy.name = mod;
}
}
if(this.subreddit === undefined) {
this.subreddit = subFromData;
}
}
this.action = action !== null ? action : undefined;
this.details = details !== null ? details : undefined;
this.description = description !== null ? description : undefined;
}
}
toRaw(): ModActionRaw {
@@ -50,4 +122,8 @@ export class ModAction {
}
}
export const asModActionRaw = (data: any): data is ModActionRaw => {
return data !== null && 'reddit_id' in data;
}
export default ModAction;

View File

@@ -81,7 +81,7 @@ export class ModNote {
this.createdBy.name = data.operator;
}
this.action = new ModAction(data.mod_action_data, client);
this.action = new ModAction({...data.mod_action_data, createdBy: this.createdBy, subreddit: this.subreddit}, client);
if (this.action.actedOn instanceof RedditUser && this.action.actedOn.id === this.user.id) {
this.action.actedOn = this.user;
}

View File

@@ -57,7 +57,7 @@ import {
filterByTimeRequirement,
asSubreddit,
modActionCriteriaSummary,
parseRedditFullname, asStrongImageHashCache, matchesRelativeDateTime
parseRedditFullname, asStrongImageHashCache, matchesRelativeDateTime, generateFullWikiUrl
} from "../util";
import LoggedError from "../Utils/LoggedError";
import {
@@ -1770,7 +1770,7 @@ export class SubredditResources {
try {
// @ts-ignore
const wikiPage = sub.getWikiPage(wikiContext.wiki);
const wikiPage = sub.getWikiPage(wiki);
const wikiContent = await wikiPage.content_md;
return {val: wikiContent, fromCache: false, hash: cacheKey};
} catch (err: any) {
@@ -1786,9 +1786,9 @@ export class SubredditResources {
}
}
throw new CMError(`Wiki page ${location} ${error} (${err.statusCode})${reasons.length > 0 ? `because: ${reasons.join(' | ')}` : '.'}`, {cause: err});
throw new CMError(`Wiki page ${generateFullWikiUrl(subreddit, wiki)} ${error} (${err.statusCode})${reasons.length > 0 ? `because: ${reasons.join(' | ')}` : '.'}`, {cause: err});
} else {
throw new CMError(`Wiki page ${location} could not be read`, {cause: err});
throw new CMError(`Wiki page ${generateFullWikiUrl(subreddit, wiki)} could not be read`, {cause: err});
}
}
}