Skip to content

Commit

Permalink
Merge branch 'AkaruiDevelopment:v6' into v6
Browse files Browse the repository at this point in the history
  • Loading branch information
Faf4a authored Nov 14, 2023
2 parents 4599f04 + 86e489f commit 2ff5f4a
Show file tree
Hide file tree
Showing 21 changed files with 546 additions and 579 deletions.
53 changes: 21 additions & 32 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"discordbot"
],
"dependencies": {
"@akarui/aoi.db": "^1.0.0",
"@akarui/aoi.db": "github:akaruidevelopment/aoi.db#v2",
"@akarui/structures": "^1.0.2",
"chalk": "^4.1.2",
"discord.js": "^14.13.0",
Expand Down
80 changes: 49 additions & 31 deletions src/classes/AoiBase.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Discord = require("discord.js");
const {VariableManager} = require("./Variables.js");
const { VariableManager } = require("./Variables.js");
const InteractionManager = require("./Interaction.js");
const LoadCommands = require("./LoadCommands.js");
const {
Expand All @@ -9,14 +9,12 @@ const {
EventsToDjsEvents,
EventstoFile,
} = require("../utils/Constants.js");
const {
AoijsAPI
} = require("./Database.js");
const Database = require("./Database.js");
const CacheManager = require("./CacheManager.js");
const {CommandManager} = require("./Commands.js");
const {Group} = require("@akarui/structures");
const { CommandManager } = require("./Commands.js");
const { Group } = require("@akarui/structures");
const AoiError = require("./AoiError.js");
const {functions: parser} = require("../core/AoiReader.js");
const { functions: parser } = require("../core/AoiReader.js");

class BaseClient extends Discord.Client {
constructor(options) {
Expand Down Expand Up @@ -51,26 +49,41 @@ class BaseClient extends Discord.Client {
this.variableManager = new VariableManager(this);

if (
[
"default",
"aoi.db",
].includes(options?.database?.type)
["default", "aoi.db"].includes(options?.database?.type) ||
!options?.database
) {
this.db = new AoijsAPI(
options?.database?.db || require("@akarui/aoi.db"),
{
path: options?.database?.path || "./database/",
tables: options?.database?.tables || ["main"],
},
const dbData = options?.database;

this.db = new Database(
dbData?.type
? dbData?.type === "default"
? "aoi.db"
: dbData?.type
: "aoi.db",
dbData?.db ?? require("@akarui/aoi.db"),
dbData?.dbType ?? "KeyValue",
{
type: options?.database?.type || "default",
promisify: options?.database?.promisify || false,
dataConfig: {
path: dbData?.path ?? "./database",
tables: dbData?.tables?.length
? [...dbData?.tables, "__aoijs_vars__"]
: ["main", "__aoijs_vars__"],
},
encryptionConfig: {
securityKey:
dbData?.securityKey ??
"a-32-characters-long-string-here",
encriptData: dbData?.encriptData ?? false,
},
...dbData?.extraOptions,
},
options?.database?.extraOptions || {},
);
}

if (Array.isArray(options?.disableFunctions) && options?.disableFunctions.length) {
if (
Array.isArray(options?.disableFunctions) &&
options?.disableFunctions.length
) {
options?.disableFunctions.forEach((func) => {
const index = parser.findIndex((f) => f === func);
if (index !== -1) {
Expand All @@ -82,7 +95,7 @@ class BaseClient extends Discord.Client {
this.prefix = options.prefix;
this.#bindEvents();

Object.defineProperty(this, "statuses", {value: new Group()});
Object.defineProperty(this, "statuses", { value: new Group() });

this.on("ready", async () => {
await require("../handler/NonIntents/ready.js")(this);
Expand All @@ -93,16 +106,16 @@ class BaseClient extends Discord.Client {
}

loadCommands(directory, debug = true) {

const loader = new LoadCommands(this);
loader.load(this.cmd, directory, debug);
}

status(...statuses) {
for (const status of statuses) {
status.type =
Object.keys(ActivityTypeAvailables).includes(status.type.toLowerCase()) ||
Object.values(ActivityTypeAvailables).includes(status.type)
Object.keys(ActivityTypeAvailables).includes(
status.type.toLowerCase(),
) || Object.values(ActivityTypeAvailables).includes(status.type)
? ActivityTypeAvailables[status.type.toLowerCase()]
: ActivityTypeAvailables.playing;

Expand All @@ -113,7 +126,7 @@ class BaseClient extends Discord.Client {
};

this.statuses.set(this.statuses.size, {
status: status.status || 'online',
status: status.status || "online",
time: isNaN(status.time) ? 12 : status.time,
activity: option,
afk: status.afk || false,
Expand All @@ -128,7 +141,9 @@ class BaseClient extends Discord.Client {
*/
variables(d, table = this.db?.tables?.[0]) {
if (this.db === undefined) {
throw new TypeError('A database must be provided to use the variables method.');
throw new TypeError(
"A database must be provided to use the variables method.",
);
}

for (const [name, value] of Object.entries(d)) {
Expand Down Expand Up @@ -168,15 +183,18 @@ class BaseClient extends Discord.Client {
].includes(event)
? require(`../shardhandler/${event}.js`)
: Array.isArray(file)
? file.map((x) => require(`../handler/${filedir}/${x}.js`))
: require(`../handler/${filedir}/${file}.js`);
? file.map((x) => require(`../handler/${filedir}/${x}.js`))
: require(`../handler/${filedir}/${file}.js`);

this.on(eventName, (...args) => {
if (Array.isArray(func)) func.forEach((x) => x(...args, this));
if (Array.isArray(func))
func.forEach((x) => x(...args, this));
else func(...args, this);
});
} catch (error) {
throw new TypeError(`Error loading "${event}" event, does not exist!`);
throw new TypeError(
`Error loading "${event}" event, does not exist!`,
);
}
}
}
Expand Down
Loading

0 comments on commit 2ff5f4a

Please sign in to comment.