Skip to content

Commit d6a1559

Browse files
committed
refactor: new webhook system
1 parent d8a0acf commit d6a1559

File tree

10 files changed

+94
-1022
lines changed

10 files changed

+94
-1022
lines changed

package-lock.json

Lines changed: 1 addition & 909 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
"license": "MIT",
1616
"dependencies": {
1717
"discord.js": "^14.19.3",
18-
"dotenv": "^16.5.0",
19-
"express": "^5.1.0"
18+
"dotenv": "^16.5.0"
2019
},
2120
"devDependencies": {
22-
"@types/express": "^5.0.3",
2321
"@types/node": "^20.0.0",
2422
"prettier": "^3.5.3",
2523
"tsx": "^4.19.4",

src/commands/checklink.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export async function execute(
106106
if (!interaction.guild) {
107107
await interaction.reply({
108108
content:
109-
"**THIS SACRED RITE CAN ONLY BE PERFORMED WITHIN THE GUILD HALLS!**",
109+
"**THIS SACRED RITE CAN ONLY BE PERFORMED WITHIN THE SACRED HALLS!**",
110110
flags: MessageFlags.Ephemeral,
111111
});
112112
return;

src/commands/link.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export async function execute(
117117
if (!interaction.guild) {
118118
await interaction.reply({
119119
content:
120-
"**THIS SACRED RITE CAN ONLY BE PERFORMED WITHIN THE GUILD HALLS!**",
120+
"**THIS SACRED RITE CAN ONLY BE PERFORMED WITHIN THE SACRED HALLS!**",
121121
flags: MessageFlags.Ephemeral,
122122
});
123123
return;

src/commands/removelink.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export async function execute(
2525
if (!interaction.guild) {
2626
await interaction.reply({
2727
content:
28-
"**THIS SACRED RITE CAN ONLY BE PERFORMED WITHIN THE GUILD HALLS!**",
28+
"**THIS SACRED RITE CAN ONLY BE PERFORMED WITHIN THE SACRED HALLS!**",
2929
flags: MessageFlags.Ephemeral,
3030
});
3131
return;

src/commands/synctop5.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import {
2+
ChatInputCommandInteraction,
3+
SlashCommandBuilder,
4+
EmbedBuilder,
5+
MessageFlags,
6+
GuildMember,
7+
} from "discord.js";
8+
import { TopContributorsManager } from "../utils/topContributors.js";
9+
import { RolePermissions } from "../utils/rolePermissions.js";
10+
11+
export const data = new SlashCommandBuilder()
12+
.setName("synctop5")
13+
.setDescription("SYNCHRONIZE THE TOP 5 CONTRIBUTORS ROLES WITH THE RANKINGS");
14+
15+
export async function execute(
16+
interaction: ChatInputCommandInteraction,
17+
): Promise<void> {
18+
if (!interaction.guild) {
19+
await interaction.reply({
20+
content: "**THIS SACRED RITE CAN ONLY BE PERFORMED WITHIN THE SACRED HALLS!**",
21+
flags: MessageFlags.Ephemeral,
22+
});
23+
return;
24+
}
25+
26+
if (!RolePermissions.hasCommandPermission(interaction.member as GuildMember, "synctop5")) {
27+
await interaction.reply({
28+
content: RolePermissions.getPermissionErrorMessage("synctop5"),
29+
flags: MessageFlags.Ephemeral,
30+
});
31+
return;
32+
}
33+
34+
try {
35+
await interaction.deferReply();
36+
37+
console.log('📊 Manual top contributor sync requested by', interaction.user.tag);
38+
39+
const result = await TopContributorsManager.syncAllTopContributorRoles(interaction.guild);
40+
41+
const embed = new EmbedBuilder()
42+
.setColor(result.errors.length > 0 ? "#FFA500" : "#00FF00")
43+
.setTitle("🏆 TOP CONTRIBUTORS SYNCHRONIZATION COMPLETE")
44+
.setDescription("**THE RANKINGS HAVE BEEN SYNCHRONIZED WITH THE DIVINE ROLES!**")
45+
.addFields(
46+
{
47+
name: "📊 SYNCHRONIZATION STATISTICS",
48+
value: [
49+
`**Linked Users Processed**: ${result.processed}`,
50+
`**Roles Granted**: ${result.rolesGranted}`,
51+
`**Roles Removed**: ${result.rolesRemoved}`,
52+
`**Errors Encountered**: ${result.errors.length}`
53+
].join('\n'),
54+
inline: false,
55+
}
56+
)
57+
.setTimestamp();
58+
59+
if (result.errors.length > 0) {
60+
const errorSample = result.errors.slice(0, 3).join('\n');
61+
const additionalErrors = result.errors.length > 3 ? `\n... and ${result.errors.length - 3} more errors` : '';
62+
63+
embed.addFields({
64+
name: "⚠️ ERRORS ENCOUNTERED",
65+
value: `\`\`\`${errorSample}${additionalErrors}\`\`\``,
66+
inline: false,
67+
});
68+
}
69+
70+
if (result.rolesGranted === 0 && result.rolesRemoved === 0 && result.errors.length === 0) {
71+
embed.addFields({
72+
name: "ℹ️ STATUS",
73+
value: "All top contributor roles were already properly synchronized. No changes were needed.",
74+
inline: false,
75+
});
76+
}
77+
78+
await interaction.editReply({ embeds: [embed] });
79+
80+
} catch (error) {
81+
console.error("Error during manual top contributor sync:", error);
82+
await interaction.editReply({
83+
content: "**A DISTURBANCE IN THE SACRED HALLS! The synchronization ritual failed. The oracles are perplexed. Try again later, or consult the high scribes.**",
84+
});
85+
}
86+
}

src/index.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,12 @@ import {
2121
import { loadCommands, Command } from "./utils/commandLoader.js";
2222
import { ReactionRoleHandler } from "./utils/reactionRoleHandler.js";
2323
import { RolePermissions } from "./utils/rolePermissions.js";
24-
import { WebhookServer } from "./utils/webhookServer.js";
2524

2625
class AltershaperBot {
2726
private client: Client;
2827
private readonly BOT_TOKEN = process.env.DISCORD_TOKEN;
2928
private readonly WELCOME_CHANNEL_ID = "1366495690796040315";
30-
private readonly GUILD_ID = process.env.GUILD_ID;
3129
private commands: Collection<string, Command>;
32-
private webhookServer?: WebhookServer;
3330

3431
constructor() {
3532
this.client = new Client({
@@ -55,18 +52,6 @@ class AltershaperBot {
5552
this.client.user?.setActivity("ALTER EGOISTS", { type: 3 });
5653
await this.registerSlashCommands();
5754
await ReactionRoleHandler.initialize(this.client);
58-
59-
if (this.GUILD_ID) {
60-
const guild = this.client.guilds.cache.get(this.GUILD_ID);
61-
if (guild) {
62-
this.webhookServer = new WebhookServer(guild);
63-
this.webhookServer.start();
64-
} else {
65-
console.warn("⚠️ Guild not found, webhook server not started");
66-
}
67-
} else {
68-
console.warn("⚠️ GUILD_ID not set, webhook server not started");
69-
}
7055
});
7156

7257
this.client.on("interactionCreate", this.handleInteraction.bind(this));
@@ -245,14 +230,12 @@ class AltershaperBot {
245230
// Graceful shutdown
246231
process.on("SIGINT", () => {
247232
console.log("🛑 Shutting down gracefully...");
248-
this.webhookServer?.stop();
249233
this.client.destroy();
250234
process.exit(0);
251235
});
252236

253237
process.on("SIGTERM", () => {
254238
console.log("🛑 Shutting down gracefully...");
255-
this.webhookServer?.stop();
256239
this.client.destroy();
257240
process.exit(0);
258241
});

src/utils/commandLoader.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import * as info from "../commands/info.js";
1313
import * as link from "../commands/link.js";
1414
import * as unlink from "../commands/removelink.js";
1515
import * as checklink from "../commands/checklink.js";
16+
import * as synctop5 from "../commands/synctop5.js";
1617

1718
export interface Command {
1819
data: any;
@@ -37,6 +38,7 @@ export function loadCommands(): Collection<string, Command> {
3738
link,
3839
unlink,
3940
checklink,
41+
synctop5,
4042
];
4143

4244
for (const command of commandModules) {

src/utils/rolePermissions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const COMMAND_PERMISSIONS: Record<string, PermissionLevel> = {
2020
clear: PermissionLevel.MODERATOR,
2121
archives: PermissionLevel.MODERATOR,
2222
sins: PermissionLevel.MODERATOR,
23+
synctop5: PermissionLevel.MODERATOR,
2324

2425
// Basic
2526
help: PermissionLevel.BASIC,

src/utils/webhookServer.ts

Lines changed: 0 additions & 90 deletions
This file was deleted.

0 commit comments

Comments
 (0)