Начальный коммит - конфиг и обрывки кода
This commit is contained in:
commit
04a73cb018
|
@ -0,0 +1,3 @@
|
|||
/config.ini
|
||||
/config.yml
|
||||
/vendor
|
|
@ -0,0 +1,11 @@
|
|||
# Бот оглашения результатов КРИЛ
|
||||
|
||||
Бот для оглашения результатов.
|
||||
|
||||
Принимает список победителей и постит объявления в Twitter и Telegram с конца списка с интервалом 5 минут.
|
||||
|
||||
## Установка
|
||||
|
||||
1. Скопировать `config.yml.example` в `config.yml`, отредактировать.
|
||||
1. `composer install`
|
||||
1. Запустить `run.php`
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"minimum-stability": "dev",
|
||||
"require": {
|
||||
"aura/autoload": "^2.0",
|
||||
"ryakad/pandoc-php": "^1.0",
|
||||
"longman/telegram-bot": "dev-master",
|
||||
"mremi/url-shortener": "dev-master",
|
||||
"revolution/laravel-mastodon-api": "dev-master",
|
||||
"symfony/yaml": "^4.2@dev"
|
||||
},
|
||||
"require-dev": {
|
||||
},
|
||||
"scripts": {
|
||||
"test": "phpunit tests/"
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,13 @@
|
|||
DRY_RUN: true
|
||||
TELEGRAM: true
|
||||
MASTODON: true
|
||||
MASTODON_ACCESS_TOKEN: token
|
||||
MASTODON_SERVER: https://botsin.space
|
||||
MASTODON_USER: user
|
||||
TELEGRAM_API_KEY: some-key-here
|
||||
TELEGRAM_BOT_NAME: bot name
|
||||
TELEGRAM_CHAT_ID: id
|
||||
BITLY_TOKEN: token
|
||||
games:
|
||||
30: "«Тринадцать» — А.Я.Клешня, И.Я.Клешня"
|
||||
20: "«Хорошие числа» — Аноним"
|
|
@ -0,0 +1,89 @@
|
|||
#!/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'));
|
||||
|
||||
var_dump($config['games']);
|
||||
die();
|
||||
$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 ($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());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue