-
-
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.
Merge pull request #503 from Faf4a/v6
- Loading branch information
Showing
23 changed files
with
677 additions
and
523 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,72 +1,84 @@ | ||
const aoidb = require("@akarui/aoi.db"); | ||
const AoiError = require("../classes/AoiError.js"); | ||
|
||
class Database { | ||
/** | ||
* @type {aoidb.KeyValue | aoidb.Transmitter} db | ||
* @type {boolean} ready | ||
* @type {number} readyAt | ||
* @type {"aoi.db"} type | ||
* @type {"KeyValue" | "Transmitter"} moduleType | ||
* @type {string[]} tables | ||
*/ | ||
db; | ||
ready = false; | ||
readyAt = 0; | ||
type; | ||
tables = []; | ||
moduleType = "KeyValue"; | ||
/** | ||
* Description | ||
* @param {any} module | ||
* @param {"KeyValue" | "Transmitter"} type | ||
* @param {aoidb.KeyValueOptions | aoidb.TransmitterOptions} config | ||
* @returns {any} | ||
*/ | ||
constructor(moduleType, module, type, config) { | ||
this.moduleType = type; | ||
this.db = new module[type](config); | ||
this.tables = config.dataConfig.tables; | ||
this.type = moduleType; | ||
this.db.on(aoidb.DatabaseEvents.Connect, () => { | ||
console.log(`[@akarui/aoi.db] Connected ${type} database`); | ||
this.ready = true; | ||
this.readyAt = Date.now(); | ||
}); | ||
/** | ||
* @type {aoidb.KeyValue | aoidb.Transmitter} db | ||
* @type {boolean} ready | ||
* @type {number} readyAt | ||
* @type {"aoi.db"} type | ||
* @type {"KeyValue" | "Transmitter"} moduleType | ||
* @type {string[]} tables | ||
*/ | ||
db; | ||
ready = false; | ||
readyAt = 0; | ||
type; | ||
tables = []; | ||
moduleType = "KeyValue"; | ||
/** | ||
* Description | ||
* @param {any} module | ||
* @param {"KeyValue" | "Transmitter"} type | ||
* @param {aoidb.KeyValueOptions | aoidb.TransmitterOptions} config | ||
* @returns {any} | ||
*/ | ||
constructor(moduleType, module, type, config) { | ||
this.moduleType = type; | ||
this.db = new module[type](config); | ||
this.tables = config.dataConfig.tables; | ||
this.type = moduleType; | ||
this.db.on(aoidb.DatabaseEvents.Connect, () => { | ||
AoiError.createCustomBoxedMessage( | ||
[ | ||
{ | ||
text: `Successfully connected ${type} database`, | ||
textColor: "white", | ||
}, | ||
], | ||
"white", | ||
{ text: "@akarui/db ", textColor: "cyan" } | ||
); | ||
|
||
this.db.connect(); | ||
} | ||
// console.log(`[@akarui/aoi.db] Connected ${type} database`); | ||
this.ready = true; | ||
this.readyAt = Date.now(); | ||
}); | ||
|
||
async set(table, key, id, value) { | ||
return await this.db.set(table, id ? `${key}_${id}` : key, { value }); | ||
} | ||
this.db.connect(); | ||
} | ||
|
||
async get(table, key, id) { | ||
return await this.db.get(table, id ? `${key}_${id}` : key); | ||
} | ||
async set(table, key, id, value) { | ||
return await this.db.set(table, id ? `${key}_${id}` : key, { value }); | ||
} | ||
|
||
async delete(table, key, id) { | ||
return await this.db.delete(table, id ? `${key}_${id}` : key); | ||
} | ||
async get(table, key, id) { | ||
return await this.db.get(table, id ? `${key}_${id}` : key); | ||
} | ||
|
||
async all(table, query, limit) { | ||
return await this.db.all(table, query, limit); | ||
} | ||
async delete(table, key, id) { | ||
return await this.db.delete(table, id ? `${key}_${id}` : key); | ||
} | ||
|
||
async has(table, key, id) { | ||
return await this.db.has(table, id ? `${key}_${id}` : key); | ||
} | ||
async all(table, query, limit) { | ||
return await this.db.all(table, query, limit); | ||
} | ||
|
||
async deleteMany(table, query) { | ||
return await this.db.deleteMany(table, query); | ||
} | ||
async has(table, key, id) { | ||
return await this.db.has(table, id ? `${key}_${id}` : key); | ||
} | ||
|
||
async findOne(table, query) { | ||
return await this.db.findOne(table, query); | ||
} | ||
async deleteMany(table, query) { | ||
return await this.db.deleteMany(table, query); | ||
} | ||
|
||
async findMany(table, query, limit) { | ||
return await this.db.findMany(table, query, limit); | ||
} | ||
async findOne(table, query) { | ||
return await this.db.findOne(table, query); | ||
} | ||
|
||
async findMany(table, query, limit) { | ||
return await this.db.findMany(table, query, limit); | ||
} | ||
} | ||
|
||
module.exports = Database; | ||
module.exports = Database; |
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,18 +1,22 @@ | ||
module.exports = async (d) => { | ||
const data = d.util.aoiFunc(d); | ||
if (data.err) return d.error(data.err); | ||
const data = d.util.aoiFunc(d); | ||
if (data.err) return d.error(data.err); | ||
|
||
const [func] = data.inside.splits; | ||
const [func] = data.inside.splits; | ||
|
||
function evalfunc(client, {func}) { | ||
return eval(func) | ||
} | ||
function evalfunc(client, { func }) { | ||
return eval(func); | ||
} | ||
|
||
data.result = await d.client.shard.broadcastEval(evalfunc, {context: {func: func}}); | ||
if (!d.client.shard) return d.aoiError.fnError(d,"custom", {}, "ClientShard Class is Not Initialised"); | ||
|
||
data.result = data.result.join(" , "); | ||
data.result = await d.client.shard.broadcastEval(evalfunc, { | ||
context: { func: func }, | ||
}); | ||
|
||
return { | ||
code: d.util.setCode(data), | ||
}; | ||
}; | ||
data.result = data.result.join(" , "); | ||
|
||
return { | ||
code: d.util.setCode(data), | ||
}; | ||
}; |
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,14 +1,14 @@ | ||
const {BulkData} = require("../../utils/EventUtil.js"); | ||
const { BulkData } = require("../../utils/EventUtil.js"); | ||
|
||
module.exports = d => { | ||
const data = d.util.aoiFunc(d); | ||
if (data.err) return d.error(data.err); | ||
module.exports = (d) => { | ||
const data = d.util.aoiFunc(d); | ||
if (data.err) return d.error(data.err); | ||
|
||
const [option] = data.inside.splits; | ||
const [option, sep = " , "] = data.inside.splits; | ||
|
||
data.result = BulkData(d, option).deleteBrackets(); | ||
data.result = BulkData(d, sep, option).deleteBrackets(); | ||
|
||
return { | ||
code: d.util.setCode(data) | ||
} | ||
} | ||
return { | ||
code: d.util.setCode(data), | ||
}; | ||
}; |
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,28 +1,29 @@ | ||
module.exports = async d => { | ||
const {code} = d.command; | ||
const inside = d.unpack(); | ||
const err = d.inside(inside); | ||
if (err) return d.error(err); | ||
const data = d.util.aoiFunc(d); | ||
const { code } = d.command; | ||
if (data.err) return d.error(data.err); | ||
|
||
let [channelID, name, archive = "MAX", type = "public", startMessage, returnID = "false"] = inside.splits; | ||
let [channelID, name, archive = "MAX", type = "public", startMessage, returnID = "false"] = data.inside.splits; | ||
|
||
const channel = await d.util.getChannel(d, channelID); | ||
if (!channel) return d.aoiError.fnError(d, "channel", {inside}); | ||
if (!channel) return d.aoiError.fnError(d, "channel", { inside: data.inside }); | ||
|
||
type = d.util.threadTypes[type]; | ||
if (!type) return d.aoiError.fnError(d, "custom", {inside}, "Invalid Type Provided In"); | ||
if (!["60", "1440", "4320", "10080", "MAX"].includes(archive.toUpperCase())) d.aoiError.fnError(d, "custom", {inside}, "Invalid Archive Duration Provided In"); | ||
if (!type) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Invalid Type Provided In"); | ||
if (!["60", "1440", "4320", "10080", "MAX"].includes(archive.toUpperCase())) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Archive Duration Provided In"); | ||
|
||
const result = await channel.threads.create({ | ||
name, | ||
autoArchiveDuration: archive, | ||
autoArchiveDuration: archive.toUpperCase().replace("MAX", "10080"), | ||
type, | ||
startMessage: startMessage?.trim() === "" ? undefined : startMessage | ||
}).catch(e => { | ||
d.aoiError.fnError(d, "custom", {}, "Failed To Create Thread With Reason: " + e); | ||
return d.aoiError.fnError(d, "custom", {}, "Failed To Create Thread With Reason: " + e); | ||
}); | ||
|
||
data.result = returnID === "true" ? result?.id : undefined; | ||
|
||
return { | ||
code: d.util.setCode({function: d.func, code, inside, result: returnID === "true" ? result?.id : ""}) | ||
code: d.util.setCode(data) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -11,4 +11,4 @@ module.exports = async d => { | |
return { | ||
code: d.util.setCode(data) | ||
} | ||
} | ||
} |
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,14 +1,18 @@ | ||
module.exports = async d => { | ||
const data = d.util.aoiFunc(d); | ||
module.exports = async (d) => { | ||
const data = d.util.aoiFunc(d); | ||
|
||
const [guildID = d.guild?.id] = data.inside.splits; | ||
const [guildID = d.guild?.id, option = "id"] = data.inside.splits; | ||
|
||
const guild = await d.util.getGuild(d, guildID); | ||
if (!guild) return d.aoiError.fnError(d, 'guild', {inside: data.inside}); | ||
const guild = await d.util.getGuild(d, guildID); | ||
if (!guild) return d.aoiError.fnError(d, "guild", { inside: data.inside }); | ||
|
||
data.result = [...guild.roles.cache.sort((a, b) => a.position - b.position)][1]?.[0]; | ||
const role = guild.roles.cache.filter((role) => role.id !== guild.id).sort((a, b) => a.position - b.position) .first(); | ||
|
||
return { | ||
code: d.util.setCode(data) | ||
} | ||
} | ||
data.result = !role | ||
? guild?.roles.everyone.id | ||
: role === undefined | ||
? guild.id | ||
: role?.[option.toLowerCase()]; | ||
|
||
return { code: d.util.setCode(data) }; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const Interpreter = require("../../core/interpreter.js"); | ||
|
||
module.exports = async (d) => { | ||
const data = d.util.aoiFunc(d); | ||
if (data.err) return d.error(data.err); | ||
|
||
const [awaitfunc] = data.inside.splits; | ||
|
||
const cmd = d.client.cmd.awaited.find( | ||
(x) => x.name.toLowerCase() === awaitfunc.addBrackets().toLowerCase() | ||
); | ||
|
||
if (!cmd) | ||
return d.aoiError.fnError( | ||
d, | ||
"custom", | ||
{}, | ||
`Invalid Awaited Command: '${awaitfunc.addBrackets()}' Provided` | ||
); | ||
|
||
await Interpreter( | ||
d.client, | ||
d.message, | ||
d.args, | ||
cmd, | ||
d.client.db, | ||
false, | ||
undefined, | ||
d.data | ||
); | ||
|
||
data.result = null; | ||
|
||
return { | ||
code: d.util.setCode(data), | ||
}; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module.exports = async (d) => { | ||
const data = d.util.aoiFunc(d); | ||
|
||
let [resolver] = data.inside.splits; | ||
|
||
const guild = d.client.guilds.cache.get(d.guild?.id); | ||
if (!guild) return d.aoiError.fnError(d, "guild", { inside: data.inside }); | ||
|
||
const sticker = await d.util.getSticker(guild, resolver); | ||
if (!sticker) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "sticker"); | ||
|
||
try { | ||
await d.channel.send({ stickers: [sticker.id] }); | ||
} catch (err) { | ||
return d.aoiError.fnError(d, "custom", { inside: data.inside }, `Failed to send resolver: ${err}`); | ||
} | ||
|
||
return { code: d.util.setCode(data) }; | ||
}; |
Oops, something went wrong.