Skip to content

Commit

Permalink
messageCreate: Add server infos in message content
Browse files Browse the repository at this point in the history
  • Loading branch information
Woomymy committed May 1, 2022
1 parent 529955d commit a048a89
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -e
DIR="$(realpath "$(dirname "${0}")")"

until PGPASSWORD="${POSTGRES_PASSWORD}" psql -h "${DB_HOST}" -U "${POSTGRES_USER}" -c '\q' 2>/dev/null
until PGPASSWORD="${POSTGRES_PASSWORD}" psql -h "${DB_HOST}" -U "${POSTGRES_USER}" -c '\q' "${POSTGRES_DB}" 2>/dev/null
do
echo "PostgreSQL is starting... Waiting"
sleep 1
Expand Down
23 changes: 16 additions & 7 deletions src/events/messageCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Prisma } from "@prisma/client";
import { Message, TextChannel } from "discord.js";
import { InterServerClient } from "../classes/Client";
import { EventData } from "../typings/index";
import { INTERSERVER_WH_NAME } from "../utils/constants.js";
import { INTERSERVER_WH_NAME, SERVERS_HEADERS } from "../utils/constants.js";

const data: EventData = {
name: "messageCreate",
Expand Down Expand Up @@ -36,15 +36,24 @@ const data: EventData = {
});
}

const lastMessage = (
await msg.channel.messages.fetch({ limit: 2 })
).last();

const whMessage = await webhook.send({
content:
msg.cleanContent.length == 0
? "​" // Invisible char
: msg.cleanContent,
username: `${msg.author.username} - ${msg.guild.name}`,
content: `${
lastMessage?.author.id === msg.author.id &&
lastMessage?.guildId === msg.guildId
? ""
: `***${
SERVERS_HEADERS[msg.guildId] ??
`❓ ${msg.guild.name}`
}***`
}\n${msg.content}`,
username: msg.author.username,
avatarURL: msg.author.avatarURL(),
embeds: msg.embeds,
allowedMentions: { parse: ["users"] },
allowedMentions: { parse: [] },
files: msg.attachments.map((attachement) => attachement.url)
});
clones.push({ channelId, id: whMessage.id });
Expand Down
11 changes: 11 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,14 @@
* Name of the interserver webhook
*/
export const INTERSERVER_WH_NAME = "FIIBOT_INTERSERVEUR";

/**
* Server emoji names map
*/
export enum SERVERS_HEADERS {
"622831434427662346" = "<:lpt:970386551945187338> LPT",
"696156347946762240" = "<:mim:970386612162797638> MIM",
"456901919344951298" = "<:cli:970386525906948106> CLI",
"706283053160464395" = "<:hub:970386593405894687> HUB",
"793993155343024160" = "<:hub:970386593405894687> TEST"
}

0 comments on commit a048a89

Please # to comment.