is an IRC Bot "qui plante... ou pas" © niko - under the artistic license beta version.
- multi channels
- write easily your own plugins (see below and lib/botaniko/plugin/*.pm)
- plugin twitter: management of a twitter account (retweet catched url and notice in irc its own timeline)
- plugin url: keep trace of all URLs published on a channel by indexing them in ElasticSearch.
- ElasticSearch
- Perl modules (see Makefile.PL)
Make sure ElasticSearch is started (or add -nodb)
#show available options
bin/botaniko -help
#first start
bin/botaniko -dbinit -c=mychannel -s=myircserver -n=mybotnick -pass=mypassphrase
#usual start
bin/botaniko
Note that all commands have to be sent to the bot, either via publics or privates messages.
help [command]
: get some help on a commandmute
: turn off all outputsunmute
: turn on all outputsuptime
version
search query [from=0] [count=5] [type=tweet|url|...]
: search in the DB
These commands require an admin access, granted by sending your passphrase to
your bot: /msg mybot mypassphrase
.
join #mychan
: join a channelleave #mychan
: leave a channelload plugin
: load a pluginunload plugin
: unload a pluginreload plugin
: reload a pluginplugins
: list loaded pluginsset key [[=] value]
: get or set a configuration variablequit
The first time you’ll launch your bot, it’ll create a botaniko.yml
file in the
current directory. You can then use this file to configure it, but you’ll have
to restart your bot for the changes to take effect. You may prefer to use the
set
command to set some variables without restarting the bot.
Load the plugin with load ephemeride
. You can now get some info on the current
day like in an almanac, or optionally
for a date given as an argument.
By default, the plugin will use the latitude and longitude of Paris, France. You change this:
set plugins.ephemeride.latitude = 48.86
set plugins.ephemeride.longitude = 2.33
ephemeride [yyy-mm-dd]
Load the plugin with load say
. It let you make your bot say something on any
channel (you need to be admin).
say <channel> <the message>
Load the plugin with load scraper
. It allows you and others to capture some
text from a Web page with a regex.
By default, the bot will prefix all matches with =>
. You can change this with:
set plugins.scraper.prefix = *
-
scrap name url rule
: Create or update a scrape.name
is its name,url
is the page URL, andrule
is a regular expression. For example, here is a quick rule to get the number of articles in the English version of Wikipedia:scrap wk https://en.wikipedia.org/wiki/Special:Statistics Content pages.*?>([^<]+)</td
This register the scrap as
wk
. -
scrap name
. Execute a scrap (e.g.scrap wk
). The bot will print all matches (there’s only one in the example above). -
scrap -name
. Delete the scrap known asname
. -
scrap
. List all recorded scraps.
Load the plugin with load twitter
.
This plugin needs to be configured before usage. Don’t worry, it’s easy and you’ll have to do that only once. First, make sure you have a Twitter account for your bot (you may want to create a dedicated one). Then, you’ll have to create an app. Go here, login with your bot’s account, fill the required fields, and submit the form. Then, go to the “Settings” tab and under “Application Type” check “Read and Write”. Go back to the “Details” tab, and click on “Create my access token” at the bottom. All you have to do now is to copy the tokens in your bot config:
set plugins.twitter.name = your_bot_account_name
set plugins.twitter.consumer_key = your_consumer_key
set plugins.twitter.consumer_secret = your_consumer_secret
set plugins.twitter.access_token = your_access_token
set plugins.twitter.access_token_secret = your_access_token_secret
All the tweets from users you follow will be notified in all irc channels by default. to disable the output in a specific channel:
set channels.mychan.plugins.twitter.echo = 0
[un]follow some_user
: (un)follow an user (requires admin access)follower [regex]
: list the followers of your bot, optionally filtered by a regex. filter.following [regex]
: list the accounts your bot is following, optionally filtered by a regex.dm user message
: send a direct message.
Load the plugin with load url
. This plugin doesn’t provide any additional
command. It watches for URLs mentionned in a chan, on Twitter or in an RSS feed,
and store them in ElasticSearch. If someone mention an URL that has already been
mentionned before, it warn the user, and print the delay between the last
mention and now. It also tweets each URL on its Twitter account if
plugins.url.tweet_url
is set (default), and can optionally download and store
images in a local directory. You can post an old link without being warned by
using #oldlink
in your message. You can also avoid the automatic tweet by using
#notweet
.
#to disable user url check in a specific chan:
set channels.mychan.plugins.url.test_url = 0
#to disable url publication on twitter in a specific chan:
set channels.mychan.plugins.url.tweet_url = 0
#if an url is an image, it can be stored with the option:
set channels.rtgi.plugins.url.store_image = /var/wwww/botaniko/images/
set channels.rtgi.plugins.url.chmod = 0666
Load the plugin with load wikipedia
. It adds a wikipedia
command that can be
used to search for any subject on Wikipedia:
wikipedia something
#change the default language
set plugins.wikipedia.loc = en
Load the plugin with load meme
. This plugin allows you to make an image with a top and/or a bottom text.
#setup the path to the font to use
set plugins.meme.font = /usr/share/fonts/TTF/DroidSans-Bold.ttf
#setup where computed images are stored
set plugins.meme.savedir = /var/www/meme/
#setup rights for computed images
set plugins.meme.chmod = 0666
#setup the "root" urls of computed images
set plugins.meme.geturl = http://mydomain.com/meme/
#setup default size
set plugins.meme.size = medium
#setup this if meme url must be twitted
set plugins.meme.tweet = 1
meme img=url text1[|text2] [size=small|medium|large|huge] [fontsize=size1[|size2]]
: generate a meme and return its url
Load the plugin with load moc
.
Load the plugin with load rss
. It allows you to subscribe your bot to rss feeds. News are notified in all irc channels by default.
#disable rss notification in a specific channel
set channels.mychan.plugins.rss.echo = 0
rss add myfeed http://myfeed.com/url [user=name password=pwd]
: subscribe to a rss feedrss rm myfeed
: unsubscriberss list
: list all rss feedsrss read myfeed [count=5]
: read a rss feed
you can easily setup a default configuration, hook events,
add commands, and delay/repeat code.
your plugin must be a module under botaniko::plugin::
.
see lib/botaniko/plugin/*.pm to see samples.
to setup a default conf:
use botaniko::config;
#global config
cfg_default 'plugins.quiz' => {
version => 1
quiz => [
{ query=>'what is the answer?', answer=>42 }
]
};
#per channel config
chancfg_default 'plugins.quiz' => {
enabled => 1
};
to read conf:
if( chancfg($chan,'plugins.quiz.enabled') ) {
send_channel $chan=>'quiz v'.cfg('plugins.quiz.version')
}
to hook an event:
available event are (with given parameters):
CONNECT $cnx
DISCONNECT $cnx
MSG $msg,$user, $from, $chan
JOIN $chan
PART $chan
QUIT $chan
USERJOIN $user, $chan
USERPART $user, $chan, $msg
USERQUIT $user, $msg
NICKCHANGE $old, $new
TWEET $msg, $user
example:
use botaniko::hook;
use botaniko::irc;
hook MSG => sub{
my($msg,$user,$from,$chan) = @_;
send_channel $chan => "$user: are you sure?";
};
to add a command:
package botaniko::plugin::calc;
use botaniko::command;
command calc => {
help => 'evaluate a formula', #help for this command
root => 0, #admin only ?
bin => sub{
my $formula = join(' ',@_);
$formula =~ s/[^\d\.\+\-\/\*\(\)]//g;
my $e = eval { $formula };
#you have to return an arrayref of strings
#to send to the channel
defined $e
? [ "result: $e" ]
: [ pickone("unable to compute your stuff","check your syntax","what?!" ];
}
};
to async code:
use botaniko 'async';
use botaniko::irc;
async(
id => 'helloworld', #timer id
cb => sub{
send_channel all=>"it's ".(scalar localtime)." !";
},
delay => 0, #delay in second before starting
interval => 3600, #repeat interval in seconds,
#set to undef to run one time only
);