# User Notification Service. my(%messages); # If you want to DBM this, be my guest. Rather you than me. my(%notified); sub msg_store { ($to, $from, $what) = @_; push @{$messages{$to}}, { from => $from, what => $what, when => scalar localtime }; delete $notified{$to}; &msg($from, "OK, $from, I'll let them know."); } sub msg_seen_hook { # Call this from verifyUser my $who = shift; if (@{$messages{$who}} and not exists $notified{$who}) { &msg($who,"Hi $who; you have ".(scalar @{$messages{$who}})." new botmail messages (/msg me with `botmail next' to read)"); $notified{$who}=1; } } sub msg_next { my $who = shift; if (@{$messages{$who}}) { my $next= shift @{$messages{$who}}; delete $messages{$who} unless @{$messages{$who}}; # Save mem? &msg($who,"From: ".$next->{from}. " at ".$next->{when}. ": ".$next->{what}); &msg($who,(scalar @{$messages{$who}})." messages left.") if @{$messages{$who}}; } else { &msg($who,"You don't have any more botmail!"); } } sub msg_check { my $who=shift; my $from=""; my @mails=@{$messages{$who}}; unless (@mails) { &msg($who,"You have no botmail."); return; } $from=join ", ", map {$_->{from}} @mails; &msg($who,"You have ".(scalar @mails)." messages, from: $from"); } "Go away";