예제 #1
0
 /**
  * Automatically adds a R9K ban to the specified board.
  *
  * @static
  * @param  \App\Board  $board  The board the ban is to be added in.
  * @param  binary|string|null  $ip  Optional. The IP to ban. Defaults to client IP.
  * @return static
  */
 public static function addRobotBan(Board $board, $ip = null)
 {
     $ip = new IP($ip);
     // Default time is 2 seconds.
     $time = 2;
     // Pull the ban that expires the latest.
     $ban = $board->bans()->whereIpInBan($ip)->whereRobot()->orderBy('expires_at', 'desc')->first();
     if ($ban instanceof static) {
         if (!$ban->isExpired()) {
             return $ban;
         }
         $time = $ban->created_at->diffInSeconds($ban->expires_at) * 2;
     }
     return static::create(['ban_ip_start' => $ip, 'ban_ip_end' => $ip, 'expires_at' => Carbon::now()->addSeconds($time), 'board_uri' => $board->board_uri, 'is_robot' => true, 'justification' => trans('validation.custom.unoriginal_content')]);
 }