Announce bans from ip ban

This commit is contained in:
Ajay
2026-01-22 03:40:45 -05:00
parent b3a6d6f7c1
commit 117ece6381
3 changed files with 29 additions and 1 deletions

View File

@@ -48,6 +48,7 @@ addDefaults(config, {
discordDeArrowWarnedWebhookURL: null,
discordNewUserWebhookURL: null,
discordRejectedNewUserWebhookURL: null,
discordAutobanWebhookURL: null,
minReputationToSubmitChapter: 0,
minReputationToSubmitFiller: 0,
getTopUsersCacheTimeMinutes: 240,

View File

@@ -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);
@@ -183,4 +185,28 @@ 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");
});
}
}

View File

@@ -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}`));
}