forked from scrollback/scrollback
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunban.js
38 lines (32 loc) · 880 Bytes
/
unban.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
"use strict";
var pg = require("pg");
var log = require("../lib/logger.js");
function unban(config) {
var connString = "pg://" + config.pg.username + ":" +
config.pg.password + "@" + config.pg.server + "/" + config.pg.db;
pg.connect(connString, function(error, client, done) {
var query = "update relations set " +
"role = transitionrole," +
"transitionrole = 'none'," +
"transitiontime = null," +
"transitiontype = null " +
"where transitiontime < CURRENT_TIMESTAMP and transitiontype = 'timeout';";
if (error) {
log.e("Unable to connect to " + connString, error);
done();
return;
}
client.query(query, function(err) {
if (err) {
log.e("Query failed", err.message, query);
done();
return;
}
log.i("Unban done");
done();
});
});
}
module.exports = function(core, config) {
setTimeout(unban, 60000, config);
};