2020-12-27 18:21:03 +00:00
|
|
|
<?php declare(strict_types=1);
|
2020-12-19 15:51:19 +00:00
|
|
|
|
|
|
|
namespace nogueiracodes\RaspberryBot\Bot\Commands;
|
|
|
|
|
2020-12-27 19:26:38 +00:00
|
|
|
use Analog\Analog;
|
2020-12-19 15:51:19 +00:00
|
|
|
use Exception;
|
|
|
|
use nogueiracodes\RaspberryBot\Core\Interfaces\Command;
|
|
|
|
use nogueiracodes\RaspberryBot\Traits\HasSignature;
|
|
|
|
use Zttp\Zttp;
|
|
|
|
|
|
|
|
class NumberFact implements Command
|
|
|
|
{
|
|
|
|
use HasSignature;
|
|
|
|
|
|
|
|
|
|
|
|
public $signature = "numberfact {number: The number for which you want facts for.}";
|
|
|
|
|
|
|
|
|
2020-12-27 19:26:38 +00:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
Analog::log('Commands: Loaded NumberFact!');
|
|
|
|
}
|
|
|
|
|
2020-12-19 15:51:19 +00:00
|
|
|
public function run(array $parameters)
|
|
|
|
{
|
|
|
|
|
|
|
|
$number = $parameters['number'];
|
|
|
|
$result = Zttp::get('http://numbersapi.com/' . $number . '?json');
|
|
|
|
|
|
|
|
if ($result->isOk())
|
|
|
|
{
|
|
|
|
return $result->json()['text'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new Exception("Sorry, but I can\'t fetch number facts right now. Try again later.");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|