Skip to content

Commit

Permalink
feat: Use hub name for non-compact webhook usernames (#20)
Browse files Browse the repository at this point in the history
Instead of having the username as "InterChat" it will now display the hub's name.
  • Loading branch information
dev-737 authored Aug 31, 2023
1 parent 26c4af0 commit c3ea336
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Events/messageCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ export default {
if (message.author.bot || message.webhookId || message.system) return;

const db = getDb();
const channelInDb = await db.connectedList.findFirst({ where: { channelId: message.channel.id } });
const channelInDb = await db.connectedList.findFirst({
where: { channelId: message.channel.id },
include: { hub: { include: { connections: true } } },
});

if (channelInDb?.connected) {
if (channelInDb?.connected && channelInDb.hub) {
if (!await checks.execute(message, channelInDb)) return;

message.censored_content = censor(message.content);
Expand Down Expand Up @@ -70,8 +73,7 @@ export default {
const censoredEmbed = EmbedBuilder.from(embed).setDescription(message.censored_content || null);

// send the message to all connected channels in apropriate format (compact/profanity filter)
const hubConnections = await db.connectedList.findMany({ where: { hubId: channelInDb.hubId, connected: true } });
const messageResults = hubConnections?.map(async (connection) => {
const messageResults = channelInDb.hub?.connections?.map(async (connection) => {
const reply = replyInDb?.channelAndMessageIds.find((msg) => msg.channelId === connection.channelId);
const replyLink = reply ? `https://discord.com/channels/${connection.serverId}/${reply.channelId}/${reply.messageId}` : undefined;
const replyButton = replyLink && referredAuthor
Expand Down Expand Up @@ -113,8 +115,8 @@ export default {
webhookMessage = {
components: replyButton ? [replyButton] : undefined,
embeds: [connection.profFilter ? censoredEmbed : embed],
username: message.client.user.username,
avatarURL: message.client.user.avatarURL() || undefined,
username: `${channelInDb.hub?.name}`,
avatarURL: channelInDb.hub?.iconUrl,
files: attachment ? [attachment] : [],
threadId: connection.parentId ? connection.channelId : undefined,
allowedMentions: { parse: [] },
Expand Down

0 comments on commit c3ea336

Please sign in to comment.