File tree Expand file tree Collapse file tree 1 file changed +22
-6
lines changed Expand file tree Collapse file tree 1 file changed +22
-6
lines changed Original file line number Diff line number Diff line change 1
1
import { INITIAL_SESSION } from '../../constants/index.js'
2
+ import { db } from '../../db/index.js'
2
3
// TODO: сделать цикл и возможность отправки сообщений группам пользователей
3
4
export const sendMessage = bot => {
4
5
bot . onText ( / ^ \/ m s g + / ig, async msg => {
5
- if ( msg ?. chat ?. id == process . env . NOTIF_GROUP ) {
6
+ if ( msg ?. chat ?. id === process . env . NOTIF_GROUP ) {
6
7
const text = msg . text . split ( '&&' )
7
8
const { id : chatId } = msg . chat
8
9
const options = {
9
10
parse_mode : 'HTML'
10
11
}
11
12
msg [ 'ctx' ] = INITIAL_SESSION
12
13
try {
13
- await bot . sendMessage (
14
- text [ 1 ] ,
15
- `🤖\n${ text [ 2 ] } ` ,
16
- options
17
- )
14
+ if ( text [ 1 ] === 'all' ) {
15
+ const subscribers = await db . subscriber . findAll ( {
16
+ subQuery : false ,
17
+ order : [ [ 'createdAt' , 'DESC' ] ]
18
+ } )
19
+
20
+ if ( msg [ 'reply_to_message' ] . photo . length ) {
21
+ console . log ( 'msg[\'reply_to_message\'].photo' , msg [ 'reply_to_message' ] . photo )
22
+ // отправить всем пользователям сообщение с картинкой
23
+ // subscribers.map(user => bot.sendPhoto(user['chat_id']))
24
+ } else {
25
+ subscribers . map ( user => bot . sendMessage ( user . chat_id , '🔮' ) )
26
+ }
27
+ } else {
28
+ await bot . sendMessage (
29
+ text [ 1 ] ,
30
+ `🤖\n${ text [ 2 ] } ` ,
31
+ options
32
+ )
33
+ }
18
34
} catch ( error ) {
19
35
await bot . sendMessage ( chatId , `${ error . message } ` , options )
20
36
}
You can’t perform that action at this time.
0 commit comments