+ def do_chanstats(m, p)
+ stats = chan_stats(m.channel)
+ np = stats['played']
+ nf = stats['finished']
+ if np > 0
+ str = _("%{nf} %{uno} games completed over %{np} games played. ") % {
+ :np => np, :uno => UnoGame::UNO, :nf => nf
+ }
+ cgt = stats['finished_runtime']
+ tgt = stats['played_runtime']
+ str << _("%{cgt} game time for completed games") % {
+ :cgt => Utils.secs_to_string(cgt)
+ }
+ if np > nf
+ str << _(" on %{tgt} total game time. ") % {
+ :tgt => Utils.secs_to_string(tgt)
+ }
+ else
+ str << ". "
+ end
+ str << _("%{avg} average game time for completed games") % {
+ :avg => Utils.secs_to_string(cgt/nf)
+ }
+ str << _(", %{tavg} for all games") % {
+ :tavg => Utils.secs_to_string(tgt/np)
+ } if np > nf
+ m.reply str
+ else
+ m.reply _("nobody has played %{uno} on %{chan} yet") % {
+ :uno => UnoGame::UNO, :chan => m.channel
+ }
+ end
+ end
+
+ def do_pstats(m, p)
+ dnick = p[:nick] || m.source # display-nick, don't later case
+ nick = dnick.downcase
+ ps = chan_pstats(m.channel)[nick]
+ if ps.played == 0
+ m.reply _("%{nick} never played %{uno} here") % {
+ :uno => UnoGame::UNO, :nick => dnick
+ }
+ return
+ end
+ np = ps.played
+ nf = ps.forfeits
+ nw = ps.won.length
+ score = ps.won.inject(0) { |sum, w| sum += w.score }
+ str = _("%{nick} played %{np} %{uno} games here, ") % {
+ :nick => dnick, :np => np, :uno => UnoGame::UNO
+ }
+ str << _("forfeited %{nf} games, ") % { :nf => nf } if nf > 0
+ str << _("won %{nw} games") % { :nw => nw}
+ if nw > 0
+ str << _(" with %{score} total points") % { :score => score }
+ avg = ps.won.inject(0) { |sum, w| sum += w.score/w.opponents }/nw
+ str << _(" and an average of %{avg} points per opponent") % { :avg => avg }
+ end
+ m.reply str
+ end
+
+ def replace_player(m, p)
+ unless @games.key?(m.channel)
+ m.reply _("There is no %{uno} game running here") % { :uno => UnoGame::UNO }
+ return
+ end
+ @games[m.channel].replace_player(p[:old], p[:new])
+ end
+
+ def drop_player(m, p)
+ unless @games.key?(m.channel)
+ m.reply _("There is no %{uno} game running here") % { :uno => UnoGame::UNO }
+ return
+ end
+ @games[m.channel].drop_player(p[:nick] || m.source.nick)
+ end
+