Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
    0: #!/usr/bin/perl
    1: 
    2: #===[ MonkBot ]===============================================================
    3: #
    4: # Jabber bot that serves as an IM gateway to the perlmonks.org chatterbox.
    5: # Homepage: http://hutta.com/perl/jabberbots/monkbot.html
    6: #
    7: # Note that this requires Net::Jabber, Net::Jabber::Bot and PerlMonks::Chat
    8: # http://download.jabber.org/perl/
    9: # http://hutta.com/perl/jabberbots/
    10: # http://www.cerias.purdue.edu/homes/zamboni/perlmonks.html
    11: #
    12: # My personal MonkBot is on jabber as MonkBot@jabber.icgcorp.net.
    13: # Add him to your roster and you can test this out.
    14: #
    15: #===[ TODO ]==================================================================
    16: #
    17: # - Let MonkBot take user/pass to allow people to send messages as themselves.
    18: # - More integration with PM... New nodes, etc, etc, etc.
    19: #
    20: #=============================================================================
    21: 
    22: use Net::Jabber::Bot;
    23: use PerlMonks::Chat;
    24: 
    25: #===[ Initialize ]============================================================
    26: 
    27: my $pm = new PerlMonks::Chat;
    28: $pm->add_cookies;
    29: 
    30: my $bot = new Net::Jabber::Bot(
    31:         client  => 'MonkBot',
    32:         verbos  => '2',
    33:         logfile => '/tmp/monkbot.log',
    34:         version => '1.0',
    35:         status  => 'Meditating',
    36: );
    37: 
    38: $bot->connect(
    39:         hostname => 'jabber.com',
    40:         port     => '5222'
    41: ) || die "Can't connect"; 
    42: 
    43: $bot->auth(
    44:         username => 'MonkBot',
    45:         password => 'passwordhere',
    46:         resource => 'bot',
    47:         digest   => '1'
    48: );
    49: 
    50: $bot->send_presence();
    51: 
    52: #===[ Defining Callbacks ]====================================================
    53: 
    54: $bot->set_callback( "hello" => \&SayHello );
    55: $bot->set_callback( "hi"    => \&SayHello );
    56: $bot->set_callback( "help"  => \&SayHello );
    57: $bot->set_callback( "all"   => \&SendAll );
    58: 
    59: sub SayHello {
    60:         my $user = shift;
    61:         $user->write("Greetings.");
    62:         $user->write("Add me to your roster/buddylist and I'll send you every" . 
    63:                      "thing that happens on the chatterbox automatically.  " .
    64:                      "Send the command 'all' to get all lines currently " . 
    65:                      "available.");
    66: }
    67: 
    68: sub SendAll {
    69:         my $user = shift;
    70:         my ($lines) = ($pm->getalllines(1,1));
    71:         foreach (@{$lines}) {
    72:                 $user->write("$_");
    73:         }
    74: }
    75: 
    76: #===[ The main loop. ]========================================================
    77: #
    78: # This is where the bot will spend most of its time.  Looping and looping,
    79: # waiting for new chatterbox messages.  When we get them, we'll send them
    80: # out to anyone subscribed to our presence.
    81: #
    82: #=============================================================================
    83: 
    84: while (1) {
    85:         $bot->Process(5);
    86: 
    87:         foreach ($pm->getnewlines(1,1)) { 
    88:                 $bot->broadcast(body=>"$_", type=>'chat');
    89:         }
    90: 
    91:         $bot->Connected() || die "Lost my connection!";
    92: }
    93: # Edited: Sun Oct 14 06:52:45 2001 (GMT), by [footpad]
    94: # Fixed formatting by adding line line breaks.
    

In reply to Jabber Bot For Chatterbox by Hutta

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2022-01-24 11:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (64 votes). Check out past polls.

    Notices?