@arox/framework 0.1.1 → 0.1.2-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/constants/messages.d.ts +2 -0
  2. package/dist/events/interaction.d.ts +4 -1
  3. package/dist/events/message.d.ts +4 -1
  4. package/dist/events/ready.d.ts +4 -1
  5. package/dist/index.cjs +3 -0
  6. package/dist/index.d.cts +2 -0
  7. package/dist/index.d.ts +3 -3
  8. package/dist/index.js +3 -15
  9. package/dist/structures/builder/Builder.d.ts +18 -0
  10. package/dist/structures/builder/Command.d.ts +23 -24
  11. package/dist/structures/builder/Context.d.ts +24 -18
  12. package/dist/structures/builder/Event.d.ts +7 -9
  13. package/dist/structures/builder/index.d.ts +4 -4
  14. package/dist/structures/core/Client.d.ts +6 -7
  15. package/dist/structures/core/index.d.ts +1 -1
  16. package/dist/structures/index.d.ts +2 -2
  17. package/dist/utils/index.d.ts +3 -3
  18. package/dist/utils/logger/ILogger.d.ts +1 -43
  19. package/dist/utils/logger/Logger.d.ts +6 -41
  20. package/dist/utils/normalizeArray.d.ts +15 -0
  21. package/dist/utils/util.d.ts +5 -3
  22. package/package.json +1 -62
  23. package/types/client.d.ts +14 -13
  24. package/types/logger.d.ts +63 -0
  25. package/cliff.toml +0 -48
  26. package/dist/context.d.ts +0 -4
  27. package/dist/context.js +0 -28
  28. package/dist/events/interaction.js +0 -38
  29. package/dist/events/message.js +0 -36
  30. package/dist/events/ready.js +0 -11
  31. package/dist/structures/builder/Argument.d.ts +0 -22
  32. package/dist/structures/builder/Argument.js +0 -42
  33. package/dist/structures/builder/Command.js +0 -74
  34. package/dist/structures/builder/Context.js +0 -67
  35. package/dist/structures/builder/Event.js +0 -53
  36. package/dist/structures/builder/index.js +0 -9
  37. package/dist/structures/core/Client.js +0 -111
  38. package/dist/structures/core/index.js +0 -6
  39. package/dist/structures/index.js +0 -7
  40. package/dist/utils/Files.js +0 -47
  41. package/dist/utils/index.js +0 -8
  42. package/dist/utils/logger/ILogger.js +0 -37
  43. package/dist/utils/logger/Logger.js +0 -380
  44. package/dist/utils/util.js +0 -35
