@ -4,6 +4,7 @@ const AR = require('../../models/ar');
const GuildData = require ( '../../models/guild' ) ;
const GuildData = require ( '../../models/guild' ) ;
const ask = require ( '../../util/ask' ) ;
const ask = require ( '../../util/ask' ) ;
const { Pagination } = require ( '../../util/pagination' ) ;
module . exports = {
module . exports = {
name : "ar" ,
name : "ar" ,
@ -27,19 +28,57 @@ module.exports = {
function sortARs ( tar ) {
function sortARs ( tar ) {
let t = tar . triggers ;
let t = tar . triggers ;
let res = { } ;
res . paginate = t . length > 10 ;
let ar = tar . ars ;
let ar = tar . ars ;
if ( res . paginate ) {
let pages = [ ] ;
let cond = false ;
let x = 0 ;
while ( true ) {
let s = '' ;
for ( let i = 0 ; i < 10 ; i ++ ) {
if ( ar [ ( x * 10 ) + i ] === undefined ) { cond = true ; break ; }
s += ` \` ${ ( x * 10 ) + i + 1 } . \` ${ t [ ( x * 10 ) + i ] } \n -> ${ ar [ ( x * 10 ) + i ] } \n \n ` ;
if ( ( x * 10 ) + i >= ar . length ) { cond = true ; break ; }
}
pages . push ( new Discord . MessageEmbed ( )
. setTitle ( ` Auto-Responses in this Server ` )
. setDescription ( s )
. setColor ( 'c375f0' )
. setTimestamp ( )
) ;
if ( cond ) { break ; }
x ++ ;
}
res . pagination = new Pagination ( message . channel , pages , message , client , true ) ;
} else {
let s = '' ;
let s = '' ;
for ( let i = 0 ; i < t . length ; i ++ ) { s += ` \` ${ i + 1 } . \` ${ t [ i ] } \n -> ${ ar [ i ] } \n \n ` ; }
for ( let i = 0 ; i < t . length ; i ++ ) { s += ` \` ${ i + 1 } . \` ${ t [ i ] } \n -> ${ ar [ i ] } \n \n ` ; }
return s ;
res . s = s ;
}
return res ;
}
}
function viewARs ( string ) {
function viewARs ( res , mode ) {
return new Discord . MessageEmbed ( )
return new Promise ( async resolve => {
if ( res . paginate ) {
if ( mode ) { res . pagination . pages . forEach ( page => page . addField ( mode === 'edit' ? "Editing" : 'Deletion' , ` Please say the **number** of the AR you wish to ${ mode } . ` ) ) ; }
let r = await res . pagination . start ( { endTime : 60000 , user : message . author . id } ) ;
return resolve ( r ) ;
} else {
let string = res . s ;
let embed = new Discord . MessageEmbed ( )
. setTitle ( "Auto-Responses in this Server" )
. setTitle ( "Auto-Responses in this Server" )
. setDescription ( string )
. setDescription ( string )
. setColor ( 'c375f0' )
. setColor ( 'c375f0' )
. setFooter ( "Natsuki" , client . user . avatarURL ( ) )
. setFooter ( "Natsuki" , client . user . avatarURL ( ) )
. setTimestamp ( ) ;
. setTimestamp ( ) ;
if ( mode ) { embed . addField ( mode === 'edit' ? "Editing" : 'Deletion' , ` Please say the **number** of the AR you wish to ${ mode } . ` ) ; }
let r = await message . channel . send ( { embeds : [ embed ] } ) ;
return resolve ( r ) ;
}
} ) ;
}
}
if ( [ 'a' , 'add' ] . includes ( args [ 0 ] . toLowerCase ( ) ) ) {
if ( [ 'a' , 'add' ] . includes ( args [ 0 ] . toLowerCase ( ) ) ) {
@ -64,7 +103,7 @@ module.exports = {
if ( ! tar || ! tar . triggers . length ) { return message . channel . send ( "You can't edit any auto-responses... because there aren't any here..." ) ; }
if ( ! tar || ! tar . triggers . length ) { return message . channel . send ( "You can't edit any auto-responses... because there aren't any here..." ) ; }
let sar = sortARs ( tar ) ;
let sar = sortARs ( tar ) ;
await message . channel . send ( { embeds : [ viewARs ( sar ) . addField ( "Editing" , "Please say the **number** of the AR you wish to edit." ) ] } ) ;
await viewARs ( sar , 'edit' ) ;
let collected ;
let collected ;
try { collected = await message . channel . awaitMessages ( { filter : m => m . author . id === message . author . id , errors : [ 'time' ] , time : 60001 , max : 1 } ) ; }
try { collected = await message . channel . awaitMessages ( { filter : m => m . author . id === message . author . id , errors : [ 'time' ] , time : 60001 , max : 1 } ) ; }
catch { return message . channel . send ( "This question has timed out. Please try again!" ) ; }
catch { return message . channel . send ( "This question has timed out. Please try again!" ) ; }
@ -89,7 +128,7 @@ module.exports = {
if ( ! tar || ! tar . triggers . length ) { return message . channel . send ( "It's not like this server has any ARs for me to delete in the first place!" ) ; }
if ( ! tar || ! tar . triggers . length ) { return message . channel . send ( "It's not like this server has any ARs for me to delete in the first place!" ) ; }
let sar = sortARs ( tar ) ;
let sar = sortARs ( tar ) ;
await message . channel . send ( { embeds : [ viewARs ( sar ) . addField ( "Deletion" , "Please say the **number** of the AR you wish to delete." ) ] } ) ;
await viewARs ( sar , 'delete' ) ;
let collected ;
let collected ;
try { collected = await message . channel . awaitMessages ( { filter : m => m . author . id === message . author . id , errors : [ 'time' ] , time : 60000 , max : 1 } ) ; }
try { collected = await message . channel . awaitMessages ( { filter : m => m . author . id === message . author . id , errors : [ 'time' ] , time : 60000 , max : 1 } ) ; }
catch { return message . channel . send ( "This question has timed out. Please try again!" ) ; }
catch { return message . channel . send ( "This question has timed out. Please try again!" ) ; }
@ -113,7 +152,7 @@ module.exports = {
if ( [ 'v' , 'view' , 'l' , 'list' ] . includes ( args [ 0 ] . toLowerCase ( ) ) ) {
if ( [ 'v' , 'view' , 'l' , 'list' ] . includes ( args [ 0 ] . toLowerCase ( ) ) ) {
let tar = await AR . findOne ( { gid : message . guild . id } ) ;
let tar = await AR . findOne ( { gid : message . guild . id } ) ;
if ( ! tar || ! tar . triggers . length ) { return message . channel . send ( "This server has no ARs!" ) ; }
if ( ! tar || ! tar . triggers . length ) { return message . channel . send ( "This server has no ARs!" ) ; }
return message . channel . send ( { embeds : [ viewARs ( sortARs ( tar ) ) ] } ) ;
return viewARs ( sortARs ( tar ) ) ;
}
}
if ( [ 's' , 'settings' ] . includes ( args [ 0 ] . toLowerCase ( ) ) ) {
if ( [ 's' , 'settings' ] . includes ( args [ 0 ] . toLowerCase ( ) ) ) {