import { TextChannel } from 'discord.js' ; import Constants from '../../common/constants' ; import { Plugin } from '../../common/plugin' ; import { ChannelType , IContainer , IMessage , Maybe , RoleType } from '../../common/types' ; import { Moderation } from '../../services/moderation.service' ; export default class ModReportPlugin extends Plugin { public commandName : string = 'modreport' ; public name : string = 'Mod Report Plugin' ; public description : string = '`Add`: Adds a report to a user.\n' + '`List:` Gets a small summary of a user.\n' + "`Full:` Gets a downloadable, full report on all of a user's offences." ; public usage : string = 'modreport add  <tag | id> <reason> <screenshot>\n' + 'modreport warn <tag | id> <reason> <screenshot>\n' + 'modreport list <tag | id>\n' + 'modreport full <tag | id>' ; public override pluginAlias = [ ] ; public permission : ChannelType = ChannelType . Staff ; public override pluginChannelName : string = Constants . Channels . Staff . ModCommands ; public override minRoleToRun : RoleType = RoleType . Moderator ; public override commandPattern : RegExp = /(add|list|warn|ban|full)\s+(([^#]+#\d{4})|\d{17,18})\s*(.*)/ ; constructor ( public container ) { super ( ) ; } public async execute ( message , args ) { const parsed = this . parseArgs ( args ) ; if ( ! parsed ) { await message . reply ( 'Invalid syntax' ) ; return ; } const { subCommand , givenHandle , description } = parsed ; try { if ( subCommand === 'add' ) { await this . _handleAddReport ( message , givenHandle , description ) ; } else if ( subCommand === 'warn' ) { await this . _handleIssueWarning ( message , givenHandle , description ) ; } else if ( subCommand === 'ban' ) { await this . _handleIssueBan ( message , givenHandle , description ) ; } else if ( subCommand === 'list' ) { await this . _handleListReport ( message , givenHandle ) ; return ; } else if ( subCommand === 'full' ) { await this . _handleFullList ( message , givenHandle ) ; return ; } await this . _handleListReport ( message , givenHandle ) ; } catch ( e ) { await message . reply ( 'Something went wrong. Did you put the username correctly?' ) ; this . container . loggerService . error ( e ) ; } } public parseArgs ( args ) { const match_arr = args . join ( ' ' ) . match ( this . commandPattern ) ; if ( ! match_arr ) { return null ; } const [ subCommand , userHandle , id , description ] = match_arr . slice ( 1 ) ; const givenHandle = userHandle ?? id ; return { subCommand , givenHandle , description } ; } private async _createReport ( message , user_handle , description ? ) { const id = await Moderation . Helpers . resolveUser ( this . container . guildService . get ( ) , user_handle ) ; if ( ! id ) { return ; } const rep = new Moderation . Report ( this . container . guildService . get ( ) , id , description , message . attachments . map ( ( e ) => e . url ) ) ; return rep ; } private async _handleAddReport ( message , user_handle , description ? ) { const rep = await this . _createReport ( message , user_handle , description ) ; if ( ! rep ) { await message . reply ( 'Error creating report' ) ; return ; } message . reply ( await this . container . modService . fileReport ( rep ) ) ; } private async _handleListReport ( message , user_handle ) { this . container . messageService . sendStringOrEmbed ( message . channel as TextChannel , await this . container . modService . getModerationSummary ( this . container . guildService . get ( ) , user_handle ) ) ; } private async _handleFullList ( message , user_handle ) { try { await message . reply ( { content : `Full Report for ${ user_handle }` , files : [ await this . container . modService . getFullReport ( this . container . guildService . get ( ) , user_handle ) , ] , } ) ; } catch ( e ) { await message . reply ( `Error getting report: ${ e }` ) ; } } private async _handleIssueWarning ( message , user_handle , description ? ) { const rep = await this . _createReport ( message , user_handle , description ) ; if ( ! rep ) { await message . reply ( 'Error creating report' ) ; return ; } message . reply ( await this . container . modService . fileWarning ( rep ) ) ; } private async _handleIssueBan ( message , user_handle , description ? ) { const rep = await this . _createReport ( message , user_handle , description ) ; if ( ! rep ) { await message . reply ( 'Error creating report' ) ; return ; } message . reply ( await this . container . modService . fileBan ( rep , true ) ) ; } }