1
0
Fork 0
Бот для оглашения результатов конкурса
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.4 KiB

#!/usr/bin/php
<?php
/*
A set of utilities for tracking text-based game releases
Copyright (C) 2017-2018 Alexander Yakovlev
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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'));
$games = $config['games'];
krsort($games);
$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);
}
foreach ($games as $place => $game) {
$description = $place.' место: '.$game;
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']);
$mastodon->createStatus($description, [
'language' => 'ru'
]);
if (!$config['DRY_RUN']) {
file_put_contents('.lastrun', time());
}
}
}