1+
2+ const { glob } = require ( "glob" ) ;
3+ const { promisify } = require ( "util" ) ;
4+ const globPromise = promisify ( glob ) ;
5+ const localdb = require ( "croxydb" ) ;
6+ module . exports = function ( client , ops ) {
7+ let commands = [ ] ;
8+ globPromise ( `${ __dirname } /../commands/**/*.js` ) . then ( ( files ) => {
9+ files . forEach ( ( f ) => {
10+ const props = require ( f ) ;
11+
12+ let same = commands . filter ( ( c ) => c . command == props . name ) ;
13+ if ( same . length > 0 ) return console . log ( colors . red ( `[!] ${ moment ( ) . format ( ( "YYYY-MM-DD HH:mm:ss" ) ) } ` ) + colors . yellow ( ` > ${ props . name } komutunun ismi başka bir komutla aynı.` ) ) ;
14+
15+ commands . push ( {
16+ command : props . name ,
17+ description : props . description ,
18+ } ) ;
19+
20+ console . log ( colors . green ( `[+] ${ moment ( ) . format ( ( "YYYY-MM-DD HH:mm:ss" ) ) } ` ) + colors . yellow ( ` > Yüklenen komut: ${ props . name } ` ) ) ;
21+
22+ bot . command ( props . name , ( ctx ) => {
23+
24+ if ( props . cooldown ) {
25+ if ( localdb . has ( `cooldown.${ ctx . from . id } .${ props . name } ` ) ) {
26+ let cooldown = localdb . fetch ( `cooldown.${ ctx . from . id } .${ props . name } ` ) ;
27+ if ( cooldown > Date . now ( ) ) {
28+ let time = cooldown - Date . now ( ) ;
29+ let seconds = Math . floor ( time / 1000 ) ;
30+ let minutes = Math . floor ( seconds / 60 ) ;
31+ let hours = Math . floor ( minutes / 60 ) ;
32+ let days = Math . floor ( hours / 24 ) ;
33+
34+ // let timeLeft = [];
35+ // if (days) timeLeft.push(`${days} gün`);
36+ // if (hours) timeLeft.push(`${hours % 24} saat`);
37+ // if (minutes) timeLeft.push(`${minutes % 60} dakika`);
38+ // if (seconds) timeLeft.push(`${seconds % 60} saniye`);
39+
40+ // ? Arada boşluk olmamasını istiyorsanız üsteki kodu kullanabilirsiniz.
41+
42+ return ctx . reply ( `Bu komutu kullanmak için ${ days ? `${ days } gün,` : "" } ${ hours ? `${ hours % 24 } saat,` : "" } ${ minutes ? `${ minutes % 60 } dakika,` : "" } ${ seconds % 60 } saniye beklemelisiniz.` ) ;
43+ } else {
44+ localdb . set ( `cooldown.${ ctx . from . id } .${ props . name } ` , Date . now ( ) + props . cooldown * 1000 ) ;
45+ }
46+ } else {
47+ localdb . set ( `cooldown.${ ctx . from . id } .${ props . name } ` , Date . now ( ) + props . cooldown * 1000 ) ;
48+ }
49+ }
50+
51+
52+ console . log ( colors . green ( `[+] ${ moment ( ) . format ( ( "YYYY-MM-DD HH:mm:ss" ) ) } ` ) + colors . yellow ( ` > Kullanılan komut: ${ props . name } ` ) + colors . red ( ` > Kullanıcı: ${ ctx . from . username } (${ ctx . from . id } )` ) )
53+
54+ let values = [ ] ;
55+ let err = false ;
56+ let parsedParams = [ ]
57+ let args = ctx . message . text . split ( " " ) ;
58+ let params = args . slice ( 1 ) ;
59+
60+ for ( const param of params ) {
61+ const [ name , value ] = param . split ( ":" ) ;
62+ parsedParams . push ( { name : name . toLowerCase ( ) , value : value } ) ;
63+ }
64+
65+ if ( props . options ) {
66+ props . options . forEach ( ( option ) => {
67+ if ( err ) return ;
68+ let Dname = parsedParams . find ( ( p ) => p . name == option . name . toLowerCase ( ) ) ;
69+ if ( option . required ) {
70+ if ( option . type == 1 ) {
71+ if ( Dname ) {
72+ values . push ( { name : Dname . name , value : Number ( Dname . value ) } ) ;
73+ } else return ctx . reply ( option . error ) && ( err = true ) ;
74+ } else if ( option . type == 2 ) {
75+ if ( Dname ) {
76+ values . push ( Dname ) ;
77+ } else return ctx . reply ( option . error ) && ( err = true ) ;
78+ } else if ( option . type == 3 ) {
79+ if ( Dname ) {
80+ if ( Dname . value . toLowerCase ( ) == "true" || Dname . value . toLowerCase ( ) == "false" ) {
81+ values . push ( { name : Dname . name , value : Dname . value . toLowerCase ( ) == "true" ? true : false } ) ;
82+ } else return ctx . reply ( option . error ) && ( err = true ) ;
83+ } else return ctx . reply ( option . error ) && ( err = true ) ;
84+ } else if ( option . type == 4 ) {
85+ if ( Dname ) {
86+ // User bilgilerini çekme işlemi yapılmadı kendiniz geliştirebilirsiniz. Power By FastUptime
87+ values . push ( Dname ) ;
88+ } else return ctx . reply ( option . error ) && ( err = true ) ;
89+ } else if ( option . type == 5 ) {
90+ if ( Dname ) {
91+ let choice = option . choices . find ( ( c ) => c . value . toLowerCase ( ) == Dname . value . toLowerCase ( ) ) ;
92+ if ( choice ) {
93+ values . push ( Dname ) ;
94+ } else return ctx . reply ( option . error ) && ( err = true ) ;
95+ } else return ctx . reply ( option . error ) && ( err = true ) ;
96+ }
97+ } else {
98+ if ( option . type == 1 ) {
99+ if ( Dname ) {
100+ values . push ( Dname ) ;
101+ } else values . push ( null ) ;
102+ } else if ( option . type == 2 ) {
103+ if ( Dname ) {
104+ values . push ( Dname ) ;
105+ } else values . push ( null ) ;
106+ } else if ( option . type == 3 ) {
107+ if ( Dname ) {
108+ values . push ( Dname ) ;
109+ } else values . push ( null ) ;
110+ } else if ( option . type == 4 ) {
111+ if ( Dname ) {
112+ values . push ( Dname ) ;
113+ } else values . push ( null ) ;
114+ } else if ( option . type == 5 ) {
115+ if ( Dname ) {
116+ values . push ( Dname ) ;
117+ } else values . push ( null ) ;
118+ }
119+ }
120+ } ) ;
121+ }
122+
123+ if ( err ) return ;
124+ props . run ( bot , ctx , values ) ;
125+ } ) ;
126+
127+ if ( props . options ) {
128+ props . options . forEach ( ( option ) => {
129+ if ( option . name . match ( / [ A - Z ] / g) ) {
130+ console . log ( colors . red ( `[!] ${ moment ( ) . format ( ( "YYYY-MM-DD HH:mm:ss" ) ) } ` ) + colors . yellow ( ` > ${ props . name } komutunun ${ option . name } seçeneğinin ismi büyük harf içeremez.` ) ) ;
131+ return ;
132+ }
133+
134+ if ( option . type < 1 || option . type > 5 ) {
135+ console . log ( colors . red ( `[!] ${ moment ( ) . format ( ( "YYYY-MM-DD HH:mm:ss" ) ) } ` ) + colors . yellow ( ` > ${ props . name } komutunun ${ option . name } seçeneğinin tipi geçerli değil. (1-5)` ) ) ;
136+ return ;
137+ }
138+
139+ let same = props . options . filter ( ( o ) => o . name == option . name ) ;
140+ if ( same . length > 1 ) {
141+ console . log ( colors . red ( `[!] ${ moment ( ) . format ( ( "YYYY-MM-DD HH:mm:ss" ) ) } ` ) + colors . yellow ( ` > ${ props . name } komutunun ${ option . name } seçeneğinin ismi başka bir seçenekle aynı.` ) ) ;
142+ return ;
143+ }
144+
145+ if ( option . choices ) {
146+ option . choices . forEach ( ( choice ) => {
147+ let same = option . choices . filter ( ( c ) => c . value == choice . value ) ;
148+ if ( same . length > 1 ) {
149+ console . log ( colors . red ( `[!] ${ moment ( ) . format ( ( "YYYY-MM-DD HH:mm:ss" ) ) } ` ) + colors . yellow ( ` > ${ props . name } komutunun ${ option . name } seçeneğinin ${ choice . name } seçeneğinin değeri başka bir seçenekle aynı.` ) ) ;
150+ return ;
151+ }
152+
153+ if ( ! choice . value || choice . value == "" || choice . value . match ( / [ A - Z ] / g) ) {
154+ console . log ( colors . red ( `[!] ${ moment ( ) . format ( ( "YYYY-MM-DD HH:mm:ss" ) ) } ` ) + colors . yellow ( ` > ${ props . name } komutunun ${ option . name } seçeneğinin ${ choice . name } seçeneğinin değeri boş veya büyük harf içeremez.` ) ) ;
155+ return ;
156+ }
157+
158+ } ) ;
159+ }
160+
161+ } ) ;
162+ }
163+
164+ if ( ! props . description || props . description == "" ) {
165+ console . log ( colors . red ( `[!] ${ moment ( ) . format ( ( "YYYY-MM-DD HH:mm:ss" ) ) } ` ) + colors . yellow ( ` > ${ props . name } komutunun açıklaması eksik.` ) ) ;
166+ return ;
167+ }
168+
169+ if ( props . cooldown ) {
170+ if ( isNaN ( props . cooldown ) ) {
171+ console . log ( colors . red ( `[!] ${ moment ( ) . format ( ( "YYYY-MM-DD HH:mm:ss" ) ) } ` ) + colors . yellow ( ` > ${ props . name } komutunun cooldown değeri sayı olmalı.` ) ) ;
172+ return ;
173+ }
174+ }
175+ } ) ;
176+ } ) . then ( ( ) => {
177+ bot . telegram . setMyCommands ( commands ) ;
178+ } ) ;
179+ } ;
0 commit comments