refactor: initial moves

This commit is contained in:
syntaxbullet
2026-01-08 16:09:26 +01:00
parent 53a2f1ff0c
commit 88b266f81b
164 changed files with 529 additions and 280 deletions

View File

@@ -0,0 +1,35 @@
import { Events } from "discord.js";
import type { Event } from "@shared/lib/types";
import { config } from "@lib/config";
import { userService } from "@shared/modules/user/user.service";
// Visitor role
const event: Event<Events.GuildMemberAdd> = {
name: Events.GuildMemberAdd,
execute: async (member) => {
console.log(`👤 New member joined: ${member.user.tag} (${member.id})`);
try {
const user = await userService.getUserById(member.id);
if (user && user.class) {
console.log(`🔄 Returning student detected: ${member.user.tag}`);
await member.roles.remove(config.visitorRole);
await member.roles.add(config.studentRole);
if (user.class.roleId) {
await member.roles.add(user.class.roleId);
console.log(`Restored class role ${user.class.name} to ${member.user.tag}`);
}
console.log(`Restored student role to ${member.user.tag}`);
} else {
await member.roles.add(config.visitorRole);
console.log(`Assigned visitor role to ${member.user.tag}`);
}
console.log(`User Roles: ${member.roles.cache.map(role => role.name).join(", ")}`);
} catch (error) {
console.error(`Failed to handle role assignment for ${member.user.tag}:`, error);
}
},
};
export default event;

View File

@@ -0,0 +1,22 @@
import { Events } from "discord.js";
import { ComponentInteractionHandler, AutocompleteHandler, CommandHandler } from "@/lib/handlers";
import type { Event } from "@shared/lib/types";
const event: Event<Events.InteractionCreate> = {
name: Events.InteractionCreate,
execute: async (interaction) => {
if (interaction.isButton() || interaction.isStringSelectMenu() || interaction.isModalSubmit()) {
return ComponentInteractionHandler.handle(interaction);
}
if (interaction.isAutocomplete()) {
return AutocompleteHandler.handle(interaction);
}
if (interaction.isChatInputCommand()) {
return CommandHandler.handle(interaction);
}
},
};
export default event;

View File

@@ -0,0 +1,22 @@
import { Events } from "discord.js";
import { userService } from "@shared/modules/user/user.service";
import { levelingService } from "@shared/modules/leveling/leveling.service";
import type { Event } from "@shared/lib/types";
const event: Event<Events.MessageCreate> = {
name: Events.MessageCreate,
execute: async (message) => {
if (message.author.bot) return;
if (!message.guild) return;
const user = await userService.getUserById(message.author.id);
if (!user) return;
levelingService.processChatXp(message.author.id);
// Activity Tracking for Lootdrops
import("@/modules/economy/lootdrop.service").then(m => m.lootdropService.processMessage(message));
},
};
export default event;

18
bot/events/ready.ts Normal file
View File

@@ -0,0 +1,18 @@
import { Events } from "discord.js";
import { schedulerService } from "@/modules/system/scheduler";
import type { Event } from "@shared/lib/types";
const event: Event<Events.ClientReady> = {
name: Events.ClientReady,
once: true,
execute: async (c) => {
console.log(`Ready! Logged in as ${c.user.tag}`);
schedulerService.start();
// Handle post-update tasks
const { UpdateService } = await import("@/modules/admin/update.service");
await UpdateService.handlePostRestart(c);
},
};
export default event;