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

Rankingコマンドを実装 #18

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
20 changes: 18 additions & 2 deletions src/commands/ranking.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
module.exports = (client, message, db) => {
message.channel.send("工事中です。");
module.exports = async (client, message, db) => {
const channels = db.getRanking();
const servers = {};
for (const channel of channels) {
const c = client.channel.get(channel.channel_id);
if (!c) continue;
const server = c.server;
if (!servers[server.id])
servers[server.id] = [server.name, channel.boss_level];
if (servers.length > 9) break;
}
await message.channel
.send(
`\`\`\`上位10サーバーのランキング\n${Object.entries(
Object.values(servers)
).map((i, a) => `${i + 1}位:${a[0]} (Lv${a[1]})`)}\`\`\``
)
.join("\n");
};
7 changes: 6 additions & 1 deletion src/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ db.promiseAll = util.promisify(db.all);
db.promiseGet = util.promisify(db.get);
db.promiseRun = util.promisify(db.run);

db.getRanking = () =>
db.promiseAll(
"SELECT channel_id, boss_level FROM channel_status ORDER BY boss_level DESC"
);

db.getPlayerExp = async userId => {
const player = await db.promiseGet(
"SELECT experience FROM player WHERE user_id=?",
Expand Down Expand Up @@ -36,7 +41,7 @@ db.getPlayerRank = async userId => {
const { rank } = await db.promiseGet(
`SELECT (
SELECT Count(0) FROM player WHERE player.experience > player1.experience
) + 1 AS rank
) + 1 AS rank
FROM player AS player1 WHERE user_id=?`,
[userId]
);
Expand Down