@@ -4,80 +4,74 @@ const fs = require("fs");
44// The function has 2 parts to it. The first part is that which deletes all the channels from the saved file that are deleted in the channel.
55// In the second part, we delete all the temporary channels that have no user in it.
66
7- /* eslint-disable */
8-
97module . exports = {
108 name : "ready" ,
119 once : true ,
1210 execute ( client ) {
13- const timer = setInterval ( function ( ) {
14- // const temp_data = [];
15- // Reading data from the file
16- fs . readFile ( "./data/createvc.json" , "utf-8" , ( err , jsonString ) => {
17- if ( err ) {
18- console . log ( "Error reading file from disk:" , err ) ;
19- return ;
20- } else {
21- // Converting the data to a dictionary
22- const data = JSON . parse ( jsonString ) ;
23-
24- // Deleting all the channels, that should have been deleted
25- const b = data . channels . filter ( ( e ) => e . delete == true ) ;
26- b . forEach ( ( f ) =>
27- data . channels . splice (
28- data . channels . findIndex ( ( e ) => e . delete === f . delete ) ,
29- 1 ,
30- ) ,
31- ) ;
32-
33- fs . writeFileSync (
34- "./data/createvc.json" ,
35- JSON . stringify ( { users : data . users , channels : data . channels } , null , 4 ) ,
36- ) ;
11+ const timer = setInterval (
12+ function ( ) {
13+ // Reading data from the file
14+ fs . readFile ( "./data/createvc.json" , "utf-8" , ( err , jsonString ) => {
15+ if ( err ) {
16+ console . log ( "Error reading file from disk:" , err ) ;
17+ return ;
18+ } else {
19+ deleteExistentChannels ( client , jsonString ) ;
20+ }
21+ } ) ;
22+ // Write back to the file
23+ } ,
24+ 60 * 60 * 1000 ,
25+ ) ;
26+ } ,
27+ } ;
3728
38- // console.log(data);
29+ function deleteExistentChannels ( client , jsonString ) {
30+ // Converting the data to a dictionary
31+ const data = JSON . parse ( jsonString ) ;
3932
40- data . channels . forEach ( ( item ) => {
41- // item here is the channel id
42- if ( item . delete == false ) {
43- client . channels
44- . fetch ( item . channel_id )
45- . then ( ( channel ) => {
46- channel
47- . fetch ( )
48- . then ( ( channel ) => {
49- if ( channel . members . size == 0 ) {
50- // console.log(channel.name);
51- // console.log(channel.members.size);
33+ // Deleting all the channels, that should have been deleted
34+ const b = data . channels . filter ( ( e ) => e . delete == true ) ;
35+ b . forEach ( ( f ) =>
36+ data . channels . splice (
37+ data . channels . findIndex ( ( e ) => e . delete === f . delete ) ,
38+ 1 ,
39+ ) ,
40+ ) ;
5241
53- item . delete = true ;
54- fs . writeFileSync (
55- "./data/createvc.json" ,
56- JSON . stringify (
57- {
58- users : data . users ,
59- channels : data . channels ,
60- } ,
61- null ,
62- 4 ,
63- ) ,
64- ) ;
65- channel
66- . delete ( )
67- . then ( console . log )
68- . catch ( console . error ) ;
69- }
70- } )
71- . catch ( console . error ) ;
72- } )
73- . catch ( console . error ) ;
74- }
75- } ) ;
42+ fs . writeFileSync (
43+ "./data/createvc.json" ,
44+ JSON . stringify ( { users : data . users , channels : data . channels } , null , 4 ) ,
45+ ) ;
7646
77- // console.log(data.channels);
78- }
79- } ) ;
80- // Write back to the file
81- } , 60 * 60 * 1000 ) ;
82- } ,
83- } ;
47+ data . channels . forEach ( ( item ) => {
48+ // item here is the channel id
49+ if ( item . delete == false ) {
50+ client . channels
51+ . fetch ( item . channel_id )
52+ . then ( ( channel ) => {
53+ channel
54+ . fetch ( )
55+ . then ( ( vcChannel ) => {
56+ if ( vcChannel . members . size == 0 ) {
57+ item . delete = true ;
58+ fs . writeFileSync (
59+ "./data/createvc.json" ,
60+ JSON . stringify (
61+ {
62+ users : data . users ,
63+ channels : data . channels ,
64+ } ,
65+ null ,
66+ 4 ,
67+ ) ,
68+ ) ;
69+ vcChannel . delete ( ) . then ( console . log ) . catch ( console . error ) ;
70+ }
71+ } )
72+ . catch ( console . error ) ;
73+ } )
74+ . catch ( console . error ) ;
75+ }
76+ } ) ;
77+ }
0 commit comments