-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (46 loc) · 1.34 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'use strict'
// Connect data base
const { MongoClient } = require("mongodb");
const uri = "mongodb://localhost:27017";
const client = new MongoClient(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
client.connect().then(() => {
global.database = client.db('yazilib');
console.log('db connected 🔗');
})
// Connect Telegram
const Telegram = require('telegram-node-bot')
const TextCommand = Telegram.TextCommand
const tg = new Telegram.Telegram('key')
// Connect Redis
const { createClient } = require('redis');
const redis = createClient({
url: 'key'
})
redis.on('error', err => console.log('Redis Client Error', err));
redis.connect().then(() => {
global.redis = redis
console.log('********************* redis ready **************************');
});
//Load app class
const StartController = require('./controller/Start'),
OtherWiseController = require('./controller/OtherWise'),
NewController = require('./controller/new'),
PingController = require('./controller/Ping');
tg.router
.when(
new TextCommand('ping', 'pingCommand'),
new PingController()
)
.when(
new TextCommand('new', 'newCommand'),
new NewController()
)
.when(
new TextCommand('start', 'startCommand'),
new StartController()
).otherwise(
new OtherWiseController()
)