mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2026-01-27 04:40:46 +03:00
Announce bans from ip ban
This commit is contained in:
@@ -48,6 +48,7 @@ addDefaults(config, {
|
||||
discordDeArrowWarnedWebhookURL: null,
|
||||
discordNewUserWebhookURL: null,
|
||||
discordRejectedNewUserWebhookURL: null,
|
||||
discordAutobanWebhookURL: null,
|
||||
minReputationToSubmitChapter: 0,
|
||||
minReputationToSubmitFiller: 0,
|
||||
getTopUsersCacheTimeMinutes: 240,
|
||||
|
||||
@@ -8,6 +8,7 @@ import { QueryCacher } from "../utils/queryCacher";
|
||||
import { isUserVIP } from "../utils/isUserVIP";
|
||||
import { parseCategories, parseDeArrowTypes } from "../utils/parseParams";
|
||||
import { Logger } from "../utils/logger";
|
||||
import axios from "axios";
|
||||
|
||||
export async function shadowBanUser(req: Request, res: Response): Promise<Response> {
|
||||
const userID = req.query.userID as UserID;
|
||||
@@ -153,6 +154,7 @@ export async function banIP(hashedIP: HashedIP, unHideOldSubmissions: boolean, t
|
||||
//find all previous submissions and hide them
|
||||
if (unHideOldSubmissions) {
|
||||
const users = await unHideSubmissionsByIP(categories, hashedIP, type);
|
||||
announceBan([...users]);
|
||||
|
||||
await Promise.all([...users].map((user) => {
|
||||
return banUser(user, true, unHideOldSubmissions, type, categories, deArrowTypes);
|
||||
@@ -184,3 +186,27 @@ async function unHideSubmissionsByIP(categories: string[], hashedIP: HashedIP, t
|
||||
|
||||
return users;
|
||||
}
|
||||
|
||||
export function announceBan(userIDs: UserID[]) {
|
||||
if (config.discordAutobanWebhookURL) {
|
||||
axios.post(config.discordAutobanWebhookURL, {
|
||||
"embeds": [{
|
||||
"title": "Auto banned user",
|
||||
"description": userIDs.join("\n"),
|
||||
"color": 10813440,
|
||||
}],
|
||||
})
|
||||
.then(res => {
|
||||
if (res.status >= 400) {
|
||||
Logger.error("Error sending auto ban Discord hook");
|
||||
Logger.error(JSON.stringify((res.data)));
|
||||
Logger.error("\n");
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
Logger.error("Failed to send auto ban Discord hook.");
|
||||
Logger.error(JSON.stringify(err));
|
||||
Logger.error("\n");
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { HashedUserID } from "../types/user.model";
|
||||
import { db } from "../databases/databases";
|
||||
import { Category, HashedIP } from "../types/segments.model";
|
||||
import { banUser } from "../routes/shadowBanUser";
|
||||
import { announceBan, banUser } from "../routes/shadowBanUser";
|
||||
import { config } from "../config";
|
||||
import { Logger } from "./logger";
|
||||
|
||||
@@ -19,6 +19,7 @@ export async function checkBanStatus(userID: HashedUserID, ip: HashedIP): Promis
|
||||
|
||||
if (!userBanStatus && ipBanStatus) {
|
||||
// Make sure the whole user is banned
|
||||
announceBan([userID]);
|
||||
banUser(userID, true, true, 1, config.categoryList as Category[], config.deArrowTypes)
|
||||
.catch((e) => Logger.error(`Error banning user after submitting from a banned IP: ${e}`));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user