2021-08-15 22:14:04 +02:00
import { GuildMember , Message , Snowflake } from "discord.js" ;
2021-06-06 23:51:32 +02:00
import { EventEmitter } from "events" ;
import { GuildCases } from "../../data/GuildCases" ;
import { GuildLogs } from "../../data/GuildLogs" ;
import { GuildMutes } from "../../data/GuildMutes" ;
import { GuildTempbans } from "../../data/GuildTempbans" ;
import { mapToPublicFn } from "../../pluginUtils" ;
import { Queue } from "../../Queue" ;
import { MINUTES , trimPluginDescription } from "../../utils" ;
2020-07-23 00:37:33 +03:00
import { CasesPlugin } from "../Cases/CasesPlugin" ;
import { MutesPlugin } from "../Mutes/MutesPlugin" ;
2021-06-06 23:51:32 +02:00
import { TimeAndDatePlugin } from "../TimeAndDate/TimeAndDatePlugin" ;
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint" ;
2020-07-24 02:25:33 +02:00
import { AddCaseCmd } from "./commands/AddCaseCmd" ;
2021-06-06 23:51:32 +02:00
import { BanCmd } from "./commands/BanCmd" ;
2020-07-24 02:25:33 +02:00
import { CaseCmd } from "./commands/CaseCmd" ;
import { CasesModCmd } from "./commands/CasesModCmd" ;
2021-06-06 23:51:32 +02:00
import { CasesUserCmd } from "./commands/CasesUserCmd" ;
import { DeleteCaseCmd } from "./commands/DeleteCaseCmd" ;
import { ForcebanCmd } from "./commands/ForcebanCmd" ;
import { ForcemuteCmd } from "./commands/ForcemuteCmd" ;
import { ForceUnmuteCmd } from "./commands/ForceunmuteCmd" ;
2020-07-24 02:25:33 +02:00
import { HideCaseCmd } from "./commands/HideCaseCmd" ;
2021-06-06 23:51:32 +02:00
import { KickCmd } from "./commands/KickCmd" ;
import { MassbanCmd } from "./commands/MassBanCmd" ;
import { MassmuteCmd } from "./commands/MassmuteCmd" ;
import { MassunbanCmd } from "./commands/MassUnbanCmd" ;
import { MuteCmd } from "./commands/MuteCmd" ;
import { NoteCmd } from "./commands/NoteCmd" ;
import { SoftbanCmd } from "./commands/SoftbanCommand" ;
import { UnbanCmd } from "./commands/UnbanCmd" ;
2020-07-24 02:25:33 +02:00
import { UnhideCaseCmd } from "./commands/UnhideCaseCmd" ;
2021-06-06 23:51:32 +02:00
import { UnmuteCmd } from "./commands/UnmuteCmd" ;
import { UpdateCmd } from "./commands/UpdateCmd" ;
import { WarnCmd } from "./commands/WarnCmd" ;
import { CreateBanCaseOnManualBanEvt } from "./events/CreateBanCaseOnManualBanEvt" ;
import { CreateKickCaseOnManualKickEvt } from "./events/CreateKickCaseOnManualKickEvt" ;
import { CreateUnbanCaseOnManualUnbanEvt } from "./events/CreateUnbanCaseOnManualUnbanEvt" ;
import { PostAlertOnMemberJoinEvt } from "./events/PostAlertOnMemberJoinEvt" ;
2020-07-28 21:34:01 +03:00
import { banUserId } from "./functions/banUserId" ;
2021-08-15 01:44:25 +02:00
import { hasMutePermission } from "./functions/hasMutePerm" ;
2021-06-06 23:51:32 +02:00
import { kickMember } from "./functions/kickMember" ;
2021-02-14 16:58:02 +02:00
import { offModActionsEvent } from "./functions/offModActionsEvent" ;
2021-06-06 23:51:32 +02:00
import { onModActionsEvent } from "./functions/onModActionsEvent" ;
import { outdatedTempbansLoop } from "./functions/outdatedTempbansLoop" ;
2021-04-28 21:15:16 +02:00
import { updateCase } from "./functions/updateCase" ;
2021-06-06 23:51:32 +02:00
import { warnMember } from "./functions/warnMember" ;
import { BanOptions , ConfigSchema , KickOptions , ModActionsPluginType , WarnOptions } from "./types" ;
2020-07-23 00:37:33 +03:00
const defaultOptions = {
config : {
dm_on_warn : true ,
dm_on_kick : false ,
dm_on_ban : false ,
message_on_warn : false ,
message_on_kick : false ,
message_on_ban : false ,
message_channel : null ,
warn_message : "You have received a warning on the {guildName} server: {reason}" ,
kick_message : "You have been kicked from the {guildName} server. Reason given: {reason}" ,
ban_message : "You have been banned from the {guildName} server. Reason given: {reason}" ,
2021-01-28 00:20:55 +01:00
tempban_message : "You have been banned from the {guildName} server for {banTime}. Reason given: {reason}" ,
2020-07-23 00:37:33 +03:00
alert_on_rejoin : false ,
alert_channel : null ,
warn_notify_enabled : false ,
warn_notify_threshold : 5 ,
warn_notify_message :
"The user already has **{priorWarnings}** warnings!\n Please check their prior cases and assess whether or not to warn anyways.\n Proceed with the warning?" ,
ban_delete_message_days : 1 ,
can_note : false ,
can_warn : false ,
can_mute : false ,
can_kick : false ,
can_ban : false ,
2021-05-06 19:13:06 +01:00
can_unban : false ,
2020-07-23 00:37:33 +03:00
can_view : false ,
can_addcase : false ,
2021-01-28 00:23:35 +01:00
can_massunban : false ,
2020-07-23 00:37:33 +03:00
can_massban : false ,
2020-07-29 02:32:01 +02:00
can_massmute : false ,
2020-07-23 00:37:33 +03:00
can_hidecase : false ,
2020-08-09 22:44:07 +03:00
can_deletecase : false ,
2020-07-23 00:37:33 +03:00
can_act_as_other : false ,
2020-12-23 04:44:43 +02:00
create_cases_for_manual_actions : true ,
2020-07-23 00:37:33 +03:00
} ,
overrides : [
{
level : ">=50" ,
config : {
can_note : true ,
can_warn : true ,
can_mute : true ,
can_kick : true ,
can_ban : true ,
2021-05-06 19:13:06 +01:00
can_unban : true ,
2020-07-23 00:37:33 +03:00
can_view : true ,
can_addcase : true ,
} ,
} ,
{
level : ">=100" ,
config : {
2021-01-28 00:23:35 +01:00
can_massunban : true ,
2020-07-23 00:37:33 +03:00
can_massban : true ,
2020-07-29 02:32:01 +02:00
can_massmute : true ,
2020-07-23 00:37:33 +03:00
can_hidecase : true ,
can_act_as_other : true ,
} ,
} ,
] ,
} ;
2021-05-23 14:35:16 +03:00
export const ModActionsPlugin = zeppelinGuildPlugin < ModActionsPluginType > ( ) ( {
name : "mod_actions" ,
2020-07-30 13:08:06 +03:00
showInDocs : true ,
info : {
prettyName : "Mod actions" ,
description : trimPluginDescription ( `
This plugin contains the 'typical' mod actions such as warning , muting , kicking , banning , etc .
` ),
} ,
2020-08-19 00:19:12 +03:00
dependencies : [ TimeAndDatePlugin , CasesPlugin , MutesPlugin ] ,
2020-07-23 00:37:33 +03:00
configSchema : ConfigSchema ,
defaultOptions ,
2020-07-24 02:25:33 +02:00
events : [
CreateBanCaseOnManualBanEvt ,
CreateUnbanCaseOnManualUnbanEvt ,
CreateKickCaseOnManualKickEvt ,
PostAlertOnMemberJoinEvt ,
] ,
commands : [
UpdateCmd ,
NoteCmd ,
WarnCmd ,
MuteCmd ,
ForcemuteCmd ,
UnmuteCmd ,
ForceUnmuteCmd ,
KickCmd ,
SoftbanCmd ,
BanCmd ,
UnbanCmd ,
ForcebanCmd ,
MassbanCmd ,
2020-07-29 02:32:01 +02:00
MassmuteCmd ,
2021-01-28 00:23:35 +01:00
MassunbanCmd ,
2020-07-24 02:25:33 +02:00
AddCaseCmd ,
CaseCmd ,
CasesUserCmd ,
CasesModCmd ,
HideCaseCmd ,
UnhideCaseCmd ,
2020-08-09 22:44:07 +03:00
DeleteCaseCmd ,
2020-07-24 02:25:33 +02:00
] ,
2020-07-23 00:37:33 +03:00
2020-07-28 21:34:01 +03:00
public : {
warnMember ( pluginData ) {
2021-06-02 04:07:50 +02:00
return ( member : GuildMember , reason : string , warnOptions? : WarnOptions ) = > {
2020-07-28 21:34:01 +03:00
warnMember ( pluginData , member , reason , warnOptions ) ;
} ;
} ,
kickMember ( pluginData ) {
2021-06-02 04:07:50 +02:00
return ( member : GuildMember , reason : string , kickOptions? : KickOptions ) = > {
2020-07-28 21:34:01 +03:00
kickMember ( pluginData , member , reason , kickOptions ) ;
} ;
} ,
banUserId ( pluginData ) {
2021-04-28 21:42:54 +02:00
return ( userId : string , reason? : string , banOptions? : BanOptions , banTime? : number ) = > {
banUserId ( pluginData , userId , reason , banOptions , banTime ) ;
2020-07-28 21:34:01 +03:00
} ;
} ,
2021-02-14 16:58:02 +02:00
2021-04-28 21:15:16 +02:00
updateCase ( pluginData ) {
return ( msg : Message , caseNumber : number | null , note : string ) = > {
updateCase ( pluginData , msg , { caseNumber , note } ) ;
} ;
} ,
2021-08-15 01:44:25 +02:00
hasMutePermission ( pluginData ) {
2021-08-15 22:02:18 +02:00
return ( member : GuildMember , channelId : Snowflake ) = > {
2021-08-15 01:44:25 +02:00
return hasMutePermission ( pluginData , member , channelId ) ;
} ;
} ,
2021-04-28 21:15:16 +02:00
2021-02-14 16:58:02 +02:00
on : mapToPublicFn ( onModActionsEvent ) ,
off : mapToPublicFn ( offModActionsEvent ) ,
getEventEmitter ( pluginData ) {
return ( ) = > pluginData . state . events ;
} ,
2020-07-28 21:34:01 +03:00
} ,
2021-05-23 17:13:11 +03:00
beforeLoad ( pluginData ) {
2020-07-24 02:25:33 +02:00
const { state , guild } = pluginData ;
state . mutes = GuildMutes . getGuildInstance ( guild . id ) ;
state . cases = GuildCases . getGuildInstance ( guild . id ) ;
2021-01-28 00:20:55 +01:00
state . tempbans = GuildTempbans . getGuildInstance ( guild . id ) ;
2020-07-24 02:25:33 +02:00
state . serverLogs = new GuildLogs ( guild . id ) ;
2021-01-28 00:20:55 +01:00
state . unloaded = false ;
state . outdatedTempbansTimeout = null ;
2020-07-24 02:25:33 +02:00
state . ignoredEvents = [ ] ;
2021-05-22 13:47:10 +03:00
// Massbans can take a while depending on rate limits,
// so we're giving each massban 15 minutes to complete before launching the next massban
state . massbanQueue = new Queue ( 15 * MINUTES ) ;
2021-01-28 00:20:55 +01:00
2021-02-14 16:58:02 +02:00
state . events = new EventEmitter ( ) ;
2021-05-23 17:13:11 +03:00
} ,
2021-02-14 16:58:02 +02:00
2021-05-23 17:13:11 +03:00
afterLoad ( pluginData ) {
2021-01-28 00:20:55 +01:00
outdatedTempbansLoop ( pluginData ) ;
} ,
2021-05-23 14:35:16 +03:00
beforeUnload ( pluginData ) {
2021-01-28 00:20:55 +01:00
pluginData . state . unloaded = true ;
2021-02-14 16:58:02 +02:00
pluginData . state . events . removeAllListeners ( ) ;
2020-07-24 02:25:33 +02:00
} ,
2020-07-23 00:37:33 +03:00
} ) ;