package Seen; use strict; use warnings; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); use Carp; require Exporter; @ISA = qw(Exporter AutoLoader); @EXPORT = qw(); $VERSION = '0.01'; # Set us up the bomb sub new { my $class = shift; my %args = @_; return bless \%args, $class; } # Start things up # Check for existing seen log # Load seen info from file if possible sub _load { my $self = shift; my %seen = (); # Load seen info from previous session. if ( -e $self->{'file'} ) { open( FILE, $self->{'file'} ) || croak "Cannot Open $self->{'f +ile'}!"; %seen = map { chomp; split /\|/; } <FILE>; close(FILE) || croak "Cannot Close $self->{'file'}!"; } return %seen; } # Dump seen info into file sub logSeen { my ( $self, $who, $message ) = @_; my %seen = $self->_load(); $who =~ s/\|/<pipe>/g; # So we don't confuse things :) $message =~ s/\|/<pipe>/g; # Ditto $seen{$who} = $message . " on " . scalar(localtime); open( FILE, ">>$self->{'file'}" ) || croak "Cannot Open $self->{'f +ile'}!"; print FILE "$who|$seen{$who}\n"; close(FILE) || croak "Cannot Close $self->{'file'}!"; } # Recieves list of names from your script # to load current channel users. # Look at the pod for more info. sub loadCurrent { my $self = shift; my %seen = $self->_load(); my $names = shift; my @names = split ( / /, $names ); open( FILE, ">>$self->{'file'}" ) || croak "Cannot Open $self->{'f +ile'}!"; foreach my $name (@names) { $name =~ s/@//; $name =~ s/\|/<pipe>/g; $seen{$name} = "On channel as of " . scalar(localtime); print FILE "$name|$seen{$name}\n"; } close(FILE) || croak "Cannot Close $self->{'file'}!"; } # Got a seen request, handle it. sub getSeen { my $self = shift; my $nick = shift; my %seen = $self->_load(); $nick =~ s/\|/<pipe>/g; my $nick1 = $nick; if ( defined $seen{$nick} ) { $nick =~ s/<pipe>/\|/g; $seen{$nick1} =~ s/<pipe>/\|/g; return "Saw $nick $seen{$nick1}"; } else { $nick =~ s/<pipe>/\|/g; return "Haven't Seen $nick"; } } # Clear logfile of unwanted seen data sub clearLog { my $self = shift; unlink( $self->{'file'} ) || croak "Cannot Unlink $self->{'file'}! +"; } sub DESTROY { } 1; __END__ =head1 NAME Seen.pm - A module for handling seen requests on IRC. =head1 SYNOPSIS use Seen; my $seen = Seen->new( file => '/path/to/seen.log' ); # later on... # Log join event, assuming Poe::Component::IRC use.. sub on_join { my ( $kernel, $who, $where ) = @_[ KERNEL, ARG0, ARG1 ]; my $nick = ( split /!/, $who )[0]; # Do Stuff... $seen->logSeen( $nick, "Joining $where" ); } =head1 DESCRIPTION Provides seen functionality for an IRC bot. =head1 METHODS =over 4 =item 1 B<logSeen()> takes two arguments, stores info into a hash, and logs to file specified when creating the new object. Returns nothing. Use like so: $seen->logSeen( $nick, $msg ); =item 2 B<getSeen()> takes a nickname as an argument. Checks to see if it is defined in the hash and returns the results. Use like so: $seen->getSeen( $nick ); =item 3 B<loadCurrent()> takes list from irc_353 (names command) as an argumen +t and loads it into the hash, and logfile, so current users on the channel a +re seen. Use like so: $seen->loadCurrent( $names ); =item 4 B<clearLog()> clears the currently loaded log file, takes no args. =back =head1 AUTHOR Benjamin Smith (DeFyance) defyance@just-another.net =head1 SEE ALSO POE::Component::IRC =cut

In reply to Seen.pm by defyance

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.