@@ -0,0 +1,2 @@
1
+ export declare const COMMAND_DISABLED_MESSAGE = "Command not found or disabled.";
2
+ export declare const COMMAND_EXECUTE_ERROR_MESSAGE = "There was an error while executing this command!";
@@ -1 +1,4 @@
1
- export {};
1
+ import { Events } from "discord.js";
2
+ import { EventBuilder } from "../structures/index.js";
3
+ declare const _default: EventBuilder<Events.InteractionCreate>;
4
+ export default _default;
@@ -1 +1,4 @@
1
- export {};
1
+ import { Events } from "discord.js";
2
+ import { EventBuilder } from "../structures/index.js";
3
+ declare const _default: EventBuilder<Events.MessageCreate>;
4
+ export default _default;
@@ -1 +1,4 @@
1
- export {};
1
+ import { Events } from "discord.js";
2
+ import { EventBuilder } from "../structures/index.js";
3
+ declare const _default: EventBuilder<Events.ClientReady>;
4
+ export default _default;
package/dist/index.cjs ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";var bt=Object.create;var D=Object.defineProperty;var Mt=Object.getOwnPropertyDescriptor;var Ct=Object.getOwnPropertyNames;var xt=Object.getPrototypeOf,yt=Object.prototype.hasOwnProperty;var l=(e,t)=>()=>(e&&(t=e(e=0)),t);var B=(e,t)=>{for(var r in t)D(e,r,{get:t[r],enumerable:!0})},z=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Ct(t))!yt.call(e,s)&&s!==r&&D(e,s,{get:()=>t[s],enumerable:!(i=Mt(t,s))||i.enumerable});return e};var I=(e,t,r)=>(r=e!=null?bt(xt(e)):{},z(t||!e||!e.__esModule?D(r,"default",{value:e,enumerable:!0}):r,e)),At=e=>z(D({},"__esModule",{value:!0}),e);function _(e,t=15e3){return new Promise(r=>{setTimeout(()=>{e.delete().catch(()=>{}),r()},t)})}function N(e){if(e&&Dt.has(e))return e}function $(e){return e.isInteraction()?N(e.data.locale)??N(e.data.guildLocale)??O.Locale.EnglishUS:e.isMessage()?N(e.data.guild?.preferredLocale)??O.Locale.EnglishUS:O.Locale.EnglishUS}var O,V,Dt,H=l(()=>{"use strict";O=require("discord.js"),V=["id","en-US","en-GB","bg","zh-CN","zh-TW","hr","cs","da","nl","fi","fr","de","el","hi","hu","it","ja","ko","lt","no","pl","pt-BR","ro","ru","es-ES","es-419","sv-SE","th","tr","uk","vi"],Dt=new Set(V)});function v(e){return K.default.sync(["**/*.ts","**/*.js","**/*.cjs","**/*.mjs"],{cwd:e,absolute:!0,ignore:["**/*.d.ts","node_modules/**",".git/**","dist/**","lib/**","out/**","build/**",".next/**","coverage/**"]})}function k(){let e=[];e.push(m.default.resolve(process.cwd()));let t=typeof require<"u"?require.main?.filename:void 0;t&&e.push(m.default.dirname(m.default.resolve(t))),typeof module<"u"&&module.parent?.filename&&e.push(m.default.dirname(m.default.resolve(module.parent.filename)));for(let r of e){let i=Bt(r);if(i)return i}return e[0]}function Bt(e){let t=m.default.resolve(e);for(;;){let r=m.default.join(t,"package.json");if((0,q.existsSync)(r))return m.default.normalize(t);let i=m.default.dirname(t);if(i===t)return null;t=i}}var K,q,m,X=l(()=>{"use strict";K=I(require("fast-glob"),1),q=require("node:fs"),m=I(require("path"),1)});var n,U=l(()=>{"use strict";n=(function(e){return e[e.Trace=10]="Trace",e[e.Debug=20]="Debug",e[e.Info=30]="Info",e[e.Warn=40]="Warn",e[e.Error=50]="Error",e[e.Fatal=60]="Fatal",e[e.None=100]="None",e})({})});var Q,Z,a,L,w,y,R,g,Jt,It,Ot,Nt,A,j=l(()=>{"use strict";Q=require("console"),Z=require("util"),a=I(require("colorette"),1),L=require("@sapphire/timestamp");U();U();w=class e{level;formats;join;depth;console;static instance=null;static LOG_METHODS=new Map([[n.Trace,"trace"],[n.Debug,"debug"],[n.Info,"info"],[n.Warn,"warn"],[n.Error,"error"],[n.Fatal,"error"]]);static DEFAULT_COLORS=new Map([[n.Trace,a.gray],[n.Debug,a.magenta],[n.Info,a.cyan],[n.Warn,a.yellow],[n.Error,a.red],[n.Fatal,a.bgRed],[n.None,a.white]]);static DEFAULT_NAMES=new Map([[n.Trace,"TRACE"],[n.Debug,"DEBUG"],[n.Info,"INFO"],[n.Warn,"WARN"],[n.Error,"ERROR"],[n.Fatal,"FATAL"],[n.None,""]]);constructor(t={}){this.level=t.level??n.Info,this.console=new Q.Console(t.stdout??process.stdout,t.stderr??process.stderr),this.formats=this.createFormatMap(t.format,t.defaultFormat??t.format?.none??{}),this.join=t.join??" ",this.depth=t.depth??2}static getInstance(){return this.instance||(this.instance=new e),this.instance}static get stylize(){return a.isColorSupported}setLevel(t){this.level=t}has(t){return t>=this.level}trace(...t){this.write(n.Trace,...t)}debug(...t){this.write(n.Debug,...t)}info(...t){this.write(n.Info,...t)}log(...t){this.write(n.Info,...t)}warn(...t){this.write(n.Warn,...t)}error(...t){this.write(n.Error,...t)}fatal(...t){this.write(n.Fatal,...t)}write(t,...r){if(t<this.level)return;let i=e.LOG_METHODS.get(t),o=(this.formats.get(t)??this.formats.get(n.None)).run(this.preprocess(r));switch(i){case"trace":this.console.trace(o);break;case"debug":this.console.debug(o);break;case"info":this.console.info(o);break;case"warn":this.console.warn(o);break;case"error":this.console.error(o);break;default:this.console.log(o)}}preprocess(t){let r={colors:a.isColorSupported,depth:this.depth};return t.map(i=>typeof i=="string"?i:(0,Z.inspect)(i,r)).join(this.join)}createFormatMap(t={},r){let i=new Map;for(let[s,o]of e.DEFAULT_COLORS){let h=e.DEFAULT_NAMES.get(s),c=t[this.getLevelKey(s)]??this.createDefaultLevel(r,o,h??"");i.set(s,c instanceof g?c:new g(c))}return i}createDefaultLevel(t,r,i){return new g({...t,timestamp:t.timestamp===null?null:{...t.timestamp,color:r},infix:i.length?`${r(i.padEnd(5," "))} `:""})}getLevelKey(t){return{[n.Trace]:"trace",[n.Debug]:"debug",[n.Info]:"info",[n.Warn]:"warn",[n.Error]:"error",[n.Fatal]:"fatal",[n.None]:"none"}[t]}},y=class{style;constructor(t={}){if(typeof t=="function")this.style=t;else{let r=this.buildStyleArray(t);this.style=this.combineStyles(r)}}run(t){return this.style(String(t))}buildStyleArray(t){let r=[];return t.effects&&r.push(...t.effects.map(i=>a[i])),t.text&&r.push(a[t.text]),t.background&&r.push(a[t.background]),r}combineStyles(t){return t.length===0?a.reset:t.length===1?t[0]:(r=>t.reduce((i,s)=>s(i),r))}},R=class{timestamp;utc;color;formatter;constructor(t={}){this.timestamp=new L.Timestamp(t.pattern??"YYYY-MM-DD HH:mm:ss"),this.utc=t.utc??!1,this.color=t.color===null?null:new y(t.color),this.formatter=t.formatter??(r=>`${r} `)}run(){let t=new Date,r=this.utc?this.timestamp.displayUTC(t):this.timestamp.display(t);return this.formatter(this.color?this.color.run(r):r)}},g=class{timestamp;infix;message;constructor(t={}){this.timestamp=t.timestamp===null?null:new R(t.timestamp),this.infix=t.infix??"",this.message=t.message===null?null:new y(t.message)}run(t){let r=(this.timestamp?.run()??"")+this.infix;if(r.length){let i=this.message?s=>r+this.message?.run(s):s=>r+s;return t.split(`
2
+ `).map(i).join(`
3
+ `)}return this.message?this.message.run(t):t}},Jt=w.getInstance(),It=(function(e){return e.Reset="reset",e.Bold="bold",e.Dim="dim",e.Italic="italic",e.Underline="underline",e.Inverse="inverse",e.Hidden="hidden",e.Strikethrough="strikethrough",e})({}),Ot=(function(e){return e.Black="black",e.Red="red",e.Green="green",e.Yellow="yellow",e.Blue="blue",e.Magenta="magenta",e.Cyan="cyan",e.White="white",e.Gray="gray",e.BlackBright="blackBright",e.RedBright="redBright",e.GreenBright="greenBright",e.YellowBright="yellowBright",e.BlueBright="blueBright",e.MagentaBright="magentaBright",e.CyanBright="cyanBright",e.WhiteBright="whiteBright",e})({}),Nt=(function(e){return e.Black="bgBlack",e.Red="bgRed",e.Green="bgGreen",e.Yellow="bgYellow",e.Blue="bgBlue",e.Magenta="bgMagenta",e.Cyan="bgCyan",e.White="bgWhite",e.BlackBright="bgBlackBright",e.RedBright="bgRedBright",e.GreenBright="bgGreenBright",e.YellowBright="bgYellowBright",e.BlueBright="bgBlueBright",e.MagentaBright="bgMagentaBright",e.CyanBright="bgCyanBright",e.WhiteBright="bgWhiteBright",e})({}),A=class{type="logger";constructor(t){this.logger=t}log(...t){this.logger.debug("[i18next]",...t)}warn(...t){this.logger.warn("[i18next]",...t)}error(...t){this.logger.error("[i18next]",...t)}}});var S=l(()=>{"use strict";H();X();j()});var et={};B(et,{default:()=>_t});var tt,_t,rt=l(()=>{"use strict";tt=require("discord.js");E();_t=new u(tt.Events.ClientReady).onExecute(async function(e){e.client.options.autoRegisterCommands&&await e.client.registerCommands()})});var b,G,W=l(()=>{"use strict";b="Command not found or disabled.",G="There was an error while executing this command!"});var it={};B(it,{default:()=>Rt});var p,Rt,st=l(()=>{"use strict";p=require("discord.js");W();E();Rt=new u(p.Events.InteractionCreate,!1).onExecute(async function(e,t){if(!t.isChatInputCommand())return;let r=e.client.commands.get(t.commandName),i=new d(e.client,{interaction:t});if(!r){await t.reply({content:i.t("error:command.notfound",{defaultValue:b}),flags:p.MessageFlags.Ephemeral});return}if(!r.supportsSlash){await t.reply({content:i.t("error:command.disabled",{defaultValue:b}),flags:p.MessageFlags.Ephemeral});return}try{e.logger.debug(`${i.author?.tag??"Unknown"} used ${r.data.name}(interaction)`),r._onInteraction&&await r._onInteraction(i.toJSON())}catch(s){e.client.logger.error(`Error executing command ${r.data.name}:`,s),t.replied||t.deferred?await t.followUp({content:G,flags:p.MessageFlags.Ephemeral}):await t.reply({content:G,flags:p.MessageFlags.Ephemeral})}})});var at={};B(at,{default:()=>St});var nt,St,ot=l(()=>{"use strict";nt=require("discord.js");W();E();S();St=new u(nt.Events.MessageCreate,!1,async function(e,t){if(t.author.bot)return;let r=e.client.prefix(new d(e.client,{message:t}));if(typeof r!="string"||r.length===0||!t.content.startsWith(r))return;let i=t.content.slice(r.length).trim().split(/ +/),s=i.shift()?.toLowerCase();if(!s)return;let o=e.client.aliases.findKey(x=>x.has(s)),h=new d(e.client,{message:t,args:i}),c=e.client.commands.get(o??s);if(!c){await t.reply({content:h.t("error:command.notfound",{defaultValue:b}),allowedMentions:{repliedUser:!1}}).then(_);return}if(!c.supportsPrefix){await t.reply({content:h.t("error:command.disabled",{defaultValue:b}),allowedMentions:{repliedUser:!1}}).then(_);return}try{e.logger.debug(`${h.author?.tag??"Unknown"} used ${c.data.name}(message)`),c._onMessage&&await c._onMessage(h.toJSON())}catch(x){e.client.logger.error(`Error executing command ${c.data.name}:`,x)}})});var f,lt,J,ht,Ft,P,ct=l(()=>{"use strict";f=require("discord.js"),lt=require("node:fs"),J=I(require("node:path"),1),ht=require("node:url");S();E();Ft={includePaths:["events","commands"],autoRegisterCommands:!0,getDefaultLang:$},P=class extends f.Client{logger;commands;aliases;prefix;i18n;constructor(t){super({...Ft,...t}),this.logger=new w(t.logger),this.commands=new f.Collection,this.aliases=new f.Collection,this.prefix=this.options.prefix??(()=>!1),this.options.i18n&&(this.i18n=this.options.i18n,this.i18n.use(new A(this.logger)))}async login(t){await this.#r();for(let r of this.options.includePaths)try{let i=J.default.isAbsolute(r)?r:J.default.join(k(),r);await this.#t(i)}catch(i){this.logger.error(`Error loading ${r}:`,i)}return this.i18n&&!this.i18n.isInitialized&&await this.i18n.init(),super.login(t)}async#t(t){if(!(0,lt.existsSync)(t)){this.logger.debug(`Directory not found: ${t}`);return}let r=v(t);for(let i of r)await this.#e(i)}async#r(){let t=[()=>Promise.resolve().then(()=>(rt(),et)),()=>Promise.resolve().then(()=>(st(),it))];for(let r of t){let i=await r();await this.#i(i,"[core]")}if(this.options.prefix){let r=await Promise.resolve().then(()=>(ot(),at));await this.#i(r,"[core]")}}async#e(t){try{let r=(0,ht.pathToFileURL)(t);r.searchParams.set("ts",Date.now().toString(36));let i=await import(r.href);await this.#i(i,t)}catch(r){this.logger.error(`Error loading file ${t}:`,r)}}async#i(t,r){let i=new Set;for(let s of Object.values(t))i.add(s);for(let s of i)await this.#s(s,r)}async#s(t,r){if(t!=null){if(Array.isArray(t)){for(let i of t)await this.#s(i,r);return}if(t instanceof M){t.attach(this);return}if(t instanceof u){t.attach(this);return}if(typeof t=="object"&&t!==null&&"attach"in t&&typeof t.attach=="function"){t.attach(this);return}if(typeof t=="function"){let i=await t(this);await this.#s(i,r);return}this.logger.debug(`Skipped unsupported export type in ${r}: ${typeof t}`)}}async registerCommands(){if(!this.token){this.logger.warn("registerCommands skipped: client token is not set.");return}if(!this.application){this.logger.warn("registerCommands skipped: client application is not ready.");return}let t=this.commands.filter(i=>i.supportsSlash).map(i=>i.data.toClientJSON(this)),r=new f.REST({version:"10"}).setToken(this.token);try{this.logger.debug(`Started refreshing ${t.length} application (/) commands.`),await r.put(f.Routes.applicationCommands(this.application.id),{body:t}),this.logger.info(`Loaded ${t.length} application (/) commands.`)}catch(i){this.logger.error("Failed to register commands:",i)}}}});var ut=l(()=>{"use strict";ct()});var M,Y,mt=l(()=>{"use strict";M=class{#t=null;#r=null;#e;#i;#s=!1;_onMessage;_onInteraction;get client(){if(!this.#t)throw new Error("Command is not attached to a client");return this.#t}get logger(){if(!this.#r)throw new Error("Command is not attached to a client");return this.#r}get supportsSlash(){return this.#e&&this._onInteraction}get supportsPrefix(){return this.#i&&this._onMessage}constructor(t){this.data=t;let r=t.toJSON(),{name:i}=r;if(this.#i=r.prefix_support??!1,this.#e=r.slash_support??!1,!this.#i&&!this.#e)throw new Error(`Command ${i} must support either slash or prefix commands.`)}attach(t){if(this.#s)return this;let r=this.data.toJSON(),{name:i,aliases:s}=r;if(this.#t=t,this.#r=t.logger,t.commands.has(i))throw new Error(`Command name "${i}" is already registered.`);let o=t.aliases.findKey(h=>h.has(i));if(o)throw new Error(`Command name "${i}" is already registered as an alias for command "${o}".`);for(let h of s){if(t.commands.has(h))throw new Error(`Alias "${h}" is already registered as a command name.`);let c=t.aliases.findKey(x=>x.has(h));if(c)throw new Error(`Alias "${h}" is already registered as an alias for command "${c}".`)}return t.commands.set(i,this),s.length>0&&t.aliases.set(i,new Set(s)),this.logger.debug(`Loaded Command ${i}`),this.#s=!0,this}onMessage(t){return this._onMessage=t,this}onInteraction(t){return this._onInteraction=t,this}},Y=class extends M{constructor(t){super(t.data);let r=t.data.toJSON(),i=t.execute;(r.prefix_support??!1)&&(t.onMessage||i)&&this.onMessage(s=>t.onMessage?t.onMessage(s):i?.(s)),(r.slash_support??!1)&&(t.onInteraction||i)&&this.onInteraction(s=>t.onInteraction?t.onInteraction(s):i?.(s))}}});var C,d,ft=l(()=>{"use strict";C=require("discord.js"),d=class{args;data;locale;constructor(t,r){this.client=t,this.args=r.args??[],"interaction"in r?this.data=r.interaction:this.data=r.message,this.locale=this.client.options.getDefaultLang?.(this)}isInteraction(){return this.data instanceof C.ChatInputCommandInteraction}isMessage(){return this.data instanceof C.Message}get author(){return this.isInteraction()?this.data.user:this.isMessage()?this.data.author:null}t(t,r){if(!this.client.i18n)throw new Error("i18n is not initialized");let i=this.locale??this.client.options.getDefaultLang?.(this)??(Array.isArray(this.client.i18n.options.fallbackLng)?this.client.i18n.options.fallbackLng[0]:this.client.i18n.options.fallbackLng)??C.Locale.EnglishUS,o=this.client.i18n.getFixedT(i)(t,r);return o===t&&r?.defaultValue?r.defaultValue:o}toJSON(){let{data:t,args:r,author:i}=this;return this.isInteraction()?{kind:"interaction",interaction:t,author:i,t:(s,o)=>this.t(s,o)}:{kind:"message",message:t,args:r,author:i,t:(s,o)=>this.t(s,o)}}}});var u,dt=l(()=>{"use strict";u=class{#t=null;#r=null;#e;#i=!1;get client(){if(!this.#t)throw new Error("Event is not attached to a client");return this.#t}get logger(){if(!this.#r)throw new Error("Event is not attached to a client");return this.#r}#s=async(...t)=>{if(this.#t&&this.#e)try{await this.#e(this,...t)}catch(r){this.client.logger.error(`Error executing event ${this.name} (${this.constructor.name}):`,r)}};constructor(t,r=!1,i){this.name=t,this.once=r,i&&(this.#e=i)}#n(){this.#i||!this.#e||!this.#t||!this.#r||(this.once?this.client.once(this.name,this.#s):this.client.on(this.name,this.#s),this.#i=!0,this.logger.debug(`Loaded Event ${String(this.name)}`))}attach(t){return this.#t?this:(this.#t=t,this.#r=t.logger,this.#n(),this)}onExecute(t){return this.#e=t,this.#n(),this}}});function F(e){return Array.isArray(e[0])?[...e[0]]:e}var pt=l(()=>{"use strict"});var gt,T,wt=l(()=>{"use strict";gt=require("discord.js");pt();T=class extends gt.SlashCommandBuilder{prefix_support=!0;slash_support=!0;aliases=[];setAliases(...t){return this.aliases=F(t),this}addAliases(...t){return this.aliases=F([...this.aliases,...F(t)]),this}setPrefixSupport(t){return this.prefix_support=t,this}setSlashSupport(t){return this.slash_support=t,this}toJSON(){return super.toJSON()}toClientJSON(t){return{...this.toJSON()}}}});var Et=l(()=>{"use strict";mt();ft();dt();wt()});var E=l(()=>{"use strict";ut();Et()});var vt={};B(vt,{ApplicationCommandBuilder:()=>T,Client:()=>P,Command:()=>Y,CommandBuilder:()=>M,Context:()=>d,EventBuilder:()=>u,I18nLoggerAdapter:()=>A,LogLevel:()=>n,Logger:()=>w,LoggerLevel:()=>g,LoggerStyle:()=>y,LoggerStyleBackground:()=>Nt,LoggerStyleEffect:()=>It,LoggerStyleText:()=>Ot,LoggerTimestamp:()=>R,allowedLocales:()=>V,deleteMessageAfterSent:()=>_,getDefaultLang:()=>$,getFiles:()=>v,getProjectRoot:()=>k,toAllowedLocale:()=>N,version:()=>$t});module.exports=At(vt);E();S();j();var $t="v0.1.2-beta.2";0&&(module.exports={ApplicationCommandBuilder,Client,Command,CommandBuilder,Context,EventBuilder,I18nLoggerAdapter,LogLevel,Logger,LoggerLevel,LoggerStyle,LoggerStyleBackground,LoggerStyleEffect,LoggerStyleText,LoggerTimestamp,allowedLocales,deleteMessageAfterSent,getDefaultLang,getFiles,getProjectRoot,toAllowedLocale,version});
@@ -0,0 +1,2 @@
1
+ import type * as Arox from "./index.js";
2
+ export = Arox;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from "#structures";
2
- export * from "./utils/logger/Logger";
3
- export * from "#ctx";
1
+ export * from "./structures/index.js";
2
+ export * from "./utils/index.js";
3
+ export * from "./utils/logger/Logger.js";
4
4
  export declare const version = "[VI]{{version}}[/VI]";
package/dist/index.js CHANGED
@@ -1,15 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "version", {
6
- enumerable: true,
7
- get: function() {
8
- return version;
9
- }
10
- });
11
- const _export_star = require("@swc/helpers/_/_export_star");
12
- _export_star._(require("#structures"), exports);
13
- _export_star._(require("./utils/logger/Logger"), exports);
14
- _export_star._(require("#ctx"), exports);
15
- const version = "v0.1.1";
1
+ var nt=Object.defineProperty;var D=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var l=(e,t)=>()=>(e&&(t=e(e=0)),t);var B=(e,t)=>{for(var r in t)nt(e,r,{get:t[r],enumerable:!0})};import{Locale as I}from"discord.js";function N(e,t=15e3){return new Promise(r=>{setTimeout(()=>{e.delete().catch(()=>{}),r()},t)})}function O(e){if(e&&ot.has(e))return e}function v(e){return e.isInteraction()?O(e.data.locale)??O(e.data.guildLocale)??I.EnglishUS:e.isMessage()?O(e.data.guild?.preferredLocale)??I.EnglishUS:I.EnglishUS}var at,ot,k=l(()=>{"use strict";at=["id","en-US","en-GB","bg","zh-CN","zh-TW","hr","cs","da","nl","fi","fr","de","el","hi","hu","it","ja","ko","lt","no","pl","pt-BR","ro","ru","es-ES","es-419","sv-SE","th","tr","uk","vi"],ot=new Set(at)});import lt from"fast-glob";import{existsSync as ht}from"node:fs";import m from"path";function U(e){return lt.sync(["**/*.ts","**/*.js","**/*.cjs","**/*.mjs"],{cwd:e,absolute:!0,ignore:["**/*.d.ts","node_modules/**",".git/**","dist/**","lib/**","out/**","build/**",".next/**","coverage/**"]})}function j(){let e=[];e.push(m.resolve(process.cwd()));let t=typeof D<"u"?D.main?.filename:void 0;t&&e.push(m.dirname(m.resolve(t))),typeof module<"u"&&module.parent?.filename&&e.push(m.dirname(m.resolve(module.parent.filename)));for(let r of e){let i=ct(r);if(i)return i}return e[0]}function ct(e){let t=m.resolve(e);for(;;){let r=m.join(t,"package.json");if(ht(r))return m.normalize(t);let i=m.dirname(t);if(i===t)return null;t=i}}var G=l(()=>{"use strict"});var s,_=l(()=>{"use strict";s=(function(e){return e[e.Trace=10]="Trace",e[e.Debug=20]="Debug",e[e.Info=30]="Info",e[e.Warn=40]="Warn",e[e.Error=50]="Error",e[e.Fatal=60]="Fatal",e[e.None=100]="None",e})({})});import{Console as ut}from"console";import{inspect as mt}from"util";import*as a from"colorette";import{Timestamp as ft}from"@sapphire/timestamp";var E,M,R,w,Yt,Tt,zt,Vt,C,S=l(()=>{"use strict";_();_();E=class e{level;formats;join;depth;console;static instance=null;static LOG_METHODS=new Map([[s.Trace,"trace"],[s.Debug,"debug"],[s.Info,"info"],[s.Warn,"warn"],[s.Error,"error"],[s.Fatal,"error"]]);static DEFAULT_COLORS=new Map([[s.Trace,a.gray],[s.Debug,a.magenta],[s.Info,a.cyan],[s.Warn,a.yellow],[s.Error,a.red],[s.Fatal,a.bgRed],[s.None,a.white]]);static DEFAULT_NAMES=new Map([[s.Trace,"TRACE"],[s.Debug,"DEBUG"],[s.Info,"INFO"],[s.Warn,"WARN"],[s.Error,"ERROR"],[s.Fatal,"FATAL"],[s.None,""]]);constructor(t={}){this.level=t.level??s.Info,this.console=new ut(t.stdout??process.stdout,t.stderr??process.stderr),this.formats=this.createFormatMap(t.format,t.defaultFormat??t.format?.none??{}),this.join=t.join??" ",this.depth=t.depth??2}static getInstance(){return this.instance||(this.instance=new e),this.instance}static get stylize(){return a.isColorSupported}setLevel(t){this.level=t}has(t){return t>=this.level}trace(...t){this.write(s.Trace,...t)}debug(...t){this.write(s.Debug,...t)}info(...t){this.write(s.Info,...t)}log(...t){this.write(s.Info,...t)}warn(...t){this.write(s.Warn,...t)}error(...t){this.write(s.Error,...t)}fatal(...t){this.write(s.Fatal,...t)}write(t,...r){if(t<this.level)return;let i=e.LOG_METHODS.get(t),o=(this.formats.get(t)??this.formats.get(s.None)).run(this.preprocess(r));switch(i){case"trace":this.console.trace(o);break;case"debug":this.console.debug(o);break;case"info":this.console.info(o);break;case"warn":this.console.warn(o);break;case"error":this.console.error(o);break;default:this.console.log(o)}}preprocess(t){let r={colors:a.isColorSupported,depth:this.depth};return t.map(i=>typeof i=="string"?i:mt(i,r)).join(this.join)}createFormatMap(t={},r){let i=new Map;for(let[n,o]of e.DEFAULT_COLORS){let h=e.DEFAULT_NAMES.get(n),c=t[this.getLevelKey(n)]??this.createDefaultLevel(r,o,h??"");i.set(n,c instanceof w?c:new w(c))}return i}createDefaultLevel(t,r,i){return new w({...t,timestamp:t.timestamp===null?null:{...t.timestamp,color:r},infix:i.length?`${r(i.padEnd(5," "))} `:""})}getLevelKey(t){return{[s.Trace]:"trace",[s.Debug]:"debug",[s.Info]:"info",[s.Warn]:"warn",[s.Error]:"error",[s.Fatal]:"fatal",[s.None]:"none"}[t]}},M=class{style;constructor(t={}){if(typeof t=="function")this.style=t;else{let r=this.buildStyleArray(t);this.style=this.combineStyles(r)}}run(t){return this.style(String(t))}buildStyleArray(t){let r=[];return t.effects&&r.push(...t.effects.map(i=>a[i])),t.text&&r.push(a[t.text]),t.background&&r.push(a[t.background]),r}combineStyles(t){return t.length===0?a.reset:t.length===1?t[0]:(r=>t.reduce((i,n)=>n(i),r))}},R=class{timestamp;utc;color;formatter;constructor(t={}){this.timestamp=new ft(t.pattern??"YYYY-MM-DD HH:mm:ss"),this.utc=t.utc??!1,this.color=t.color===null?null:new M(t.color),this.formatter=t.formatter??(r=>`${r} `)}run(){let t=new Date,r=this.utc?this.timestamp.displayUTC(t):this.timestamp.display(t);return this.formatter(this.color?this.color.run(r):r)}},w=class{timestamp;infix;message;constructor(t={}){this.timestamp=t.timestamp===null?null:new R(t.timestamp),this.infix=t.infix??"",this.message=t.message===null?null:new M(t.message)}run(t){let r=(this.timestamp?.run()??"")+this.infix;if(r.length){let i=this.message?n=>r+this.message?.run(n):n=>r+n;return t.split(`
2
+ `).map(i).join(`
3
+ `)}return this.message?this.message.run(t):t}},Yt=E.getInstance(),Tt=(function(e){return e.Reset="reset",e.Bold="bold",e.Dim="dim",e.Italic="italic",e.Underline="underline",e.Inverse="inverse",e.Hidden="hidden",e.Strikethrough="strikethrough",e})({}),zt=(function(e){return e.Black="black",e.Red="red",e.Green="green",e.Yellow="yellow",e.Blue="blue",e.Magenta="magenta",e.Cyan="cyan",e.White="white",e.Gray="gray",e.BlackBright="blackBright",e.RedBright="redBright",e.GreenBright="greenBright",e.YellowBright="yellowBright",e.BlueBright="blueBright",e.MagentaBright="magentaBright",e.CyanBright="cyanBright",e.WhiteBright="whiteBright",e})({}),Vt=(function(e){return e.Black="bgBlack",e.Red="bgRed",e.Green="bgGreen",e.Yellow="bgYellow",e.Blue="bgBlue",e.Magenta="bgMagenta",e.Cyan="bgCyan",e.White="bgWhite",e.BlackBright="bgBlackBright",e.RedBright="bgRedBright",e.GreenBright="bgGreenBright",e.YellowBright="bgYellowBright",e.BlueBright="bgBlueBright",e.MagentaBright="bgMagentaBright",e.CyanBright="bgCyanBright",e.WhiteBright="bgWhiteBright",e})({}),C=class{type="logger";constructor(t){this.logger=t}log(...t){this.logger.debug("[i18next]",...t)}warn(...t){this.logger.warn("[i18next]",...t)}error(...t){this.logger.error("[i18next]",...t)}}});var x=l(()=>{"use strict";k();G();S()});var W={};B(W,{default:()=>pt});import{Events as dt}from"discord.js";var pt,J=l(()=>{"use strict";d();pt=new u(dt.ClientReady).onExecute(async function(e){e.client.options.autoRegisterCommands&&await e.client.registerCommands()})});var p,F,$=l(()=>{"use strict";p="Command not found or disabled.",F="There was an error while executing this command!"});var P={};B(P,{default:()=>wt});import{Events as gt,MessageFlags as y}from"discord.js";var wt,Y=l(()=>{"use strict";$();d();wt=new u(gt.InteractionCreate,!1).onExecute(async function(e,t){if(!t.isChatInputCommand())return;let r=e.client.commands.get(t.commandName),i=new f(e.client,{interaction:t});if(!r){await t.reply({content:i.t("error:command.notfound",{defaultValue:p}),flags:y.Ephemeral});return}if(!r.supportsSlash){await t.reply({content:i.t("error:command.disabled",{defaultValue:p}),flags:y.Ephemeral});return}try{e.logger.debug(`${i.author?.tag??"Unknown"} used ${r.data.name}(interaction)`),r._onInteraction&&await r._onInteraction(i.toJSON())}catch(n){e.client.logger.error(`Error executing command ${r.data.name}:`,n),t.replied||t.deferred?await t.followUp({content:F,flags:y.Ephemeral}):await t.reply({content:F,flags:y.Ephemeral})}})});var T={};B(T,{default:()=>bt});import{Events as Et}from"discord.js";var bt,z=l(()=>{"use strict";$();d();x();bt=new u(Et.MessageCreate,!1,async function(e,t){if(t.author.bot)return;let r=e.client.prefix(new f(e.client,{message:t}));if(typeof r!="string"||r.length===0||!t.content.startsWith(r))return;let i=t.content.slice(r.length).trim().split(/ +/),n=i.shift()?.toLowerCase();if(!n)return;let o=e.client.aliases.findKey(g=>g.has(n)),h=new f(e.client,{message:t,args:i}),c=e.client.commands.get(o??n);if(!c){await t.reply({content:h.t("error:command.notfound",{defaultValue:p}),allowedMentions:{repliedUser:!1}}).then(N);return}if(!c.supportsPrefix){await t.reply({content:h.t("error:command.disabled",{defaultValue:p}),allowedMentions:{repliedUser:!1}}).then(N);return}try{e.logger.debug(`${h.author?.tag??"Unknown"} used ${c.data.name}(message)`),c._onMessage&&await c._onMessage(h.toJSON())}catch(g){e.client.logger.error(`Error executing command ${c.data.name}:`,g)}})});import{Client as Mt,Collection as V,REST as Ct,Routes as xt}from"discord.js";import{existsSync as yt}from"node:fs";import H from"node:path";import{pathToFileURL as At}from"node:url";var Dt,K,q=l(()=>{"use strict";x();d();Dt={includePaths:["events","commands"],autoRegisterCommands:!0,getDefaultLang:v},K=class extends Mt{logger;commands;aliases;prefix;i18n;constructor(t){super({...Dt,...t}),this.logger=new E(t.logger),this.commands=new V,this.aliases=new V,this.prefix=this.options.prefix??(()=>!1),this.options.i18n&&(this.i18n=this.options.i18n,this.i18n.use(new C(this.logger)))}async login(t){await this.#r();for(let r of this.options.includePaths)try{let i=H.isAbsolute(r)?r:H.join(j(),r);await this.#t(i)}catch(i){this.logger.error(`Error loading ${r}:`,i)}return this.i18n&&!this.i18n.isInitialized&&await this.i18n.init(),super.login(t)}async#t(t){if(!yt(t)){this.logger.debug(`Directory not found: ${t}`);return}let r=U(t);for(let i of r)await this.#e(i)}async#r(){let t=[()=>Promise.resolve().then(()=>(J(),W)),()=>Promise.resolve().then(()=>(Y(),P))];for(let r of t){let i=await r();await this.#i(i,"[core]")}if(this.options.prefix){let r=await Promise.resolve().then(()=>(z(),T));await this.#i(r,"[core]")}}async#e(t){try{let r=At(t);r.searchParams.set("ts",Date.now().toString(36));let i=await import(r.href);await this.#i(i,t)}catch(r){this.logger.error(`Error loading file ${t}:`,r)}}async#i(t,r){let i=new Set;for(let n of Object.values(t))i.add(n);for(let n of i)await this.#s(n,r)}async#s(t,r){if(t!=null){if(Array.isArray(t)){for(let i of t)await this.#s(i,r);return}if(t instanceof b){t.attach(this);return}if(t instanceof u){t.attach(this);return}if(typeof t=="object"&&t!==null&&"attach"in t&&typeof t.attach=="function"){t.attach(this);return}if(typeof t=="function"){let i=await t(this);await this.#s(i,r);return}this.logger.debug(`Skipped unsupported export type in ${r}: ${typeof t}`)}}async registerCommands(){if(!this.token){this.logger.warn("registerCommands skipped: client token is not set.");return}if(!this.application){this.logger.warn("registerCommands skipped: client application is not ready.");return}let t=this.commands.filter(i=>i.supportsSlash).map(i=>i.data.toClientJSON(this)),r=new Ct({version:"10"}).setToken(this.token);try{this.logger.debug(`Started refreshing ${t.length} application (/) commands.`),await r.put(xt.applicationCommands(this.application.id),{body:t}),this.logger.info(`Loaded ${t.length} application (/) commands.`)}catch(i){this.logger.error("Failed to register commands:",i)}}}});var X=l(()=>{"use strict";q()});var b,Q,Z=l(()=>{"use strict";b=class{#t=null;#r=null;#e;#i;#s=!1;_onMessage;_onInteraction;get client(){if(!this.#t)throw new Error("Command is not attached to a client");return this.#t}get logger(){if(!this.#r)throw new Error("Command is not attached to a client");return this.#r}get supportsSlash(){return this.#e&&this._onInteraction}get supportsPrefix(){return this.#i&&this._onMessage}constructor(t){this.data=t;let r=t.toJSON(),{name:i}=r;if(this.#i=r.prefix_support??!1,this.#e=r.slash_support??!1,!this.#i&&!this.#e)throw new Error(`Command ${i} must support either slash or prefix commands.`)}attach(t){if(this.#s)return this;let r=this.data.toJSON(),{name:i,aliases:n}=r;if(this.#t=t,this.#r=t.logger,t.commands.has(i))throw new Error(`Command name "${i}" is already registered.`);let o=t.aliases.findKey(h=>h.has(i));if(o)throw new Error(`Command name "${i}" is already registered as an alias for command "${o}".`);for(let h of n){if(t.commands.has(h))throw new Error(`Alias "${h}" is already registered as a command name.`);let c=t.aliases.findKey(g=>g.has(h));if(c)throw new Error(`Alias "${h}" is already registered as an alias for command "${c}".`)}return t.commands.set(i,this),n.length>0&&t.aliases.set(i,new Set(n)),this.logger.debug(`Loaded Command ${i}`),this.#s=!0,this}onMessage(t){return this._onMessage=t,this}onInteraction(t){return this._onInteraction=t,this}},Q=class extends b{constructor(t){super(t.data);let r=t.data.toJSON(),i=t.execute;(r.prefix_support??!1)&&(t.onMessage||i)&&this.onMessage(n=>t.onMessage?t.onMessage(n):i?.(n)),(r.slash_support??!1)&&(t.onInteraction||i)&&this.onInteraction(n=>t.onInteraction?t.onInteraction(n):i?.(n))}}});import{ChatInputCommandInteraction as Bt,Locale as It,Message as Ot}from"discord.js";var f,L=l(()=>{"use strict";f=class{args;data;locale;constructor(t,r){this.client=t,this.args=r.args??[],"interaction"in r?this.data=r.interaction:this.data=r.message,this.locale=this.client.options.getDefaultLang?.(this)}isInteraction(){return this.data instanceof Bt}isMessage(){return this.data instanceof Ot}get author(){return this.isInteraction()?this.data.user:this.isMessage()?this.data.author:null}t(t,r){if(!this.client.i18n)throw new Error("i18n is not initialized");let i=this.locale??this.client.options.getDefaultLang?.(this)??(Array.isArray(this.client.i18n.options.fallbackLng)?this.client.i18n.options.fallbackLng[0]:this.client.i18n.options.fallbackLng)??It.EnglishUS,o=this.client.i18n.getFixedT(i)(t,r);return o===t&&r?.defaultValue?r.defaultValue:o}toJSON(){let{data:t,args:r,author:i}=this;return this.isInteraction()?{kind:"interaction",interaction:t,author:i,t:(n,o)=>this.t(n,o)}:{kind:"message",message:t,args:r,author:i,t:(n,o)=>this.t(n,o)}}}});var u,tt=l(()=>{"use strict";u=class{#t=null;#r=null;#e;#i=!1;get client(){if(!this.#t)throw new Error("Event is not attached to a client");return this.#t}get logger(){if(!this.#r)throw new Error("Event is not attached to a client");return this.#r}#s=async(...t)=>{if(this.#t&&this.#e)try{await this.#e(this,...t)}catch(r){this.client.logger.error(`Error executing event ${this.name} (${this.constructor.name}):`,r)}};constructor(t,r=!1,i){this.name=t,this.once=r,i&&(this.#e=i)}#n(){this.#i||!this.#e||!this.#t||!this.#r||(this.once?this.client.once(this.name,this.#s):this.client.on(this.name,this.#s),this.#i=!0,this.logger.debug(`Loaded Event ${String(this.name)}`))}attach(t){return this.#t?this:(this.#t=t,this.#r=t.logger,this.#n(),this)}onExecute(t){return this.#e=t,this.#n(),this}}});function A(e){return Array.isArray(e[0])?[...e[0]]:e}var et=l(()=>{"use strict"});import{SlashCommandBuilder as Nt}from"discord.js";var rt,it=l(()=>{"use strict";et();rt=class extends Nt{prefix_support=!0;slash_support=!0;aliases=[];setAliases(...t){return this.aliases=A(t),this}addAliases(...t){return this.aliases=A([...this.aliases,...A(t)]),this}setPrefixSupport(t){return this.prefix_support=t,this}setSlashSupport(t){return this.slash_support=t,this}toJSON(){return super.toJSON()}toClientJSON(t){return{...this.toJSON()}}}});var st=l(()=>{"use strict";Z();L();tt();it()});var d=l(()=>{"use strict";X();st()});d();x();S();var $e="v0.1.2-beta.2";export{rt as ApplicationCommandBuilder,K as Client,Q as Command,b as CommandBuilder,f as Context,u as EventBuilder,C as I18nLoggerAdapter,s as LogLevel,E as Logger,w as LoggerLevel,M as LoggerStyle,Vt as LoggerStyleBackground,Tt as LoggerStyleEffect,zt as LoggerStyleText,R as LoggerTimestamp,at as allowedLocales,N as deleteMessageAfterSent,v as getDefaultLang,U as getFiles,j as getProjectRoot,O as toAllowedLocale,$e as version};
@@ -0,0 +1,18 @@
1
+ import { SlashCommandBuilder, RESTPostAPIChatInputApplicationCommandsJSONBody } from "discord.js";
2
+ import { Client } from "../core/index.js";
3
+ export interface ApplicationJSONBody extends RESTPostAPIChatInputApplicationCommandsJSONBody {
4
+ prefix_support: boolean;
5
+ slash_support: boolean;
6
+ aliases: string[];
7
+ }
8
+ export declare class ApplicationCommandBuilder extends SlashCommandBuilder {
9
+ protected prefix_support: boolean;
10
+ protected slash_support: boolean;
11
+ protected aliases: string[];
12
+ setAliases(...alias: string[]): this;
13
+ addAliases(...alias: string[]): this;
14
+ setPrefixSupport(support: boolean): this;
15
+ setSlashSupport(support: boolean): this;
16
+ toJSON(): ApplicationJSONBody;
17
+ toClientJSON(_client: Client): ReturnType<ApplicationCommandBuilder["toJSON"]>;
18
+ }
@@ -1,33 +1,32 @@
1
- import { ApplicationCommandOptionData, ChatInputCommandInteraction, Message } from "discord.js";
2
- import { Context, Client } from "#structures";
3
- import { Argument } from "./Argument";
4
- import { MaybePromise } from "#types/extra.js";
5
- import { Logger } from "#utils";
6
- type MessageContext = NonNullable<ReturnType<Context<Message>["toJSON"]>>;
7
- type InteractionContext = NonNullable<ReturnType<Context<ChatInputCommandInteraction>["toJSON"]>>;
8
- export interface CommandOptions {
9
- name: string;
10
- description: string;
11
- aliases?: string[];
12
- options?: (ApplicationCommandOptionData | Argument)[];
13
- slash?: boolean;
14
- prefix?: boolean;
15
- }
1
+ import { Client } from "../index.js";
2
+ import { Logger } from "../../utils/index.js";
3
+ import type { MaybePromise } from "#types/extra.js";
4
+ import { ApplicationCommandBuilder } from "../builder/Builder.js";
5
+ import type { InteractionContextJSON, MessageContextJSON } from "../builder/Context.js";
6
+ type MessageContext = MessageContextJSON;
7
+ type InteractionContext = InteractionContextJSON;
8
+ type CommandContext = MessageContext | InteractionContext;
16
9
  export declare class CommandBuilder {
17
- readonly client: Client;
18
- readonly logger: Logger;
19
- readonly name: string;
20
- readonly description: string;
21
- readonly aliases: string[];
22
- readonly options: ApplicationCommandOptionData[];
23
- private _supportsSlash;
24
- private _supportsPrefix;
10
+ #private;
11
+ readonly data: ApplicationCommandBuilder;
25
12
  _onMessage?: (ctx: MessageContext) => MaybePromise<void>;
26
13
  _onInteraction?: (ctx: InteractionContext) => MaybePromise<void>;
14
+ get client(): Client;
15
+ get logger(): Logger;
27
16
  get supportsSlash(): false | ((ctx: InteractionContext) => MaybePromise<void>) | undefined;
28
17
  get supportsPrefix(): false | ((ctx: MessageContext) => MaybePromise<void>) | undefined;
29
- constructor(options: CommandOptions);
18
+ constructor(data: ApplicationCommandBuilder);
19
+ attach(client: Client): this;
30
20
  onMessage(func: (ctx: MessageContext) => MaybePromise<void>): this;
31
21
  onInteraction(func: (ctx: InteractionContext) => MaybePromise<void>): this;
32
22
  }
23
+ export interface CommandOptions {
24
+ data: ApplicationCommandBuilder;
25
+ execute?: (ctx: CommandContext) => MaybePromise<void>;
26
+ onMessage?: (ctx: MessageContext) => MaybePromise<void>;
27
+ onInteraction?: (ctx: InteractionContext) => MaybePromise<void>;
28
+ }
29
+ export declare class Command extends CommandBuilder {
30
+ constructor(options: CommandOptions);
31
+ }
33
32
  export {};
@@ -1,5 +1,6 @@
1
- import { Message, User, ChatInputCommandInteraction, Locale } from "discord.js";
2
- import { Client } from "#structures";
1
+ import { ChatInputCommandInteraction, Locale, Message, User } from "discord.js";
2
+ import type { TOptions } from "i18next";
3
+ import type { Client } from "../index.js";
3
4
  type ContextPayload<T extends ChatInputCommandInteraction | Message> = T extends ChatInputCommandInteraction ? {
4
5
  interaction: T;
5
6
  args?: string[];
@@ -7,6 +8,22 @@ type ContextPayload<T extends ChatInputCommandInteraction | Message> = T extends
7
8
  message: T;
8
9
  args?: string[];
9
10
  };
11
+ type TranslateFn = (key: string, options?: TOptions & {
12
+ defaultValue?: string;
13
+ }) => string;
14
+ export interface InteractionContextJSON {
15
+ kind: "interaction";
16
+ interaction: ChatInputCommandInteraction;
17
+ author: User | null;
18
+ t: TranslateFn;
19
+ }
20
+ export interface MessageContextJSON {
21
+ kind: "message";
22
+ message: Message;
23
+ args: string[];
24
+ author: User | null;
25
+ t: TranslateFn;
26
+ }
10
27
  export declare class Context<T extends ChatInputCommandInteraction | Message> {
11
28
  readonly client: Client;
12
29
  readonly args: string[];
@@ -16,21 +33,10 @@ export declare class Context<T extends ChatInputCommandInteraction | Message> {
16
33
  isInteraction(): this is Context<ChatInputCommandInteraction>;
17
34
  isMessage(): this is Context<Message>;
18
35
  get author(): User | null;
19
- t(key: string, args?: Record<string, any>): string;
20
- toJSON(): {
21
- kind: "interaction";
22
- interaction: T;
23
- author: User | null;
24
- t: any;
25
- message?: undefined;
26
- args?: undefined;
27
- } | {
28
- kind: "message";
29
- message: Message;
30
- args: string[];
31
- author: User | null;
32
- t: any;
33
- interaction?: undefined;
34
- };
36
+ t(key: string, options?: TOptions & {
37
+ defaultValue?: string;
38
+ }): string;
39
+ toJSON(this: Context<ChatInputCommandInteraction>): InteractionContextJSON;
40
+ toJSON(this: Context<Message>): MessageContextJSON;
35
41
  }
36
42
  export {};
@@ -1,19 +1,17 @@
1
1
  import { ClientEvents } from "discord.js";
2
- import { MaybePromise } from "#types/extra.js";
3
- import { Client } from "#structures";
4
- import { Logger } from "#utils";
2
+ import type { MaybePromise } from "#types/extra.js";
3
+ import { Client } from "../index.js";
4
+ import { Logger } from "../../utils/index.js";
5
5
  type EventArgs<K extends keyof ClientEvents> = ClientEvents[K];
6
6
  type EventHandler<K extends keyof ClientEvents> = (context: EventBuilder<K>, ...args: EventArgs<K>) => MaybePromise<void>;
7
7
  export declare class EventBuilder<K extends keyof ClientEvents> {
8
+ #private;
8
9
  readonly name: K;
9
10
  readonly once: boolean;
10
- readonly client: Client;
11
- readonly logger: Logger;
12
- private handler?;
13
- private bound;
14
- private readonly listener;
11
+ get client(): Client;
12
+ get logger(): Logger;
15
13
  constructor(name: K, once?: boolean, _handler?: EventHandler<K>);
16
- private register;
14
+ attach(client: Client): this;
17
15
  onExecute(func: EventHandler<K>): this;
18
16
  }
19
17
  export {};
@@ -1,4 +1,4 @@
1
- export * from "./Argument";
2
- export * from "./Command";
3
- export * from "./Context";
4
- export * from "./Event";
1
+ export * from "./Command.js";
2
+ export * from "./Context.js";
3
+ export * from "./Event.js";
4
+ export * from "./Builder.js";
@@ -1,20 +1,19 @@
1
1
  import { Client as DiscordClient, Collection, IntentsBitField } from "discord.js";
2
- import { CommandBuilder } from "#structures";
3
- import { Logger } from "#utils";
4
- import { FrameworkOptions } from "#types/client.js";
5
- import { i18n } from "i18next";
2
+ import type { i18n } from "i18next";
3
+ import type { FrameworkOptions, PrefixFn } from "#types/client.js";
4
+ import { Logger } from "../../utils/index.js";
5
+ import { CommandBuilder } from "../index.js";
6
6
  export declare class Client<Ready extends boolean = boolean> extends DiscordClient<Ready> {
7
+ #private;
7
8
  readonly logger: Logger;
8
9
  commands: Collection<string, CommandBuilder>;
9
10
  aliases: Collection<string, Set<string>>;
10
- readonly prefix: string | false;
11
+ readonly prefix: PrefixFn;
11
12
  i18n: i18n | undefined;
12
13
  options: Omit<FrameworkOptions, "intents"> & {
13
14
  intents: IntentsBitField;
14
15
  };
15
16
  constructor(opts: FrameworkOptions);
16
17
  login(token?: string): Promise<string>;
17
- loadDir(dir: string): Promise<void>;
18
- loadFile(file: string): Promise<void>;
19
18
  registerCommands(): Promise<void>;
20
19
  }
@@ -1 +1 @@
1
- export * from "./Client";
1
+ export * from "./Client.js";
@@ -1,2 +1,2 @@
1
- export * from "./core";
2
- export * from "./builder";
1
+ export * from "./core/index.js";
2
+ export * from "./builder/index.js";
@@ -1,3 +1,3 @@
1
- export * from "./util";
2
- export * from "./Files";
3
- export * from "./logger/Logger";
1
+ export * from "./util.js";
2
+ export * from "./Files.js";
3
+ export * from "./logger/Logger.js";
@@ -31,46 +31,4 @@ export declare enum LogLevel {
31
31
  */
