This is something I made when playing around with Win32::GuiTest. It logs AIM conversations as you're having them (it logs at 5 second intervals).
I tested it against AIM 5.9.3861, but it should work with any version of AIM that supports the Linked ScreenNames feature, since these versions of AIM put both your screenname and the buddy's screenname in the window titles.
It hasn't been tested on Triton, and I personally do not use Triton. However, its code could probably be adapted to work with Triton by just changing a few of the regexp patterns.
So... here's the code:
Code:
#!/usr/bin/perl -w
use strict;
use warnings;
use Win32::GUI;
use Win32::GuiTest qw(:ALL);
use Time::Format qw(time_format);
# Make a Win32-GUI window.
my $win32 = new Win32::GUI::DialogBox (
-height => 1,
-width => 1,
-name => 'Win32GUI',
);
my $icon = new Win32::GUI::Icon ('amaim.ico');
# Add a system tray icon.
new Win32::GUI::NotifyIcon (
$win32,
-name => 'Notify',
-id => 1,
-icon => $icon,
-tip => 'AIM Logger',
);
sub Win32GUI_Terminate {
-1;
}
# This hashref will keep track of individual conversations per-day.
our $conversations = {};
# These hashes will keep track of existing convo windows.
my %windows = (); # Windows from last run
my %current = (); # Windows from this run
# Load all the existing conversation files for today.
our $today = time_format ('yyyy-mm{on}-dd');
&scanDir ('.');
while (1) {
# Search for AIM windows.
my @windows = FindWindowLike ('','(Instant Message)','');
# Blank out these windows.
%current = ();
# Loop through each one.
foreach my $aim (@windows) {
print "$aim> " . GetWindowText($aim) . "\n";
# Get the two screennames for the exchange.
my ($to,$from) = GetWindowText($aim) =~ /^(.*?) : (.*?) - Instant Message$/i;
# Skip if these fields don't both exist (characteristic of opening a NEW window)
next unless defined $to;
next unless defined $from;
print "\tFrom: $from To: $to\n";
$current{GetWindowText($aim)} = 1;
# Make a new folder for these users?
mkdir ("./$from") unless -d "./$from";
mkdir ("./$from/$to") unless -d "./$from/$to";
# Get its children.
my @children = GetChildWindows($aim);
foreach my $child (@children) {
# Get this child's text.
my $text = WMGetText($child);
# Grab AIM convo's.
if ($text =~ /<HTML>(.*?)<\/HTML/i) {
my $html = $1;
# Skip buddy icon windows and mobile notifications.
next if $html =~ m~aim:BuddyIcon\?ScreenName=~;
# Skip mobile notifications.
next if $html =~ m~^<BODY BGCOLOR="#ffffff"><FONT LANG="0">This member is using a</FONT></BODY>~i;
next if $html =~ m~http://aimtoday.aol.com/today/mobile/presence.adp~;
# Now we should have the conversation to log.
# Get today's date.
my $date = time_format ('yyyy-mm{on}-dd');
if ($today ne $date) {
# We can assume that midnight has passed.
# Delete yesterday's cache.
delete $conversations->{$today};
$today = $date;
}
# Substitute <font back> for <span>s...
$html =~ s~BACK="#(......)"~STYLE="background-color: #$1"~sg;
# If we already had a conversation from before...
if (exists $conversations->{$today}->{"$from-$to"}) {
print "A convo already exists from $from-$to\n";
$html = $conversations->{$today}->{"$from-$to"} . "<BR>\n" . $html;
# Now $html should be (the convo that existed on startup) + new convo
}
# New File.
open (OUT, ">./$from/$to/$date\.html");
print OUT "<HTML>$html";
close (OUT);
print "Logged conversation.\n\n";
}
}
}
# See if any windows were closed.
foreach my $old (keys %windows) {
if (not exists $current{$old}) {
# A window was closed! Recollect the conversation
# in case we chat with him again later today.
# Add an "End of Session" notification.
open (OUT, ">>./$from/$to/$today\.html");
print OUT "<hr><b>Session concluded at " . localtime() . "</b><hr>\n";
close (OUT);
&scanFile ("./$from/$to",$from,$to);
delete $windows{$old};
}
}
foreach my $new (keys %current) {
if (not exists $windows{$new}) {
# A new window was opened. Sync it with our %windows.
$windows{$new} = 1;
}
}
opendir (DIR, ".");
foreach my $user (sort(grep(!/^\./, readdir(DIR)))) {
next unless -d $user;
&scanUsers ($user);
}
closedir (DIR);
}
sub scanUsers {
my $user = shift;
opendir (DIR, "./$user");
foreach my $folder (sort(grep(!/^\./, readdir(DIR)))) {
# Open this user's chat history for today.
if (-f "./$user/$folder/$today\.html") {
&scanFile ("./$user/$folder",$user,$folder);
}
}
closedir (DIR);
}
sub scanFile {
my $file = shift;
my $user = shift;
my $folder = shift;
# This routine loads an individual conversation into memory.
open (TODAY, "$file/$today\.html");
my @convo = <TODAY>;
close (TODAY);
chomp @convo;