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,
|
discordDeArrowWarnedWebhookURL: null,
|
||||||
discordNewUserWebhookURL: null,
|
discordNewUserWebhookURL: null,
|
||||||
discordRejectedNewUserWebhookURL: null,
|
discordRejectedNewUserWebhookURL: null,
|
||||||
|
discordAutobanWebhookURL: null,
|
||||||
minReputationToSubmitChapter: 0,
|
minReputationToSubmitChapter: 0,
|
||||||
minReputationToSubmitFiller: 0,
|
minReputationToSubmitFiller: 0,
|
||||||
getTopUsersCacheTimeMinutes: 240,
|
getTopUsersCacheTimeMinutes: 240,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { QueryCacher } from "../utils/queryCacher";
|
|||||||
import { isUserVIP } from "../utils/isUserVIP";
|
import { isUserVIP } from "../utils/isUserVIP";
|
||||||
import { parseCategories, parseDeArrowTypes } from "../utils/parseParams";
|
import { parseCategories, parseDeArrowTypes } from "../utils/parseParams";
|
||||||
import { Logger } from "../utils/logger";
|
import { Logger } from "../utils/logger";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
export async function shadowBanUser(req: Request, res: Response): Promise<Response> {
|
export async function shadowBanUser(req: Request, res: Response): Promise<Response> {
|
||||||
const userID = req.query.userID as UserID;
|
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
|
//find all previous submissions and hide them
|
||||||
if (unHideOldSubmissions) {
|
if (unHideOldSubmissions) {
|
||||||
const users = await unHideSubmissionsByIP(categories, hashedIP, type);
|
const users = await unHideSubmissionsByIP(categories, hashedIP, type);
|
||||||
|
announceBan([...users]);
|
||||||
|
|
||||||
await Promise.all([...users].map((user) => {
|
await Promise.all([...users].map((user) => {
|
||||||
return banUser(user, true, unHideOldSubmissions, type, categories, deArrowTypes);
|
return banUser(user, true, unHideOldSubmissions, type, categories, deArrowTypes);
|
||||||
@@ -183,4 +185,28 @@ async function unHideSubmissionsByIP(categories: string[], hashedIP: HashedIP, t
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
return users;
|
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 { HashedUserID } from "../types/user.model";
|
||||||
import { db } from "../databases/databases";
|
import { db } from "../databases/databases";
|
||||||
import { Category, HashedIP } from "../types/segments.model";
|
import { Category, HashedIP } from "../types/segments.model";
|
||||||
import { banUser } from "../routes/shadowBanUser";
|
import { announceBan, banUser } from "../routes/shadowBanUser";
|
||||||
import { config } from "../config";
|
import { config } from "../config";
|
||||||
import { Logger } from "./logger";
|
import { Logger } from "./logger";
|
||||||
|
|
||||||
@@ -19,6 +19,7 @@ export async function checkBanStatus(userID: HashedUserID, ip: HashedIP): Promis
|
|||||||
|
|
||||||
if (!userBanStatus && ipBanStatus) {
|
if (!userBanStatus && ipBanStatus) {
|
||||||
// Make sure the whole user is banned
|
// Make sure the whole user is banned
|
||||||
|
announceBan([userID]);
|
||||||
banUser(userID, true, true, 1, config.categoryList as Category[], config.deArrowTypes)
|
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}`));
|
.catch((e) => Logger.error(`Error banning user after submitting from a banned IP: ${e}`));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user