Skip to content

Commit

Permalink
fix(blacklist): interchat mods can now unblacklist other hubs
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-737 committed Jun 9, 2024
1 parent ac7b91b commit 8b6689d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/commands/context-menu/blacklist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class Blacklist extends BaseCommand {

const isStaffOrHubMod = checkIfStaff(interaction.user.id) || isHubMod;

if (!messageInDb || (!isStaffOrHubMod && !checkIfStaff(interaction.user.id))) {
if (!messageInDb || !isStaffOrHubMod) {
await interaction.reply({
embeds: [
simpleEmbed(
Expand Down
18 changes: 7 additions & 11 deletions src/commands/slash/Main/blacklist/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { captureException } from '@sentry/node';
import { ChatInputCommandInteraction, EmbedBuilder, time } from 'discord.js';
import { simpleEmbed } from '../../../../utils/Utils.js';
import { checkIfStaff, simpleEmbed } from '../../../../utils/Utils.js';
import { emojis } from '../../../../utils/Constants.js';
import db from '../../../../utils/Db.js';
import BlacklistCommand from './index.js';
Expand All @@ -17,18 +17,14 @@ export default class UserBlacklist extends BlacklistCommand {
await interaction.deferReply();

const hub = interaction.options.getString('hub', true);
const hubInDb = await db.hubs.findFirst({ where: { name: hub } });

const hubInDb = await db.hubs.findFirst({
where: {
name: hub,
OR: [
{ ownerId: interaction.user.id },
{ moderators: { some: { userId: interaction.user.id } } },
],
},
});
const isStaffOrHubMod =
hubInDb?.ownerId === interaction.user.id ||
hubInDb?.moderators.find((mod) => mod.userId === interaction.user.id) ||
checkIfStaff(interaction.user.id);

if (!hubInDb) {
if (!hubInDb || !isStaffOrHubMod) {
await interaction.editReply({
embeds: [
simpleEmbed(
Expand Down
19 changes: 8 additions & 11 deletions src/commands/slash/Main/blacklist/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import BlacklistCommand from './index.js';
import BlacklistManager from '../../../../managers/BlacklistManager.js';
import parse from 'parse-duration';
import { emojis } from '../../../../utils/Constants.js';
import { simpleEmbed } from '../../../../utils/Utils.js';
import { checkIfStaff, simpleEmbed } from '../../../../utils/Utils.js';
import { t } from '../../../../utils/Locale.js';
import Logger from '../../../../utils/Logger.js';
import { logBlacklist, logUnblacklist } from '../../../../utils/HubLogger/ModLogs.js';
Expand All @@ -14,18 +14,15 @@ export default class Server extends BlacklistCommand {
await interaction.deferReply();

const hub = interaction.options.getString('hub', true);
const hubInDb = await db.hubs.findFirst({ where: { name: hub } });

const hubInDb = await db.hubs.findFirst({
where: {
name: hub,
OR: [
{ ownerId: interaction.user.id },
{ moderators: { some: { userId: interaction.user.id } } },
],
},
});
const isStaffOrHubMod =
hubInDb?.ownerId === interaction.user.id ||
hubInDb?.moderators.find((mod) => mod.userId === interaction.user.id) ||
checkIfStaff(interaction.user.id);
console.log(isStaffOrHubMod);

if (!hubInDb) {
if (!hubInDb || !isStaffOrHubMod) {
await interaction.editReply({
embeds: [
simpleEmbed(
Expand Down

0 comments on commit 8b6689d

Please sign in to comment.