-
-
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.
Update leaderboard function for more flexibility
- Loading branch information
Showing
3 changed files
with
109 additions
and
75 deletions.
There are no files selected for viewing
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,80 +1,93 @@ | ||
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; | ||
|
||
if (!d.client.variableManager.has(variable, table)) return d.aoiError.fnError(d, 'custom', {}, `Variable "${variable}" Not Found`); | ||
|
||
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(); | ||
|
||
let y = 0; | ||
let value; | ||
let content = []; | ||
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)); | ||
} | ||
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], | ||
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); | ||
|
||
if (text.includes("{execute:")) { | ||
let ins = text.split("{execute:")[1].split("}")[0]; | ||
const awaited = d.client.cmd.awaited.find((c) => c.name === ins); | ||
let y = 0; | ||
let value; | ||
let content = []; | ||
|
||
if (!awaited) | ||
return d.aoiError.fnError( | ||
d, | ||
"custom", | ||
{ inside: data.inside }, | ||
` Invalid awaited command '${ins}' in`, | ||
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)); | ||
} | ||
|
||
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); | ||
} | ||
|
||
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); | ||
content.push(text); | ||
} | ||
content.push(text); | ||
} | ||
} | ||
|
||
data.result = content.join("\n"); | ||
data.result = content.join("\n"); | ||
|
||
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
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