Mastodon support

This commit is contained in:
Alexander Yakovlev 2017-06-17 02:03:07 +07:00
parent 2dd252673c
commit 6337d56424
3 changed files with 274 additions and 17 deletions

24
bot.php
View file

@ -4,7 +4,7 @@ use Symfony\Component\Yaml\Yaml;
use Mremi\UrlShortener\Model\Link; use Mremi\UrlShortener\Model\Link;
use Mremi\UrlShortener\Provider\Bitly\BitlyProvider; use Mremi\UrlShortener\Provider\Bitly\BitlyProvider;
use Mremi\UrlShortener\Provider\Bitly\GenericAccessTokenAuthenticator; use Mremi\UrlShortener\Provider\Bitly\GenericAccessTokenAuthenticator;
use Baguette\Mastodon; use Revolution\Mastodon\MastodonClient;
$config = Yaml::parse(file_get_contents('config.yml')); $config = Yaml::parse(file_get_contents('config.yml'));
$lastrun = 0; $lastrun = 0;
@ -55,14 +55,8 @@ $telegram = new Longman\TelegramBot\Telegram(
$config['TELEGRAM_API_KEY'], $config['TELEGRAM_API_KEY'],
$config['TELEGRAM_BOT_NAME'] $config['TELEGRAM_BOT_NAME']
); );
$mastodon = Mastodon\session( $mastodon = new MastodonClient();
$config['MASTODON_SERVER'],
$config['MASTODON_CLIENT_ID'],
$config['MASTODON_SECRET'],
[
'scope' => 'read write',
]
);
foreach ($articles as $article) { foreach ($articles as $article) {
if (strtotime($article['pubDate']) <= $lastrun) { if (strtotime($article['pubDate']) <= $lastrun) {
continue; continue;
@ -99,16 +93,18 @@ foreach ($articles as $article) {
} }
} }
if ($config['MASTODON'] === true) { if ($config['MASTODON'] === true) {
$mastodon->domain($config['MASTODON_SERVER'])->token($config['MASTODON_ACCESS_TOKEN']);
$mdescription = "$title\n\n".ellipse($description, 400); $mdescription = "$title\n\n".ellipse($description, 400);
$mdescription .= ": $link"; $mdescription .= ": $link";
/*
if ($image) { if ($image) {
$attachment = Mastodon\request($mastodon, 'POST', '/api/v1/media', [ $attachment = $mastodon->post('/media', [
'file' => $image 'file' => $image
], Mastodon\Entity\Account::class); ]);
var_dump($attachment);
$mdescription .= $attachment->url; $mdescription .= $attachment->url;
} }*/
echo $mdescription; $mastodon->status_post($mdescription);
//$mastodon->postStatus(Mastodon\toot($mdescription));
} }
} else { } else {
echo $description."\n"; echo $description."\n";

View file

@ -4,6 +4,7 @@
"sabre/xml": "^2.0", "sabre/xml": "^2.0",
"ryakad/pandoc-php": "^1.0", "ryakad/pandoc-php": "^1.0",
"symfony/yaml": "^3.2", "symfony/yaml": "^3.2",
"mremi/url-shortener": "^2.1" "mremi/url-shortener": "^2.1",
"revolution/laravel-mastodon-api": "^1.1"
} }
} }

264
composer.lock generated
View file

