discord-bot/src/common.ts

21 lines
941 B
TypeScript
Raw Normal View History

import state from './state';
import * as data from './data';
import logger from './logging';
import UserBan from './models/UserBan';
2022-09-14 08:30:27 +00:00
import * as discord from 'discord.js';
2021-10-28 21:38:02 +00:00
export async function ban (user: discord.User, moderator: discord.User, guild: discord.Guild | null) {
const count = state.warnings.filter(x => x.id === user.id && !x.cleared).length || 0;
2021-10-28 21:38:02 +00:00
logger.info(`${moderator.toString()} has banned ${user.toString()} ${user.id} ${user.username}.`);
await state.logChannel?.send(`${moderator.toString()} has banned ${user.id} ${user.toString()} [${count}].`);
2021-10-28 21:38:02 +00:00
state.bans.push(new UserBan(user.id, user.username, moderator.id, moderator.username, count));
guild?.members?.ban(user).catch(async function (error) {
await state.logChannel?.send(`Error banning ${user.toString()} ${user.username}`);
logger.error(`Error banning ${user.toString()} ${user.id} ${user.username}.`, error);
});
2021-10-28 21:38:02 +00:00
data.flushBans();
}