Skip to content
This repository was archived by the owner on Aug 3, 2020. It is now read-only.

Commit 9839d2e

Browse files
committed
aiiiuuuda
1 parent a9d16b1 commit 9839d2e

16 files changed

+114
-1
lines changed

app/Espinoso/Espinoso.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(Collection $handlers)
2828
*/
2929
public function executeHandlers(ApiTelegram $telegram, Message $message)
3030
{
31-
$this->handlers->map(function ($handler) use ($telegram) {
31+
$this->getHandlers()->map(function ($handler) use ($telegram) {
3232
return new $handler($this, $telegram);
3333
})->filter(function (EspinosoHandler $handler) use ($message) {
3434
return $handler->shouldHandle($message);
@@ -41,6 +41,14 @@ public function executeHandlers(ApiTelegram $telegram, Message $message)
4141
});
4242
}
4343

44+
/**
45+
* @return Collection
46+
*/
47+
public function getHandlers(): Collection
48+
{
49+
return $this->handlers;
50+
}
51+
4452
// public function register(stdClass $update)
4553
// {
4654
// $from = $update->message->from;

app/Espinoso/Handlers/BardoDelEspinosoHandler.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ class BardoDelEspinosoHandler extends EspinosoCommandHandler
1313
*/
1414
protected $pattern = "send me nudes$";
1515

16+
protected $signature = "[espi] send me nudes";
17+
protected $description = "no sé, fijate";
18+
1619
public function handle(Message $message)
1720
{
1821
return $this->telegram->sendPhoto([

app/Espinoso/Handlers/BrainHandler.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ class BrainHandler extends EspinosoHandler
1010
protected $allNodes;
1111
protected $matchedNodes;
1212

13+
protected $signature = "macri, facu, ine, alan, asado, ...";
14+
protected $description = "Macri Gato, Facu Puto";
15+
1316
public function __construct(Espinoso $espinoso, ApiTelegram $telegram)
1417
{
1518
parent::__construct($espinoso, $telegram);

app/Espinoso/Handlers/CinemaHandler.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ class CinemaHandler extends EspinosoCommandHandler
1111
*/
1212
protected $pattern = ".{0,100}\b(cine)\b.{0,100}$";
1313

14+
protected $signature = "espi cine";
15+
protected $description = "te muestro que hay para ver en el cine y ponerla";
16+
1417
public function handle(Message $message)
1518
{
1619
$crawler = GoutteClient::request('GET', config('espinoso.url.cinema'));

app/Espinoso/Handlers/EspinosoHandler.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ abstract class EspinosoHandler
1717
*/
1818
protected $telegram;
1919

20+
protected $signature;
21+
protected $description;
22+
23+
protected function help()
24+
{
25+
return empty($this->signature) ? '' : "*{$this->signature}*\n\t\t\t{$this->description}";
26+
}
27+
2028
public function __construct(Espinoso $espinoso, ApiTelegram $telegram)
2129
{
2230
$this->espinoso = $espinoso;

app/Espinoso/Handlers/GitHubHandler.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ class GitHubHandler extends EspinosoCommandHandler
1010
*/
1111
protected $pattern = "(issue)(\s+)(?'title'.+)$";
1212

13+
protected $signature = "espi issue <title>";
14+
protected $description = "genera un issue en el repo";
15+
1316
public function handle(Message $message)
1417
{
1518
$response = GuzzleClient::post(config('espinoso.url.issues'), [

app/Espinoso/Handlers/GoogleInfoBoxHandler.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class GoogleInfoBoxHandler extends EspinosoCommandHandler
1717
*/
1818
protected $pattern = "(?'i'\b(info)\b)(?'query'.+)$";
1919

20+
protected $signature = "[espi] info <cosa a buscar>";
21+
protected $description = "trato de traer data";
22+
2023
public function handle(Message $message)
2124
{
2225
$response = $this->buildResponse(rawurlencode(trim($this->matches['query'])));

app/Espinoso/Handlers/GoogleStaticMapsHandler.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class GoogleStaticMapsHandler extends EspinosoCommandHandler
1515
*/
1616
protected $pattern = "(?'gsm'\b(gsm)\b)\s+(?'params'(\S+:\S+\s+)*)(?'address'.+)$";
1717

18+
protected $signature = "[espi] gsm <lugar>";
19+
protected $description = "te tiro un mapa... tiene algunos params pero me da paja decírtelos";
20+
1821
/**
1922
* Default options
2023
*
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php namespace App\Espinoso\Handlers;
2+
3+
use Telegram\Bot\Objects\Message;
4+
5+
class HelpHandler extends EspinosoCommandHandler
6+
{
7+
/**
8+
* @var string
9+
*/
10+
protected $pattern = "(ayuda|help|aiiiuuuda)(!)*";
11+
12+
protected $signature = "espi help|ayuda|aiiiuuda";
13+
protected $description = "muestra cosas que entiendo";
14+
15+
public function handle(Message $message)
16+
{
17+
$data = $this->espinoso->getHandlers()->map(function ($handler) {
18+
return new $handler($this->espinoso, $this->telegram);
19+
})->map(function (EspinosoHandler $handler) {
20+
return $handler->help();
21+
})->reject(function (string $help) {
22+
return empty($help);
23+
})->implode("\n");
24+
25+
return $this->telegram->sendMessage([
26+
'chat_id' => $message->getChat()->getId(),
27+
'text' => "Entiendo masomenos estas cosas:\n\n{$data}",
28+
'parse_mode' => 'Markdown'
29+
]);
30+
}
31+
}

app/Espinoso/Handlers/IMDbHandler.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ class IMDbHandler extends EspinosoCommandHandler
1414
* @var string
1515
*/
1616
protected $pattern = "(?'type'\b(imdb|movie|peli|serie|tv)\b)(?'query'.+)";
17+
18+
protected $signature = "espi imdb|movie|peli|serie|tv <cosa a buscar>";
19+
protected $description = "busco pelis y series, vieja!";
20+
1721
/**
1822
* @var array
1923
*/

0 commit comments

Comments
 (0)