浏览代码

cannot find_by with no field to find by

Kylie Jo Swistak 5 年之前
父节点
当前提交
3b529d6fde
共有 1 个文件被更改,包括 6 次插入4 次删除
  1. 6 4
      bot.rb

+ 6 - 4
bot.rb

@@ -1956,9 +1956,10 @@ bot.member_leave do |event|
     end
     ct = CharTeam.find_by(char_id: char.id)
     ct.update(active: false) if ct
-    t = Team.find_by(ct.team_id) if ct
+    t = Team.find(ct.team_id) if ct
 
-    updated.push("#{char.name}, #{t.name} -- #{char.active}")
+    updated.push("#{char.name}, #{t.name} -- #{char.active}") if t
+    updated.push("#{char.name}, no team data -- #{char.active}") if t.nil?
   end
 
   fields.push({
@@ -2000,9 +2001,10 @@ bot.user_ban do |event|
     end
     ct = CharTeam.find_by(char_id: char.id)
     ct.update(active: false) if ct
-    t = Team.find_by(ct.team_id) if ct
+    t = Team.find(ct.team_id) if ct
 
-    updated.push("#{char.name}, #{t.name} -- #{char.active}")
+    updated.push("#{char.name}, #{t.name} -- #{char.active}") if t
+    updated.push("#{char.name}, no team data -- #{char.active}") if t.nil?
   end
 
   fields.push({