mirror of
https://github.com/yuzu-emu/Command-fix.git
synced 2024-11-25 04:05:45 +01:00
commands: split ban function into common
This commit is contained in:
parent
b24c635c55
commit
791b306650
@ -1,29 +1,9 @@
|
||||
import state from '../state';
|
||||
import * as data from '../data';
|
||||
import logger from '../logging';
|
||||
import UserBan from '../models/UserBan';
|
||||
import { ban } from '../common';
|
||||
import discord = require('discord.js');
|
||||
|
||||
export const roles = ['Admins', 'Moderators', 'CitraBot'];
|
||||
export function command (message: discord.Message) {
|
||||
message.mentions.users.map((user) => {
|
||||
const count = state.warnings.filter(x => x.id === user.id && !x.cleared).length || 0;
|
||||
|
||||
logger.info(`${message.author.toString()} has banned ${user.toString()} ${user} ${user.username}.`);
|
||||
state.logChannel.send(`${message.author.toString()} has banned ${user} ${user.toString()} [${count}].`);
|
||||
|
||||
state.bans.push(new UserBan(user.id, user.username, message.author.id, message.author.username, count));
|
||||
let member = message.guild?.member(user);
|
||||
if (!member) {
|
||||
state.logChannel.send(`Error banning ${user} ${user.username}: user not found.`);
|
||||
logger.error(`User not found: ${user.toString()} ${user} ${user.username} when executing a ban`);
|
||||
// we don't need a return here, because of the optional chaining below
|
||||
}
|
||||
member?.ban().catch(function (error) {
|
||||
state.logChannel.send(`Error banning ${user.toString()} ${user.username}`);
|
||||
logger.error(`Error banning ${user.toString()} ${user} ${user.username}.`, error);
|
||||
});
|
||||
|
||||
data.flushBans();
|
||||
ban(user, message.author, message.guild);
|
||||
});
|
||||
};
|
||||
|
26
src/common.ts
Normal file
26
src/common.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import state from './state';
|
||||
import * as data from './data';
|
||||
import logger from './logging';
|
||||
import UserBan from './models/UserBan';
|
||||
import discord = require('discord.js');
|
||||
|
||||
export 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;
|
||||
|
||||
logger.info(`${moderator.toString()} has banned ${user.toString()} ${user} ${user.username}.`);
|
||||
state.logChannel.send(`${moderator.toString()} has banned ${user} ${user.toString()} [${count}].`);
|
||||
|
||||
state.bans.push(new UserBan(user.id, user.username, moderator.id, moderator.username, count));
|
||||
let member = guild?.member(user);
|
||||
if (!member) {
|
||||
state.logChannel.send(`Error banning ${user} ${user.username}: user not found.`);
|
||||
logger.error(`User not found: ${user.toString()} ${user} ${user.username} when executing a ban`);
|
||||
// we don't need a return here, because of the optional chaining below
|
||||
}
|
||||
member?.ban().catch(function (error) {
|
||||
state.logChannel.send(`Error banning ${user.toString()} ${user.username}`);
|
||||
logger.error(`Error banning ${user.toString()} ${user} ${user.username}.`, error);
|
||||
});
|
||||
|
||||
data.flushBans();
|
||||
}
|
Loading…
Reference in New Issue
Block a user