So, my AIM bot is almost complete, and now I'm adding a PM system to it. That's the one thing that's always annoyed me about AIM; IRC services have MemoServ, so why can't AIM?
This is the code I have for it at the moment:
} elsif ($pm_command[0] eq 'send') {
# User wants to send a PM to another user
# Do we have everything we need?
if ((!$pm_command[2]) || ($pm_command[2] !~ /|/)) {
#goto PMNOUSERNAME;
}
# Does the username exist?
my $pm_user_exists = 0;
foreach $psn (@thegoodguys) { if ($psn eq $pm_command[1]) { $pm_user_exists = 1; } }
if ($pm_user_exists ne '1') {
$mymsg = &html(qq~<b>$pm_command[1]</b> is not a registered Member of TPMBot.~);
goto PMNOUSERNAME;
}
# Everything is fine - Send the PM
my (@recipient_pms, $sent_datetime, @pm_content, $pm_content_uf);
my $sent_datetime = &nice_gmt;
my $pm_content_uf = join(" ", @pm_command);
$pm_content_uf =~ s/send $pm_command[1] //;
my @new_pm_content = split(/|/, $pm_content_uf);
open(PMRECIPIENT, "<$vars{pm_dir}/$pm_command[1].txt") || goto JUSTWRITEPM;
my @recipient_pms = <PMRECIPIENT>;
close(PMRECIPIENT);
my @readded_pms;
# Make sure this PM is at the top of the list
JUSTWRITEPM: push(@readded_pms, qq~$nick|^|$sent_datetime|^|NEW|^|$new_pm_content[0]|^|$new_pm_content[1]~);
# Now readd the existing messages
foreach my $readd_pm (@recipient_pms) {
$readd_pm =~ s/n//;
push(@readded_pms, qq~$readd_pm~);
}
$readded_pm_list = join("n", @readded_pms);
#print "$readded_pm_listn";
open(PMRECIPIENT, ">$vars{pm_dir}/$pm_command[1].txt");
print PMRECIPIENT $readded_pm_list;
close(PMRECIPIENT);
$mymsg = &html(qq~Your PM to <b>$pm_command[1]</b> was successfully sent.~);
PMNOUSERNAME: $nothing = '1';
The PM will be "sent" to the folder /pm/screenname.txt, where screenname is the user's screen name.
When I use the "send PM" command for the first time, it works fine. The PM is written to the user's file:
However, when I send a PM for the second time to the same user, it writes both the first AND second PMs as the second:
And anything after that works fine:
PM #7
PM #6
PM #5
PM #4
PM #3
PM #1
PM #2
PM #1
It's just when I send that second PM.
There's obviously something wrong with the code I posted, I'm just not sure what. Could someone take a look at it for me please?
Thanks
