dm forwarding discord and fluxer implementation
This commit is contained in:
@@ -1,13 +1,7 @@
|
||||
import { CommandKeys } from "@avocadi/bot-core/entities/commands/commands.schema";
|
||||
import {
|
||||
ChannelManager,
|
||||
type DMChannel,
|
||||
Events,
|
||||
type Message,
|
||||
} from "@fluxerjs/core";
|
||||
import { type Channel, Events, type Message } from "@fluxerjs/core";
|
||||
import { config } from "config";
|
||||
import { messagesService } from "entities/messages/messages.service";
|
||||
import { logChannelService } from "features/log-channel/log-channel.service";
|
||||
import client from "lib/client";
|
||||
import { logger } from "lib/common-logger";
|
||||
import { handleCommand } from "./handle-command";
|
||||
@@ -18,41 +12,60 @@ client.on(Events.MessageCreate, async (message: Message) => {
|
||||
const channel =
|
||||
client.channels.get(message.channelId) ??
|
||||
(await client.channels.fetch(message.channelId));
|
||||
const messageAuthor = message.author;
|
||||
if (channel?.isDM()) {
|
||||
await logChannelService.sendLogMessage(
|
||||
`<@${messageAuthor?.id}> wrote to <@${client.user?.id}>\n"${message.content}"`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (message.content?.startsWith(config.commandPrefix) && channel) {
|
||||
await messagesService.logMessage(message);
|
||||
logger.info(
|
||||
`Command received: ${message.content} from user ${message.author.id}`,
|
||||
);
|
||||
//await forward(message /*, channel as DMChannel*/);
|
||||
}
|
||||
|
||||
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} is valid.`);
|
||||
await handleCommand(result.data, parameters, message.channel.id);
|
||||
} else {
|
||||
logger.warn(`Command ${command} is not recognized.`);
|
||||
}
|
||||
if (message.content?.startsWith(config.commandPrefix) && channel) {
|
||||
await recognizedCommand(message, channel);
|
||||
}
|
||||
});
|
||||
|
||||
//async function forward(message: Message /*, channel: DMChannel*/) {
|
||||
// const author = message.author;
|
||||
// console.log(`forward message from ${author.username}`);
|
||||
// let context: string;
|
||||
|
||||
// getting the recipient is currently not supported in fluxer.js
|
||||
/*if (message.author.bot) {
|
||||
const channelId = channel.id;
|
||||
const recipient = channel.recipients[0]?.id;
|
||||
context = `<@${author}> hat an <@${recipient}> geschrieben:\n"${message.content}"`;
|
||||
} else {*/
|
||||
//context = `<@${author.id}> wrote:\n"${message.content}"`;
|
||||
//}
|
||||
|
||||
//await logChannelService.sendLogMessage(context);
|
||||
// `<@${messageAuthor?.id}> wrote to <@${client.user?.id}>\n"${message.content}"`,
|
||||
//}
|
||||
|
||||
async function recognizedCommand(message: Message, channel: Channel) {
|
||||
if (!channel) 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.`);
|
||||
await handleCommand(result.data, parameters, channel.id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user