mirror of
https://github.com/FoxxMD/context-mod.git
synced 2026-01-14 16:08:02 -05:00
Compare commits
1 Commits
banCriteri
...
modlog
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
381976d6af |
@@ -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'];
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user