oreolek
/
news-script
Архивировано
1
0
Форкнуть 0
Этот коммит содержится в:
Alexander Yakovlev 2019-08-06 20:59:04 +07:00
родитель 2b98c00cd7
Коммит a77d099498
Подписано: oreolek
Идентификатор ключа GPG: 1CDC4B7820C93BD3
7 изменённых файлов: 239 добавлений и 49 удалений

Просмотреть файл

@ -35,8 +35,10 @@ $mastodon = new Publisher\Mastodon($config);
$jabber = new Publisher\Jabber($config);
$telegram = new Publisher\Telegram($config);
// $jabber->publish('hello world!'); die();
$parsers = [
// 'urq',
// 'urq',
'anivisual',
'kvester',
'apero',
@ -66,7 +68,7 @@ function check($classname, $command) {
global $telegram;
global $config;
if (in_array($command, $parsers)) {
$cname = 'Source\\'.$classname;
$cname = 'Oreolek\\Source\\'.$classname;
$source = (new $cname());
$source->check();
if (empty($source->games)) {

Просмотреть файл

@ -8,7 +8,8 @@
"ryakad/pandoc-php": "^1.0",
"longman/telegram-bot": "dev-master",
"revolution/laravel-mastodon-api": "dev-master",
"symfony/yaml": "^4.2@dev"
"symfony/yaml": "^4.2@dev",
"norgul/xmpp-php": "^2.2"
},
"require-dev": {
"phpunit/phpunit": "^8.0"

184
composer.lock сгенерированный
Просмотреть файл

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "10fed75d3afc511f898c29c5ddf8ec3f",
"content-hash": "3ba31f238d4c481e493ac118f1b29f36",
"packages": [
{
"name": "addwiki/mediawiki-api",
@ -784,6 +784,54 @@
],
"time": "2019-07-28T09:02:12+00:00"
},
{
"name": "norgul/xmpp-php",
"version": "v2.2.2",
"source": {
"type": "git",
"url": "https://github.com/Norgul/xmpp-php.git",
"reference": "a150d5e931403731e830e8d19698948b24091913"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Norgul/xmpp-php/zipball/a150d5e931403731e830e8d19698948b24091913",
"reference": "a150d5e931403731e830e8d19698948b24091913",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "3.0.x-dev",
"phpmd/phpmd": "2.6.0",
"phpunit/phpunit": "6.*",
"squizlabs/php_codesniffer": "3.4.2"
},
"type": "project",
"autoload": {
"psr-4": {
"Norgul\\Xmpp\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Marko Dupor",
"email": "marko.dupor@gmail.com"
}
],
"description": "PHP library for XMPP.",
"keywords": [
"jabber",
"library",
"php",
"xmpp"
],
"time": "2019-05-23T10:32:26+00:00"
},
{
"name": "psr/container",
"version": "1.0.0",
@ -1695,6 +1743,140 @@
],
"time": "2019-03-17T17:37:11+00:00"
},
{
"name": "fabiang/xmpp",
"version": "0.7.0",
"source": {
"type": "git",
"url": "https://github.com/fabiang/xmpp.git",
"reference": "d5fe3acc355f948a4dd0407a7840692f4cf133c3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fabiang/xmpp/zipball/d5fe3acc355f948a4dd0407a7840692f4cf133c3",
"reference": "d5fe3acc355f948a4dd0407a7840692f4cf133c3",
"shasum": ""
},
"require": {
"php": "^5.6 || ^7.0",
"psr/log": "^1.0"
},
"require-dev": {
"behat/behat": "^2.5.5",
"monolog/monolog": "^1.22",
"phpunit/phpunit": "^5.7.20",
"satooshi/php-coveralls": "^1.0",
"symfony/console": "^2.8",
"symfony/dependency-injection": "^2.8",
"symfony/finder": "^2.8"
},
"suggest": {
"psr/log-implementation": "Allows more advanced logging of the xmpp connection"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Fabiang\\Xmpp\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-2-Clause"
],
"authors": [
{
"name": "Fabian Grutschus",
"role": "developer",
"email": "f.grutschus@lubyte.de",
"homepage": "http://www.lubyte.de/"
}
],
"description": "Library for XMPP protocol (Jabber) connections",
"homepage": "https://github.com/fabiang/xmpp",
"keywords": [
"jabber",
"xmpp"
],
"time": "2017-05-23T12:47:08+00:00"
},
{
"name": "jaxl/jaxl",
"version": "v3.1.0",
"source": {
"type": "git",
"url": "https://github.com/jaxl/JAXL.git",
"reference": "27aa43c4600b05809779428843d8d51db6ce6e0d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/jaxl/JAXL/zipball/27aa43c4600b05809779428843d8d51db6ce6e0d",
"reference": "27aa43c4600b05809779428843d8d51db6ce6e0d",
"shasum": ""
},
"require": {
"ext-curl": "*",
"ext-hash": "*",
"ext-json": "*",
"ext-libxml": "*",
"ext-openssl": "*",
"ext-pcre": "*",
"ext-sockets": "*",
"php": ">=5.2.4"
},
"require-dev": {
"phpunit/phpunit": "^3.7.0",
"squizlabs/php_codesniffer": "*"
},
"suggest": {
"ext-pcntl": "Interrupt JAXL with signals"
},
"bin": [
"jaxlctl"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.1.x-dev"
}
},
"autoload": {
"classmap": [
"src/JAXL"
],
"exclude-from-classmap": [
"/tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Abhinavsingh",
"homepage": "https://abhinavsingh.com/"
}
],
"description": "Jaxl - Async, Non-Blocking, Event based Networking Library in PHP.",
"homepage": "http://jaxl.readthedocs.org/en/latest/index.html",
"keywords": [
"abhinavsingh",
"asynchronous",
"event loop",
"http",
"jabber",
"jaxl",
"non blocking",
"php",
"xmpp"
],
"time": "2016-09-13T01:59:35+00:00"
},
{
"name": "myclabs/deep-copy",
"version": "1.9.1",

Просмотреть файл

@ -1,16 +1,14 @@
<?php
namespace Oreolek;
class Publisher {
public $text;
abstract class Publisher {
protected $dry_run = true;
public function __construct($config) {
$this->dry_run = $config['DRY_RUN'];
}
protected function _publish(string $text): void {
}
abstract protected function _publish(string $text);
public function publish(string $text): void {
if (empty($this->client)) {

Просмотреть файл

@ -1,56 +1,63 @@
<?php
namespace Oreolek\Publisher;
use \Oreolek\Publisher;
use \Norgul\Xmpp\Options;
use \Norgul\Xmpp\XmppClient;
class Jabber extends Publisher {
protected $client;
protected $text;
public function __construct($config) {
super::__construct($config);
Publisher::__construct($config);
if ($config['JABBER'] === true) {
$this->client = new JAXL(array(
'jid' => $config['JABBER_JID'],
'pass' => $config['JABBER_PASSWORD'],
));
$this->client->require_xep([
'0060' // Publish-Subscribe
]);
$options = new Options();
$options->setHost($config['JABBER_HOST']);
$options->setUsername($config['JABBER_JID']);
$options->setPassword($config['JABBER_PASSWORD']);
$this->client = new XmppClient($options);
$this->client->connect();
}
}
protected function _publish(string $text): void {
$this->text = $text;
$this->client->add_cb('on_auth_success', function() {
$this->on_auth_success_callback();
});
$client->add_cb('on_auth_failure', function() {
$this->on_auth_failure_callback();
});
$this->client->start();
public function __destruct() {
$this->client->disconnect();
}
protected function on_auth_success_callback()
{
// create node
// $client->xeps['0060']->create_node('pubsub.localhost', 'dummy_node');
// publish
$item = new JAXLXml('item', null, array('id' => time()));
$item->c('entry', 'http://www.w3.org/2005/Atom');
$item->c('title')->t('Soliloquy')->up();
$item->c('summary')->t($this->text)->up();
$item->c(
'link',
null,
array('rel' => 'alternate', 'type' => 'text/html', 'href' => 'http://denmark.lit/2003/12/13/atom03')
)->up();
$item->c('published')->t('2003-12-13T18:30:02Z')->up();
$item->c('updated')->t('2003-12-13T18:30:02Z')->up();
$this->client->xeps['0060']->publish_item('pubsub.localhost', 'dummy_node', $item);
}
protected function _publish(string $text) {
if (empty($this->text)) {
return;
}
protected function on_auth_failure_callback($reason)
{
$this->client->send_end_stream();
$xml = <<<END
<iq type='set'
from='dicebot@oreolek.ru/blogbot'
to='pubsub.oreolek.ru'
id='publish1'>
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
<publish node='princely_musings'>
<item id='bnd81g37d61f49fgn581'>
<entry xmlns='http://www.w3.org/2005/Atom'>
<title>Soliloquy</title>
<summary>
To be, or not to be: that is the question:
Whether 'tis nobler in the mind to suffer
The slings and arrows of outrageous fortune,
Or to take arms against a sea of troubles,
And by opposing end them?
</summary>
<link rel='alternate' type='text/html'
href='http://denmark.lit/2003/12/13/atom03'/>
<id>tag:denmark.lit,2003:entry-32397</id>
<published>2003-12-13T18:30:02Z</published>
<updated>2003-12-13T18:30:02Z</updated>
</entry>
</item>
</publish>
</pubsub>
</iq>
END;
$this->client->send($xml);
$response = $this->client->getResponse();
$this->client->prettyPrint($response);
}
}

Просмотреть файл

@ -6,7 +6,7 @@ class Mastodon extends Publisher {
protected $client;
public function __construct($config) {
super::__construct($config);
Publisher::__construct($config);
if ($config['MASTODON'] === true) {
$guzzle = new GuzzleClient([
'timeout' => 30,

Просмотреть файл

@ -6,7 +6,7 @@ class Telegram extends Publisher {
protected $client;
protected $chat_id;
public function __construct($config) {
super::__construct($config);
Publisher::__construct($config);
if ($config['TELEGRAM'] === true) {
$this->chat_id = $config['TELEGRAM_CHAT_ID'];
$this->client = new Longman\TelegramBot\Telegram(