Add ban tracking
- Add bans table - Periodically refresh bans list every 1-1.25 hoursmaster
parent
85b48f90f4
commit
4555dd6b7f
|
@ -0,0 +1,3 @@
|
||||||
|
CREATE TABLE bans (
|
||||||
|
userid integer
|
||||||
|
)
|
25
src/app.ts
25
src/app.ts
|
@ -262,11 +262,32 @@ app.get("/", async (request, response) => {
|
||||||
//
|
//
|
||||||
//});
|
//});
|
||||||
|
|
||||||
app.get("/streamer/auth", async ({}, response) => response.redirect(307, `https://id.twitch.tv/oauth2/authorize?client_id=${config.twitchClientId}&redirect_uri=${config.urlPrefix}/callback&response_type=code&scope=channel:read:subscriptions moderation:read`));
|
|
||||||
|
|
||||||
// Logout
|
// Logout
|
||||||
app.get("/logout", async (request, response) => request.session!.destroy(() => response.redirect(307, '/')));
|
app.get("/logout", async (request, response) => request.session!.destroy(() => response.redirect(307, '/')));
|
||||||
|
|
||||||
|
async function processBannedUsers() {
|
||||||
|
console.log("processBannedUsers run at " + new Date().toISOString());
|
||||||
|
var streamer = await db.query(queries.getStreamerIdToken).then((result: pg.QueryResult) => result.rows[0]);
|
||||||
|
if (streamer['tokenpair'] != null) {
|
||||||
|
var response = await twitch.apiRequest(streamer['tokenpair'],"/moderation/banned?broadcaster_id=" + streamer['userid']);
|
||||||
|
var dbconn = await db.connect();
|
||||||
|
try {
|
||||||
|
await dbconn.query('BEGIN');
|
||||||
|
for (var ban of response.data) {
|
||||||
|
if (ban.expires_at == '') dbconn.query(Object.assign(queries.insertBan,{ values: [ban.user_id] }))
|
||||||
|
}
|
||||||
|
await dbconn.query('COMMIT');
|
||||||
|
} catch (e) {
|
||||||
|
await dbconn.query('ROLLBACK');
|
||||||
|
} finally {
|
||||||
|
dbconn.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setTimeout(processBannedUsers,3600000+Math.floor(Math.random()*900000)) // Run every 1-1.25 hours to balance load
|
||||||
|
}
|
||||||
|
|
||||||
|
processBannedUsers();
|
||||||
|
|
||||||
app.listen(config.port, () => {
|
app.listen(config.port, () => {
|
||||||
console.log(`Listening on port ${config.port}`);
|
console.log(`Listening on port ${config.port}`);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue