This repository was archived by the owner on Jul 17, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Original file line number Diff line number Diff line change
1
+ ( function ( ) {
2
+ "use strict" ;
3
+
4
+ bot . addCommand ( {
5
+ name : 'export' ,
6
+ fun : function ( args ) {
7
+ var req = new XMLHttpRequest ( ) ;
8
+ req . open ( 'POST' , 'https://api.github.com/gists' , false ) ;
9
+ req . send ( JSON . stringify ( {
10
+ files : {
11
+ 'bot.json' : {
12
+ content : JSON . stringify ( bot . memory . data )
13
+ }
14
+ }
15
+ } ) ) ;
16
+
17
+ if ( req . status !== 201 ) {
18
+ var resp = '' ;
19
+ if ( req . responseText ) {
20
+ resp = '\n' + req . responseText . match ( / .{ 1 , 400 } / g) . join ( '\n' ) ;
21
+ }
22
+ return 'Failed: ' + req . status + ': ' + req . statusText + resp ;
23
+ }
24
+
25
+ var resp = JSON . parse ( req . responseText ) ;
26
+
27
+ return 'Exported to gist, id: `' + resp . id + '` viewable at ' + resp . html_url ;
28
+ } ,
29
+ permissions : { del : 'NONE' , use : 'OWNER' } ,
30
+ description : 'Blurts out a message with the persistent memory storage for export `/export`'
31
+ } ) ;
32
+ } ) ( ) ;
Original file line number Diff line number Diff line change
1
+ ( function ( ) {
2
+ "use strict" ;
3
+
4
+ bot . addCommand ( {
5
+ name : 'import' ,
6
+ fun : function ( args ) {
7
+ if ( args . trim ( ) === 'clear' ) {
8
+ bot . memory . clear ( ) ;
9
+
10
+ return 'Bot memory cleared. Please restart the bot.' ;
11
+ }
12
+
13
+ var req = new XMLHttpRequest ( ) ;
14
+ req . open ( 'GET' , 'https://api.github.com/gists/' + args , false ) ;
15
+ req . send ( null ) ;
16
+
17
+ if ( req . status !== 200 ) {
18
+ var resp = '' ;
19
+ if ( req . responseText ) {
20
+ resp = '\n' + req . responseText . match ( / .{ 1 , 400 } / g) . join ( '\n' ) ;
21
+ }
22
+ return 'Failed: ' + req . status + ': ' + req . statusText + resp ;
23
+ }
24
+
25
+ var resp = JSON . parse ( req . responseText ) ;
26
+
27
+ bot . memory . data = JSON . parse ( resp . files [ 'bot.json' ] . content ) ;
28
+ bot . memory . save ( ) ;
29
+
30
+ return "Imported and persisted successfully. Please restart the bot." ;
31
+ } ,
32
+ permissions : { del : 'NONE' , use : 'OWNER' } ,
33
+ description : 'Imports the persistent memory described in args `/export <exported-content>`'
34
+ } ) ;
35
+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments