-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
58 lines (57 loc) · 2.55 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
const config = require('./config');
const mongoose = require('mongoose');
mongoose.connect('localhost', 'suzette');
/*--------------------------------------------------*\
# Express
\*--------------------------------------------------*/
const express = require('express');
const app = express();
const router = require('./app/routes/main')
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
next();
});
app.use(express.static('public'));
app.use('/', router);
app.listen(3000, function () {
console.log('App listening on port 3000!');
});
/*--------------------------------------------------*\
# END Express
\*--------------------------------------------------*/
//getUserById -> userid, rtm
const listen = require('./app/services/listen-service');
const userService = require('./app/services/user-service');
const userManager = require('./app/managers/user-manager');
userManager.registerUsersFromWs();
const pwonedHelper = require('./app/services/pwoned.helper.js');
const RtmClient = require('@slack/client').RtmClient;
// The memory data store is a collection of useful functions we can include in our RtmClient
const MemoryDataStore = require('@slack/client').MemoryDataStore;
const CLIENT_EVENTS = require('@slack/client').CLIENT_EVENTS;
const RTM_EVENTS = require('@slack/client').RTM_EVENTS;
const RTM_CLIENT_EVENTS = require('@slack/client').CLIENT_EVENTS.RTM;
rtm = new RtmClient(config.key, {
// Sets the level of logging we require
logLevel: config.logLevel,
// Initialise a data store for our client, this will load additional helper functions for the storing and retrieval of data
dataStore: new MemoryDataStore()
});
rtm.start();
rtm.on(CLIENT_EVENTS.RTM.AUTHENTICATED, function (rtmStartData) {
console.log(`Logged in as ${rtmStartData.self.name} of team ${rtmStartData.team.name}, but not yet connected to a channel`);
});
rtm.on(RTM_EVENTS.MESSAGE, function (message) {
listen.listenToSuze(message);
listen.listenRandom(message);
listen.listenAlone(message);
listen.listenResult(message);
});
// you need to wait for the client to fully connect before you can send messages
rtm.on(RTM_CLIENT_EVENTS.RTM_CONNECTION_OPENED, function () {
// This will send the message 'this is a test message' to the channel identified by id 'C0CHZA86Q'
// rtm.sendMessage('gabriel va reussir son annee', 'C2J8W4RK4', function messageSent() {
// // optionally, you can supply a callback to execute once the message has been sent
// });
});