mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-05-18 21:34:13 +02:00
feat(arabot): add better checks for types for temp bans
This commit is contained in:
parent
e6b1463a1a
commit
62d941dfcb
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
import { ScheduledTask } from '@sapphire/plugin-scheduled-tasks';
|
import { ScheduledTask } from '@sapphire/plugin-scheduled-tasks';
|
||||||
import IDs from '#utils/ids';
|
import IDs from '#utils/ids';
|
||||||
import { TextChannel, EmbedBuilder } from 'discord.js';
|
import { EmbedBuilder } from 'discord.js';
|
||||||
import { checkBan } from '#utils/database/ban';
|
import { checkBan } from '#utils/database/ban';
|
||||||
import { checkTempBan, removeTempBan } from '#utils/database/tempBan';
|
import { checkTempBan, removeTempBan } from '#utils/database/tempBan';
|
||||||
|
|
||||||
@ -36,7 +36,9 @@ export class TempBan extends ScheduledTask {
|
|||||||
// Get the guild where the user is in
|
// Get the guild where the user is in
|
||||||
let guild = this.container.client.guilds.cache.get(payload.guildId);
|
let guild = this.container.client.guilds.cache.get(payload.guildId);
|
||||||
if (guild === undefined) {
|
if (guild === undefined) {
|
||||||
guild = await this.container.client.guilds.fetch(payload.guildId);
|
guild = await this.container.client.guilds
|
||||||
|
.fetch(payload.guildId)
|
||||||
|
.catch(() => undefined);
|
||||||
if (guild === undefined) {
|
if (guild === undefined) {
|
||||||
this.container.logger.error('Temp Unban Task: Guild not found!');
|
this.container.logger.error('Temp Unban Task: Guild not found!');
|
||||||
return;
|
return;
|
||||||
@ -48,7 +50,7 @@ export class TempBan extends ScheduledTask {
|
|||||||
let user = guild.client.users.cache.get(userId);
|
let user = guild.client.users.cache.get(userId);
|
||||||
|
|
||||||
if (user === undefined) {
|
if (user === undefined) {
|
||||||
user = await guild.client.users.fetch(userId);
|
user = await guild.client.users.fetch(userId).catch(() => undefined);
|
||||||
if (user === undefined) {
|
if (user === undefined) {
|
||||||
this.container.logger.error(
|
this.container.logger.error(
|
||||||
'Temp Unban Task: Could not fetch banned user!',
|
'Temp Unban Task: Could not fetch banned user!',
|
||||||
@ -70,20 +72,27 @@ export class TempBan extends ScheduledTask {
|
|||||||
await removeTempBan(userId);
|
await removeTempBan(userId);
|
||||||
|
|
||||||
// Log unban
|
// Log unban
|
||||||
let logChannel = guild.channels.cache.get(IDs.channels.logs.restricted) as
|
let logChannel = guild.channels.cache.get(IDs.channels.logs.restricted);
|
||||||
| TextChannel
|
|
||||||
| undefined;
|
|
||||||
|
|
||||||
if (logChannel === undefined) {
|
if (logChannel === undefined) {
|
||||||
logChannel = (await guild.channels.fetch(
|
const logChannelFetch = await guild.channels
|
||||||
IDs.channels.logs.restricted,
|
.fetch(IDs.channels.logs.restricted)
|
||||||
)) as TextChannel | undefined;
|
.catch(() => null);
|
||||||
if (logChannel === undefined) {
|
if (logChannelFetch === null) {
|
||||||
this.container.logger.error(
|
this.container.logger.error(
|
||||||
`Temp Ban Listener: Could not fetch log channel. User Snowflake: ${userId}`,
|
`Temp Ban Listener: Could not fetch log channel. User Snowflake: ${userId}`,
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logChannel = logChannelFetch;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!logChannel.isTextBased()) {
|
||||||
|
this.container.logger.error(
|
||||||
|
'Temp Ban Listener: Log channel is not a text based channel!',
|
||||||
|
);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const log = new EmbedBuilder()
|
const log = new EmbedBuilder()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user