feat(arabot): add type checking to checkStaff command

This commit is contained in:
Anthony Berg 2024-01-04 12:40:24 +00:00
parent 750b10062f
commit a498cde933
3 changed files with 19 additions and 16 deletions

View File

@ -75,10 +75,9 @@ export class RestrictLogsCommand extends Command {
userId = user.id;
}
let staffChannel = false;
if (channel.type === ChannelType.GuildText) {
const staffChannel = checkStaff(channel);
if (staffChannel) {
channel = channel as TextChannel;
staffChannel = checkStaff(channel);
if (userId === null) {
let topic: string[];

View File

@ -20,14 +20,13 @@
import { RegisterBehavior, Args } from '@sapphire/framework';
import { Subcommand } from '@sapphire/plugin-subcommands';
import {
ChannelType,
EmbedBuilder,
ActionRowBuilder,
ButtonBuilder,
ButtonInteraction,
ButtonStyle,
} from 'discord.js';
import type { Message, GuildMember, TextChannel } from 'discord.js';
import type { Message, GuildMember } from 'discord.js';
import { isMessageInstance } from '@sapphire/discord.js-utilities';
import { addExistingUser } from '#utils/database/dbExistingUser';
import {
@ -43,7 +42,10 @@ import IDs from '#utils/ids';
// TODO add a check when they join the server to give the user the sus role again
export class SusCommand extends Subcommand {
public constructor(context: Subcommand.LoaderContext, options: Subcommand.Options) {
public constructor(
context: Subcommand.LoaderContext,
options: Subcommand.Options,
) {
super(context, {
...options,
name: 'sus',
@ -201,14 +203,7 @@ export class SusCommand extends Subcommand {
return;
}
let staffChannel = false;
let { channel } = interaction;
if (channel !== null) {
if (channel.type === ChannelType.GuildText) {
channel = channel as TextChannel;
staffChannel = checkStaff(channel);
}
}
const staffChannel = checkStaff(interaction.channel);
// Gets the sus notes from the database
const notes = await findNotes(user.id, true);

View File

@ -17,8 +17,9 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import type { TextChannel } from 'discord.js';
import type { TextBasedChannel } from 'discord.js';
import IDs from '#utils/ids';
import { ChannelType } from 'discord.js';
/**
* Checks if the channel is in the staff category.
@ -26,7 +27,15 @@ import IDs from '#utils/ids';
* @returns {boolean} true if is in staff channel
*/
export function checkStaff(channel: TextChannel) {
export function checkStaff(channel: TextBasedChannel | null) {
if (channel === null) {
return false;
}
if (channel.type !== ChannelType.GuildText) {
return false;
}
if (channel.parent === null) {
return false;
}