.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.ie \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. nr % 0
. rr F
.\}
.el \{\
. de IX
..
.\}
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
. \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "JABBER-QUERYBOT 1p"
.TH JABBER-QUERYBOT 1p "2012-02-03" "perl v5.14.2" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
jabber\-querybot \- a modular perl jabber bot
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
jabber-querybot connects a jabber account and wait for messages. If a message
comes in, it forward it to your self programmend modul. The return string of
your module, jabber-querybot send it back to the jabber sender.
.PP
It is designed to be re-usable and to make it easy to write small
Jabber bots that do one thing and do it well. A simple concept with a
lot of examples and experiences are implemented.
.PP
1. Create a jabber account on a jabber-server around
.PP
2. Create a bot application:
.Sp
.Vb 4
\& cd examples
\& cp Querymodule.pm /etc/jabber\-querybot/Mybot.pm
\& cd /etc/jabber\-querybot
\& ln \-s Mybot.pm Querymodule.pm
.Ve
.PP
Modify login parameters to your jabber-bot-account
.PP
vim Mybot.pm
.Sp
.Vb 10
\& our $hostname = "swissjabber.ch";
\& our $user = "";
\& our $password = "";
\& our $ident = "Testbot";
\& our $bot_admin = "\e@swissjabber.ch";
\& our $port = "5222";
\& our $timeout = "5";
\& our $service_name = "$user\e@$hostname";
\& our $bot_description = "Bot help title
\& Bot description";
.Ve
.PP
For each jabber message, jabber-querybot will execute sub run_query,
that you can write here your application.
.PP
You can control how your jabber response will be:
.IP "\(bu" 4
error = error message stanza
.IP "\(bu" 4
presence = error as presence stanza
.IP "\(bu" 4
ignore = ignore message
.SH "OPTIONS"
.IX Header "OPTIONS"
jabber-querybot has a lot of variables which you can easy modify for
what you need:
.SS "querystatus"
.IX Subsection "querystatus"
\&\f(CW$querystatus\fR = [ 0 | 1 ]
.IP "\(bu" 4
0 = Bot will not proceed any incoming jabber messages.
.IP "\(bu" 4
1 = Bot will proceed incoming messages.
.SS "penalty_status"
.IX Subsection "penalty_status"
If the bot has too much workload, it goes to penalty status and wait some
time until his status change back to normal.
.PP
\&\f(CW$timer_reconnect_default\fR = 21600
.PP
Every 21600 seconds (6 hours) the bot will shutdown automatically, wait 10
seconds and starting up again.
.PP
\&\f(CW$timer_auto_query\fR = 0
.PP
If you set in your module this variable to 60, the bot will every 60 seconds
call the function \fIrun_auto_query()\fR which you may use for several things.
.SS "System load"
.IX Subsection "System load"
If your systems load is >=6, this bot will shutdown the jabber connection
and check every 10 seconds systems load. If load <=2, bot will start over.
.SH "EXAMPLES"
.IX Header "EXAMPLES"
/usr/share/doc/jabber\-querybot/examples/Testbot.pm
.SH "FILES"
.IX Header "FILES"
/etc/jabber\-querybot/Querymodule.pm
.PP
/usr/bin/jabber\-querybot
.SH "RESOURCES"
.IX Header "RESOURCES"
http://github.com/micressor/jabber\-querybot/
.SH "METHODS"
.IX Header "METHODS"
.SS "\fIInMessage()\fP"
.IX Subsection "InMessage()"
An incoming jabber message to the bot will hook this function.
.IP "\(bu" 2
Read parameters of incoming stanza
.SS ""
.IX Subsection ""
.IP "\(bu" 2
Decode utf8 string
.SS ""
.IX Subsection ""
.IP "\(bu" 2
increment timer overload and do not process message if bot is
overloaded.
.SS ""
.IX Subsection ""
.IP "\(bu" 2
Ignore message if it is from myself
.SS ""
.IX Subsection ""
.IP "\(bu" 2
Be sure, that it is not a message from another transport
.SS ""
.IX Subsection ""
.IP "\(bu" 2
Check any systemcommands for the bot
.SS ""
.IX Subsection ""
.IP "\(bu" 2
If the bot has sleeping status, change it to work
.SS ""
.IX Subsection ""
.IP "\(bu" 2
We process only normal text or chat type jabber messages
.SS ""
.IX Subsection ""
.IP "\(bu" 2
And now we give the real text string which was incoming to the
bot via \fIrun_query()\fR.
.IP "\(bu" 2
If \fIrun_query()\fR say us 'ignore` we do a log entry and do not answer
via jabber to the user.
.SS ""
.IX Subsection ""
.IP "\(bu" 2
If \fIrun_query()\fR says 'error` we send a jabber error stanza wiht the
status message from \fIrun_query()\fR back to the user.
.SS ""
.IX Subsection ""
.IP "\(bu" 2
If there was no error, we update the statistic vars and send the
answer from \fIrun_query()\fR back to the jabber user.
.SS "\fIconnect_server()\fP"
.IX Subsection "connect_server()"
This function connects to the jabber server with the given credentials from
Querymodule.pm.
.SS ""
.IX Subsection ""
Set the call back functions. This functions will be executed
if a message of the types or
are incoming.
.SS "\fIStop()\fP"
.IX Subsection "Stop()"
Shutdown jabber connection and exit main program
.SS "\fIdisconnect_server()\fP"
.IX Subsection "disconnect_server()"
Only disconnect from the jabber-server.
.SS "\fIreconnect_server()\fP"
.IX Subsection "reconnect_server()"
Reconnect and create a log entry.
.SS "\fIInIQ()\fP"
.IX Subsection "InIQ()"
We do not proceed any iq (information query), this is only for
statisic.
.SS "\fIInPresence()\fP"
.IX Subsection "InPresence()"
.IP "\(bu" 2
Increment timer overload
.IP "\(bu" 2
Do not process message if we are overloaded \fIpenalty_handler()\fR.
.SS ""
.IX Subsection ""
We have a problem in Net::Jabber. An incoming message with a ` in resource
blocks the bot. We will hotfix that for the moment.
.SS ""
.IX Subsection ""
A subscription type `subscribe` is incoming. Send `subscribed` tho the user
and say hello ;)
.SS ""
.IX Subsection ""
.IP "\(bu" 2
Send presence to user
.SS ""
.IX Subsection ""
.IP "\(bu" 2
Remove subscription if a user remove this bot from his roster
.SS "\fIsendPresence()\fP"
.IX Subsection "sendPresence()"
Send presence information to user
.SS "\fIsystemcommands()\fP"
.IX Subsection "systemcommands()"
.IP "\(bu" 2
If user type '!help` send a help instruction to the user
.SS ""
.IX Subsection ""
.IP "\(bu" 2
Send statistic information to the user if he types '!status`
.SS ""
.IX Subsection ""
.IP "\(bu" 2
Is it a bot command?
.IP "\(bu" 2
Is the bot command from the bot admin? If not, send \*(L"not allowed\*(R"
.IP "\(bu" 2
\&'!shutdown` will shutdown your bot via jabber invoke.
.IP "\(bu" 2
\&'!query off` turn off queries
.IP "\(bu" 2
\&'!query on` turn on queries
.SS "\fIget_barejid()\fP"
.IX Subsection "get_barejid()"
Remove resource id from a jabber id.
.SS "\fIcalcualte_stats()\fP"
.IX Subsection "calcualte_stats()"
Calculate message statistics
.SS "\fIjabber_set_presence()\fP"
.IX Subsection "jabber_set_presence()"
Set new presence if we have another presence status or we have set the force
flag (for transport presence).
.SS "\fIjabber_send_message()\fP"
.IX Subsection "jabber_send_message()"
This function send all jabber messages which are outgoing from the
jabber-querybot.
.SS "\fIset_wakeup_mode()\fP"
.IX Subsection "set_wakeup_mode()"
Set jabber presence via \fIjabber_set_presence()\fR
.SS "\fIpenalty_handler()\fP"
.IX Subsection "penalty_handler()"
This function checks if the bot is overloaded with incoming mesages and
reject if it is. Two times that's ok so 2:1 because while in main.
.SS ""
.IX Subsection ""
Bot admin got everytime an answer.
.SS "\fIjabber_add_footer()\fP"
.IX Subsection "jabber_add_footer()"
Add footer to the processed message.
.SS "\fIcalcualte_elapsed_time()\fP"
.IX Subsection "calcualte_elapsed_time()"
Calculate elapsed worktime for a query
.SS "\fIsendError()\fP"
.IX Subsection "sendError()"
sendError($message, \f(CW$from\fR, \f(CW$to\fR, 404, \*(L"text\*(R");
.SS "\fIsystem_load_check()\fP"
.IX Subsection "system_load_check()"
.IP "\(bu" 2
Calculate system load
.IP "\(bu" 2
If load is too high shutdown bot.
.IP "\(bu" 2
If load is ok, starting up bot
.SS "\fIconnect_bot()\fP"
.IX Subsection "connect_bot()"
Connect bot and initialize all timers.
.SS "\fIcheck_before_start()\fP"
.IX Subsection "check_before_start()"
Check configuration variables in Querybotmodule.pm and give answer if anything
does not match or is missing.
.SH "COPYRIGHT AND LICENSE"
.IX Header "COPYRIGHT AND LICENSE"
Copyright (C) 2009\-2012 Marco Balmer
.PP
The Debian packaging is licensed under the
\&\s-1GPL\s0, see `/usr/share/common\-licenses/GPL\-3'.