-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f8cfb4
commit a5600bb
Showing
56 changed files
with
4,473 additions
and
3,358 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
node_modules | ||
dist | ||
coverage | ||
index.mjs | ||
index.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,91 @@ | ||
export default class AoiClient { | ||
import Transpiler from '@aoi.js/core/Transpiler.js'; | ||
import { CommandManager } from '@aoi.js/managers/Command.js'; | ||
import FunctionManager from '@aoi.js/managers/Function.js'; | ||
import { type IAoiClientOptions } from '@aoi.js/typings/interface.js'; | ||
import { type AoiClientProps } from '@aoi.js/typings/type.js'; | ||
import { Client, DefaultWebSocketManagerOptions, Partials, type ClientOptions } from 'discord.js'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging | ||
interface AoiClient extends AoiClientProps { | ||
client: Client; | ||
} | ||
|
||
|
||
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging | ||
class AoiClient { | ||
client!: Client; | ||
|
||
} | ||
transpiler: Transpiler; | ||
database = null; | ||
managers!: { | ||
commands: CommandManager; | ||
functions: FunctionManager; | ||
}; | ||
|
||
readonly #options: IAoiClientOptions; | ||
|
||
|
||
constructor(options: IAoiClientOptions) { | ||
this.#validateOptions(options); | ||
this.#options = options; | ||
|
||
const transpilerOptions = { | ||
minify: options.transpilerOptions?.minify ?? true, | ||
customFunctions: {}, | ||
}; | ||
|
||
this.transpiler = new Transpiler(transpilerOptions, this); | ||
this.managers = { | ||
commands: new CommandManager(this), | ||
functions: new FunctionManager(this), | ||
}; | ||
|
||
if (options.testMode) return; | ||
|
||
const djsOptions: ClientOptions = options.djsClientOptions ?? { intents: 0 }; | ||
djsOptions.partials ||= [ | ||
Partials.GuildMember, | ||
Partials.Channel, | ||
Partials.Message, | ||
Partials.Reaction, | ||
Partials.User, | ||
Partials.GuildScheduledEvent, | ||
Partials.ThreadMember, | ||
]; | ||
djsOptions.intents = options.intents; | ||
|
||
this.client = new Client(djsOptions); | ||
} | ||
|
||
async start() { | ||
await this.client.login(this.#options.token); | ||
} | ||
|
||
#validateOptions(options: IAoiClientOptions) { | ||
if (options.intents === undefined) { | ||
throw new SyntaxError('Intents not provided, "Guilds" intent is required'); | ||
} | ||
|
||
if (isNaN(options.intents)) { | ||
throw new TypeError('Provided intents are not of type "number"'); | ||
} | ||
|
||
if (!options.token) { | ||
throw new SyntaxError('Token not provided'); | ||
} | ||
|
||
if (!options.prefix?.length) { | ||
throw new SyntaxError('Prefix not provided'); | ||
} | ||
} | ||
|
||
get prefix() { | ||
return this.#options.prefix; | ||
} | ||
|
||
get options() { | ||
return this.#options; | ||
} | ||
} | ||
|
||
export default AoiClient; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,78 @@ | ||
import Transpiler from '@aoi.js/core/Transpiler'; | ||
import { type CommandTypes } from '@aoi.js/typings/type.js'; | ||
import { type AsyncFunction, type CommandTypes } from '@aoi.js/typings/type.js'; | ||
import type AoiClient from './AoiClient'; | ||
import { type ICommandOptions } from '@aoi.js/typings/interface.js'; | ||
import { type Snowflake } from 'discord.js'; | ||
|
||
export default class Command { | ||
[key: string]: unknown; | ||
name!: string; | ||
type!: CommandTypes; | ||
code!: string | (() => Promise<void>); | ||
aliases?: string[]; | ||
channel?: string | bigint; | ||
channel?: string; | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
__path__!: string; | ||
reverseRead?: boolean; | ||
executeAt?: 'guild' | 'dm' | 'both'; | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
__compiled__!: () => Promise<void>; | ||
__compiled__!: AsyncFunction; | ||
|
||
constructor(data: ICommandOptions, client: AoiClient) { | ||
// this.name = data.name; | ||
// this.type = data.type; | ||
// this.code = data.code; | ||
// this.aliases = data.aliases; | ||
// this.__path__ = data.__path__; | ||
// this.executeAt = data.executeAt ?? 'both'; | ||
// this.reverseRead = data.reverseRead ?? false; | ||
// for (const key in data) { | ||
// if ( | ||
// ![ | ||
// 'name', | ||
// 'type', | ||
// 'code', | ||
// 'aliases', | ||
// '__path__', | ||
// 'executeAt', | ||
// 'reverseRead', | ||
// ].includes(key) | ||
// ) | ||
// this[key] = data[key]; | ||
// } | ||
// if (this.code instanceof Function) this.__compiled__ = this.code; | ||
// else { | ||
// let chan: Snowflake | undefined | AsyncFunction; | ||
// if (this.channel) { | ||
// if ( | ||
// typeof this.channel === 'string' && | ||
// this.channel.startsWith('$') | ||
// ) { | ||
// chan = new Transpiler(this.channel, { | ||
// sendMessage: false, | ||
// minify: true, | ||
// customFunctions: client.managers.functions.functions.toJSON(), | ||
// scopeData: { | ||
// name: 'GLOBAL_CHANNEL', | ||
// }, | ||
// client, | ||
// }).func; | ||
// } else if (typeof this.channel === 'string') | ||
// chan = BigInt(this.channel); | ||
// else chan = this.channel; | ||
// } | ||
// const func = new Transpiler(this.code, { | ||
// sendMessage: true, | ||
// minify: true, | ||
// reverse: this.reverseRead, | ||
// customFunctions: client.managers.functions.functions.toJSON(), | ||
// client, | ||
// scopeData: { | ||
// functions: | ||
// typeof chan === 'function' | ||
// ? `${chan.toString()}` | ||
// : undefined, | ||
// useChannel: | ||
// typeof chan === 'function' ? `${chan.name}()` : chan, | ||
// }, | ||
// }); | ||
// this.__compiled__ = func.func; | ||
this.name = data.name; | ||
this.type = data.type; | ||
this.code = data.code; | ||
this.aliases = data.aliases; | ||
this.__path__ = data.__path__; | ||
this.executeAt = data.executeAt ?? 'both'; | ||
this.reverseRead = data.reverseRead ?? false; | ||
|
||
const transpiler = client.transpiler; | ||
|
||
for (const key in data) { | ||
if ( | ||
![ | ||
'name', | ||
'type', | ||
'code', | ||
'aliases', | ||
'__path__', | ||
'executeAt', | ||
'reverseRead', | ||
].includes(key) | ||
) | ||
this[key] = data[key]; | ||
} | ||
|
||
if (this.code instanceof Function) this.__compiled__ = this.code; | ||
else { | ||
let channelId: Snowflake | undefined | AsyncFunction; | ||
if (this.channel) { | ||
if ( | ||
typeof this.channel === 'string' && | ||
this.channel.startsWith('$') | ||
) { | ||
channelId = transpiler.transpile(this.channel, { | ||
sendMessage: false, | ||
scopeData: { | ||
name: 'GLOBAL_CHANNEL', | ||
}, | ||
}).func; | ||
} else channelId = this.channel; | ||
} | ||
|
||
const func = transpiler.transpile(this.code, { | ||
sendMessage: true, | ||
reverse: this.reverseRead, | ||
scopeData: { | ||
functions: | ||
typeof channelId === 'function' | ||
? [channelId.toString()] | ||
: undefined, | ||
useChannel: | ||
typeof channelId === 'function' ? `${channelId.name}()` : channelId, | ||
}, | ||
}); | ||
this.__compiled__ = func.func; | ||
} | ||
} | ||
} |
Oops, something went wrong.