Skip to content

Commit fb19ac7

Browse files
committed
Implemented new bot
1 parent e92d578 commit fb19ac7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3975
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.phpunit.result.cache
2+
config.php
3+
infection.log
4+
.idea
5+
vendor

.travis.yml

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
sudo: false
2+
3+
language: php
4+
5+
matrix:
6+
include:
7+
- name: '[REQUIRE_CHECK] With Locked Dependencies'
8+
php: '7.4snapshot'
9+
env: require=1
10+
- name: '[REQUIRE_CHECK] With Lowest Dependencies'
11+
php: '7.4snapshot'
12+
env: require=1 dependencies=lowest
13+
- name: '[REQUIRE_CHECK] With Highest Dependencies'
14+
php: '7.4snapshot'
15+
env: require=1 dependencies=highest
16+
17+
- name: '[CS] PHP 7.4 With Locked Dependencies'
18+
php: '7.4snapshot'
19+
env: cs=1
20+
- name: '[CS] PHP 7.4 With Lowest Dependencies'
21+
php: '7.4snapshot'
22+
env: cs=1 dependencies=lowest
23+
- name: '[CS] PHP 7.4 With Highest Dependencies'
24+
php: '7.4snapshot'
25+
env: cs=1 dependencies=highest
26+
- name: '[CS] PHP Nightly With Locked Dependencies'
27+
php: nightly
28+
env: cs=1
29+
- name: '[CS] PHP Nightly With Lowest Dependencies'
30+
php: nightly
31+
env: cs=1 dependencies=lowest
32+
- name: '[CS] PHP Nightly With Highest Dependencies'
33+
php: nightly
34+
env: cs=1 dependencies=highest
35+
36+
- name: '[UNIT] PHP 7.4 With Locked Dependencies'
37+
php: '7.4snapshot'
38+
env: unit=1
39+
- name: '[UNIT] PHP 7.4 With Lowest Dependencies'
40+
php: '7.4snapshot'
41+
env: dependencies=lowest unit=1
42+
- name: '[UNIT] PHP 7.4 With Highest Dependencies'
43+
php: '7.4snapshot'
44+
env: dependencies=highest unit=1
45+
- name: '[UNIT] PHP Nightly With Locked Dependencies'
46+
php: nightly
47+
env: unit=1
48+
- name: '[UNIT] PHP Nightly With Highest Dependencies'
49+
php: nightly
50+
env: dependencies=highest unit=1
51+
- name: '[UNIT] PHP Nightly With Lowest Dependencies'
52+
php: nightly
53+
env: dependencies=lowest unit=1
54+
55+
- name: '[INTEGRATION] PHP 7.4 With Locked Dependencies'
56+
php: '7.4snapshot'
57+
env: integration=1
58+
- name: '[INTEGRATION] PHP 7.4 With Lowest Dependencies'
59+
php: '7.4snapshot'
60+
env: dependencies=lowest integration=1
61+
- name: '[INTEGRATION] PHP 7.4 With Highest Dependencies'
62+
php: '7.4snapshot'
63+
env: dependencies=highest integration=1
64+
- name: '[INTEGRATION] PHP Nightly With Locked Dependencies'
65+
php: nightly
66+
env: integration=1
67+
- name: '[INTEGRATION] PHP Nightly With Highest Dependencies'
68+
php: nightly
69+
env: dependencies=highest integration=1
70+
- name: '[INTEGRATION] PHP Nightly With Lowest Dependencies'
71+
php: nightly
72+
env: dependencies=lowest integration=1
73+
74+
- name: '[INFECTION] PHP 7.4 With Locked Dependencies'
75+
php: '7.4snapshot'
76+
env: infection=1
77+
- name: '[INFECTION] PHP 7.4 With Lowest Dependencies'
78+
php: '7.4snapshot'
79+
env: dependencies=lowest infection=1
80+
- name: '[INFECTION] PHP 7.4 With Highest Dependencies'
81+
php: '7.4snapshot'
82+
env: dependencies=highest infection=1
83+
- name: '[INFECTION] PHP Nightly With Locked Dependencies'
84+
php: nightly
85+
env: infection=1
86+
- name: '[INFECTION] PHP Nightly With Highest Dependencies'
87+
php: nightly
88+
env: dependencies=highest infection=1
89+
- name: '[INFECTION] PHP Nightly With Lowest Dependencies'
90+
php: nightly
91+
env: dependencies=lowest infection=1
92+
allow_failures:
93+
- name: '[CS] PHP 7.4 With Locked Dependencies'
94+
php: '7.4snapshot'
95+
env: cs=1
96+
- name: '[CS] PHP 7.4 With Lowest Dependencies'
97+
php: '7.4snapshot'
98+
env: cs=1 dependencies=lowest
99+
- name: '[CS] PHP 7.4 With Highest Dependencies'
100+
php: '7.4snapshot'
101+
env: cs=1 dependencies=highest
102+
- name: '[CS] PHP Nightly With Locked Dependencies'
103+
php: nightly
104+
env: cs=1
105+
- name: '[CS] PHP Nightly With Lowest Dependencies'
106+
php: nightly
107+
env: cs=1 dependencies=lowest
108+
- name: '[CS] PHP Nightly With Highest Dependencies'
109+
php: nightly
110+
env: cs=1 dependencies=highest
111+
112+
- name: '[UNIT] PHP Nightly With Locked Dependencies'
113+
php: nightly
114+
env: unit=1
115+
- name: '[UNIT] PHP Nightly With Highest Dependencies'
116+
php: nightly
117+
env: dependencies=highest unit=1
118+
- name: '[UNIT] PHP Nightly With Lowest Dependencies'
119+
php: nightly
120+
env: dependencies=lowest unit=1
121+
122+
- name: '[INTEGRATION] PHP Nightly With Locked Dependencies'
123+
php: nightly
124+
env: integration=1
125+
- name: '[INTEGRATION] PHP Nightly With Highest Dependencies'
126+
php: nightly
127+
env: dependencies=highest integration=1
128+
- name: '[INTEGRATION] PHP Nightly With Lowest Dependencies'
129+
php: nightly
130+
env: dependencies=lowest integration=1
131+
132+
- name: '[INFECTION] PHP Nightly With Locked Dependencies'
133+
php: nightly
134+
env: infection=1
135+
- name: '[INFECTION] PHP Nightly With Highest Dependencies'
136+
php: nightly
137+
env: dependencies=highest infection=1
138+
- name: '[INFECTION] PHP Nightly With Lowest Dependencies'
139+
php: nightly
140+
env: dependencies=lowest infection=1
141+
142+
before_install:
143+
- phpenv config-rm xdebug.ini || echo "No xdebug config."
144+
- composer self-update
145+
146+
install:
147+
- wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.0.0/php-coveralls.phar
148+
- chmod +x php-coveralls.phar
149+
150+
before_script:
151+
- if [ -z "$dependencies" ]; then travis_retry composer install -n; fi;
152+
- if [ "$dependencies" = "lowest" ]; then travis_retry composer update --prefer-lowest -n; fi;
153+
- if [ "$dependencies" = "highest" ]; then travis_retry composer update -n; fi;
154+
155+
script:
156+
- if [ "$unit" = 1 ]; then phpdbg -qrr vendor/bin/phpunit --testsuite UnitTestSuite --coverage-text --coverage-clover build/logs/clover.xml; fi;
157+
- if [ "$integration" = 1 ]; then phpdbg -qrr vendor/bin/phpunit --testsuite IntegrationTestSuite --coverage-text --coverage-clover build/logs/clover.xml; fi;
158+
- if [ "$cs" = 1 ]; then vendor/bin/phpcs -s; fi;
159+
- if [ "$require" = 1 ]; then vendor/bin/composer-require-checker check; fi;
160+
- if [ "$infection" = 1 ]; then phpdbg -qrr vendor/infection/infection/bin/infection --threads=4 --min-msi=100 --min-covered-msi=100; fi;
161+
162+
after_success:
163+
- if [ "$unit" = 1 ]; then travis_retry php php-coveralls.phar; fi;

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,15 @@
11
# async-bot-jeeves
2+
23
Jeeves based on https://github.com/async-bot
4+
5+
## Requirements
6+
7+
- PHP 7.4
8+
9+
## Usage
10+
11+
- Get a StackOverflow account at: https://stackoverflow.com/users/signup?ssrc=head&returnurl=https%3a%2f%2fstackoverflow.com%2f
12+
- Do not use 3rd party sign up
13+
- Copy the config file `./config.php.dist` to `./config.php`
14+
- Fill in your credentials in `./config.php`
15+
- Run the script `./bin/jeeves.php`

