Skip to content

Commit

Permalink
use tsx to run bot
Browse files Browse the repository at this point in the history
  • Loading branch information
clementvt committed Dec 30, 2024
1 parent 54d7ded commit 6de607c
Show file tree
Hide file tree
Showing 14 changed files with 134 additions and 75 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build
.sentryclirc
# Logs
logs
Expand Down
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@
"main": "dist/index.js",
"license": "MIT",
"type": "module",

"scripts": {
"ts": "yarn add typescript --save-dev -g",
"init": "yarn",
"lint": "eslint src --fix",
"start": "node dist/index.js",
"build": "tsc --build",
"watch": "tsc --watch",
"rebuild": "yarn build && yarn start",
"start": "npx tsx ./src/index.ts",
"updates": "yarn upgrade --latest"
},
"devDependencies": {
Expand All @@ -23,6 +19,7 @@
"nodemon": "^3.1.9",
"pkgroll": "^2.6.0",
"ts-node": "^10.9.2",
"tsc-watch": "^6.2.1",
"tsx": "^4.19.2",
"typescript": "^5.7.2",
"typescript-eslint": "^8.18.2"
Expand Down
4 changes: 2 additions & 2 deletions src/commands/admin/leaveGuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { sendInteractionMessage } from "../../utils/messages";


export default class LeaveGuild implements CommandType {
name = "leavegGuild";
name = "leavegguild";
description = "Leave the given guid id in the parameter.";
admin = true;
data = new SlashCommandBuilder()
.setName("leaveguild")
.setName(this.name)
.setDescription(this.description)
.addStringOption((option) =>
option.setName("guild_id")
Expand Down
9 changes: 7 additions & 2 deletions src/commands/admin/reloadCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default class reloadCommands implements CommandType {
name = "reloadcommands";
description = "Reload all commands on all clusters";
admin = true;
noDefer?: boolean | undefined = true;
data = new SlashCommandBuilder()
.setName(this.name)
.setDescription(this.description);
Expand All @@ -27,6 +26,12 @@ export default class reloadCommands implements CommandType {
});
await client.cluster.broadcastEval(async (c) => {
await c.loadCommands();
});
}).then(() => {
sendInteractionMessage(interaction, {
content: "Commands reloaded on all clusters!",
ephemeral: true,
});
}
);
}
}
2 changes: 1 addition & 1 deletion src/commands/info/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class implements CommandType {
name = "config";
description = "Configure the bot";
data = new SlashCommandBuilder()
.setName("config")
.setName(this.name)
.setDescription(this.description);
async execute(interaction: ChatInputCommandInteraction): Promise<void> {
const embed = new EmbedBuilder()
Expand Down
5 changes: 1 addition & 4 deletions src/events/client/ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,16 @@ export default class ReadyEvent implements EventType {
const message = messages[Math.floor(Math.random() * messages.length)]!;
client.user?.setActivity(message, { type: ActivityType.Watching });
}

if (client.cluster.id === 0) {
await waitForManager(client);
for (const command of client.commands.values()) {
if (command.type !== ApplicationCommandType.ChatInput) continue;
command.contexts = [0];
command.dmPermission = false;


}
await client.application?.commands.set([...client.commands.values()]).then(async (commandsData) => {
console.log("Commands registered!");
console.log(commandsData);
// console.log(commandsData);
})
}

Expand Down
1 change: 1 addition & 0 deletions src/events/shard/shardReady.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default class ShardReady implements EventType {
once = true;
async execute(shardId: number, client: WelcomerClient) {
if (!shardId) return;
console.log(`Shard ${shardId} is ready`);
client.logger.shardStatus(shardId, "ready");
}
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const hearthbeatConfig: keepAliveOptions = {
maxMissedHeartbeats: 5,
}

const clientPath = `${__dirname}/client.js`
const clientPath = `./src/client.ts`
const manager = new ClusterManager(clientPath, managerConfig);
manager.extend(new HeartbeatManager(hearthbeatConfig))
manager.extend(new ReClusterManager());
Expand Down
2 changes: 1 addition & 1 deletion src/selectMenus/testMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default class TestMenu implements SelectMenuType {
if (!guildModule)
return sendInteractionMessage(
interaction,
{ content: `No ${value} module found.`, ephemeral: true },
{ content: `No ${arg} module found. Please enable it first with the [dashboard](<https://welcomer.app>)`, ephemeral: true },
true
);
const realChannelId = guildModule.channelId;
Expand Down
2 changes: 0 additions & 2 deletions src/structure/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ export default class Logger {
}

public status(cluster: Cluster, status: string): void {
console.log(process.env.NODE_ENV);
console.log(process.env.NODE_ENV !== "production");
if (process.env.NODE_ENV !== "production") return;
const embed = new StatusEmbed(
cluster.id,
Expand Down
7 changes: 2 additions & 5 deletions src/structure/WelcomerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ export default class WelcomerClient extends Client {
process.env.ADD_REMOVE_WEBHOOK
);

this.init();
this.images.set(
"banner",
new AttachmentBuilder("banner.png").setFile("assets/banner.png")
);

this.cluster.on("ready", () => {
this.loadEvents();
this.managerReady = true;
this.init();
});
}

Expand All @@ -108,9 +108,6 @@ export default class WelcomerClient extends Client {
this.loadSelectMenus();
this.loadButtons();

this.cluster.on("managerReady", () => {
this.managerReady = true;
});
this.login(process.env.TOKEN)
.then(() => {
console.log("Client is starting");
Expand Down
20 changes: 11 additions & 9 deletions src/utils/loader.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { glob } from "glob";
import path from "path";

export async function deleteCachedFile(file: string) {
const filePath = path.resolve(file);
if (require.cache[filePath]) {
delete require.cache[filePath];
}
}
// export async function deleteCachedFile(file: string) {
// const filePath = path.resolve(file);
// if (require.cache[filePath]) {
// delete require.cache[filePath];
// }
// }

export async function loadFiles(dirName: string) {
const files = await glob(
path.join(__dirname, "../", dirName, "**/*.*s").replace(/\\/g, "/"),
path.join("./src/", dirName, "**/*.*s").replace(/\\/g, "/"),
);
const Files = files.filter(
(file) => path.extname(file) === ".js" || path.extname(file) === ".ts"
);
const Files = files.filter((file) => path.extname(file) === '.js');
await Promise.all(Files.map(deleteCachedFile));
// await Promise.all(Files.map(deleteCachedFile));
return Files;
}
64 changes: 22 additions & 42 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,23 @@
{
"compilerOptions": {
/* Basic Options */
"incremental": true,
"module": "CommonJS",
"target": "ES2022",
"outDir": "./dist",

/* Strict Type-Checking Options */
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"alwaysStrict": true,

/* Additional Checks */
"noUnusedLocals": true,
// "noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,

/* Module Resolution Options */
"moduleResolution": "node",
"esModuleInterop": true,
"baseUrl": ".",

"declaration": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"noUncheckedIndexedAccess": true,

/* Experimental Options */
"experimentalDecorators": true,

/* Advanced Options */
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*"],
"exclude": ["node_modules, dist"]
}
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"lib": ["ESNext"],
"moduleResolution": "Node",
"outDir": "./dist",
"rootDir": ".",
"baseUrl": ".",
"allowJs": true,
"noEmit": true,
"skipLibCheck": true,
"importHelpers": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"allowImportingTsExtensions": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"types": [ "node", "ws" ] // @types/node + @types/ws for showing the types...
},
"include": [ "src/**/*.ts" ],
"exclude": [ "node_modules" ]
}
Loading

0 comments on commit 6de607c

Please sign in to comment.