Previous Thread
Next Thread
Print Thread
Rate Thread
#104918 11/02/2003 10:41 AM
Joined: Nov 2001
Posts: 1,704
CTM
Offline
Moderator / Da Masta
Moderator / Da Masta
Offline
Joined: Nov 2001
Posts: 1,704
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? smile

This is the code I have for it at the moment:

Code
		} 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") &#0124;&#0124; 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:

Code
PM #1
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:

Code
PM #1
PM #2
PM #1
And anything after that works fine:

Code
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 smile

Sponsored Links
#104919 11/03/2003 11:23 AM
Joined: May 2000
Posts: 1,356
Addict
Addict
Joined: May 2000
Posts: 1,356
hmm... seems fine to me, however I have some suggestions:

Code
   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;
}
can be

Code
   my $pm_user_exists = 0;
foreach $psn (@thegoodguys) {
if ($psn eq $pm_command[1]) {
$pm_user_exists = 1;
last; # so that if we have a match at the beginnig,
# we dont waste our time with an unnecessary loop
}
}
if ($pm_user_exists != 1) {# for numbers, always use numerical operators...
$mymsg = &html(qq~<b>$pm_command[1]</b> is not a registered Member of TPMBot.~);
goto PMNOUSERNAME;
}
Code
   PMNOUSERNAME: $nothing = '1';
can be (must be!)

Code
   PMNOUSERNAME: $nothing = 1;

#104920 11/03/2003 7:27 PM
Joined: Nov 2001
Posts: 1,704
CTM
Offline
Moderator / Da Masta
Moderator / Da Masta
Offline
Joined: Nov 2001
Posts: 1,704
Okay, gotta keep searching... Thanks Burak smile

#104921 11/05/2003 1:20 AM
Joined: Sep 2000
Posts: 755
P.I.T.A. / Programmer
P.I.T.A. / Programmer
Offline
Joined: Sep 2000
Posts: 755
Rewrite your code and remove the goto statements. There's no reason for them, and they are considered very bad form. They should only be used when it is warranted, and if you (not you specifically... anyone) have to ask when that is, you don't need to use them.

Read Dijkstra's Legendary article from 1968 smile

--mark


"Annnnnnnndd now, opening for Iron Maiden...... WYLD STALLYNS!!!" --Bill S. Preston, Esquire and Ted "Theodore " Logan
#104922 11/05/2003 1:08 PM
Joined: Nov 2001
Posts: 1,704
CTM
Offline
Moderator / Da Masta
Moderator / Da Masta
Offline
Joined: Nov 2001
Posts: 1,704
Thanks for the tip, Mark smile

Sponsored Links

Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
AllenAyres
AllenAyres
Texas
Posts: 21,079
Joined: March 2000
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20221218)