180 lines
5.9 KiB
TypeScript
180 lines
5.9 KiB
TypeScript
// Metro module 11058 (f11059).
|
|
import GuildStore from "../../stores/GuildStore";
|
|
import PermissionStore from "../../stores/PermissionStore";
|
|
import { AnalyticEvents, Endpoints, Permissions } from "../../Constants";
|
|
import { _transformMetadataToSnakeCase, _transformMetadataToCamelCase } from "./DataUtils";
|
|
import { isNotNullish } from "../../utils/GlobalUtils";
|
|
import SnowflakeUtils from "../../utils/SnowflakeUtils";
|
|
import { HTTP, rejectWithMigratedError } from "../../_bundle/sendRequest";
|
|
import { openConfirmRemoveMentionRaid } from "./GuildAutomodActionActionCreators.native";
|
|
import { trackWithMetadata } from "../app_analytics/AppAnalyticsUtils";
|
|
import { Feedback } from "./AutomodFeedback";
|
|
import Dispatcher from "../../Dispatcher";
|
|
let _transformClientRuleToApiRule, _transformApiActionToClientAction, _transformApiRuletoClientRule;
|
|
const _transformClientActionToApiAction = function _transformClientActionToApiAction(a0) {
|
|
return {
|
|
type: a0.type,
|
|
metadata: _transformMetadataToSnakeCase(a0.metadata)
|
|
};
|
|
};
|
|
_transformClientRuleToApiRule = function _transformClientRuleToApiRule(a0) {
|
|
const trigger_metadata = _transformMetadataToSnakeCase(a0.triggerMetadata);
|
|
if (trigger_metadata != null) {
|
|
delete trigger_metadata["keywordLists"];
|
|
}
|
|
const r14 = {
|
|
id: a0.id,
|
|
name: a0.name,
|
|
guild_id: a0.guildId,
|
|
event_type: a0.eventType,
|
|
trigger_type: a0.triggerType,
|
|
trigger_metadata,
|
|
actions: a0.actions.filter(isNotNullish).map(_transformClientActionToApiAction),
|
|
enabled: a0.enabled,
|
|
creator_id: a0.creatorId,
|
|
position: a0.position,
|
|
exempt_channels: null,
|
|
exempt_roles: null
|
|
};
|
|
const r32 = Array;
|
|
let exemptChannels = a0.exemptChannels;
|
|
if (exemptChannels == null) {
|
|
exemptChannels = [];
|
|
}
|
|
r14.exempt_channels = r32.from(exemptChannels);
|
|
const r36 = Array;
|
|
let exemptRoles = a0.exemptRoles;
|
|
if (exemptRoles == null) {
|
|
exemptRoles = [];
|
|
}
|
|
r14.exempt_roles = r36.from(exemptRoles);
|
|
return r14;
|
|
};
|
|
_transformApiActionToClientAction = function _transformApiActionToClientAction(a0) {
|
|
return {
|
|
type: a0.type,
|
|
metadata: _transformMetadataToCamelCase(a0.metadata)
|
|
};
|
|
};
|
|
_transformApiRuletoClientRule = function _transformApiRuletoClientRule(a0) {
|
|
let id = a0.id;
|
|
if (id == null) {
|
|
id = SnowflakeUtils.fromTimestamp(Date.now());
|
|
}
|
|
const r17 = {
|
|
id,
|
|
name: a0.name,
|
|
guildId: a0.guild_id,
|
|
eventType: a0.event_type,
|
|
triggerType: a0.trigger_type,
|
|
triggerMetadata: _transformMetadataToCamelCase(a0.trigger_metadata),
|
|
actions: a0.actions.filter(isNotNullish).map(_transformApiActionToClientAction),
|
|
enabled: a0.enabled,
|
|
creatorId: a0.creator_id,
|
|
position: a0.position,
|
|
exemptChannels: null,
|
|
exemptRoles: null
|
|
};
|
|
const r42 = Set;
|
|
let exempt_channels = a0.exempt_channels;
|
|
if (exempt_channels == null) {
|
|
exempt_channels = [];
|
|
}
|
|
r17.exemptChannels = new r42(exempt_channels);
|
|
const r47 = Set;
|
|
let exempt_roles = a0.exempt_roles;
|
|
if (exempt_roles == null) {
|
|
exempt_roles = [];
|
|
}
|
|
r17.exemptRoles = new r47(exempt_roles);
|
|
if (r17.triggerMetadata != null) {
|
|
delete r17.triggerMetadata["keywordLists"];
|
|
}
|
|
return r17;
|
|
};
|
|
export async function validateAutomodRule(c26920_0) {
|
|
let c26920_2;
|
|
c26920_2 = void 0;
|
|
const body = _transformClientRuleToApiRule(c26920_0);
|
|
let c30338_0 = await HTTP.post({
|
|
url: Endpoints.GUILD_AUTOMOD_VALIDATE_RULE(c26920_0.guildId),
|
|
body,
|
|
rejectWithError: rejectWithMigratedError()
|
|
});
|
|
return _transformMetadataToCamelCase(c30338_0.body);
|
|
}
|
|
export async function createAutomodRule(c26921_0) {
|
|
const body = _transformClientRuleToApiRule(c26921_0);
|
|
delete body["id"];
|
|
const _transformApiRuletoClientRule2 = _transformApiRuletoClientRule;
|
|
return _transformApiRuletoClientRule2((await HTTP.post({
|
|
url: Endpoints.GUILD_AUTOMOD_RULES(c26921_0.guildId),
|
|
body,
|
|
rejectWithError: rejectWithMigratedError()
|
|
})).body);
|
|
}
|
|
export async function updateAutomodRule(c26922_0) {
|
|
const body = _transformClientRuleToApiRule(c26922_0);
|
|
const _transformApiRuletoClientRule3 = _transformApiRuletoClientRule;
|
|
return _transformApiRuletoClientRule3((await HTTP.patch({
|
|
url: Endpoints.GUILD_AUTOMOD_RULE(c26922_0.guildId, c26922_0.id),
|
|
body,
|
|
rejectWithError: rejectWithMigratedError()
|
|
})).body);
|
|
}
|
|
export async function deleteAutomodRule(c26923_0, c26923_1) {
|
|
await HTTP.del({
|
|
url: Endpoints.GUILD_AUTOMOD_RULE(c26923_1, c26923_0),
|
|
rejectWithError: rejectWithMigratedError()
|
|
});
|
|
return true;
|
|
}
|
|
export async function fetchAutomodRules(c26924_0) {
|
|
let c26924_2;
|
|
c26924_2 = void 0;
|
|
let c30339_0 = await HTTP.get({
|
|
url: Endpoints.GUILD_AUTOMOD_RULES(c26924_0),
|
|
rejectWithError: rejectWithMigratedError()
|
|
});
|
|
return Array.isArray(c30339_0.body) ? c30339_0.body.map(_transformApiRuletoClientRule) : [];
|
|
}
|
|
export async function executeAlertAction(message_id, c26925_1, alert_action_type) {
|
|
L11: {
|
|
if (PermissionStore.can(Permissions.MANAGE_MESSAGES, c26925_1)) {
|
|
await HTTP.post({
|
|
url: Endpoints.GUILD_AUTOMOD_ALERT_ACTION(c26925_1.guild_id),
|
|
body: {
|
|
message_id,
|
|
channel_id: c26925_1.id,
|
|
alert_action_type
|
|
},
|
|
rejectWithError: rejectWithMigratedError()
|
|
});
|
|
break L11;
|
|
}
|
|
return void 0;
|
|
}
|
|
}
|
|
export function removeMentionRaidRestrictionWithFeedback(a0, decision_id, c18504_2) {
|
|
const guild = GuildStore.getGuild(a0);
|
|
if (guild != null && PermissionStore.can(Permissions.MANAGE_GUILD, guild)) {
|
|
openConfirmRemoveMentionRaid(function() {
|
|
trackWithMetadata(AnalyticEvents.GUILD_AUTOMOD_FEEDBACK, {
|
|
feedback_type: Feedback.MENTION_RAID_REMOVE_RESTRICTION,
|
|
decision_id
|
|
});
|
|
HTTP.post({
|
|
url: Endpoints.GUILD_AUTOMOD_CLEAR_MENTION_RAID(a0),
|
|
rejectWithError: true
|
|
});
|
|
c18504_2();
|
|
});
|
|
}
|
|
}
|
|
export function clearMentionRaidDetected(a0) {
|
|
Dispatcher.dispatch({
|
|
type: "AUTO_MODERATION_MENTION_RAID_NOTICE_DISMISS",
|
|
guildId: a0
|
|
});
|
|
}
|