import { Message , RichEmbed , Guild , GuildMember } from 'discord.js' ; import { commandInterface } from '../../commands' ; import { permLevels , getPermLevel } from '../../utils/permissions' ; import { Bot } from '../..' ; import { sendError } from '../../utils/messages' ; import { permToString , stringToMember , stringToRole } from '../../utils/parsers' ; import { getDayDiff , timeFormat } from '../../utils/time' ; import dateFormat = require ( 'dateformat' ) ; var command = { name : 'roleinfo' , path : '' , dm : false , permLevel : permLevels . member , togglable : false , help : { shortDescription : 'Gives a description of a role' , longDescription : 'Gives a description of a role' , usages : [ '{command} [role]' ] , examples : [ '{command} admin' ] } , run : async ( message , args , permLevel , dm , requestTime ) => { try { if ( args . length === 0 ) { message . channel . send ( await Bot . commands . getHelpEmbed ( command , message . guild ) ) ; Bot . mStats . logMessageSend ( ) ; return false ; } var infoRole = stringToRole ( message . guild , args ) ; if ( ! infoRole || infoRole == '@here' || infoRole == '@everyone' ) { message . channel . send ( `${ args . replace ( '@' , ' ' ) } is not a valid role!` ) ; Bot . mStats . logMessageSend ( ) ; return false ; } let roleEmbed = createRoleEmbed ( infoRole , message . guild ) ; Bot . mStats . logResponseTime ( command . name , requestTime ) ; message . channel . send ( roleEmbed ) ; Bot . mStats . logMessageSend ( ) ; Bot . mStats . logCommandUsage ( command . name ) ; return true ; } catch ( e ) { sendError ( message . channel , e ) ; Bot . mStats . logError ( e , command . name ) ; return false ; } } } ; param { * } infoRole param { * } guild returns function createRoleEmbed ( infoRole , guild ) { let date = new Date ( ) ; guild . fetchMembers ( ) ; return { "embed" : { "author" : { "name" : `Description of ${ infoRole . name }` } , "footer" : { "text" : `ID: ${ infoRole . id }` } , "color" : infoRole . color , "timestamp" : date . toISOString ( ) , "fields" : [ { "name" : "Created" , "value" : `${ dateFormat ( infoRole . createdAt , timeFormat ) } \n (${ getDayDiff ( infoRole . createdAt , date . getTime ( ) ) } days ago)` , "inline" : true } , { "name" : "Color" , "value" : `${ infoRole . color } ([${ infoRole . hexColor }](https://www.color-hex.com/color/${ infoRole . hexColor . slice ( 1 ) }))` , "inline" : true } , { "name" : 'Hoisted' , "value" : infoRole . hoist , "inline" : true } , { "name" : "Mentionable" , "value" : infoRole . mentionable , "inline" : true } , { "name" : "Members" , "value" : infoRole . members . size , "inline" : true } , { "name" : "Position" , "value" : infoRole . calculatedPosition , "inline" : true } , { "name" : "Permissions" , "value" : infoRole . permissions , "inline" : true } , ] } } ; } export default command ;