Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions src/Common/Infrastructure/Atomic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
110 changes: 93 additions & 17 deletions src/Subreddit/ModNotes/ModAction.ts
Original file line number Diff line number Diff line change
@@ -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;

if (reddit_id !== null && reddit_id !== undefined) {
const thing = parseRedditFullname(reddit_id);
if (thing !== undefined) {
this.actedOn = generateSnoowrapEntityFromRedditThing(thing, client);
constructor(data: ModActionRawNormalized | ModLogRaw | undefined, client: Snoowrap, subreddit?: Subreddit) {
if(data !== undefined) {
const {
action,
details,
description
} = data || {};

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 {
Expand All @@ -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;
2 changes: 1 addition & 1 deletion src/Subreddit/ModNotes/ModNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down