Skip to content

Commit

Permalink
refactor(hub): move setHubLogChannel() to `<HubLoggerService>.setLo…
Browse files Browse the repository at this point in the history
…gChannelFor()`
  • Loading branch information
dev-737 committed Jan 22, 2024
1 parent bdee91c commit 6fe2592
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
5 changes: 3 additions & 2 deletions src/commands/slash/Main/hub/manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import { buildSettingsEmbed, buildSettingsMenu } from '../../../../scripts/hub/s
import { HubSettingsBitField, HubSettingsString } from '../../../../utils/BitFields.js';
import { checkAndFetchImgurUrl, simpleEmbed, setComponentExpiry } from '../../../../utils/Utils.js';
import { actionsSelect, hubEmbed } from '../../../../scripts/hub/manage.js';
import { genLogInfoEmbed, setHubLogChannel } from '../../../../scripts/hub/logs.js';
import { genLogInfoEmbed } from '../../../../scripts/hub/logs.js';
import HubLoggerService from '../../../../services/HubLoggerService.js';

export default class Manage extends Hub {
async execute(interaction: ChatInputCommandInteraction) {
Expand Down Expand Up @@ -505,7 +506,7 @@ export default class Manage extends Hub {
const channel = interaction.channels.first();

// set the channel in the db
await setHubLogChannel(hubInDb.id, type, channelId);
await HubLoggerService.setLogChannelFor(hubInDb.id, type, channelId);

// update the old embed with new channel value
const embed = interaction.message.embeds[0].toJSON();
Expand Down
25 changes: 0 additions & 25 deletions src/scripts/hub/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { colors, emojis } from '../../utils/Constants.js';
import { stripIndents } from 'common-tags';
import { channelMention } from '../../utils/Utils.js';
import { t } from '../../utils/Locale.js';
import db from '../../utils/Db.js';
import SuperClient from '../../SuperClient.js';

/*
for later:
Expand Down Expand Up @@ -48,26 +46,3 @@ export const genLogInfoEmbed = (hubInDb: hubs, locale = 'en') => {
text: 'Note: This feature is still experimental. Report bugs using /support report.',
});
};

export const setHubLogChannel = async (
hubId: string,
type: keyof Prisma.HubLogChannelsCreateInput,
channelId: string,
) => {
if (type === 'reports') {
await SuperClient.getInstance().reportLogger.setChannelId(hubId, channelId);
return;
}

await db.hubs.update({
where: { id: hubId },
data: {
logChannels: {
upsert: {
set: { [type]: channelId },
update: { [type]: channelId },
},
},
},
});
};
26 changes: 25 additions & 1 deletion src/services/HubLoggerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import {
import { emojis, colors } from '../utils/Constants.js';
import { toTitleCase } from '../utils/Utils.js';
import BlacklistManager from '../managers/BlacklistManager.js';
import { hubs } from '@prisma/client';
import { Prisma, hubs } from '@prisma/client';
import Factory from '../Factory.js';
import SuperClient from '../SuperClient.js';

export type ReportEvidenceOpts = {
// the message content
Expand All @@ -34,6 +35,29 @@ export default class HubLoggerService extends Factory {
return await db.hubs.findFirst({ where: { id } });
}

static async setLogChannelFor(
hubId: string,
type: keyof Prisma.HubLogChannelsCreateInput,
channelId: string,
) {
if (type === 'reports') {
await SuperClient.getInstance().reportLogger.setChannelId(hubId, channelId);
return;
}

return await db.hubs.update({
where: { id: hubId },
data: {
logChannels: {
upsert: {
set: { [type]: channelId },
update: { [type]: channelId },
},
},
},
});
}

/**
* Sends a log message to the specified channel with the provided embed.
* @param channelId The ID of the channel to send the log message to.
Expand Down

0 comments on commit 6fe2592

Please sign in to comment.