2020-04-30 22:34:54 +02:00
const { Command } = require ( 'discord-akairo' ) ;
const LogStats = require ( '../../models' ) . LogStats ;
class logCommand extends Command {
constructor ( ) {
super ( 'log' , {
aliases : [ 'log' , 'logging' ] ,
category : 'admin' ,
userPermissions : [ 'MANAGE_MESSAGES' ] ,
2020-06-22 19:50:59 +02:00
clientPermissions : [ 'MANAGE_GUILD' ] ,
2020-04-30 22:34:54 +02:00
channel : 'guild' ,
description : {
content : 'Setup logging in current channel (W.I.P)' ,
usage : '' ,
examples : [ '' ]
}
} ) ;
}
async exec ( message , args ) {
const logStats = await LogStats . findOne ( { where : { guild : message . guild . id } } ) ;
const ownerID = this . client . ownerID ;
if ( ! logStats ) {
const body = { guild : message . guild . id , channel : message . channel . id } ;
await LogStats . create ( body ) ;
return message . channel . send ( 'Logging has been enabled on this channel' ) ;
} else if ( logStats . get ( 'ownerID' ) == message . author . id || message . member . hasPermission ( 'ADMINISTRATOR' ) || message . author . id == ownerID ) {
message . channel . send ( 'The log channel is already setup, do you want to delete it? y/n' ) ;
const filter = m => m . content && m . author . id == message . author . id ;
message . channel . awaitMessages ( filter , { time : 5000 , max : 1 , errors : [ 'time' ] } )
. then ( async messages => {
let messageContent = messages . map ( messages => messages . content . toLowerCase ( ) ) ;
2020-05-08 01:26:09 +02:00
if ( messageContent [ 0 ] === 'y' || messageContent [ 0 ] === 'yes' ) {
2020-04-30 22:34:54 +02:00
await LogStats . destroy ( { where : { guild : message . guild . id } } ) ;
return message . channel . send ( 'Log channel has been disabled!' ) ;
} else {
return message . channel . send ( 'Not updating.' ) ;
}
} )
. catch ( err => {
console . error ( err ) ;
return message . channel . send ( 'Took too long to answer. didin\'t change anything.' ) ;
} ) ;
} else {
return message . channel . send ( ` You are not the owner of this tag, if you think it is problematic ask an admin to remove it by doing ${ this . client . commandHandler . prefix [ 0 ] } tag ${ args . trigger } --remove ` ) ;
}
}
}
module . exports = logCommand ;