Skip to content

Commit e432bc6

Browse files
committed
Merge branch 'develop'
2 parents 5a75b00 + 75721ca commit e432bc6

File tree

3 files changed

+99
-3
lines changed

3 files changed

+99
-3
lines changed

components/express_webserver.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,33 @@ var http = require('http');
77
var hbs = require('express-hbs');
88

99
module.exports = function(controller) {
10+
11+
/*function errorHandler (err, req, res, next) {
12+
if (res.headersSent) {
13+
return next(err);
14+
}
15+
16+
res
17+
.status(500)
18+
.render('500', {
19+
domain: req.get('host'),
20+
protocol: req.protocol,
21+
layout: 'layouts/default'
22+
});
23+
;
24+
}
25+
26+
function error404Handler (req, res) {
27+
res
28+
.status(404)
29+
.render('404', {
30+
domain: req.get('host'),
31+
protocol: req.protocol,
32+
layout: 'layouts/default'
33+
});
34+
;
35+
}*/
36+
1037
const port = process.env.PORT || 3000;
1138

1239
var webserver = express();
@@ -62,6 +89,10 @@ module.exports = function(controller) {
6289
require("./routes/" + file)(webserver, controller);
6390
});
6491

92+
/*webserver.use(error404Handler);
93+
94+
webserver.use(errorHandler);*/
95+
6596
controller.webserver = webserver;
6697
controller.httpserver = server;
6798

skills/link_to_rss.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const scrape = require('../utils/scrape');
44
const getFeed = require('../utils/get-feed-url');
55
const getChannel = require('../utils/get-channel-name');
66
const updateFeed = require('../utils/update-feed');
7+
const deleteTeamData = require('../utils/delete-team-data');
78

89
const GLOBAL_URL_REGEX = /<(https?:\/\/[-A-Z0-9._~:\/?#[\]@!$&'()*+,;=]+)>/igm;
910
const URL_REGEX = /<(https?:\/\/[-A-Z0-9._~:\/?#[\]@!$&'()*+,;=]+)>/i;
@@ -57,9 +58,10 @@ const addUrlToFeed = (url, message, channelName) => {
5758
};
5859

5960
module.exports = function(controller) {
60-
controller.on('app_uninstalled', function(...args) {
61-
console.log('===UNINSTALL===');
62-
console.log(args);
61+
controller.on('app_uninstalled', function(bot, message) {
62+
const teamId = message.team;
63+
64+
deleteTeamData(controller, teamId);
6365
});
6466

6567
controller.on('bot_channel_join', function(bot, message) {

utils/delete-team-data.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
module.exports = function(controller, teamId) {
2+
controller.storage.teams.delete(teamId, (err) => {
3+
if (err) {
4+
console.error(`ERROR: could not delete team ${teamId}:`, err);
5+
}
6+
7+
controller.storage.feeds.find({}, (err, feeds) => {
8+
if (err) {
9+
console.error(`ERROR: could not find feeds for team ${teamId}`, err);
10+
}
11+
12+
feeds.forEach((feed) => {
13+
if (feed.id.split('::')[0] === teamId) {
14+
controller.storage.feeds.delete(feed.id, (err) => {
15+
if (err) {
16+
console.error(`ERROR: could not delete feed ${teamId}::${feed.id}:`, err);
17+
} else {
18+
if (process.env.ANALYTICS === 'TRUE') {
19+
const pingFeedRequest = {
20+
method: 'GET',
21+
url: `${process.env.FEEDPRESS_API_URL}/feeds/ping.json`,
22+
data: stringify({
23+
feed: `${teamId}-${channelId}`,
24+
}),
25+
params: {
26+
key: process.env.FEEDPRESS_API_KEY,
27+
token: process.env.FEEDPRESS_API_TOKEN,
28+
feed: `${teamId}-${channelId}`,
29+
},
30+
};
31+
32+
axios(pingFeedRequest)
33+
.then(({ data }) => {
34+
if (data.errors && data.errors.length) {
35+
data.errors.forEach((err) => console.error('ERROR:', err));
36+
}
37+
})
38+
.catch((error) => {
39+
console.error('ERROR: could not ping feed for refresh:', error);
40+
})
41+
;
42+
}
43+
}
44+
});
45+
}
46+
});
47+
});
48+
49+
controller.storage.links.find({ teamId }, (err, links) => {
50+
if (err) {
51+
console.error(`ERROR: could not delete links for team ${teamId}:`, err);
52+
}
53+
54+
links.forEach((link) => {
55+
controller.storage.links.delete(link.id, (err) => {
56+
if (err) {
57+
console.error(`ERROR: could not delete link ${teamId}::${link.id}`);
58+
}
59+
});
60+
});
61+
});
62+
});
63+
};

0 commit comments

Comments
 (0)