dm forwarding discord and fluxer implementation

This commit is contained in:
mo
2026-03-10 14:52:58 +01:00
parent 330aabd928
commit fc8f90a4bc
3 changed files with 100 additions and 82 deletions

View File

@@ -26,22 +26,23 @@ export class MessagesService
}
async logMessage(message: Message): Promise<void> {
let recipient: User | null = null;
if (
message.channel.isDMBased() &&
message.channel.type !== ChannelType.GroupDM
) {
const channel = message.channel as DMChannel | PartialDMChannel;
!(
message.channel.isDMBased() &&
message.channel.type !== ChannelType.GroupDM
)
)
return;
const channel = message.channel as DMChannel | PartialDMChannel;
const recipient = channel.recipient?.id;
recipient = channel.recipient;
}
let logMessage: string;
if (recipient) {
logMessage = `<@${message.author.id}> sent a message to <@${recipient.id}>:\n"${message.content}"`;
if (message.author.bot) {
logMessage = `<@${message.author.id}> hat an <@${recipient}> geschrieben:\n"${message.content}"`;
} else {
logMessage = `<@${message.author.id}> sent a message:\n"${message.content}"`;
logMessage = `<@${message.author.id}> hat geschrieben:\n"${message.content}"`;
}
await logChannelService.sendLogMessage(logMessage);

View File

@@ -5,39 +5,46 @@ import { messagesService } from "entities/messages/messages.service";
import client from "lib/client";
import { logger } from "lib/common-logger";
client.on("messageCreate", async (message) => {
if (message.content?.startsWith(config.commandPrefix) && message.channel) {
if (!resolveModContext(message)) return;
client.on("messageCreate", async (message: Message) => {
if (message.channel.isDMBased()) {
await messagesService.logMessage(message);
logger.info(
`Command received: ${message.content} from user ${message.author.id}`,
);
}
const commandWithoutPrefix = message.content
.slice(config.commandPrefix.length)
.trim();
const commandParts = commandWithoutPrefix.split(" ");
if (commandParts.length === 0) {
logger.warn("No command found after prefix.");
return;
}
const [command, ...parameters] = commandParts;
logger.info(`Parsed command: ${command}`);
const result = CommandKeys.safeParse(command);
if (result.success) {
logger.info(`Command ${command} recognized.`);
await handleCommand(result.data, parameters, message.channel.id);
}
if (message.content?.startsWith(config.commandPrefix) && message.channel) {
await recognizedCommand(message);
}
});
async function recognizedCommand(message: Message) {
if (!resolveModContext(message)) return;
await messagesService.logMessage(message);
logger.info(
`Command received: ${message.content} from user ${message.author.id}`,
);
const commandWithoutPrefix = message.content
.slice(config.commandPrefix.length)
.trim();
const commandParts = commandWithoutPrefix.split(" ");
if (commandParts.length === 0) {
logger.warn("No command found after prefix.");
return;
}
const [command, ...parameters] = commandParts;
logger.info(`Parsed command: ${command}`);
const result = CommandKeys.safeParse(command);
if (result.success) {
logger.info(`Command ${command} recognized.`);
handleCommand(result.data, parameters, message.channel.id);
}
}
async function resolveModContext(message: Message) {
const guild = message.guild;
if (!guild) {
@@ -45,9 +52,6 @@ async function resolveModContext(message: Message) {
return;
}
const roleMod = guild.roles.cache.get(config.roleMapping.mod);
// const roleMod = guild.roles.cache.find(
// (r) => r.name === config.roleMapping.mod,
// );
if (!roleMod) {
logger.error(`Role ${roleMod} not found in guild ${guild.name}.`);