.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" 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" '' . ds C` . ds C' '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 >0, 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. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "JABBER-QUERYBOT 1p" .TH JABBER-QUERYBOT 1p "2021-01-09" "perl v5.32.0" "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 \fBrun_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 "\fBInMessage()\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 \fBrun_query()\fR. .IP "\(bu" 2 If \fBrun_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 \fBrun_query()\fR says 'error` we send a jabber error stanza wiht the status message from \fBrun_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 \fBrun_query()\fR back to the jabber user. .SS "\fBconnect_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 "\fBStop()\fP" .IX Subsection "Stop()" Shutdown jabber connection and exit main program .SS "\fBdisconnect_server()\fP" .IX Subsection "disconnect_server()" Only disconnect from the jabber-server. .SS "\fBreconnect_server()\fP" .IX Subsection "reconnect_server()" Reconnect and create a log entry. .SS "\fBInIQ()\fP" .IX Subsection "InIQ()" We do not proceed any iq (information query), this is only for statisic. .SS "\fBInPresence()\fP" .IX Subsection "InPresence()" .IP "\(bu" 2 Increment timer overload .IP "\(bu" 2 Do not process message if we are overloaded \fBpenalty_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 "\fBsendPresence()\fP" .IX Subsection "sendPresence()" Send presence information to user .SS "\fBsystemcommands()\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 "\fBget_barejid()\fP" .IX Subsection "get_barejid()" Remove resource id from a jabber id. .SS "\fBcalcualte_stats()\fP" .IX Subsection "calcualte_stats()" Calculate message statistics .SS "\fBjabber_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 "\fBjabber_send_message()\fP" .IX Subsection "jabber_send_message()" This function send all jabber messages which are outgoing from the jabber-querybot. .SS "\fBset_wakeup_mode()\fP" .IX Subsection "set_wakeup_mode()" Set jabber presence via \fBjabber_set_presence()\fR .SS "\fBpenalty_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 "\fBjabber_add_footer()\fP" .IX Subsection "jabber_add_footer()" Add footer to the processed message. .SS "\fBcalcualte_elapsed_time()\fP" .IX Subsection "calcualte_elapsed_time()" Calculate elapsed worktime for a query .SS "\fBsendError()\fP" .IX Subsection "sendError()" sendError($message, \f(CW$from\fR, \f(CW$to\fR, 404, \*(L"text\*(R"); .SS "\fBsystem_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 "\fBconnect_bot()\fP" .IX Subsection "connect_bot()" Connect bot and initialize all timers. .SS "\fBcheck_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'.