-
-
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 #518 from aho-emi/v6
edited leaderboard functions
- Loading branch information
Showing
3 changed files
with
169 additions
and
177 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
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,87 +1,90 @@ | ||
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, (data) => | ||
data.key.startsWith(variable.deleteBrackets()) && data.key.split("_").length === 2, | ||
); | ||
|
||
let y = 0; | ||
let value; | ||
let content = []; | ||
|
||
for (const Data of all.sort((x, y) => { | ||
if (d.client.db.type === "aoi.db") | ||
return Number(y.value) - Number(x.value); | ||
else return Number(y.data.value) - Number(x.data.value); | ||
})) { | ||
let user; | ||
|
||
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 (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); | ||
} | ||
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); | ||
|
||
let db = await d.client.db.all(table, (data) => data.key.startsWith(variable.deleteBrackets()) && data.key.split("_").length === 2); | ||
|
||
if (d.client.db.type === "aoi.db") | ||
db.sort((a, b) => Number(a.value) - Number(b.value)); | ||
else db.sort((a, b) => Number(y.data.value) - Number(x.data.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 db) { | ||
let guild; | ||
if (d.client.db.type === "aoi.db") value = Number(Data.value); | ||
else value = Number(Data.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)); | ||
} | ||
|
||
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: guild, | ||
channel: d.message.channel, | ||
}, | ||
d.args, | ||
awaited, | ||
undefined, | ||
true, | ||
); | ||
|
||
text = text.replaceAll(`{execute:${ins}}`, CODE); | ||
} | ||
|
||
content.push(text); | ||
} | ||
} | ||
|
||
if (type === "desc") content = content.reverse(); | ||
data.result = content.slice(page * list - list, page * list).join("\n"); | ||
|
||
const px = page * list - list, | ||
py = page * list; | ||
|
||
data.result = content.slice(px, py).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,84 @@ | ||
module.exports = async (d) => { | ||
const data = d.util.aoiFunc(d); | ||
if (data.err) return d.error(data.err); | ||
|
||
const [ | ||
guildID = d.guild?.id, | ||
variable, | ||
type = "asc", | ||
custom = `{top}. {username}: {value}`, | ||
list = 10, | ||
page = 1, | ||
table = d.client.db.tables[0], | ||
] = data.inside.splits; | ||
|
||
let all = await d.client.db.all( | ||
table, | ||
(data) => | ||
data.key.startsWith(variable.deleteBrackets()) && | ||
data.key.split("_").length === 3 && | ||
data.key.split("_")[2] === guildID, | ||
); | ||
|
||
const guild = await d.util.getGuild(d, guildID); | ||
if (!guild) return d.aoiError.fnError(d, "guild", { inside: data.inside }); | ||
|
||
let value; | ||
let content = []; | ||
|
||
const px = (page-1) * list, | ||
py = page * list; | ||
|
||
all = all.sort((x, y) => { | ||
if (d.client.db.type === "aoi.db") | ||
return Number(y.value) - Number(x.value); | ||
else return Number(y.data.value) - Number(x.data.value); | ||
}); | ||
all = all.slice(px, py); | ||
let y = px+1; | ||
|
||
for (const Data of all ) { | ||
let user; | ||
|
||
if (d.client.db.type === "aoi.db") value = Number(Data.value); | ||
else value = Number(Data.data.value); | ||
|
||
user = await d.util.getMember(guild, Data.key.split("_")[1]); | ||
|
||
let text = custom | ||
.replaceAll(`{top}`, y) | ||
.replaceAll("{id}", user.user.id) | ||
.replaceAll("{tag}", user.user.tag) | ||
.replaceAll(`{username}`, user.user.username.removeBrackets()) | ||
.replaceAll(`{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: guild, | ||
channel: d.message.channel, | ||
author: user, | ||
}, | ||
d.args, | ||
awaited, | ||
undefined, | ||
true, | ||
); | ||
|
||
text = text.replace(`{execute:${ins}}`, CODE); | ||
} | ||
|
||
content.push(text); | ||
y++; | ||
module.exports = async d => { | ||
const data = d.util.aoiFunc(d); | ||
if (data.err) return d.error(data.err); | ||
|
||
const [ | ||
guildID = d.guild?.id, | ||
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 guild = await d.util.getGuild(d, guildID); | ||
if (!guild) return d.aoiError.fnError(d, "guild", { inside: data.inside }); | ||
|
||
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); | ||
|
||
let db = await d.client.db.all(table, (data) => data.key.startsWith(variable.deleteBrackets()) && (data.key.split("_").length === 3) && (data.key.split("_")[2] == guildID)); | ||
if (d.client.db.type === "aoi.db") | ||
db.sort((a, b) => Number(a.value) - Number(b.value)); | ||
else db.sort((a, b) => Number(y.data.value) - Number(x.data.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 db) { | ||
let user; | ||
if (d.client.db.type === "aoi.db") value = Number(Data.value); | ||
else value = Number(Data.data.value); | ||
user = await d.util.getMember(guild, Data.key.split('_')[1]); | ||
|
||
if (user) { | ||
nick = user.nickname | ||
user = user.user; | ||
y++; | ||
let text = custom | ||
.replaceAll(`{top}`, y) | ||
.replaceAll("{id}", user.id) | ||
.replaceAll("{tag}", user.tag) | ||
.replaceAll(`{username}`, user.username.removeBrackets()) | ||
.replaceAll(`{value}`, value) | ||
.replaceAll(`{nick}`, nick || user.username); | ||
|
||
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: guild, | ||
channel: d.message.channel, | ||
author: user | ||
}, d.args, awaited, undefined, true); | ||
|
||
text = text.replace(`{execute:${ins}}`, CODE); | ||
} | ||
|
||
content.push(text); | ||
} | ||
} | ||
|
||
if (type === "desc") content = content.reverse(); | ||
data.result = content.slice(page * list - list, page * list).join("\n"); | ||
|
||
data.result = content.slice(px, py).join("\n"); | ||
|
||
return { | ||
code: d.util.setCode(data), | ||
}; | ||
return { | ||
code: d.util.setCode(data) | ||
}; | ||
}; |