bin/jeeves.php

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/env php
2+
<?php declare(strict_types=1);
3+
4+
namespace Room11\Jeeves\Bin;
5+
6+
use Amp\Http\Client\HttpClientBuilder;
7+
use AsyncBot\Core\Http\Client;
8+
use AsyncBot\Core\Logger\Factory as LoggerFactory;
9+
use AsyncBot\Core\Manager;
10+
use AsyncBot\Driver\StackOverflowChat\Authentication\ValueObject\Credentials;
11+
use AsyncBot\Driver\StackOverflowChat\Driver;
12+
use AsyncBot\Driver\StackOverflowChat\Factory as StackOverflowChatDriverFactory;
13+
use AsyncBot\Plugin\GitHubStatus\Parser\Html;
14+
use AsyncBot\Plugin\GitHubStatus\Plugin as GitHubStatusPlugin;
15+
use AsyncBot\Plugin\GitHubStatus\Retriever\Http;
16+
use AsyncBot\Plugin\GitHubStatus\Storage\InMemoryRepository;
17+
use AsyncBot\Plugin\Imdb\Plugin as ImdbPlugin;
18+
use AsyncBot\Plugin\Imdb\ValueObject\ApiKey;
19+
use AsyncBot\Plugin\LinuxManualPages\Plugin as LinuxManualPagesPlugin;
20+
use AsyncBot\Plugin\OpenGrok\Plugin as OpenGrokPlugin;
21+
use AsyncBot\Plugin\PackagistFinder\Plugin as PackagistFinderPlugin;
22+
use AsyncBot\Plugin\PhpBugs\Parser\Html as PhpBugsParser;
23+
use AsyncBot\Plugin\PhpBugs\Plugin as PhpBugsPlugin;
24+
use AsyncBot\Plugin\PhpBugs\Retriever\GetAllBugs;
25+
use AsyncBot\Plugin\PhpBugs\Storage\InMemoryRepository as PhpBugsStorage;
26+
use AsyncBot\Plugin\WordOfTheDay\Plugin as WordOfTheDayPlugin;
27+
use Room11\Jeeves\Command\Imdb\Listener\Listener as ImdbCommandListener;
28+
use Room11\Jeeves\Command\Man\Listener\Listener as ManListener;
29+
use Room11\Jeeves\Command\OpenGrok\Listener\Listener as OpenGrokListener;
30+
use Room11\Jeeves\Command\Packagist\Listener\Listener as PackagistFinderListener;
31+
use Room11\Jeeves\Command\WordOfTheDay\Listener\Listener as WordOfTheDayCommandListener;
32+
use Room11\Jeeves\Listener\OutputNewPhpBugs;
33+
use Room11\Jeeves\Listener\OutputGitHubStatusChange;
34+
35+
require_once __DIR__ . '/../vendor/autoload.php';
36+
37+
/**
38+
* Set up logger
39+
*/
40+
$logger = LoggerFactory::buildConsoleLogger();
41+
42+
/**
43+
* Set up the HTTP client
44+
*/
45+
$httpClient = new Client(HttpClientBuilder::buildDefault());
46+
47+
/**
48+
* Get the configuration
49+
*/
50+
$configuration = require_once __DIR__ . '/../config.php';
51+
52+
/**
53+
* Set up bot(s)
54+
*/
55+
$stackOverflowChatBot = (new StackOverflowChatDriverFactory(
56+
new Credentials(
57+
$configuration['drivers'][Driver::class]['username'],
58+
$configuration['drivers'][Driver::class]['password'],
59+
$configuration['drivers'][Driver::class]['roomUrl'],
60+
),
61+
))->build();
62+
63+
/**
64+
* Set up plugin(s)
65+
*/
66+
$imdbPlugin = new ImdbPlugin($httpClient, new ApiKey($configuration['apis']['omdbApiKey']));
67+
$wordOfTheDayPlugin = new WordOfTheDayPlugin($httpClient);
68+
$packagistPlugin = new PackagistFinderPlugin($httpClient);
69+
$openGrokPlugin = new OpenGrokPlugin($httpClient);
70+
$linuxManPlugin = new LinuxManualPagesPlugin($httpClient);
71+
72+
/**
73+
* Set up runnable plugin(s)
74+
*/
75+
$gitHubStatusPlugin = new GitHubStatusPlugin($logger, new Http($httpClient, new Html()), new InMemoryRepository());
76+
$phpBugsPlugin = new PhpBugsPlugin($logger, new GetAllBugs($httpClient, new PhpBugsParser()), new PhpBugsStorage(), new \DateInterval('PT1M'));
77+
78+
/**
79+
* Register for events
80+
*/
81+
$gitHubStatusPlugin->onStatusChange(new OutputGitHubStatusChange($stackOverflowChatBot));
82+
$phpBugsPlugin->onNewBugs(new OutputNewPhpBugs($stackOverflowChatBot));
83+
84+
/**
85+
* Add listeners for commands
86+
*/
87+
$stackOverflowChatBot->onNewMessage(new ImdbCommandListener($stackOverflowChatBot, $imdbPlugin));
88+
$stackOverflowChatBot->onNewMessage(new WordOfTheDayCommandListener($stackOverflowChatBot, $wordOfTheDayPlugin));
89+
$stackOverflowChatBot->onNewMessage(new PackagistFinderListener($stackOverflowChatBot, $packagistPlugin));
90+
$stackOverflowChatBot->onNewMessage(new OpenGrokListener($stackOverflowChatBot, $openGrokPlugin));
91+
$stackOverflowChatBot->onNewMessage(new ManListener($stackOverflowChatBot, $linuxManPlugin));
92+
93+
/**
94+
* Run the bot minions
95+
*/
96+
(new Manager($logger))
97+
->registerBot($stackOverflowChatBot)
98+
->registerPlugin($gitHubStatusPlugin)
99+
->registerPlugin($phpBugsPlugin)
100+
->run()
101+
;

