1
1
const events = require ( 'events' ) ;
2
2
const { chattools, Time } = require ( '../utils' ) ;
3
3
4
+ const STRINGS = {
5
+ help : `
6
+ Repete uma mensagem em um determinado período de tempo. Cada mensagem é representada por uma thread.
7
+
8
+ *uso:* \`\`\`!cron --args [--kwargs=<type>] ...\`\`\`
9
+
10
+ *args válidos:*
11
+ \`\`\`--create\`\`\` -> _cria uma nova thread._
12
+ \`\`\`--destroy\`\`\` -> _para e apaga uma thread._
13
+ \`\`\`--stop\`\`\` -> _para uma thread._
14
+ \`\`\`--start\`\`\` -> _inicia uma thread._
15
+ \`\`\`--log\`\`\` -> _mostra as threads existentes._
16
+ \`\`\`--help\`\`\` -> _mostra esta mensagem._
17
+
18
+ *kwargs válidos:*
19
+ \`\`\`--s=<int>\`\`\` -> _define um periodo em segundos._
20
+ \`\`\`--m=<int>\`\`\` -> _define um periodo em minutos._
21
+ \`\`\`--h=<int>\`\`\` -> _define um periodo em horas._
22
+ \`\`\`--d=<int>\`\`\` -> _define um periodo em dias._
23
+ ` . trim ( ) ,
24
+ } ;
4
25
const emitter = new events . EventEmitter ( ) ;
5
26
6
27
function Thread ( id , text , message , timer ) {
@@ -22,35 +43,18 @@ class Cron {
22
43
this . name = 'cron' ;
23
44
this . threads = [ ] ;
24
45
this . counter = 0 ;
25
- this . defaultMessage = `
26
- Repete uma mensagem em um determinado período de tempo. Cada mensagem é representada por uma thread.
27
-
28
- *uso:* \`\`\`!command [--args] [--kwargs=<type>] ...\`\`\`
29
-
30
- *args válidos:*
31
- \`\`\`--create\`\`\` -> _cria uma nova thread._
32
- \`\`\`--destroy\`\`\` -> _para e apaga uma thread._
33
- \`\`\`--stop\`\`\` -> _para uma thread._
34
- \`\`\`--start\`\`\` -> _inicia uma thread._
35
- \`\`\`--log\`\`\` -> _mostra as threads existentes._
36
-
37
- *kwargs válidos:*
38
- \`\`\`--s=<int>\`\`\` -> _define um periodo em segundos._
39
- \`\`\`--m=<int>\`\`\` -> _define um periodo em minutos._
40
- \`\`\`--h=<int>\`\`\` -> _define um periodo em horas._
41
- \`\`\`--d=<int>\`\`\` -> _define um periodo em dias._
42
- ` . trim ( ) ;
46
+ this . strings = STRINGS ;
43
47
}
44
48
45
49
async execute ( data , message ) {
46
50
const isAdm = await chattools . isAdm ( message ) ;
47
51
48
- if ( isAdm ) {
49
- message . reply ( this . runs ( data , message ) ) ;
52
+ if ( ! isAdm ) {
53
+ message . reply ( 'staff only.' ) ;
50
54
return ;
51
55
}
52
56
53
- message . reply ( 'staff only.' ) ;
57
+ message . reply ( this . runs ( data , message ) ) ;
54
58
}
55
59
56
60
create ( data , message ) {
@@ -127,13 +131,14 @@ Repete uma mensagem em um determinado período de tempo. Cada mensagem é repres
127
131
destroy : ( ) => this . destroy ( data . text ) ,
128
132
start : ( ) => this . start ( data . text ) ,
129
133
stop : ( ) => this . stop ( data . text ) ,
134
+ help : ( ) => this . strings . help ,
130
135
} ;
131
136
132
137
if ( methods [ data . args [ 0 ] ] ) {
133
138
return methods [ data . args [ 0 ] ] ( ) ;
134
139
}
135
140
136
- return this . defaultMessage ;
141
+ throw new Error ( 'Nenhum arg válido foi passado.' ) ;
137
142
}
138
143
139
144
isIdValid ( id ) {
0 commit comments