diff --git a/src/main/scala/com/github/unchama/seichiassist/menus/VoteMenu.scala b/src/main/scala/com/github/unchama/seichiassist/menus/VoteMenu.scala index 1d0132aa17..829b904c78 100644 --- a/src/main/scala/com/github/unchama/seichiassist/menus/VoteMenu.scala +++ b/src/main/scala/com/github/unchama/seichiassist/menus/VoteMenu.scala @@ -382,22 +382,21 @@ object VoteMenu extends Menu { topFourRanking.lift(1), topFourRanking.lift(2), topFourRanking.lift(3) - ).flatMap { rankDataOpt => - if (rankDataOpt.nonEmpty) { - val rankData = rankDataOpt.get.get - List( - s"${GRAY}たくさんくれたニンゲン第${rankData.rank}位!", - s"${GRAY}なまえ:${rankData.playerName} りんご:${rankData.consumed.amount}個" - ) - } else Nil + ).flatMap(_.flatten).flatMap { rankData => + List( + s"${GRAY}たくさんくれたニンゲン第${rankData.rank}位!", + s"${GRAY}なまえ:${rankData.playerName} りんご:${rankData.consumed.amount}個" + ) } - val statistics = List( - s"${AQUA}ぜーんぶで${allEatenAppleAmount.amount}個もらえた!", - "", - s"$GREEN↓呼び出したニンゲンの情報↓", - s"${GREEN}今までに${myRank.get.consumed.amount}個もらった", - s"${GREEN}ニンゲンの中では${myRank.get.rank}番目にたくさんくれる!" - ) + val statistics = myRank.map { rank => + List( + s"${AQUA}ぜーんぶで${allEatenAppleAmount.amount}個もらえた!", + "", + s"$GREEN↓呼び出したニンゲンの情報↓", + s"${GREEN}今までに${rank.consumed.amount}個もらった", + s"${GREEN}ニンゲンの中では${rank.rank}番目にたくさんくれる!" + ) + }.orEmpty Button( new IconItemStackBuilder(Material.GOLDEN_APPLE) diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/vote/subsystems/fairy/domain/FairyPersistence.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/vote/subsystems/fairy/domain/FairyPersistence.scala index 99ae4c43bd..9331e34689 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/vote/subsystems/fairy/domain/FairyPersistence.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/vote/subsystems/fairy/domain/FairyPersistence.scala @@ -86,6 +86,7 @@ trait FairyPersistence[F[_]] { /** * 妖精に食べさせたりんごの量が多いプレイヤーを上位とし、そのランキングの上から指定した件数を返す + * ただし、要素数が`top`件あることは保証しない。 * * @param top 最上位から何番目まで取得するか件数を指定する。0以下であってはならない。 * @return 指定した件数が要素数となり、その並びが消費量の降順になっているような順序つきのコレクションを返す作用。 diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/vote/subsystems/fairy/infrastructure/JdbcFairyPersistence.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/vote/subsystems/fairy/infrastructure/JdbcFairyPersistence.scala index feb5a66bbe..1e86fc4584 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/vote/subsystems/fairy/infrastructure/JdbcFairyPersistence.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/vote/subsystems/fairy/infrastructure/JdbcFairyPersistence.scala @@ -186,18 +186,19 @@ class JdbcFairyPersistence[F[_]: Sync] extends FairyPersistence[F] { ): F[Vector[Option[AppleConsumeAmountRank]]] = Sync[F].delay { DB.readOnly { implicit session => - sql"""SELECT name,given_apple_amount,COUNT(*) AS rank FROM vote_fairy + sql"""SELECT name,given_apple_amount,COUNT(*) AS rank FROM vote_fairy | INNER JOIN playerdata ON (vote_fairy.uuid = playerdata.uuid) | ORDER BY rank DESC LIMIT $top;""" .stripMargin - .map(rs => (rs.stringOpt("name"), rs.intOpt("rank"), rs.intOpt("given_apple_amount"))) + .map { rs => + for { + name <- rs.stringOpt("name") + rank <- rs.intOpt("rank") + givenAppleAmount <- rs.intOpt("given_apple_amount") + } yield AppleConsumeAmountRank(name, rank, AppleAmount(givenAppleAmount)) + } .toList() .apply() - .map(data => - if (data._1.nonEmpty) - Some(AppleConsumeAmountRank(data._1.get, data._2.get, AppleAmount(data._3.get))) - else None - ) .toVector } }