wip
This commit is contained in:
@@ -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.");
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import { Commands, type CommandsType } from "commands/index.ts";
|
||||
import config from "config";
|
||||
import client from "lib/client";
|
||||
import { getRandomInt } from "lib/utils";
|
||||
import { customContent, createEmbed } from "./customMessage.components.ts";
|
||||
import {
|
||||
type CacheType,
|
||||
ChannelType,
|
||||
type ChatInputCommandInteraction,
|
||||
Client,
|
||||
EmbedBuilder,
|
||||
type Message,
|
||||
type CacheType,
|
||||
type GuildMember,
|
||||
type Interaction,
|
||||
type Message,
|
||||
type OmitPartialGroupDMChannel,
|
||||
type ChatInputCommandInteraction,
|
||||
ChannelType,
|
||||
} from "discord.js";
|
||||
import { type CommandsType, Commands } from "commands/index.ts";
|
||||
import { time } from "drizzle-orm/mysql-core";
|
||||
import client from "lib/client";
|
||||
import { getRandomInt } from "lib/utils";
|
||||
import { createEmbed, customContent } from "./customMessage.components.ts";
|
||||
|
||||
export class CustomMessageService {
|
||||
async handleInteraction(interaction: Interaction<CacheType>) {
|
||||
@@ -75,7 +75,10 @@ export class CustomMessageService {
|
||||
|
||||
// permission check
|
||||
// permission check
|
||||
if (await this.checkPermission(interaction) && await this.checkIfServer(interaction))
|
||||
if (
|
||||
(await this.checkPermission(interaction)) &&
|
||||
(await this.checkIfServer(interaction))
|
||||
)
|
||||
try {
|
||||
const channels = client.channels;
|
||||
const channel = channels.cache.get(interaction.channelId);
|
||||
@@ -92,8 +95,7 @@ export class CustomMessageService {
|
||||
} catch (error) {
|
||||
console.error("error while creating embed:", error);
|
||||
await interaction.reply({
|
||||
content:
|
||||
"error while creating embed",
|
||||
content: "error while creating embed",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
@@ -107,7 +109,10 @@ export class CustomMessageService {
|
||||
console.log(input);
|
||||
|
||||
// permission check && server check
|
||||
if (await this.checkPermission(interaction) && await this.checkIfServer(interaction))
|
||||
if (
|
||||
(await this.checkPermission(interaction)) &&
|
||||
(await this.checkIfServer(interaction))
|
||||
)
|
||||
try {
|
||||
const channels = client.channels;
|
||||
const channel = channels.cache.get(interaction.channelId);
|
||||
@@ -124,8 +129,7 @@ export class CustomMessageService {
|
||||
} catch (error) {
|
||||
console.error("error while creating message:", error);
|
||||
await interaction.reply({
|
||||
content:
|
||||
"error while creating message",
|
||||
content: "error while creating message",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -22,10 +22,6 @@ export class AcceptUserService<U extends BaseUser = BaseUser> {
|
||||
}
|
||||
|
||||
async sendDmAcceptUser(user: U) {
|
||||
this.logger.info("test");
|
||||
|
||||
this.logger.info(`accepting ${user.id}...`);
|
||||
|
||||
const acceptUserMessage: string = await this.i18nService.t(
|
||||
"dmAcceptUser",
|
||||
this.lang,
|
||||
|
||||
Reference in New Issue
Block a user