@@ -36,6 +36,16 @@ const app = {
3636 }
3737 } ,
3838
39+ types : {
40+ channels : {
41+ GUILD_TEXT : "Text Channel" ,
42+ GUILD_VOICE : "Voice Channel" ,
43+ GUILD_CATEGORY : "Category" ,
44+ GUILD_NEWS : "News Channel" ,
45+ GUILD_STAGE_VOICE : "Stage Channel"
46+ }
47+ } ,
48+
3949 functions : {
4050 sleep : function ( ms ) {
4151 return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
@@ -123,6 +133,24 @@ const app = {
123133 app . logger . warn ( "DB" , `Server data for ${ id } removed from database!` ) ;
124134
125135 return serverSetting ;
136+ } ,
137+
138+ createVerification : async function ( serverID , userID , messageID , codeGenerated ) {
139+ const verificationSetting = await app . DBs . verification . create ( {
140+ serverID : serverID ,
141+ userID : userID ,
142+ messageID : messageID ,
143+ userCode : codeGenerated
144+ } ) ;
145+ app . logger . success ( "DB" , `Verification started for ${ userID } in ${ serverID } with code ${ codeGenerated } !` ) ;
146+
147+ return verificationSetting ;
148+ } ,
149+ deleteVerification : async function ( serverID , userID ) {
150+ const verificationSetting = await app . DBs . verification . destroy ( { where : { userID : userID , serverID : serverID } } ) ;
151+ app . logger . warn ( "DB" , `Verification data for ${ userID } in ${ serverID } removed from database!` ) ;
152+
153+ return verificationSetting ;
126154 }
127155 } ,
128156 downloadAttachments : async function ( message , attachments ) {
@@ -172,7 +200,7 @@ const app = {
172200 command . permissions != "BOT_OWNER" && message . member . permissions . has ( command . permissions ) )
173201 } ,
174202
175- missingPerms : function ( message , cantdo , command ) {
203+ missingPerms : function ( message , edit , cantdo , command ) { // 0 = Send, 1 = Edit
176204 var lackedPerms = [ ] ;
177205 if ( command ) {
178206 for ( var i = 0 ; i < command . permissions . length ; i ++ ) {
@@ -194,16 +222,27 @@ const app = {
194222 title : `${ app . config . system . emotes . error } **Missing Permissions**` ,
195223 color : app . config . system . embedColors . red ,
196224 description : `You're lacking ${ lackedPerms } to ${ cantdo } .\nSorry about that...` ,
197- footer : { text : app . config . system . footerText }
198225 } ]
199- } , 0 , true ) ;
226+ } , edit , true ) ;
200227 } ,
201228 msgHandler : async function ( message , options , action = 0 , doReply = false , callback = null ) { // action: 0 = Send, 1 = Edit
229+ if ( options . embeds ) {
230+ if ( options [ "author" ] != null ) {
231+ var author = options [ "author" ] ;
232+ if ( author . id )
233+ options . embeds [ 0 ] [ "author" ] = { name : `Hello, ${ author . tag } !` , icon_url : author . displayAvatarURL ( { format : 'png' , dynamic : true , size : 1024 } ) } ;
234+ delete options [ "author" ] ;
235+ } ;
236+ if ( ! options . embeds [ 0 ] [ "footer" ] ) options . embeds [ 0 ] [ "footer" ] = { text : app . config . system . footerText } ; // Install branding.exe
237+ } ;
238+
202239 if ( action == 0 ) {
203240 if ( doReply ) options [ "reply" ] = { messageReference : message . id } ;
204241 message . channel . send ( options ) . then ( msg => { if ( callback != null ) callback ( msg ) ; } ) ;
205- } else if ( action == 1 )
206- message . edit ( options ) . then ( msg => { if ( callback != null ) callback ( msg ) ; } ) ;
242+ } else if ( action == 1 ) {
243+ if ( message . edit ) message . edit ( options ) . then ( msg => { if ( callback != null ) callback ( msg ) ; } ) ;
244+ else if ( message . update ) message . update ( options ) . then ( msg => { if ( callback != null ) callback ( msg ) ; } ) ;
245+ } ;
207246 } ,
208247
209248 RemoveReactions : function ( app , msg ) {
@@ -212,8 +251,7 @@ const app = {
212251 app . functions . msgHandler ( msg , {
213252 embeds : [ {
214253 color : app . config . system . embedColors . red ,
215- description : "Failed to remove all reactions! Will attempt to remove my reactions only..." ,
216- footer : { text : app . config . system . footerText }
254+ description : "Failed to remove all reactions! Will attempt to remove my reactions only..."
217255 } ]
218256 } , 0 , true , ( async m => {
219257 var myID = app . client . user . id ;
@@ -226,7 +264,6 @@ const app = {
226264 embeds : [ {
227265 color : app . config . system . embedColors . red ,
228266 description : "Failed to remove my reactions! well, that's an F." ,
229- footer : { text : app . config . system . footerText }
230267 } ]
231268 } , 1 , true ) ;
232269 app . logger . error ( "DISCORD" , "Could not remove my reactions due to " + err ) ;
@@ -247,12 +284,12 @@ const app = {
247284 description : `Command \`${ ( ( command . name ) ? command . name : command ) } \` was not found!` ,
248285 fields : [
249286 { name : "Lost?" , value : `You should check out the \`${ userSettings . get ( "prefix" ) } help\`` }
250- ] ,
251- footer : { text : app . config . system . footerText }
287+ ]
252288 } ]
253289 }
254290 else {
255291 var msg = ( ( err . message && err . message != "" ) ? "js\n" + err . message : ( err && err != "" ) ? err : "Unknown Error." ) ;
292+
256293 data = {
257294 embeds : [ {
258295 title : embedTitle ,
@@ -261,16 +298,14 @@ const app = {
261298 fields : [
262299 { name : "Error Details" , value : "```" + msg + "```" }
263300
264- ] ,
265- footer : { text : app . config . system . footerText }
301+ ]
266302 } ]
267303 } ;
268304 if ( type == "error" && err . stack ) {
269305 var stack = err . stack ,
270- maxLength = 2000 ,
306+ maxLength = 1020 ,
271307 msg = "(continued)" ;
272- if ( stack . length > maxLength ) stack = stack . match ( new RegExp ( '.{1,' + ( maxLength - msg . length ) + '}' , 'g' ) ) [ 0 ] + msg ;
273- data . embeds [ 0 ] . fields . push ( { name : "Stacktrace" , value : "```js\n" + err . stack + "```" } ) ;
308+ // data.embeds[0].fields.push({ name: "Stacktrace", value: "```js\n" + err.stack + "```" });
274309 userSettings . update ( { executedCommands : ( userSettings . get ( 'errorCommands' ) + 1 ) } , { where : { userID : message . author . id } } ) ;
275310 } ;
276311 } ;
@@ -280,6 +315,25 @@ const app = {
280315 return ;
281316 } ,
282317
318+ generateRandomCode : function ( length , random = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" ) { // random could be set to "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"@#$%^&()-=+[{]}"
319+ var code = "" ;
320+ for ( var i = 0 ; i < length ; i ++ ) { code += random . charAt ( Math . floor ( Math . random ( ) * random . length ) ) ; } ;
321+ return code ;
322+ } ,
323+ getEmoji : function ( app , emojiID , full = false ) {
324+ var emoji = app . client . emojis . cache . find ( e => e . id === emojiID ) || null ;
325+
326+ var theEmoji = emoji ;
327+ if ( emoji && full ) {
328+ theEmoji = "<" ;
329+ if ( emoji . animated )
330+ emoji += ":a" ;
331+ theEmoji += ":" + emoji [ "name" ] + ":" + emoji [ "id" ] + ">" ;
332+ } ;
333+ return theEmoji || null ;
334+ } ,
335+ getID : function ( string ) { return string . replace ( / [ < # @ & ! > ] / g, '' ) ; } ,
336+ doesArrayStartsWith : function ( string , array ) { return array . findIndex ( ( item ) => { return item . startsWith ( string ) ; } , string ) != - 1 ; } ,
283337
284338 clearCache : function ( module ) {
285339 if ( module == null )
@@ -324,6 +378,16 @@ const app = {
324378 else ++ i ;
325379 return arr ;
326380 } ,
381+ getParameters : function ( array , chars ) {
382+ if ( typeof array != "object" || ! array . length ) return "gimme a array, not whatever that was!" ;
383+ else if ( typeof chars != "string" || ! chars ) return "What am I supposed to split?? Gimme a string!" ;
384+ var parameters = [ ] ;
385+ for ( var i = 0 ; i < array . length ; i ++ ) {
386+ var parameter = array [ i ] . split ( chars ) [ 1 ] ;
387+ if ( parameter ) parameters . push ( parameter ) ;
388+ } ;
389+ return parameters ;
390+ } ,
327391 RPSSystem : function ( app , action ) {
328392 if ( app . client == undefined ) { return "RPS failed to attach to client! Create Discord Client first." } else if ( app . config == undefined ) { return "RPS failed to attach to client: Missing config data." ; } ;
329393
@@ -422,9 +486,9 @@ const app = {
422486 { name : "node-fetch" , required : true } ,
423487 { name : "discord.js" , required : true } ,
424488 { name : "sequelize" , required : true } ,
425- { name : "os " , required : true } ,
426- { name : "node-os-utils " , required : true } ,
427- { name : "canvas " , required : false }
489+ { name : "http " , required : false } ,
490+ { name : "canvas " , required : false } ,
491+ { name : "os " , required : true }
428492 ]
429493}
430494
0 commit comments