1
+ const { Discord, MessageAttachment } = require ( 'discord.js' ) ; /*npm install discord.js*/
2
+ const Config = require ( '../config.json' ) ;
3
+ const download = require ( 'download' ) ; /*npm install download*/
4
+ const fs = require ( 'fs' ) ; /*npm install fs*/
5
+ const JavaScriptObfuscator = require ( 'javascript-obfuscator' ) ; /*npm install javascript-obfuscator*/
6
+
7
+ exports . run = async ( client , message , args ) => {
8
+
9
+ const status = args [ 0 ] ; /*Gets status from first argument*/
10
+
11
+ if ( ! status ) { /*If there is no status, this will send message.author a editable message*/
12
+ message . delete ( ) ;
13
+ return message . channel . send ( `$@{message.author.tag} Please specify status.` ) . then ( s => { s . delete ( { timeout : 7000 } ) } )
14
+ }
15
+
16
+ if ( status === "encode" ) {
17
+ let method = args [ 1 ] ; /*Gets method from second argument*/
18
+
19
+ if ( ! method ) { /*If there is no method, this will send message.author a editable message*/
20
+ message . delete ( ) ;
21
+ return message . channel . send ( `${ message . author . tag } Please specify encryption level, *-low*, *medium*, *-high*` ) . then ( s => { s . delete ( { timeout : 7000 } ) } )
22
+ }
23
+
24
+ if ( method === "-high" ) {
25
+ try {
26
+ Download ( ) ; /*Call function download*/
27
+ function Download ( ) {
28
+ const attachments = ( message . attachments ) . array ( ) ; // Get list of attachments
29
+ const attachment = attachments [ 0 ] ; // Take the first attachment
30
+ if ( attachments . length !== 0 ) {
31
+ download ( message . attachments . first ( ) . url , `./encoding/` , {
32
+ 'filename' : `${ message . author . tag } .txt` /*Forces the file to be saved as txt file*/
33
+ } ) ;
34
+ setTimeout ( function ( ) { Run ( ) ; } , 5000 ) ; /*Timeout 5000 = 5s*/ /*Call function Run after timeout*/
35
+ message . delete ( { timeout : 10000 } ) ; /*Deletes original attachment message*/ /*NOTICE: If your connection speed is slow, this might be a broplem. Higher number = slower deletion time which is great for bad internet connections*/
36
+ } else {
37
+ message . author . send ( 'You should send the command with an file!' ) ;
38
+ message . delete ( ) ;
39
+ }
40
+ }
41
+
42
+ function Run ( ) {
43
+ fs . readFile ( `./encoding/${ message . author . tag } .txt` , 'utf8' , function ( err , data ) {
44
+ if ( err ) {
45
+ return console . log ( err ) ;
46
+ }
47
+ var obfuscationResult = JavaScriptObfuscator . obfuscate ( data , {
48
+ compact : true ,
49
+ controlFlowFlattening : true ,
50
+ controlFlowFlatteningThreshold : 1 ,
51
+ deadCodeInjection : true , /*These options are editable, you can find the options from https://github.com/javascript-obfuscator/javascript-obfuscator*/
52
+ deadCodeInjectionThreshold : 25 ,
53
+ disableConsoleOutput : true ,
54
+ renameGlobals : true ,
55
+ selfDefending : true
56
+ } ) ;
57
+ fs . writeFile ( `./encoding/finished/${ message . author . tag } .txt` , obfuscationResult . getObfuscatedCode ( ) , function ( err ) {
58
+ if ( err ) {
59
+ return console . log ( err ) ;
60
+ }
61
+ } ) ;
62
+ } ) ;
63
+ setTimeout ( function ( ) { Send ( ) ; } , 7000 ) ; /*Timeout 7000 = 7s*/ /*Call function Send after timeout*/
64
+ }
65
+
66
+ function Send ( ) {
67
+ fs . readFile ( `./encoding/finished/${ message . author . tag } .txt` , 'utf8' , function ( err , data ) {
68
+ if ( err ) {
69
+ return console . log ( err ) ;
70
+ }
71
+ const Message = 'Your encrypted file.' ; /*This is just an example text.*/
72
+ const attachment = new MessageAttachment ( `./encoding/finished/${ message . author . tag } .txt` ) ;
73
+ message . author . send ( Message , attachment ) ;
74
+ } ) ;
75
+ setTimeout ( function ( ) { Delete ( ) ; } , 10000 ) ; /*Timeout 10000 = 10s*/ /*Call function Delete after timeout*/
76
+ }
77
+
78
+ function Delete ( ) {
79
+ fs . unlinkSync ( `./encoding/${ message . author . tag } .txt` ) ; /*Deletes message.author original file*/
80
+ fs . unlinkSync ( `./encoding/finished/${ message . author . tag } .txt` ) ; /*Deletes message.author encrypted file*/
81
+ }
82
+
83
+ } catch ( err ) {
84
+ console . log ( err ) ;
85
+ }
86
+ }
87
+
88
+ if ( method === "-medium" ) {
89
+ try {
90
+ Download ( ) ;
91
+ function Download ( ) {
92
+ const attachments = ( message . attachments ) . array ( ) ; // Get list of attachments
93
+ const attachment = attachments [ 0 ] ; // Take the first attachment
94
+ if ( attachments . length !== 0 ) {
95
+ download ( message . attachments . first ( ) . url , `./encoding/` , {
96
+ 'filename' : `${ message . author . tag } .txt` /*Forces the file to be saved as txt file*/
97
+ } ) ;
98
+ setTimeout ( function ( ) { Run ( ) ; } , 5000 ) ; /*Timeout 5000 = 5s*/ /*Call function Run after timeout*/
99
+ message . delete ( { timeout : 10000 } ) ; /*Deletes original attachment message*/ /*NOTICE: If your connection speed is slow, this might be a broplem. Higher number = slower deletion time which is great for bad internet connections*/
100
+ } else {
101
+ message . author . send ( 'You should send the command with an file!' ) ;
102
+ message . delete ( ) ;
103
+ }
104
+ }
105
+
106
+ function Run ( ) {
107
+ fs . readFile ( `./encoding/${ message . author . tag } .txt` , 'utf8' , function ( err , data ) {
108
+ if ( err ) {
109
+ return console . log ( err ) ;
110
+ }
111
+ var obfuscationResult = JavaScriptObfuscator . obfuscate ( data , {
112
+ compact : true ,
113
+ controlFlowFlattening : true ,
114
+ controlFlowFlatteningThreshold : 0.75 ,
115
+ deadCodeInjection : true ,
116
+ deadCodeInjectionThreshold : 0.4 , /*These options are editable, you can find the options from https://github.com/javascript-obfuscator/javascript-obfuscator*/
117
+ debugProtectionInterval : false ,
118
+ disableConsoleOutput : true ,
119
+ renameGlobals : false ,
120
+ selfDefending : true ,
121
+ } ) ;
122
+ fs . writeFile ( `./encoding/finished/${ message . author . tag } .txt` , obfuscationResult . getObfuscatedCode ( ) , function ( err ) {
123
+ if ( err ) {
124
+ return console . log ( err ) ;
125
+ }
126
+ } ) ;
127
+ } ) ;
128
+ setTimeout ( function ( ) { Send ( ) ; } , 7000 ) ; /*Timeout 7000 = 7s*/ /*Call function Send after timeout*/
129
+ }
130
+
131
+ function Send ( ) {
132
+ fs . readFile ( `./encoding/finished/${ message . author . tag } .txt` , 'utf8' , function ( err , data ) {
133
+ if ( err ) {
134
+ return console . log ( err ) ;
135
+ }
136
+ const Message = 'Your encrypted file.' ; /*This is just an example text.*/
137
+ const attachment = new MessageAttachment ( `./encoding/finished/${ message . author . tag } .txt` ) ;
138
+ message . author . send ( Message , attachment ) ;
139
+ } ) ;
140
+ setTimeout ( function ( ) { Delete ( ) ; } , 10000 ) ; /*Timeout 10000 = 10s*/ /*Call function Delete after timeout*/
141
+ }
142
+
143
+ function Delete ( ) {
144
+ fs . unlinkSync ( `./encoding/${ message . author . tag } .txt` ) ; /*Deletes message.author original file*/
145
+ fs . unlinkSync ( `./encoding/finished/${ message . author . tag } .txt` ) ; /*Deletes message.author encrypted file*/
146
+ }
147
+
148
+ } catch ( err ) {
149
+ console . log ( err ) ;
150
+ }
151
+ }
152
+
153
+
154
+
155
+
156
+
157
+ if ( method === "-low" ) {
158
+ try {
159
+ Download ( ) ;
160
+ function Download ( ) {
161
+ const attachments = ( message . attachments ) . array ( ) ; // Get list of attachments
162
+ const attachment = attachments [ 0 ] ; // Take the first attachment
163
+ if ( attachments . length !== 0 ) {
164
+ download ( message . attachments . first ( ) . url , `./encoding/` , {
165
+ 'filename' : `${ message . author . tag } .txt` /*Forces the file to be saved as txt file*/
166
+ } ) ;
167
+ setTimeout ( function ( ) { Run ( ) ; } , 5000 ) ; /*Timeout 5000 = 5s*/ /*Call function Run after timeout*/
168
+ message . delete ( { timeout : 10000 } ) ; /*Deletes original attachment message*/ /*NOTICE: If your connection speed is slow, this might be a broplem. Higher number = slower deletion time which is great for bad internet connections*/
169
+ } else {
170
+ message . author . send ( 'You should send the command with an file!' ) ;
171
+ message . delete ( ) ;
172
+ }
173
+ }
174
+
175
+ function Run ( ) {
176
+ fs . readFile ( `./encoding/${ message . author . tag } .txt` , 'utf8' , function ( err , data ) {
177
+ if ( err ) {
178
+ return console . log ( err ) ;
179
+ }
180
+ var obfuscationResult = JavaScriptObfuscator . obfuscate ( data , {
181
+ compact : true ,
182
+ mangle : true ,
183
+ rotateStringArray : true ,
184
+ selfDefending : true , /*These options are editable, you can find the options from https://github.com/javascript-obfuscator/javascript-obfuscator*/
185
+ stringArray : true ,
186
+ } ) ;
187
+ fs . writeFile ( `./encoding/finished/${ message . author . tag } .txt` , obfuscationResult . getObfuscatedCode ( ) , function ( err ) {
188
+ if ( err ) {
189
+ return console . log ( err ) ;
190
+ }
191
+ } ) ;
192
+ } ) ;
193
+ setTimeout ( function ( ) { Send ( ) ; } , 7000 ) ; /*Timeout 7000 = 7s*/ /*Call function Send after timeout*/
194
+ }
195
+
196
+ function Send ( ) {
197
+ fs . readFile ( `./encoding/finished/${ message . author . tag } .txt` , 'utf8' , function ( err , data ) {
198
+ if ( err ) {
199
+ return console . log ( err ) ;
200
+ }
201
+ const Message = 'Your encrypted file.' ; /*This is just an example text.*/
202
+ const attachment = new MessageAttachment ( `./encoding/finished/${ message . author . tag } .txt` ) ;
203
+ message . author . send ( Message , attachment ) ;
204
+ } ) ;
205
+ setTimeout ( function ( ) { Delete ( ) ; } , 10000 ) ; /*Timeout 10000 = 10s*/ /*Call function Delete after timeout*/
206
+ }
207
+
208
+ function Delete ( ) {
209
+ fs . unlinkSync ( `./encoding/${ message . author . tag } .txt` ) ; /*Deletes message.author original file*/
210
+ fs . unlinkSync ( `./encoding/finished/${ message . author . tag } .txt` ) ; /*Deletes message.author encrypted file*/
211
+ }
212
+
213
+ } catch ( err ) {
214
+ console . log ( err ) ;
215
+ }
216
+ }
217
+ }
218
+ }
219
+
220
+ exports . help = {
221
+ name : 'obfuscator'
222
+ }
0 commit comments