#!/usr/bin/php . */ require_once ("vendor/autoload.php"); use Symfony\Component\Yaml\Yaml; use Revolution\Mastodon\MastodonClient; use \GuzzleHttp\Client as GuzzleClient; use Mremi\UrlShortener\Provider\Bitly\BitlyProvider; use Mremi\UrlShortener\Provider\Bitly\GenericAccessTokenAuthenticator; $config = Yaml::parse(file_get_contents('config.yml')); define('STYLE',$config['STYLE']); define('FORMAT',$config['FORMAT']); require_once "Game.php"; require_once "Source.php"; require_once "download.php"; $loader = new \Aura\Autoload\Loader; $loader->register(); $loader->addPrefix('Source', 'Source'); $parsers = [ // 'urq', 'anivisual', 'kvester', 'apero', 'instead', 'hyperbook_ru', 'hyperbook_en', 'questbook', 'textadventures', 'ifdb', 'dashingdon', 'itch', 'gamejolt', 'steam', ]; $lastrun = 0; if (file_exists('.lastrun') && !$config['DRY_RUN']) { $lastrun = file_get_contents('.lastrun'); } $pandoc = new \Pandoc\Pandoc(); $bitlyProvider = new BitlyProvider( new GenericAccessTokenAuthenticator($config['BITLY_TOKEN']) ); if ($config['TELEGRAM'] === true) { $telegram = new Longman\TelegramBot\Telegram( $config['TELEGRAM_API_KEY'], $config['TELEGRAM_BOT_NAME'] ); } if ($config['MASTODON'] === true) { $guzzle = new GuzzleClient([ 'timeout' => 30, ]); $mastodon = new MastodonClient($guzzle); } function check($classname, $command) { global $parsers; global $mastodon; global $telegram; global $config; if (in_array($command, $parsers)) { $cname = 'Source\\'.$classname; $source = (new $cname()); $source->check(); if (empty($source->games)) { return; } foreach ($source->games as $game) { $description = $game->text(); if ($config['DRY_RUN']) { echo $description."\n"; continue; } if ($config['TELEGRAM'] === true) { try { $result = \Longman\TelegramBot\Request::sendMessage([ 'chat_id' => $config['TELEGRAM_CHAT_ID'], 'text' => $description, 'parse_mode' => 'Markdown' ]); if (!$config['DRY_RUN']) { file_put_contents('.lastrun', time()); } } catch (Longman\TelegramBot\Exception\TelegramException $e) { echo $e; } } if ($config['MASTODON'] === true) { $mastodon->domain($config['MASTODON_SERVER'])->token($config['MASTODON_ACCESS_TOKEN']); /* if ($image) { download('https://ifhub.club'.$image, './'.basename($image)); $attachment = $mastodon->post('/media', [ 'file' => file_get_contents('./'.basename($image)) ]); var_dump($attachment); unlink('./'.basename($image)); $mdescription .= $attachment->url; } */ $mastodon->createStatus($description, [ 'language' => 'en' ]); if (!$config['DRY_RUN']) { file_put_contents('.lastrun', time()); } } } } } foreach($config['parsers'] as $parser) { $command = strtolower($parser['classname']); if (isset($parser['command'])) { $command = $parser['command']; } check ($parser['classname'], $command); }