Skip to content

Commit

Permalink
Merge pull request #1919 from GiganticMinecraft/fix/VoteNoneGet
Browse files Browse the repository at this point in the history
  • Loading branch information
KisaragiEffective authored Feb 28, 2023
2 parents 9333f7d + 75d130b commit 72d0228
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
29 changes: 14 additions & 15 deletions src/main/scala/com/github/unchama/seichiassist/menus/VoteMenu.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ trait FairyPersistence[F[_]] {

/**
* 妖精に食べさせたりんごの量が多いプレイヤーを上位とし、そのランキングの上から指定した件数を返す
* ただし、要素数が`top`件あることは保証しない。
*
* @param top 最上位から何番目まで取得するか件数を指定する。0以下であってはならない。
* @return 指定した件数が要素数となり、その並びが消費量の降順になっているような順序つきのコレクションを返す作用。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 72d0228

Please sign in to comment.