This repository has been archived by the owner on Jun 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathapp.js
111 lines (89 loc) · 2.99 KB
/
app.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
require('dotenv').config();
const mongoose = require('mongoose');
const express = require('express');
const BotProxy = require('./src/services/BotProxy');
const app = express();
const GreetNewUserProcessor = require('./src/processors/GreetNewUserProcessor');
const ChiaProcessor = require('./src/processors/ChiaProcessor');
const ChiaImageProcessor = require('./src/processors/ChiaImageProcessor');
const MemberCountProcessor = require('./src/processors/MemberCountProcessor');
const GhwKarteProcessor = require('./src/processors/GhwKarteProcessor');
const RssNotificationProcessor = require('./src/processors/RssNotificationProcessor');
const AnswerProcessor = require('./src/processors/AnswerProcessor');
const ExpelliarmusProcessor = require('./src/processors/ExpelliarmusProcessor');
const RandomMessageProcessor = require('./src/processors/RandomMessageProcessor');
const TiradeProcessor = require('./src/processors/TiradeProcessor');
const YoutubeFeedProcessor = require('./src/processors/YoutubeFeedProcessor');
const GhwKarte = require('./src/services/GhwKarte');
let db;
let bot;
const dbConnect = () => {
return new Promise((resolve, reject) => {
db = mongoose.connection;
db.on('error', e => {
console.error(e);
reject(e.message);
});
db.once('open', () => {
console.log('Connected to database');
resolve();
});
// Connect to database;
mongoose.connect(process.env.MONGODB_CONNECT_STRING, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
})
};
const initializeBots = () => {
return new Promise((resolve, reject) => {
bot = new BotProxy();
bot.initialize()
.then(() => {
console.log('All bots are initialized');
resolve();
}).catch(reject);
});
};
const startWebserver = () => {
return new Promise((resolve, reject) => {
const ghwkarte = new GhwKarte();
app.get('/api/ghwkarte/entries', (req, res) => {
ghwkarte.getAllEntries().then(entries => res.send(entries));
});
/*const Message = require('./src/model/Message');
app.get('/api/messages', (req, res) => {
Message.find().then(data => {
res.send(data);
});
});*/
app.use('/', express.static('public'));
app.listen(process.env.PORT || 3000, '0.0.0.0', function () {
console.log('Webserver running on port 3000!');
resolve();
});
});
};
const addProcessors = () => {
return new Promise((resolve, reject) => {
new GreetNewUserProcessor(bot);
new ChiaProcessor(bot);
// new ChiaImageProcessor(bot);
new MemberCountProcessor(bot);
new GhwKarteProcessor(bot);
new RssNotificationProcessor(bot);
new AnswerProcessor(bot);
new ExpelliarmusProcessor(bot);
new RandomMessageProcessor(bot);
new TiradeProcessor(bot);
new YoutubeFeedProcessor(bot);
resolve();
});
};
initializeBots()
.then(dbConnect)
.then(startWebserver)
.then(addProcessors)
.then(() => {
console.log('Everything is up and running! :-)');
});