composer.json

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "room-11/async-bot-jeeves",
3+
"description": "Jeeves",
4+
"type": "project",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Pieter Hordijk",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"minimum-stability": "dev",
13+
"prefer-stable": true,
14+
"require": {
15+
"php": "^7.4",
16+
"amphp/http-client": "dev-master as 4.0.0",
17+
"amphp/http-client-cookies": "dev-master",
18+
"amphp/log": "^1.0",
19+
"async-bot/core": "dev-master",
20+
"async-bot/github-status-plugin": "dev-master",
21+
"async-bot/imdb-plugin": "dev-master",
22+
"async-bot/linux-manual-pages-plugin": "dev-master",
23+
"async-bot/open-grok-plugin": "dev-master",
24+
"async-bot/packagist-finder-plugin": "dev-master",
25+
"async-bot/php-bugs-plugin": "dev-master",
26+
"async-bot/stackoverflow-chat-driver": "dev-master",
27+
"async-bot/word-of-the-day-plugin": "dev-master"
28+
},
29+
"autoload": {
30+
"psr-4": {
31+
"Room11\\Jeeves\\": "src/"
32+
}
33+
},
34+
"autoload-dev": {
35+
"psr-4": {
36+
"Room11\\JeevesTest\\": "tests/"
37+
}
38+
},
39+
"config": {
40+
"sort-packages": true
41+
}
42+
}

0 commit comments

Comments
 (0)