@ -4,9 +4,76 @@
"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"
], ],
"hash": "71302a13e71405a5c30d66ccb32c62da", "hash": "1202ffc808820614be6612d0a402a758",
"content-hash": "a474f6360fb73f8cd1cfc26729f5c03a", "content-hash": "725c9d0611923400d53ba805e2785e86",
"packages": [ "packages": [
{
"name": "doctrine/inflector",
"version": "v1.1.0",
"source": {
"type": "git",
"url": "https://github.com/doctrine/inflector.git",
"reference": "90b2128806bfde671b6952ab8bea493942c1fdae"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/inflector/zipball/90b2128806bfde671b6952ab8bea493942c1fdae",
"reference": "90b2128806bfde671b6952ab8bea493942c1fdae",
"shasum": ""
},
"require": {
"php": ">=5.3.2"
},
"require-dev": {
"phpunit/phpunit": "4.*"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev"
}
},
"autoload": {
"psr-0": {
"Doctrine\\Common\\Inflector\\": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Roman Borschel",
"email": "roman@code-factory.org"
},
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de"
},
{
"name": "Guilherme Blanco",
"email": "guilhermeblanco@gmail.com"
},
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com"
},
{
"name": "Johannes Schmitt",
"email": "schmittjoh@gmail.com"
}
],
"description": "Common String Manipulations with regard to casing and singular/plural rules.",
"homepage": "http://www.doctrine-project.org",
"keywords": [
"inflection",
"pluralize",
"singularize",
"string"
],
"time": "2015-11-06 14:35:42"
},
{ {
"name": "guzzlehttp/guzzle", "name": "guzzlehttp/guzzle",
"version": "6.2.3", "version": "6.2.3",
@ -185,6 +252,105 @@
], ],
"time": "2017-03-20 17:10:46" "time": "2017-03-20 17:10:46"
}, },
{
"name": "illuminate/contracts",
"version": "v5.4.27",
"source": {
"type": "git",
"url": "https://github.com/illuminate/contracts.git",
"reference": "31f0193eb14aa3ee07841dc254081425616e79f0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/illuminate/contracts/zipball/31f0193eb14aa3ee07841dc254081425616e79f0",
"reference": "31f0193eb14aa3ee07841dc254081425616e79f0",
"shasum": ""
},
"require": {
"php": ">=5.6.4"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "5.4-dev"
}
},
"autoload": {
"psr-4": {
"Illuminate\\Contracts\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Taylor Otwell",
"email": "taylor@laravel.com"
}
],
"description": "The Illuminate Contracts package.",
"homepage": "https://laravel.com",
"time": "2017-04-19 20:17:43"
},
{
"name": "illuminate/support",
"version": "v5.4.27",
"source": {
"type": "git",
"url": "https://github.com/illuminate/support.git",
"reference": "a42393b56d0ec75f55e760f2a47bcf85a17a278d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/illuminate/support/zipball/a42393b56d0ec75f55e760f2a47bcf85a17a278d",
"reference": "a42393b56d0ec75f55e760f2a47bcf85a17a278d",
"shasum": ""
},
"require": {
"doctrine/inflector": "~1.0",
"ext-mbstring": "*",
"illuminate/contracts": "5.4.*",
"paragonie/random_compat": "~1.4|~2.0",
"php": ">=5.6.4"
},
"replace": {
"tightenco/collect": "self.version"
},
"suggest": {
"illuminate/filesystem": "Required to use the composer class (5.2.*).",
"symfony/process": "Required to use the composer class (~3.2).",
"symfony/var-dumper": "Required to use the dd function (~3.2)."
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "5.4-dev"
}
},
"autoload": {
"psr-4": {
"Illuminate\\Support\\": ""
},
"files": [
"helpers.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Taylor Otwell",
"email": "taylor@laravel.com"
}
],
"description": "The Illuminate Support package.",
"homepage": "https://laravel.com",
"time": "2017-06-15 12:35:32"
},
{ {
"name": "longman/telegram-bot", "name": "longman/telegram-bot",
"version": "0.44.1", "version": "0.44.1",
@ -365,6 +531,54 @@
], ],
"time": "2017-03-29 18:03:19" "time": "2017-03-29 18:03:19"
}, },
{
"name": "paragonie/random_compat",
"version": "v2.0.10",
"source": {
"type": "git",
"url": "https://github.com/paragonie/random_compat.git",
"reference": "634bae8e911eefa89c1abfbf1b66da679ac8f54d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/paragonie/random_compat/zipball/634bae8e911eefa89c1abfbf1b66da679ac8f54d",
"reference": "634bae8e911eefa89c1abfbf1b66da679ac8f54d",
"shasum": ""
},
"require": {
"php": ">=5.2.0"
},
"require-dev": {
"phpunit/phpunit": "4.*|5.*"
},
"suggest": {
"ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes."
},
"type": "library",
"autoload": {
"files": [
"lib/random.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Paragon Initiative Enterprises",
"email": "security@paragonie.com",
"homepage": "https://paragonie.com"
}
],
"description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7",
"keywords": [
"csprng",
"pseudorandom",
"random"
],
"time": "2017-03-13 16:27:32"
},
{ {
"name": "psr/http-message", "name": "psr/http-message",
"version": "1.0.1", "version": "1.0.1",
@ -527,6 +741,52 @@
], ],
"time": "2017-03-14 09:44:11" "time": "2017-03-14 09:44:11"
}, },
{
"name": "revolution/laravel-mastodon-api",
"version": "1.1.3",
"source": {
"type": "git",
"url": "https://github.com/kawax/laravel-mastodon-api.git",
"reference": "386bc7fbf5dc16b08582c9739c770be078314bbc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/kawax/laravel-mastodon-api/zipball/386bc7fbf5dc16b08582c9739c770be078314bbc",
"reference": "386bc7fbf5dc16b08582c9739c770be078314bbc",
"shasum": ""
},
"require": {
"guzzlehttp/guzzle": "^6.2",
"illuminate/support": "5.*",
"php": ">=7.0.0"
},
"require-dev": {
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "6.*"
},
"type": "library",
"autoload": {
"psr-4": {
"Revolution\\Mastodon\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "kawax",
"email": "kawaxbiz@gmail.com"
}
],
"description": "Mastodon API for Laravel",
"keywords": [
"laravel",
"mastodon"
],
"time": "2017-05-30 03:20:20"
},
{ {
"name": "ryakad/pandoc-php", "name": "ryakad/pandoc-php",
"version": "v1.0.0", "version": "v1.0.0",