This commit is contained in:
mo
2026-03-09 07:48:08 +01:00
parent 5271665963
commit dfb8b2781d
6 changed files with 191 additions and 127 deletions

View File

@@ -1,12 +1,70 @@
import { CommandKeys } from "@avocadi/bot-core/entities/commands/commands.schema";
import { config } from "config";
import type { Message } from "discord.js";
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.channel.id !== config.channelMapping.text.log &&
message.channel.id !== config.channelMapping.text.bot
) {
messagesService.logMessage(message);
if (message.content?.startsWith(config.commandPrefix) && message.channel) {
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.`);
await handleCommand(result.data, parameters, message.channel.id);
}
}
});
async function resolveModContext(message: Message) {
const guild = message.guild;
if (!guild) {
logger.error(`Guild not found for message ${message.id}.`);
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}.`);
return;
}
const member = await guild.members.fetch(message.author.id);
if (!member) {
logger.error(
`User with ID ${message.author.id} not found in guild ${guild.name}.`,
);
throw new Error("User not found");
}
if (!member.roles.cache.has(roleMod.id)) {
return;
}
throw new Error("Function not implemented.");
}
function handleCommand(data: string, parameters: string[], id: string) {
throw new Error("Function not implemented.");
}

View File

@@ -20,7 +20,7 @@ export const handleDynamicVoiceChannelCreation = async (
// New channel is created if user joined one of the specific channels (e.g. "Join to Create") or switched to one of them
const newChannel =
await dynamicVoiceChannelService.createDynamicVoiceChannel(channel.id);
logger.debug(`Channel found for VoiceStateUpdate event: ${channel.name}`);
if (newChannel) {
await newState.setChannel(newChannel);
}

View File

@@ -13,6 +13,7 @@ export const handleDynamicVoiceChannelDeletion = async (
if (dynamicVoiceChannelService.createdChannelIdsSet.has(channelId)) {
const channel = await voiceChannelsService.getVoiceChannelById(channelId);
if (!channel) return;
if (channel.members.size === 0) {
await dynamicVoiceChannelService.deleteDynamicVoiceChannel(channelId);
}

View File

@@ -6,7 +6,12 @@ import client from "lib/client";
import { logger } from "lib/common-logger";
import { handleCommand } from "./handle-command";
// https://fluxerjs.blstmo.com/v/latest/docs/classes/DMChannel
client.on(Events.MessageCreate, async (message: Message) => {
const messageAuthor = message.author;
const messageReceiver = message.type;
logger.info("got msg");
if (message.content?.startsWith(config.commandPrefix) && message.channel) {
await messagesService.logMessage(message);
logger.info(