Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewrite of leaderboard functions #493

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ plugins
.vscode
.DS_Store
/dist
ignore
2 changes: 1 addition & 1 deletion 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 @@ -66,4 +66,4 @@
},
"type": "commonjs",
"types": "./src/index.d.ts"
}
}
147 changes: 73 additions & 74 deletions src/functions/database/globalUserLeaderBoard.js
Original file line number Diff line number Diff line change
@@ -1,94 +1,93 @@
const {
AoijsAPI
} = require("../../classes/Database.js");

module.exports = async (d) => {
const data = d.util.aoiFunc(d);
if (data.err) return d.error(data.err);

let c = Date.now()
const [
variable,
type = "asc",
custom = `{top}. {username}: {value}`,
list = 10,
page = 1,
table = d.client.db.tables[0],
variable,
type = "asc",
custom = `{top}. {username}: {value:,}`,
list = 10,
page = 1,
table = d.client.db.tables[0],
hideNegativeValue = false,
hideZeroValue = false
] = data.inside.splits;

const all = await d.client.db.all(table, variable.addBrackets(), 1);
if (!d.client.variableManager.has(variable, table)) return d.aoiError.fnError(d, 'custom', {}, `Variable "${variable}" Not Found`);

let v = d.client.variableManager.get(variable, table)

if (v.type !== 'INTEGER') {
if (isNaN(Number(v.default ? v.default : 'null'))) return d.aoiError.fnError(d, 'custom', {}, `Variable "${variable}" is not a numbered variable`);
}

let db = await d.client.db.all(table, variable.addBrackets(), 1);
db.sort((a, b) => a.value - b.value);

if (type === "desc") db = db.reverse();

if (hideNegativeValue === "true") db = db.filter(x => x.value >= 0);
if (hideZeroValue === "true") db = db.filter(x => x.value != 0);

let y = 0;
let value;
let content = [];

for (const Data of all.sort((x, y) => {
if (d.client.db instanceof AoijsAPI) {
if (d.client.db.type === "aoi.db") return Number(y.value) - Number(x.value);

else return Number(y.data.value) - Number(x.data.value);
db = db.slice(page * list - list, page * list);

for (const Data of db) {
let user;
value = Number(Data.value);
user = await d.util.getUser(d, Data.key.split("_")[1]);

if (user) {
y++;
let text = custom
.replaceAll(`{top}`, y)
.replaceAll("{id}", user.id)
.replaceAll("{tag}", user.tag)
.replaceAll(`{username}`, user.username.removeBrackets())
.replaceAll(`{value}`, value);

if (text.includes("{value:")) {
let sep = text.split("{value:")[1].split("}")[0];
text = text.replaceAll(`{value:${sep}}`, value.toLocaleString().replaceAll(",", sep));
}
})) {
let user;

if (d.client.db instanceof AoijsAPI) {
if (d.client.db.type === "aoi.db")
value = Number(Data.value)
else value = Number(Data.data.value);

user = await d.util.getUser(d, Data.key.split("_")[1]);
if (text.includes("{execute:")) {
let ins = text.split("{execute:")[1].split("}")[0];
const awaited = d.client.cmd.awaited.find((c) => c.name === ins);

if (!awaited)
return d.aoiError.fnError(
d,
"custom",
{ inside: data.inside },
` Invalid awaited command '${ins}' in`,
);

const CODE = await d.interpreter(
d.client,
{
guild: d.message.guild,
channel: d.message.channel,
author: user,
},
d.args,
awaited,
undefined,
true,
);
text = text.replaceAll(`{execute:${ins}}`, CODE);
}

if (user) {
y++;

let text = custom
.replace(`{top}`, y)
.replace("{id}", user.id)
.replace("{tag}", user.tag)
.replace(`{username}`, user.username.removeBrackets())
.replace(`{value}`, value);

if (text.includes("{execute:")) {
let ins = text.split("{execute:")[1].split("}")[0];

const awaited = d.client.cmd.awaited.find((c) => c.name === ins);

if (!awaited)
return d.aoiError.fnError(
d,
"custom",
{inside: data.inside},
` Invalid awaited command '${ins}' in`,
);

const CODE = await d.interpreter(
d.client,
{
guild: d.message.guild,
channel: d.message.channel,
author: user,
},
d.args,
awaited,
undefined,
true,
);

text = text.replace(`{execute:${ins}}`, CODE);
}

content.push(text);
}
content.push(text);
}
}

if (type === "desc") content = content.reverse();

const px = page * list - list,
py = page * list;

data.result = content.slice(px, py).join("\n");
data.result = content.join("\n");

return {
code: d.util.setCode(data),
code: d.util.setCode(data),
};
};
};
163 changes: 81 additions & 82 deletions src/functions/database/guildLeaderBoard.js
Original file line number Diff line number Diff line change
@@ -1,90 +1,89 @@
const {
AoijsAPI
} = require("../../classes/Database.js");

module.exports = async (d) => {
const data = d.util.aoiFunc(d);
if (data.err) return d.error(data.err);

const [
variable,
type = "asc",
custom = `{top}. {username}: {value}`,
list = 10,
page = 1,
table = d.client.db.tables[0],
] = data.inside.splits;

const all = await d.client.db.all(table, variable.addBrackets(), 1);

let y = 0;
let value;
let content = [];

for (const Data of all.sort((x, y) => {
if (d.client.db instanceof AoijsAPI) {
if (d.client.db.type === "aoi.db")
return Number(y.value) - Number(x.value);
else return Number(y.data.value) - Number(x.data.value);
const data = d.util.aoiFunc(d);
if (data.err) return d.error(data.err);

const [
variable,
type = "asc",
custom = `{top}. {username}: {value:,}`,
list = 10,
page = 1,
table = d.client.db.tables[0],
hideNegativeValue = false,
hideZeroValue = false
] = data.inside.splits;

if (!d.client.variableManager.has(variable, table)) return d.aoiError.fnError(d, 'custom', {}, `Variable "${variable}" Not Found`);
let v = d.client.variableManager.get(variable, table)

if (v.type !== 'INTEGER') {
if (isNaN(Number(v.default ? v.default : 'null'))) return d.aoiError.fnError(d, 'custom', {}, `Variable "${variable}" is not a numbered variable`);
}

let db = await d.client.db.all(table, variable.addBrackets(), 1);
db.sort((a, b) => a.value - b.value);

if (type === "desc") db = db.reverse();

if (hideNegativeValue === "true") db = db.filter(x => x.value >= 0);
if (hideZeroValue === "true") db = db.filter(x => x.value != 0);

let y = 0;
let value;
let content = [];
db = db.slice(page * list - list, page * list);

for (const Data of db) {
let guild;
value = Number(Data.value);
guild = await d.util.getGuild(d, Data.key.split("_")[1]);

if (guild) {
y++;
let text = custom
.replaceAll(`{top}`, y)
.replaceAll("{id}", guild.id)
.replaceAll(`{name}`, guild.name.removeBrackets())
.replaceAll(`{value}`, value);

if (text.includes("{value:")) {
let sep = text.split("{value:")[1].split("}")[0];
text = text.replaceAll(`{value:${sep}}`, value.toLocaleString().replaceAll(",", sep));
}
})) {
let user;
if (d.client.db instanceof AoijsAPI) {
if (d.client.db.type === "aoi.db") value = Number(Data.value);
else value = Number(Data.data.value);

user = await d.util.getGuild(d, Data.key.split("_")[1]);
if (text.includes("{execute:")) {
let ins = text.split("{execute:")[1].split("}")[0];
const awaited = d.client.cmd.awaited.find((c) => c.name === ins);

if (!awaited) return d.aoiError.fnError(
d,
"custom",
{inside: data.inside},
` Invalid awaited command '${ins}' in`,
);

const CODE = await d.interpreter(
d.client,
{
guild: user,
channel: d.message.channel,
},
d.args,
awaited,
undefined,
true,
);

text = text.replaceAll(`{execute:${ins}}`, CODE);
}

if (user) {
y++;

let text = custom
.replace(`{top}`, y)
.replace("{id}", user.id)
.replace(`{name}`, user.name.removeBrackets())
.replace(`{value}`, value);

if (text.includes("{execute:")) {
let ins = text.split("{execute:")[1].split("}")[0];

const awaited = d.client.cmd.awaited.find((c) => c.name === ins);

if (!awaited)
return d.aoiError.fnError(
d,
"custom",
{inside: data.inside},
` Invalid awaited command '${ins}' in`,
);

const CODE = await d.interpreter(
d.client,
{
guild: user,
channel: d.message.channel,
},
d.args,
awaited,
undefined,
true,
);

text = text.replace(`{execute:${ins}}`, CODE);
}

content.push(text);
}
content.push(text);
}
}

if (type === "desc") content = content.reverse();

const px = page * list - list,
py = page * list;

data.result = content.slice(px, py).join("\n");
data.result = content.join("\n");

return {
code: d.util.setCode(data),
};
};
return {
code: d.util.setCode(data),
};
};
Loading
Loading