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 Oct 5, 2023
2 parents b88b531 + 73ea61b commit 05f84a5
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 103 deletions.
30 changes: 7 additions & 23 deletions src/classes/AoiBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,6 @@ class BaseClient extends Discord.Client {
);
}

if (options.presence?.activities?.length) {
if (
Object.keys(ActivityTypeAvailables).includes(
options.presence?.activities[0].type,
) ||
Object.values(ActivityTypeAvailables).includes(
options.presence?.activities[0].type,
)
) {
options.presence.activities[0].type =
ActivityTypeAvailables[
options.presence?.activities[0].type
] || options.presence?.activities[0].type;
} else {
throw new TypeError(
`Activity Type Error: Invalid Activity Type (${options.presence?.activities[0].type}) Provided`,
);
}
}

options.partials = options.partials || [
Discord.Partials.GuildMember,
Discord.Partials.Channel,
Expand Down Expand Up @@ -105,9 +85,9 @@ class BaseClient extends Discord.Client {
Object.defineProperty(this, "statuses", {value: new Group()});

this.on("ready", async () => {
await require("../handler/NonIntents/ready.js")(this);
await require("../handler/status.js")(this.statuses, this);
await require("../handler/AoiStart.js")(this);
await require("../handler/NonIntents/ready.js")(this);
});
this.login(options.token);
}
Expand Down Expand Up @@ -146,9 +126,13 @@ class BaseClient extends Discord.Client {
* @param {Record<string,string | number | object >} d
* @param table
*/
variables(d, table = this.db.tables[0]) {
variables(d, table = this.db?.tables?.[0]) {
if (this.db === undefined) {
throw new TypeError('A database must be provided to use the variables method.');
}

for (const [name, value] of Object.entries(d)) {
this.variableManager.add({name, value, table});
this.variableManager.add({ name, value, table });
}
}

Expand Down
1 change: 0 additions & 1 deletion src/classes/AoiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class Client extends BaseClient {
this.addCommandType("messageDeleteBulk", d);
}

// Add other command types here
guildJoinCommand(d = {}) {
this.addCommandType("guildJoin", d);
}
Expand Down
2 changes: 1 addition & 1 deletion src/classes/Functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CustomFunction {
this.name = d.name;
this.code = d.code;
this.type = d.type;
this.params = d.params;
this.params = d.params || [];
this.functions =
this.type === "aoi.js" ? this.serializeFunctions() : undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion src/functions/client/killClient.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = d => {
const data = d.util.aoiFunc(d);

data.result = d.client.destroy();
d.client.destroy();

return {
code: d.util.setCode(data)
Expand Down
36 changes: 20 additions & 16 deletions src/handler/AoiStart.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const Interpreter = require("../core/interpreter.js");

module.exports = async (client) => {
module.exports = async (client, options) => {

if (client.aoiOptions.aoiLogs !== false) {
await require("./AoiLogs.js")(client);
}
Expand All @@ -13,21 +14,24 @@ module.exports = async (client) => {
await require("./AoiAutoUpdate.js")(client);
}

await require("./Custom/timeout.js")(
{client, interpreter: Interpreter},
undefined,
undefined,
undefined,
true,
);
await require("./Custom/timeoutPulse.js")(
{client, interpreter: Interpreter},
undefined,
undefined,
undefined,
undefined,
true,
);
if (client.aoiOptions.database && client.aoiOptions.database) {
await require("./Custom/timeout.js")(
{ client, interpreter: Interpreter },
undefined,
undefined,
undefined,
true
);

await require("./Custom/timeoutPulse.js")(
{ client, interpreter: Interpreter },
undefined,
undefined,
undefined,
undefined,
true
);
}

if (client.cmd.loop.size) {
await require("./Custom/loop.js")(client);
Expand Down
106 changes: 49 additions & 57 deletions src/handler/status.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,54 @@
const createCustomBoxedMessage = require('../utils/CustomBox.js');
module.exports = async (statuses, client) => {
if (statuses.size === 0) {
return;
}

let recommendationLogged = false;
const statusArray = statuses.allValues();
let y = 0;

module.exports = async (statuses, client) => {
if (statuses.size !== 0) {
let y = 0;
const processStatus = async () => {
if (!statusArray[y]) {
y = 0;
}

let status = statuses.allValues();
const f = async () => {
if (!status[y]) {
y = 0;
}
setTimeout(async () => {
const stats = {};
stats.activity = {};

stats.activity.type = status[y].activity.type;
stats.activity.url = status[y].activity.url;

if (status[y].activity.name) {

if (status[y].activity.name.includes("$")) {
stats.activity.name = (
await client.functionManager.interpreter(
client,
{},
[],
{ code: status[y].activity.name },
client.db,
true,
)
)?.code;
} else {
stats.activity.name = status[y].activity.name;
}
} else {
if (!recommendationLogged) {
const recommendationMessage = `Use the name method or provide a name for status[${y}]`;
createCustomBoxedMessage([{ text: recommendationMessage, textColor: 'red' }], 'white', {
text: 'AoiWarning',
textColor: 'yellow',
})
recommendationLogged = true;
}

stats.activity.name = "Using aoi.js";
}

client.user.setPresence({
status: status[y].status,
activities: [stats.activity],
afk: status[y].afk,
});

y++;
await f();
}, (status[y]?.time || 12) * 1000);
const stats = {
activity: {
type: statusArray[y].activity.type,
url: statusArray[y].activity.url,
},
};
f();
}

if (statusArray[y].activity.name) {
if (statusArray[y].activity.name.includes("$")) {
stats.activity.name = (
await client.functionManager.interpreter(
client,
{},
[],
{ code: statusArray[y].activity.name },
client.db,
true
)
)?.code;
} else {
stats.activity.name = statusArray[y].activity.name;
}
} else {
throw new TypeError(`Use the name method or provide a name for status[${y}]`);
}

client.user.setPresence({
status: statusArray[y].status,
activities: [stats.activity],
afk: statusArray[y].afk,
});

y++;

if (y < statusArray.length) {
setTimeout(processStatus, statusArray[y]?.time * 1000 || 0);
}
};

await processStatus();
};
8 changes: 4 additions & 4 deletions src/utils/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,11 +569,13 @@ const EventsToDjsEvents = {
// Guild Message Typings
onTypingStart: Events.TypingStart,

// Guild Webhooks
onWebhooksUpdate: Events.WebhooksUpdate,

// Non-Intents
onInteractionCreate: Events.InteractionCreate,
onApplicationCommandPermissionsUpdate: Events.ApplicationCommandPermissionsUpdate,
onUserUpdate: Events.UserUpdate,
onWebhooksUpdate: Events.WebhooksUpdate,

//Automod
onAutoModerationActionExecution: Events.AutoModerationActionExecution,
Expand Down Expand Up @@ -658,11 +660,9 @@ const EventstoFile = {
onVoiceStateUpdate: "update",
onPresenceUpdate: "update",

// Interaction and command events
// Non-Intents
onInteractionCreate: "interaction",
onApplicationCommandPermissionsUpdate: "appCmdPermissionsUpdate",

// User events
onUserUpdate: "userUpdate",

// Variable events
Expand Down

0 comments on commit 05f84a5

Please sign in to comment.