Skip to content

Commit

Permalink
fix: remove tags from hubs
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-737 committed Oct 3, 2023
1 parent 54916bb commit 72b38ad
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 89 deletions.
1 change: 0 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ model hubs {
id String @id @default(auto()) @map("_id") @db.ObjectId
name String @unique
description String
tags String[]
rating HubRating[]
ownerId String
iconUrl String
Expand Down
28 changes: 20 additions & 8 deletions src/Events/messageCreate.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import checks from '../Scripts/message/checks';
import messageContentModifiers from '../Scripts/message/messageContentModifiers';
import cleanup from '../Scripts/message/cleanup';
import emojis from '../Utils/JSON/emoji.json';
import { APIMessage, ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, HexColorString, Message, User, WebhookClient, WebhookMessageCreateOptions } from 'discord.js';
import {
APIMessage,
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
EmbedBuilder,
HexColorString,
Message,
User,
WebhookClient,
WebhookMessageCreateOptions,
} from 'discord.js';
import { getDb } from '../Utils/utils';
import { censor } from '../Utils/wordFilter';
import { messageData } from '@prisma/client';
import { HubSettingsBitField } from '../Utils/hubSettingsBitfield';
import checks from '../Scripts/message/checks';
import cleanup from '../Scripts/message/cleanup';
import messageContentModifiers from '../Scripts/message/messageContentModifiers';
import emojis from '../Utils/JSON/emoji.json';


export interface NetworkMessage extends Message {
censored_content: string,
Expand Down Expand Up @@ -56,13 +68,13 @@ export default {
}
}

const useNicknames = settings.has('UseNicknames');
const useNicknameSetting = settings.has('UseNicknames');

// for nicknames setting
const displayNameOrUsername = useNicknames
const displayNameOrUsername = useNicknameSetting
? message.member?.displayName || message.author.displayName
: message.author.username;
const avatarURL = useNicknames
const avatarURL = useNicknameSetting
? message.member?.user.displayAvatarURL()
: message.author.displayAvatarURL();

Expand Down
13 changes: 1 addition & 12 deletions src/Scripts/hub/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@ export default {
.setStyle(TextInputStyle.Paragraph)
.setCustomId('description'),
),
new ActionRowBuilder<TextInputBuilder>().addComponents(
new TextInputBuilder()
.setLabel('Tags:')
.setPlaceholder('Seperated by commas. Eg. Gaming, Music, Fun')
.setMaxLength(100)
.setStyle(TextInputStyle.Short)
.setCustomId('tags'),
),
// new ActionRowBuilder<TextInputBuilder>().addComponents(
// new TextInputBuilder()
// .setLabel('Language')
Expand All @@ -90,20 +82,17 @@ export default {
interaction.awaitModalSubmit({ time: 60 * 5000 })
.then(async submitIntr => {
const description = submitIntr.fields.getTextInputValue('description');
const tags = submitIntr.fields.getTextInputValue('tags');

// FIXME: settings is a required field, add the fields to every collection
// in prod db before pushing it
await db.hubs.create({
data: {
name: hubName,
description,
private: true,
tags: tags.replaceAll(', ', ',').split(',', 5),
ownerId: submitIntr.user.id,
iconUrl: imgurIcons?.at(0) ?? interaction.client.user.displayAvatarURL(),
bannerUrl: imgurBanners?.[0],
settings: HubSettingsBits.SpamFilter,
settings: HubSettingsBits.SpamFilter | HubSettingsBits.Reactions,
},
});

Expand Down
61 changes: 0 additions & 61 deletions src/Scripts/hub/manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ export default {
description: 'Edit the hub description.',
emoji: '✏️',
},
{
label: 'Edit Tags',
value: 'tags',
description: 'Edit the hub tags.',
emoji: '🏷️',
},
{
label: 'Toggle Visibility',
value: 'visibility',
Expand Down Expand Up @@ -78,7 +72,6 @@ export default {
.setColor('Random')
.setDescription(stripIndents`
${hub.description}
- __**Tags:**__ ${hub.tags.join(', ')}
- __**Public:**__ ${hub.private ? emojis.normal.no : emojis.normal.yes}
`)
.setThumbnail(hub.iconUrl)
Expand Down Expand Up @@ -231,60 +224,6 @@ export default {
break;
}

case 'tags': {
const modal = new ModalBuilder()
.setCustomId(i.id)
.setTitle('Edit Hub Tags')
.addComponents(
new ActionRowBuilder<TextInputBuilder>().addComponents(
new TextInputBuilder()
.setLabel('Enter Tags')
.setPlaceholder('Seperate each tag with a comma.')
.setMaxLength(1024)
.setStyle(TextInputStyle.Paragraph)
.setCustomId('tags'),
),
);

await i.showModal(modal);

const modalResponse = await i.awaitModalSubmit({
filter: m => m.customId === modal.data.custom_id,
time: 60_000 * 5,
}).catch(e => {
if (!e.message.includes('ending with reason: time')) {
logger.error(e);
captureException(e, {
user: { id: i.user.id, username: i.user.username },
extra: { context: 'This happened when user tried to edit hub desc.' },
});
}
return null;
});

if (!modalResponse) return;

const newTags = modalResponse.fields.getTextInputValue('tags').trim();

if (newTags.length < 3 || newTags === '') {
await modalResponse.reply({
content: 'Invalid tags.',
ephemeral: true,
});
return;
}

await db.hubs.update({
where: { id: hubInDb?.id },
data: { tags: newTags.length > 1 ? newTags.replaceAll(', ', ',').split(',', 5) : [newTags] },
});
await modalResponse.reply({
content: 'Successfully updated tags!',
ephemeral: true,
});
break;
}

case 'banner': {
const modal = new ModalBuilder()
.setCustomId(i.id)
Expand Down
3 changes: 0 additions & 3 deletions src/Scripts/network/displaySettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,3 @@ export default {
});
},
};

// TODO: Hub leave command shows channel and now thread names in autocomplete
// TODO: channelId is no longer unique, either make it unique or fix the whole code
4 changes: 1 addition & 3 deletions src/Scripts/networkLogs/modActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@ interface unblacklistServer {
}

// TODO: Make the logs channel into a forum, which includes the folowing posts:
// Network Log
// Network Log - DONE
// Reports
// Judgement
// Make sure the logs channel isn't closed before logging stuff, that will be the main problem here.
// That is the reason I have left it as a todo. :D
export async function modActions(moderator: User, action: blacklistUser | unblacklistUser | blacklistServer | unblacklistServer | leaveServer | disconnectServer) {
const modLogs = await moderator.client.channels.fetch(constants.channel.modlogs);
const emoji = emojis.normal;
Expand Down
1 change: 0 additions & 1 deletion src/Utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ export function createHubListingsEmbed(hub: hubs, extra?: HubListingExtraInput)
### ${hub.name}
${hub.description}
**Tags:** ${hub.tags.join(', ')}
**Rating:** ${hub.rating?.length > 0 ? '⭐'.repeat(calculateAverageRating(hub.rating.map(hr => hr.rating))) : '-'}
**Connections:** ${extra?.connections ?? 'Unknown.'}
**Created At:** <t:${Math.round(hub.createdAt.getTime() / 1000)}:d>
Expand Down

0 comments on commit 72b38ad

Please sign in to comment.