Jabber WIP
This commit is contained in:
parent
2b98c00cd7
commit
a77d099498
4
bot.php
4
bot.php
|
@ -35,6 +35,8 @@ $mastodon = new Publisher\Mastodon($config);
|
||||||
$jabber = new Publisher\Jabber($config);
|
$jabber = new Publisher\Jabber($config);
|
||||||
$telegram = new Publisher\Telegram($config);
|
$telegram = new Publisher\Telegram($config);
|
||||||
|
|
||||||
|
// $jabber->publish('hello world!'); die();
|
||||||
|
|
||||||
$parsers = [
|
$parsers = [
|
||||||
// 'urq',
|
// 'urq',
|
||||||
'anivisual',
|
'anivisual',
|
||||||
|
@ -66,7 +68,7 @@ function check($classname, $command) {
|
||||||
global $telegram;
|
global $telegram;
|
||||||
global $config;
|
global $config;
|
||||||
if (in_array($command, $parsers)) {
|
if (in_array($command, $parsers)) {
|
||||||
$cname = 'Source\\'.$classname;
|
$cname = 'Oreolek\\Source\\'.$classname;
|
||||||
$source = (new $cname());
|
$source = (new $cname());
|
||||||
$source->check();
|
$source->check();
|
||||||
if (empty($source->games)) {
|
if (empty($source->games)) {
|
||||||
|
|
|
@ -8,7 +8,8 @@
|
||||||
"ryakad/pandoc-php": "^1.0",
|
"ryakad/pandoc-php": "^1.0",
|
||||||
"longman/telegram-bot": "dev-master",
|
"longman/telegram-bot": "dev-master",
|
||||||
"revolution/laravel-mastodon-api": "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": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^8.0"
|
"phpunit/phpunit": "^8.0"
|
||||||
|
|
184
composer.lock
generated
184
composer.lock
generated
|
@ -4,7 +4,7 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "10fed75d3afc511f898c29c5ddf8ec3f",
|
"content-hash": "3ba31f238d4c481e493ac118f1b29f36",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "addwiki/mediawiki-api",
|
"name": "addwiki/mediawiki-api",
|
||||||
|
@ -784,6 +784,54 @@
|
||||||
],
|
],
|
||||||
"time": "2019-07-28T09:02:12+00:00"
|
"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",
|
"name": "psr/container",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
|
@ -1695,6 +1743,140 @@
|
||||||
],
|
],
|
||||||
"time": "2019-03-17T17:37:11+00:00"
|
"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",
|
"name": "myclabs/deep-copy",
|
||||||
"version": "1.9.1",
|
"version": "1.9.1",
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Oreolek;
|
namespace Oreolek;
|
||||||
|
|
||||||
class Publisher {
|
abstract class Publisher {
|
||||||
public $text;
|
|
||||||
protected $dry_run = true;
|
protected $dry_run = true;
|
||||||
|
|
||||||
public function __construct($config) {
|
public function __construct($config) {
|
||||||
$this->dry_run = $config['DRY_RUN'];
|
$this->dry_run = $config['DRY_RUN'];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function _publish(string $text): void {
|
abstract protected function _publish(string $text);
|
||||||
}
|
|
||||||
|
|
||||||
public function publish(string $text): void {
|
public function publish(string $text): void {
|
||||||
if (empty($this->client)) {
|
if (empty($this->client)) {
|
||||||
|
|
|
@ -1,56 +1,63 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Oreolek\Publisher;
|
namespace Oreolek\Publisher;
|
||||||
use \Oreolek\Publisher;
|
use \Oreolek\Publisher;
|
||||||
|
use \Norgul\Xmpp\Options;
|
||||||
|
use \Norgul\Xmpp\XmppClient;
|
||||||
|
|
||||||
class Jabber extends Publisher {
|
class Jabber extends Publisher {
|
||||||
protected $client;
|
protected $client;
|
||||||
protected $text;
|
|
||||||
|
|
||||||
public function __construct($config) {
|
public function __construct($config) {
|
||||||
super::__construct($config);
|
Publisher::__construct($config);
|
||||||
if ($config['JABBER'] === true) {
|
if ($config['JABBER'] === true) {
|
||||||
$this->client = new JAXL(array(
|
$options = new Options();
|
||||||
'jid' => $config['JABBER_JID'],
|
$options->setHost($config['JABBER_HOST']);
|
||||||
'pass' => $config['JABBER_PASSWORD'],
|
$options->setUsername($config['JABBER_JID']);
|
||||||
));
|
$options->setPassword($config['JABBER_PASSWORD']);
|
||||||
$this->client->require_xep([
|
$this->client = new XmppClient($options);
|
||||||
'0060' // Publish-Subscribe
|
$this->client->connect();
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function _publish(string $text): void {
|
public function __destruct() {
|
||||||
$this->text = $text;
|
$this->client->disconnect();
|
||||||
$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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function on_auth_success_callback()
|
protected function _publish(string $text) {
|
||||||
{
|
if (empty($this->text)) {
|
||||||
// create node
|
return;
|
||||||
// $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 on_auth_failure_callback($reason)
|
$xml = <<<END
|
||||||
{
|
<iq type='set'
|
||||||
$this->client->send_end_stream();
|
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;
|
protected $client;
|
||||||
|
|
||||||
public function __construct($config) {
|
public function __construct($config) {
|
||||||
super::__construct($config);
|
Publisher::__construct($config);
|
||||||
if ($config['MASTODON'] === true) {
|
if ($config['MASTODON'] === true) {
|
||||||
$guzzle = new GuzzleClient([
|
$guzzle = new GuzzleClient([
|
||||||
'timeout' => 30,
|
'timeout' => 30,
|
||||||
|
|
|
@ -6,7 +6,7 @@ class Telegram extends Publisher {
|
||||||
protected $client;
|
protected $client;
|
||||||
protected $chat_id;
|
protected $chat_id;
|
||||||
public function __construct($config) {
|
public function __construct($config) {
|
||||||
super::__construct($config);
|
Publisher::__construct($config);
|
||||||
if ($config['TELEGRAM'] === true) {
|
if ($config['TELEGRAM'] === true) {
|
||||||
$this->chat_id = $config['TELEGRAM_CHAT_ID'];
|
$this->chat_id = $config['TELEGRAM_CHAT_ID'];
|
||||||
$this->client = new Longman\TelegramBot\Telegram(
|
$this->client = new Longman\TelegramBot\Telegram(
|
||||||
|
|
Reference in a new issue