Compare commits
3 Commits
6735d6217a
...
3a39cf8513
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a39cf8513 | ||
|
|
bca6ee8512 | ||
|
|
2af166e3e6 |
82
README.md
82
README.md
@@ -5,33 +5,99 @@
|
||||
It is based on Perl modules [Telegram::Bot][1] and [Hailo][2] as conversation
|
||||
generator.
|
||||
|
||||
I have to fork [Telegram::Bot][1] and add some of new methods that are already
|
||||
appear in [Telegram API][3], but author seems to abandon lib. Also, I decide to
|
||||
rename it to avoid collision in the future, now it is Teapot::Bot and is bundled
|
||||
with bot. When lib become mature enough, maybe I release it separately.
|
||||
I have to fork [Telegram::Bot][1] and update it according to features appeared
|
||||
in [Telegram Bot API v5][3]. Also, I decide to rename it to avoid collision in
|
||||
the future, now it is Teapot::Bot and is bundled with bot. When lib becomes
|
||||
mature enough, maybe I release it separately.
|
||||
|
||||
Bot config located in **data/config.json**, sample config provided as
|
||||
**data/sample_config.json**.
|
||||
|
||||
Bot can be run via **bin/aleesa-telegram-bot** and acts as daemon.
|
||||
Bot can be run via **bin/aleesa-telegram-bot** and acts as daemon (double fork()
|
||||
and detaches stdio).
|
||||
|
||||
## Installation
|
||||
|
||||
In order to run this application, you need to "bootstrap" it - download and build
|
||||
all required dependencies and libraries.
|
||||
|
||||
You'll need "Development Tools" or similar group of packages, perl, perl-devel,
|
||||
perl-local-lib, perl-app-cpanm, sqlite-devel, zlib-devel, openssl-devel,
|
||||
libdb4-devel (Berkeley DB devel), make.
|
||||
You'll need perl-5.18 or newer, "Development Tools" or similar group of
|
||||
packages, perl, perl-devel, perl-local-lib, perl-app-cpanm, sqlite-devel,
|
||||
zlib-devel, openssl-devel, libdb4-devel (Berkeley DB devel), make.
|
||||
|
||||
After installing required dependencies it is possible to run:
|
||||
|
||||
```bash
|
||||
|
||||
bash bootstrap.sh
|
||||
|
||||
```
|
||||
|
||||
and all libraries should be downloaded, built, tested and installed.
|
||||
|
||||
## Running
|
||||
|
||||
This bot does not [ultilize][4] webhooks, so in order to run it only well
|
||||
internet connection is requied, no public-available ip address is needed.
|
||||
|
||||
### Additional Settings to be performed in order to run bot as it designed
|
||||
|
||||
There are some "plugins" that requires registration on thrird party services
|
||||
and API keys and secrets in order to work.
|
||||
|
||||
#### OpenWeatherMap
|
||||
|
||||
You should [register][5], [login][6] and [create][7] api key. Free plan have
|
||||
all required features to run this "plugin".
|
||||
|
||||
Once key is created you should put it in **config.json** under openweathermap
|
||||
section as appid. Thats it.
|
||||
|
||||
It is still impossible to disable this plugin, but "I'm working on it".
|
||||
|
||||
#### Imgur
|
||||
|
||||
This plugin "just exists" and is actually used nowhere around the code.
|
||||
Anyway, to make use of it besides registering apropriate handler in code, you
|
||||
should sign in imgur and get access token.
|
||||
|
||||
Actually at this time this "plugin" can be stub-ed with default config values.
|
||||
|
||||
Anyway, to fetch access token you should [login][8] and perform [registration][9]
|
||||
of your app. Then you should authorise your app according to [this][10] manual. Or
|
||||
[this][11] one.
|
||||
|
||||
#### Flickr
|
||||
|
||||
This "plugin" is really used to implement random picture link retrival plugins.
|
||||
|
||||
There is helper script in **bin/flickr_init.pl** that helps to get all required keys
|
||||
and secrets from flickr api.
|
||||
|
||||
Before using it bot must be bootstrapped via **`bootstrap.sh`**.
|
||||
|
||||
[Login][11] and create an [app][12] in your flickr account. Then *logout* flickr account.
|
||||
(It is required in order to properly get "verfier" parameter later).
|
||||
|
||||
Put your [app key and secret][13] to **config.json**. Ensure that "verifier" parameter
|
||||
in Flickr-related part of config either absent or commented out.
|
||||
|
||||
Run **bin/flickr_init.pl** first time and follow on screen instuctions - copy and
|
||||
paste given link to browser login to flickr account adn yo'll be redirected to
|
||||
example.com. Check address bar in browser to get so-called "verifier", put it in
|
||||
**config.json**. Then run **bin/flickr_init.pl** again to store API access token in db
|
||||
under data/image directory (in default config). You're done.
|
||||
|
||||
[1]: https://metacpan.org/pod/Telegram::Bot
|
||||
[2]: https://metacpan.org/pod/Hailo
|
||||
[3]: https://core.telegram.org/bots/api
|
||||
[4]: https://core.telegram.org/bots/api#getting-updates
|
||||
[5]: https://home.openweathermap.org/users/sign_up
|
||||
[6]: https://home.openweathermap.org/users/sign_in
|
||||
[7]: https://home.openweathermap.org/api_keys
|
||||
[8]: https://imgur.com/signin
|
||||
[9]: https://api.imgur.com/oauth2/addclient
|
||||
[10]: https://apidocs.imgur.com/#authorization-and-oauth
|
||||
[11]: https://identity.flickr.com/login
|
||||
[12]: https://www.flickr.com/services/apps/create/apply/
|
||||
[13]: https://www.flickr.com/services/api/keys/
|
||||
|
||||
@@ -1,40 +1,65 @@
|
||||
{
|
||||
"user" : "nobody",
|
||||
"debug_log" : "/var/log/aleesa-telegram-bot/debug.log",
|
||||
"admin" : {
|
||||
# store per-channel (per-conversation) settings
|
||||
"dir" : "data/admin"
|
||||
},
|
||||
"image": {
|
||||
"dir" : "data/image",
|
||||
"imgur" : {
|
||||
"client-id" : "imgur api client id",
|
||||
"secret" : "secret for client id",
|
||||
"access_token" : "access token for querying imgur api",
|
||||
"refresh_token" : "token for refreshing access token"
|
||||
}
|
||||
},
|
||||
"friday" : {
|
||||
"dir" : "data/friday",
|
||||
"src" : "data/friday.txt"
|
||||
},
|
||||
|
||||
"fortune" : {
|
||||
"dir" : "data/fortune",
|
||||
"srcdir" : "data/fortune_src"
|
||||
},
|
||||
"telegrambot" : {
|
||||
"csign" : "!",
|
||||
"token" : "get_it_from_botfather",
|
||||
"braindir": "data/telegrambot-brains"
|
||||
|
||||
"friday" : {
|
||||
"dir" : "data/friday",
|
||||
"src" : "data/friday.txt"
|
||||
},
|
||||
"openweathermap" : {
|
||||
"appid": "get_it_on_openweathermap.org",
|
||||
"cachedir" : "data/cache"
|
||||
|
||||
"image": {
|
||||
"dir" : "data/image",
|
||||
"imgur" : {
|
||||
# see README.md about these settings - auth'ed search settings
|
||||
"client-id" : "imgur api client id",
|
||||
"secret" : "secret for client id",
|
||||
"access_token" : "access token for querying imgur api",
|
||||
"refresh_token" : "token for refreshing access token"
|
||||
},
|
||||
"flickr" : {
|
||||
# see README.md about these settings - auth'ed search settings
|
||||
"consumer_key" : "md5-like_hash",
|
||||
"consumer_secret" : "some_hash-like_string",
|
||||
"verifier": "some_hash-like_string"
|
||||
}
|
||||
},
|
||||
|
||||
"karma": {
|
||||
"dir": "data/karma"
|
||||
},
|
||||
|
||||
"lat" : {
|
||||
"brain": "data/lat/lat.sqlite",
|
||||
"brain": "data/lat/brain.sqlite",
|
||||
"src": "data/lat.txt"
|
||||
},
|
||||
"karma" : {
|
||||
"dir": "data/karma"
|
||||
}
|
||||
|
||||
# required for debugging reasons, if commented out or not exist, no debug logging appears at all
|
||||
"log" : "/var/log/aleesa-telegram-bot/debug.log",
|
||||
|
||||
# openwatermap plugin
|
||||
"openweathermap" : {
|
||||
"appid" : "md5sum-like_string",
|
||||
# result cache, stores data for 4 hours
|
||||
"cachedir" : "data/cache",
|
||||
},
|
||||
|
||||
# stuff for telegram itself
|
||||
"telegrambot" : {
|
||||
# directory with per-conversation "brains"
|
||||
"braindir" : "data/telegrambot-brains",
|
||||
# prefix-sign for all commands. in many irc-bots (eggdrop/windrop) it is "." (dot), in sulci it was "!"
|
||||
# in telegram commands begin with "/" on the start of first (and only) line.
|
||||
"csign" : "!",
|
||||
"token" : "Long_string_given_by_@BotFather"
|
||||
},
|
||||
|
||||
# unprivileged user to run this bot from
|
||||
"user" : "unit",
|
||||
}
|
||||
|
||||
@@ -76,6 +76,12 @@ sub command {
|
||||
sleep (irand (2) + 1);
|
||||
$msg->replyMd ($reply);
|
||||
return;
|
||||
} elsif (substr ($text, 1) eq 'monkeyuser') {
|
||||
$msg->typing ();
|
||||
$reply = monkeyuser ();
|
||||
sleep (irand (2) + 1);
|
||||
$msg->replyMd ($reply);
|
||||
return;
|
||||
} elsif (substr ($text, 1) eq 'cat' || substr ($text, 1) eq 'кис') {
|
||||
$msg->typing ();
|
||||
$reply = kitty ();
|
||||
@@ -185,6 +191,7 @@ ${csign}fortune | ${csign}фортунка - рандомная фраз
|
||||
${csign}fox | ${csign}лис - лисичка
|
||||
${csign}friday | ${csign}пятница - а не пятница ли сегодня?
|
||||
${csign}lat | ${csign}лат - сгенерить фразу из крылатых латинских выражений
|
||||
${csign}monkeyuser - рандомный стрип MonkeyUser
|
||||
${csign}owl | ${csign}сова - сова
|
||||
${csign}ping | ${csign}пинг - попинговать бота
|
||||
${csign}ver | ${csign}version | ${csign}версия - что-то про версию ПО
|
||||
|
||||
62
lib/monkeyuser.pm
Normal file
62
lib/monkeyuser.pm
Normal file
@@ -0,0 +1,62 @@
|
||||
package monkeyuser;
|
||||
|
||||
use 5.018;
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
use open qw (:std :utf8);
|
||||
use English qw ( -no_match_vars );
|
||||
use Carp qw (cluck);
|
||||
use HTTP::Tiny;
|
||||
use HTML::TokeParser;
|
||||
use Math::Random::Secure qw (irand);
|
||||
|
||||
use version; our $VERSION = qw (1.0);
|
||||
use Exporter qw (import);
|
||||
our @EXPORT_OK = qw (monkeyuser);
|
||||
|
||||
sub monkeyuser {
|
||||
my $r;
|
||||
my $ret = 'Нету Monkey User-ов, они все спрятались.';
|
||||
my @link;
|
||||
|
||||
for (1..3) {
|
||||
my $http = HTTP::Tiny->new (timeout => 3);
|
||||
$r = $http->get ('https://www.monkeyuser.com/toc/');
|
||||
|
||||
if ($r->{success}) {
|
||||
last;
|
||||
}
|
||||
|
||||
sleep 2;
|
||||
}
|
||||
|
||||
if ($r->{success}) {
|
||||
my $p = HTML::TokeParser->new(\$r->{content});
|
||||
my @a;
|
||||
|
||||
do {
|
||||
$#a = -1;
|
||||
@a = $p->get_tag("a");
|
||||
|
||||
if (defined $a[0][1]->{class} && $a[0][1]->{class} eq 'lazyload small-image') {
|
||||
if (defined $a[0][1]->{"data-src"} && ($a[0][1]->{"data-src"} !~ /adlitteram/)) {
|
||||
push @link, $a[0][1]->{"data-src"};
|
||||
}
|
||||
}
|
||||
|
||||
} while ($#{$a[0]} > 1);
|
||||
|
||||
if ($#link > 0) {
|
||||
$ret = sprintf '[MonkeyUser](https://www.monkeyuser.com%s)', $link [irand (1 + $#link)];
|
||||
}
|
||||
} else {
|
||||
cluck sprintf 'Server return status %s with message: %s', $r->{status}, $r->{reason};
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
# vim: set ft=perl noet ai ts=4 sw=4 sts=4:
|
||||
Reference in New Issue
Block a user