-
Notifications
You must be signed in to change notification settings - Fork 0
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 #40 from claustra01/feat/view_ranking
ランキング表示コマンド
- Loading branch information
Showing
4 changed files
with
71 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Reply, ReplyType } from '../../usecase/types/reply'; | ||
import { playerController } from '../queries/player'; | ||
|
||
export const commandRanking = async (args: string[]): Promise<Reply> => { | ||
if (args.length !== 2) { | ||
return { | ||
type: ReplyType.Error, | ||
errorText: `Invalid Arguments: maxRange`, | ||
}; | ||
} | ||
const maxRange = parseInt(args[1]); | ||
if (isNaN(maxRange)) { | ||
return { | ||
type: ReplyType.Error, | ||
errorText: `Error: maxRange is not a number`, | ||
}; | ||
} | ||
if (maxRange < 1 || maxRange > 10) { | ||
return { | ||
type: ReplyType.Error, | ||
errorText: `Error: maxRange must be between 1 and 10`, | ||
}; | ||
} | ||
try { | ||
const players = await playerController.readRanking(maxRange); | ||
let replyText = ''; | ||
players.forEach((player, index) => { | ||
replyText += `${index + 1}. ${ | ||
player.discordId ? player.discordId : player.playerName | ||
}: ${player.currentRate}pt\n`; | ||
}); | ||
return { | ||
type: ReplyType.Text, | ||
contentText: replyText, | ||
}; | ||
} catch (error) { | ||
return { | ||
type: ReplyType.Error, | ||
errorText: `${error}`, | ||
}; | ||
} | ||
}; |
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