-
Notifications
You must be signed in to change notification settings - Fork 0
/
FeedCommand.php
49 lines (42 loc) · 1.39 KB
/
FeedCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace pimax\slackbot;
use PicoFeed\Reader\Reader;
abstract class FeedCommand extends AdvancedCommand
{
protected function getFeed($feed, $token)
{
try {
$reader = new Reader;
$resource = $reader->download($feed);
$parser = $reader->getParser(
$resource->getUrl(),
$resource->getContent(),
$resource->getEncoding()
);
$feed = $parser->execute();
$items = array_reverse($feed->getItems());
if (count($items))
{
foreach ($items as $itm) {
$url = $itm->getUrl();
$message = substr(strip_tags($itm->getContent()), 0, 150);
if (!$message) {
$message = "Don't have details.";
}
$this->postMessage($token, $this->getCurrentChannel(), null, '', [
[
'title' => $itm->getTitle(),
'title_link' => $url,
'text' => $message
]
]);
}
} else {
$this->getClient()->send($this->getCurrentChannel(), null, 'Not found a new projects.');
}
}
catch (Exception $e) {
}
return true;
}
}