2021-08-06 17:11:27 -04:00
import { Message } from 'discord.js' ;
2021-09-13 12:47:54 -04:00
import { Converter } from 'showdown' ;
2020-06-29 02:50:26 -04:00
import { Client , Command } from '../class' ;
2020-03-30 07:22:32 -04:00
export default class Warn extends Command {
constructor ( client : Client ) {
super ( client ) ;
this . name = 'warn' ;
this . description = 'Sends an official warning to user.' ;
2020-11-09 23:56:56 -05:00
this . usage = ` ${ this . client . config . prefix } warn [username | user ID] [reason] ` ;
2020-04-20 16:18:19 -04:00
this . permissions = { roles : [ '662163685439045632' , '701454780828221450' ] } ;
2020-03-30 07:22:32 -04:00
this . enabled = true ;
}
public async run ( message : Message , args : string [ ] ) {
try {
2020-11-09 23:56:56 -05:00
if ( ! args . length || ! args [ 1 ] ) return this . client . commands . get ( 'help' ) . run ( message , [ this . name ] ) ;
2020-06-29 02:35:14 -04:00
const edit = await this . loading ( message . channel , 'Processing warning...' ) ;
2021-08-08 22:41:32 -04:00
const account = await this . client . db . Account . findOne ( { $or : [ { username : args [ 0 ] } , { userID : args [ 0 ] . replace ( /[<@!>]/gi , '' ) } ] } ) ;
2020-03-30 07:22:32 -04:00
if ( ! account ) return edit . edit ( ` *** ${ this . client . stores . emojis . error } Cannot find user.*** ` ) ;
if ( account . root ) return edit . edit ( ` *** ${ this . client . stores . emojis . error } Permission denied.*** ` ) ;
2021-08-08 22:41:32 -04:00
await this . client . util . createModerationLog ( account . userID , message . author , 1 , args . slice ( 1 ) . join ( ' ' ) ) ;
2020-03-30 07:22:32 -04:00
message . delete ( ) ;
2020-05-01 02:51:02 -04:00
edit . edit ( ` *** ${ this . client . stores . emojis . success } Account ${ account . username } has been warned by Technician ${ message . author . username } # ${ message . author . discriminator } .*** ` ) ;
2020-05-22 22:19:38 -04:00
await this . client . util . sendMessageToUserTerminal ( account . username , ` WARNING FROM TECHNICIAN: ${ args . slice ( 1 ) . join ( ' ' ) } ` ) . catch ( ( ) = > { } ) ;
2020-03-30 07:22:32 -04:00
return this . client . util . transport . sendMail ( {
to : account.emailAddress ,
from : 'Library of Code sp-us | Cloud Services <help@libraryofcode.org>' ,
2020-08-28 02:35:39 -04:00
replyTo : 'cloud-help@libraryofcode.org' ,
2020-03-30 07:22:32 -04:00
subject : 'Your account has been warned' ,
html : `
< h1 > Library of Code sp - us | Cloud Services < / h1 >
< p > Your account has received an official warning from a Moderator . Please get the underlying issue resolved to avoid < i > possible < / i > moderative action . < / p >
2021-09-13 12:47:54 -04:00
< p > < strong > Reason : < / strong > $ { args . slice ( 1 ) . length ? new Converter ( ) . makeHtml ( args . slice ( 1 ) . join ( ' ' ) ) : 'Not Specified' } < / p >
2020-05-01 02:51:02 -04:00
< p > < strong > Technician : < / strong > $ { message . author . username } < / p >
2020-03-30 07:22:32 -04:00
< b > < i > Library of Code sp - us | Support Team < / i > < / b >
` ,
} ) ;
} catch ( error ) {
return this . client . util . handleError ( error , message , this ) ;
}
}
}