mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-11-07 03:39:49 +01:00
feat(arabot): add type checking to checkStaff command
This commit is contained in:
parent
750b10062f
commit
a498cde933
@ -75,10 +75,9 @@ export class RestrictLogsCommand extends Command {
|
|||||||
userId = user.id;
|
userId = user.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
let staffChannel = false;
|
const staffChannel = checkStaff(channel);
|
||||||
if (channel.type === ChannelType.GuildText) {
|
if (staffChannel) {
|
||||||
channel = channel as TextChannel;
|
channel = channel as TextChannel;
|
||||||
staffChannel = checkStaff(channel);
|
|
||||||
|
|
||||||
if (userId === null) {
|
if (userId === null) {
|
||||||
let topic: string[];
|
let topic: string[];
|
||||||
|
|||||||
@ -20,14 +20,13 @@
|
|||||||
import { RegisterBehavior, Args } from '@sapphire/framework';
|
import { RegisterBehavior, Args } from '@sapphire/framework';
|
||||||
import { Subcommand } from '@sapphire/plugin-subcommands';
|
import { Subcommand } from '@sapphire/plugin-subcommands';
|
||||||
import {
|
import {
|
||||||
ChannelType,
|
|
||||||
EmbedBuilder,
|
EmbedBuilder,
|
||||||
ActionRowBuilder,
|
ActionRowBuilder,
|
||||||
ButtonBuilder,
|
ButtonBuilder,
|
||||||
ButtonInteraction,
|
ButtonInteraction,
|
||||||
ButtonStyle,
|
ButtonStyle,
|
||||||
} from 'discord.js';
|
} 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 { isMessageInstance } from '@sapphire/discord.js-utilities';
|
||||||
import { addExistingUser } from '#utils/database/dbExistingUser';
|
import { addExistingUser } from '#utils/database/dbExistingUser';
|
||||||
import {
|
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
|
// TODO add a check when they join the server to give the user the sus role again
|
||||||
|
|
||||||
export class SusCommand extends Subcommand {
|
export class SusCommand extends Subcommand {
|
||||||
public constructor(context: Subcommand.LoaderContext, options: Subcommand.Options) {
|
public constructor(
|
||||||
|
context: Subcommand.LoaderContext,
|
||||||
|
options: Subcommand.Options,
|
||||||
|
) {
|
||||||
super(context, {
|
super(context, {
|
||||||
...options,
|
...options,
|
||||||
name: 'sus',
|
name: 'sus',
|
||||||
@ -201,14 +203,7 @@ export class SusCommand extends Subcommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let staffChannel = false;
|
const staffChannel = checkStaff(interaction.channel);
|
||||||
let { channel } = interaction;
|
|
||||||
if (channel !== null) {
|
|
||||||
if (channel.type === ChannelType.GuildText) {
|
|
||||||
channel = channel as TextChannel;
|
|
||||||
staffChannel = checkStaff(channel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gets the sus notes from the database
|
// Gets the sus notes from the database
|
||||||
const notes = await findNotes(user.id, true);
|
const notes = await findNotes(user.id, true);
|
||||||
|
|||||||
@ -17,8 +17,9 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
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 IDs from '#utils/ids';
|
||||||
|
import { ChannelType } from 'discord.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the channel is in the staff category.
|
* 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
|
* @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) {
|
if (channel.parent === null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user