32
32
  None = 100
33
33
  }
34
- export interface ILogger {
35
- /**
36
- * Checks whether a level is supported.
37
- * @param level The level to check.
38
- */
39
- has(level: LogLevel): boolean;
40
- /**
41
- * Alias of {@link ILogger.write} with {@link LogLevel.Trace} as level.
42
- * @param values The values to log.
43
- */
44
- trace(...values: readonly unknown[]): void;
45
- /**
46
- * Alias of {@link ILogger.write} with {@link LogLevel.Debug} as level.
47
- * @param values The values to log.
48
- */
49
- debug(...values: readonly unknown[]): void;
50
- /**
51
- * Alias of {@link ILogger.write} with {@link LogLevel.Info} as level.
52
- * @param values The values to log.
53
- */
54
- info(...values: readonly unknown[]): void;
55
- /**
56
- * Alias of {@link ILogger.write} with {@link LogLevel.Warn} as level.
57
- * @param values The values to log.
58
- */
59
- warn(...values: readonly unknown[]): void;
60
- /**
61
- * Alias of {@link ILogger.write} with {@link LogLevel.Error} as level.
62
- * @param values The values to log.
63
- */
64
- error(...values: readonly unknown[]): void;
65
- /**
66
- * Alias of {@link ILogger.write} with {@link LogLevel.Fatal} as level.
67
- * @param values The values to log.
68
- */
69
- fatal(...values: readonly unknown[]): void;
70
- /**
71
- * Writes the log message given a level and the value(s).
72
- * @param level The log level.
73
- * @param values The values to log.
74
- */
75
- write(level: LogLevel, ...values: readonly unknown[]): void;
76
- }
34
+ export type { ILogger } from "#types/logger.js";
@@ -1,9 +1,12 @@
1
1
  import { Console } from "console";
