소스 검색

show all stats

Kylie Jo Swistak 6 년 전
부모
커밋
0b4ede5566
2개의 변경된 파일28개의 추가작업 그리고 9개의 파일을 삭제
  1. 21 0
      app/responses/users.rb
  2. 7 9
      bot.rb

+ 21 - 0
app/responses/users.rb

@@ -0,0 +1,21 @@
+def show_stats(usr, member)
+  rows = []
+  rows << ['', 'Current', 'Base', 'IVs']
+  rows << :separator
+  rows << ['HP', usr.hp, usr.hp_base, usr.hp_iv]
+  rows << ['A', usr.attack, usr.a_base, usr.a_iv]
+  rows << ['D', usr.defense, usr.d_base, usr.d_iv]
+  rows << ['SA', usr.sp_attack, usr.sa_base, usr.sa_iv]
+  rows << ['SD', usr.sp_defense, usr.sd_base, usr.sd_iv]
+  rows << ['S', usr.speed, usr.s_base, usr.s_iv]
+
+  stats = Terminal::Table.new rows: rows
+
+  embed = Embed.new(
+    title: member.nickname || member.name,
+    description: "```#{stats.to_s}```",
+  )
+
+  embed.color = member.color.combined if member.color
+  embed
+end

+ 7 - 9
bot.rb

@@ -230,7 +230,7 @@ opts = {
   "@user" => "List all user stats",
 }
 desc = "Shows ones stats, level, rank, and experience"
-stats = Command.new(:stats, desc, opts) do |event, name|
+stats = Command.new(:stats, desc, opts) do |event, name, all|
 
   case name
   when UID
@@ -240,16 +240,14 @@ stats = Command.new(:stats, desc, opts) do |event, name|
     #See if you can find the name some other way?
   end
 
-  channel = event.channel.id
-
-  # C# code for getting the percantage to the next level
-    #int levelprior = LevelUp[task].NextLevel - (10 * (LevelUp[task].CurrentLevel - 1) ^ 2);
-    #double ratio = (double)(LevelUp[task].Messages - levelprior) / (double)(LevelUp[task].NextLevel - levelprior);
-
   usr = User.find_by!(id: user&.id)
 
-  output_file = stat_image(usr, user)
-  bot.send_file(channel, File.open(output_file, 'r'))
+  if all
+    show_stats(usr, user)
+  else
+    output_file = stat_image(usr, user)
+    bot.send_file(event.channel.id, File.open(output_file, 'r'))
+  end
 rescue ActiveRecord::RecordNotFound => e
   error_embed(e.message)
 end