Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
uses: taiki-e/install-action@git-cliff

- name: Run github release script
run: npm run release:git
run: node scripts/actions/github.js
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
Expand Down Expand Up @@ -95,7 +95,7 @@ jobs:
run: npm install

- name: Run npm release script
run: npm run release:npm
run: node scripts/actions/npm.js
env:
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_SHA: ${{ github.sha }}
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
CHANGELOG.md
cargo.toml
.husky
cliff.toml

# Test
examples
Expand Down
21 changes: 13 additions & 8 deletions examples/basic_client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ const arox = require("../../dist/index");
const backend = require("i18next-fs-backend");
const path = require("node:path");
const { LogLevel } = require("../../dist/utils/logger/ILogger");
const { IntentsBitField } = require("discord.js");

const myinstance = i18next.createInstance({
supportedLngs: ["en-US", "tr"],
fallbackLng: "en-US",
defaultNS: "translation",
ns: ["translation", "test"],
ns: ["translation", "test", "error"],
backend: {
loadPath: path.join(__dirname, "locales/{{lng}}/{{ns}}.json"),
},
Expand All @@ -19,7 +20,11 @@ const myinstance = i18next.createInstance({
myinstance.use(backend);

const client = new arox.Client({
intents: 37376,
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
],
prefix: { enabled: true, prefix: "a!" },
logger: {
level: LogLevel.Trace,
Expand All @@ -29,12 +34,12 @@ const client = new arox.Client({
});

arox.setClient(client);
const command = new arox.CommandBuilder({
name: "arox",
description: "Arox test command",
slash: true,
prefix: true,
});
const command = new arox.CommandBuilder(
new arox.ApplicationCommandBuilder()
.setName("arox")
.setDescription("Arox Test Command")
.addAliases("a")
);
arox.clearClient();

command
Expand Down
4 changes: 4 additions & 0 deletions examples/basic_client/locales/en-US/error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"command.notfound": "Command not found or disabled1",
"command.disabled": "Command not found or disabled2"
}
Comment thread
fhyrox marked this conversation as resolved.
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 4 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"imports": {
"#types/*": "./types/*",
"#utils": "./src/utils/index.ts",
"#structures": "./src/structures/index.ts",
"#ctx": "./src/context.ts"
"#types/*": "./types/*"
},
"scripts": {
"prepare": "node scripts/prepareHusky.js",
Expand All @@ -32,24 +29,21 @@
"format": "oxfmt",
"build:js": "swc src -d dist --strip-leading-paths --copy-files",
"build:dts": "tsc --emitDeclarationOnly",
"build": "npm run build:js && node ./scripts/actions/patch.js && npm run build:dts",
"release:git": "node scripts/actions/github.js",
"release:npm": "node scripts/actions/npm.js"
"build": "npm run build:js && node ./scripts/actions/patch.js && npm run build:dts"
},
"dependencies": {
"@sapphire/timestamp": "^1.0.5",
"@swc/helpers": "^0.5.18",
"colorette": "^2.0.20",
"fast-glob": "^3.3.3",
"i18next": "^25.8.0",
"i18next-fs-backend": "^2.6.1",
"lodash": "^4.17.21"
"i18next": "^25.8.0"
},
"devDependencies": {
"@swc/cli": "^0.7.10",
"@types/lodash": "^4.17.23",
"@types/node": "^25.0.9",
"husky": "^9.1.7",
"i18next-fs-backend": "^2.6.1",
"libnpmpack": "^9.0.12",
"oxfmt": "^0.27.0",
"oxlint": "^1.39.0",
Expand Down
5 changes: 4 additions & 1 deletion scripts/utils/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ module.exports = async function buildPackage(tempjson) {
console.error("Build failed, aborting release");
throw err;
}

delete tempjson.scripts;
delete tempjson.devDependencies;
await writeFile(
path.join(process.cwd(), "package.json"),
JSON.stringify(tempjson, null, 2)
JSON.stringify(tempjson)
);
console.log("Packing npm...");
const tarballBuffer = await pack(process.cwd());
Expand Down
2 changes: 1 addition & 1 deletion src/context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Client } from "#structures";
import { Client } from "./structures";

// Birden fazla client olursa hata çıkartabilir ama aklıma gelen tek şey bu
export let currentClient: Client | null = null;
Expand Down
25 changes: 18 additions & 7 deletions src/events/interaction.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
import { Events, MessageFlags } from "discord.js";
import { EventBuilder, Context } from "#structures";
import { EventBuilder, Context } from "../structures/index";

new EventBuilder(Events.InteractionCreate, false).onExecute(
async function (context, interaction) {
if (!interaction.isChatInputCommand()) return;

const command = context.client.commands.get(interaction.commandName);
if (!command || !command.supportsSlash) {
const ctx = new Context(context.client, { interaction });

if (!command) {
await interaction.reply({
content: "Command not found or disabled.",
content: ctx.t("error.command.notfound", {
defaultValue: "Command not found or disabled.",
}),
flags: MessageFlags.Ephemeral,
});
return;
}
if (!command.supportsSlash) {
await interaction.reply({
content: ctx.t("error.command.disabled", {
defaultValue: "Command not found or disabled.",
}),
flags: MessageFlags.Ephemeral,
});
return;
}
Comment thread
fhyrox marked this conversation as resolved.

try {
const ctx = new Context(context.client, { interaction });
ctx.locale = interaction.locale;
context.logger.debug(
`${ctx.author?.tag ?? "Unknown"} used ${command.name}(interaction)`
`${ctx.author?.tag ?? "Unknown"} used ${command.data.name}(interaction)`
);
if (command._onInteraction) await command._onInteraction(ctx.toJSON());
} catch (error) {
context.client.logger.error(
`Error executing command ${command.name}:`,
`Error executing command ${command.data.name}:`,
error
);
if (interaction.replied || interaction.deferred) {
Expand Down
29 changes: 22 additions & 7 deletions src/events/message.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Events } from "discord.js";
import { EventBuilder, Context } from "#structures";
import { deleteMessageAfterSent } from "#utils";
import { EventBuilder, Context } from "../structures/index";
import { deleteMessageAfterSent } from "../utils/index";

new EventBuilder(
Events.MessageCreate,
Expand All @@ -22,27 +22,42 @@ new EventBuilder(
const commandAlias = context.client.aliases.findKey((cmd) =>
cmd.has(commandName)
);
const ctx = new Context(context.client, { message, args });
Comment thread
fhyrox marked this conversation as resolved.

let command = context.client.commands.get(commandAlias ?? commandName);
if (!command || !command.supportsPrefix) {

if (!command) {
await message
.reply({
content: ctx.t("error.command.notfound", {
defaultValue: "Command not found or disabled.",
}),
allowedMentions: { repliedUser: false },
})
.then(deleteMessageAfterSent);
return;
}

if (!command.supportsPrefix) {
await message
.reply({
content: "Command not found or disabled.",
content: ctx.t("error.command.disabled", {
defaultValue: "Command not found or disabled.",
}),
allowedMentions: { repliedUser: false },
})
.then(deleteMessageAfterSent);
return;
}
Comment thread
fhyrox marked this conversation as resolved.

try {
const ctx = new Context(context.client, { message, args });
context.logger.debug(
`${ctx.author?.tag ?? "Unknown"} used ${command.name}(message)`
`${ctx.author?.tag ?? "Unknown"} used ${command.data.name}(message)`
);
if (command._onMessage) await command._onMessage(ctx.toJSON());
} catch (error) {
context.client.logger.error(
`Error executing command ${command.name}:`,
`Error executing command ${command.data.name}:`,
error
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/events/ready.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Events } from "discord.js";
import { EventBuilder } from "#structures";
import { EventBuilder } from "../structures/index";

new EventBuilder(Events.ClientReady).onExecute(async function (context) {
if (context.client.options.autoRegisterCommands) {
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from "#structures";
export * from "./structures";
export * from "./utils/logger/Logger";
export * from "#ctx";
export * from "./context";

export const version = "[VI]{{version}}[/VI]";
46 changes: 0 additions & 46 deletions src/structures/builder/Argument.ts

This file was deleted.

56 changes: 56 additions & 0 deletions src/structures/builder/Builder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {
SlashCommandBuilder,
RESTPostAPIChatInputApplicationCommandsJSONBody,
} from "discord.js";
import { normalizeArray } from "../../utils/normalizeArray";
import { Client } from "../core";

export interface ApplicationJSONBody extends RESTPostAPIChatInputApplicationCommandsJSONBody {
prefix_support: boolean;
slash_support: boolean;
aliases: string[];
}
export class ApplicationCommandBuilder extends SlashCommandBuilder {
constructor() {
super();
}
Comment thread
fhyrox marked this conversation as resolved.
protected prefix_support: boolean = true;
protected slash_support: boolean = true;
protected aliases: string[] = [];

setAliases(...alias: string[]) {
Reflect.set(this, "aliases", normalizeArray(alias));
return this;
}

addAliases(...alias: string[]) {
const currentAliases = Reflect.get(this, "aliases") || [];
Reflect.set(
this,
"aliases",
normalizeArray([...currentAliases, ...normalizeArray(alias)])
);
return this;
}

setPrefixSupport(support: boolean) {
Reflect.set(this, "prefix_support", support);
return this;
}

setSlashSupport(support: boolean) {
Reflect.set(this, "slash_support", support);
return this;
}
Comment thread
fhyrox marked this conversation as resolved.
override toJSON(): ApplicationJSONBody {
return super.toJSON() as ApplicationJSONBody;
}
Comment thread
fhyrox marked this conversation as resolved.

toClientJSON(
client: Client
): ReturnType<ApplicationCommandBuilder["toJSON"]> {
return {
...this.toJSON(),
};
}
Comment thread
vrdons marked this conversation as resolved.
}
Loading
Loading