2
2
  import type { Color } from "colorette";
3
3
  import { Timestamp } from "@sapphire/timestamp";
4
- import type { ILogger } from "./ILogger";
5
- import { LogLevel } from "./ILogger";
6
- import { LoggerModule } from "i18next";
4
+ import type { ILogger } from "./ILogger.js";
5
+ import { LogLevel } from "./ILogger.js";
6
+ import type { LoggerLevelOptions, LoggerOptions, LoggerStyleResolvable, LoggerTimestampFormatter, LoggerTimestampOptions } from "#types/logger.js";
7
+ import type { LoggerModule } from "i18next";
8
+ export { LogLevel } from "./ILogger.js";
9
+ export type { LoggerFormatOptions, LoggerLevelOptions, LoggerOptions, LoggerStyleOptions, LoggerStyleResolvable, LoggerTimestampFormatter, LoggerTimestampOptions, } from "#types/logger.js";
7
10
  export declare class Logger implements ILogger {
8
11
  level: LogLevel;
9
12
  readonly formats: Map<LogLevel, LoggerLevel>;
@@ -56,44 +59,6 @@ export declare class LoggerLevel {
56
59
  }
57
60
  declare const _default: Logger;
58
61
  export default _default;
59
- export interface LoggerOptions {
60
- stdout?: NodeJS.WritableStream;
61
- stderr?: NodeJS.WritableStream;
62
- defaultFormat?: LoggerLevelOptions;
63
- format?: LoggerFormatOptions;
64
- level?: LogLevel;
65
- join?: string;
66
- depth?: number;
67
- }
68
- export interface LoggerFormatOptions {
69
- trace?: LoggerLevelOptions;
70
- debug?: LoggerLevelOptions;
71
- info?: LoggerLevelOptions;
72
- warn?: LoggerLevelOptions;
73
- error?: LoggerLevelOptions;
74
- fatal?: LoggerLevelOptions;
75
- none?: LoggerLevelOptions;
76
- }
77
- export interface LoggerLevelOptions {
78
- timestamp?: LoggerTimestampOptions | null;
79
- infix?: string;
80
- message?: LoggerStyleResolvable | null;
81
- }
82
- export interface LoggerTimestampOptions {
83
- pattern?: string;
84
- utc?: boolean;
85
- color?: LoggerStyleResolvable | null;
86
- formatter?: LoggerTimestampFormatter;
87
- }
88
- export interface LoggerTimestampFormatter {
89
- (timestamp: string): string;
90
- }
91
- export interface LoggerStyleOptions {
92
- effects?: LoggerStyleEffect[];
93
- text?: LoggerStyleText;
94
- background?: LoggerStyleBackground;
95
- }
96
- export type LoggerStyleResolvable = Color | LoggerStyleOptions;
97
62
  export declare enum LoggerStyleEffect {
98
63
  Reset = "reset",
99
64
  Bold = "bold",
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Normalizes data that is a rest parameter or an array into an array with a depth of 1.
3
+ *
4
+ * @typeParam ItemType - The data that must satisfy {@link RestOrArray}.
5
+ * @param arr - The (possibly variadic) data to normalize
6
+ */
7
+ export declare function normalizeArray<ItemType>(arr: RestOrArray<ItemType>): ItemType[];
8
+ /**
9
+ * Represents data that may be an array or came from a rest parameter.
10
+ *
11
+ * @remarks
12
+ * This type is used throughout builders to ensure both an array and variadic arguments
13
+ * may be used. It is normalized with {@link normalizeArray}.
14
+ */
15
+ export type RestOrArray<Type> = Type[] | [Type[]];
@@ -1,4 +1,6 @@
1
- import { PrefixOptions } from "#types/client.js";
2
- import { InteractionResponse, Message } from "discord.js";
1
+ import { ChatInputCommandInteraction, InteractionResponse, Locale, Message } from "discord.js";
2
+ import type { Context } from "../structures/index.js";
3
+ export declare const allowedLocales: readonly ["id", "en-US", "en-GB", "bg", "zh-CN", "zh-TW", "hr", "cs", "da", "nl", "fi", "fr", "de", "el", "hi", "hu", "it", "ja", "ko", "lt", "no", "pl", "pt-BR", "ro", "ru", "es-ES", "es-419", "sv-SE", "th", "tr", "uk", "vi"];
3
4
  export declare function deleteMessageAfterSent(message: Message | InteractionResponse, time?: number): Promise<void>;
4
- export declare function getPrefix(opts: PrefixOptions): string | false;
5
+ export declare function toAllowedLocale(locale: string | null | undefined): `${Locale}` | undefined;
6
+ export declare function getDefaultLang(ctx: Context<ChatInputCommandInteraction | Message>): `${Locale}`;
package/package.json CHANGED
@@ -1,62 +1 @@
1
- {
2
- "name": "@arox/framework",
3
- "version": "0.1.1",
4
- "description": "",
5
- "keywords": [
6
- "discord.js",
7
- "framework"
8
- ],
9
- "homepage": "https://github.com/AroxBot/framework#readme",
10
- "bugs": {
11
- "url": "https://github.com/AroxBot/framework/issues"
12
- },
13
- "license": "Apache-2.0",
14
- "author": "vrdons",
15
- "repository": {
16
- "type": "git",
17
- "url": "git+https://github.com/AroxBot/framework.git"
18
- },
19
- "type": "commonjs",
20
- "main": "dist/index.js",
21
- "types": "dist/index.d.ts",
22
- "imports": {
23
- "#types/*": "./types/*",
24
- "#utils": "./src/utils/index.ts",
25
- "#structures": "./src/structures/index.ts",
26
- "#ctx": "./src/context.ts"
27
- },
28
- "scripts": {
29
- "prepare": "node scripts/prepareHusky.js",
30
- "test": "echo \"Error: no test specified\" && exit 1",
31
- "check": "oxfmt --check && oxlint --type-aware --type-check",
32
- "format": "oxfmt",
33
- "build:js": "swc src -d dist --strip-leading-paths --copy-files",
34
- "build:dts": "tsc --emitDeclarationOnly",
35
- "build": "npm run build:js && node ./scripts/actions/patch.js && npm run build:dts",
36
- "release:git": "node scripts/actions/github.js",
37
- "release:npm": "node scripts/actions/npm.js"
38
- },
39
- "dependencies": {
40
- "@sapphire/timestamp": "^1.0.5",
41
- "@swc/helpers": "^0.5.18",
42
- "colorette": "^2.0.20",
43
- "fast-glob": "^3.3.3",
44
- "i18next": "^25.8.0",
45
- "i18next-fs-backend": "^2.6.1",
46
- "lodash": "^4.17.21"
47
- },
48
- "devDependencies": {
49
- "@swc/cli": "^0.7.10",
50
- "@types/lodash": "^4.17.23",
51
- "@types/node": "^25.0.9",
52
- "husky": "^9.1.7",
53
- "libnpmpack": "^9.0.12",
54
- "oxfmt": "^0.26.0",
55
- "oxlint": "^1.39.0",
56
- "oxlint-tsgolint": "^0.11.0",
57
- "typescript": "^5.9.3"
58
- },
59
- "peerDependencies": {
60
- "discord.js": ">=14.25.1"
61
- }
62
- }
1
+ {"name":"@arox/framework","version":"0.1.2-beta.2","description":"","keywords":["arox","discord.js","framework"],"homepage":"https://github.com/AroxBot/framework#readme","bugs":{"url":"https://github.com/AroxBot/framework/issues"},"license":"Apache-2.0","author":"vrdons","contributors":["fhyrox"],"repository":{"type":"git","url":"git+https://github.com/AroxBot/framework.git"},"type":"module","main":"dist/index.cjs","module":"dist/index.js","types":"dist/index.d.ts","imports":{"#types/*":"./types/*.d.ts"},"exports":{".":{"types":"./dist/index.d.ts","require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"},"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"default":"./dist/index.js"}},"dependencies":{"@sapphire/timestamp":"^1.0.5","colorette":"^2.0.20","fast-glob":"^3.3.3","i18next":"^25.8.0"},"peerDependencies":{"discord.js":">=14.25.1"}}
package/types/client.d.ts CHANGED
@@ -1,21 +1,22 @@
1
- import { ClientOptions } from "discord.js";
2
- import { LoggerOptions } from "../src/utils/logger/Logger";
1
+ import {
2
+ ChatInputCommandInteraction,
3
+ ClientOptions,
4
+ Locale,
5
+ Message,
6
+ } from "discord.js";
7
+ import type { LoggerOptions } from "./logger.js";
3
8
  import { i18n } from "i18next";
9
+ import type { Context } from "../src/structures/builder/Context.js";
4
10
 
5
- export interface FrameworkPaths {
6
- events?: string;
7
- commands?: string;
8
- locales?: string;
9
- }
10
-
11
- export type PrefixOptions =
12
- | { enabled: true; prefix: string }
13
- | { enabled: false }
14
- | string;
11
+ export type PrefixFn = (ctx: Context<Message>) => string | false;
12
+ export type GetDefaultLangFn = (
13
+ ctx: Context<ChatInputCommandInteraction | Message>
14
+ ) => `${Locale}` | undefined;
15
15
 
16
16
  export interface FrameworkOptions extends ClientOptions {
17
17
  logger?: LoggerOptions;
18
- prefix?: PrefixOptions;
18
+ prefix?: PrefixFn;
19
+ getDefaultLang?: GetDefaultLangFn;
19
20
  autoRegisterCommands?: boolean;
20
21
  includePaths: string[];
21
22
  i18n?: i18n;