User Control Panel
Advertisements

HELP US, HELP YOU!

Proposed change to List Functions.

 
Post new topic   Reply to topic    Bot Depot Forum Index -> MSN.pm Development
View unanswered posts
Author Message
eric256
The Keymaker
The Keymaker


Joined: 03 May 2006
Posts: 2292
Location: Colorado
Reputation: 47Reputation: 47Reputation: 47Reputation: 47Reputation: 47

PostPosted: Tue Jan 27, 2004 7:58 pm    Post subject: Reply with quote

Alot of redundant error checking, should be changed around a bit.

Code:
<br />sub addcontact {<br />    my ($self,$email) = @_;<br />    my $client = $self->GetMaster();<br /><br />    unless ($email) {<br />           carp "email address required to add";<br />           return 0;<br />    }<br /><br />    $self->_add_to_list('FL', $email);<br />    return 1;<br />}<br /><br />sub remcontact {<br />    my ($self,$email) = @_;<br />    my $client = $self->GetMaster();<br /><br />    unless ($email) {<br />           carp "email address required to rem";<br />           return 0;<br />    }<br />    <br />    $self->_rem_from_list('FL', $email);    <br />    return 1;<br />}<br /><br />sub unblock {<br />    my ($self,$email) = @_;<br />    <br />    unless ($email) {<br />           carp "email address required to unblock";<br />           return 0;<br />    }<br /><br />    $self->_rem_from_list('AL', $email);<br />    $self->_add_to_list('BL', $email);  <br />    return 1; <br />}<br /><br />sub block {<br />    my ($self,$email) = @_;<br />    <br />    unless ($email) {<br />           carp "email address required to block";<br />           return 0;<br />    }<br /><br />    $self->_rem_from_list('AL', $email);<br />    $self->_add_to_list('BL', $email);  <br />    return 1; <br />}<br /><br /><br /><br />sub _rem_from_list {<br />    my ($self, $list, $email) = @_;<br />    my $client = $self->GetMaster();<br />    <br />    unless ($email) {<br />           carp "email address required to add to list $list";<br />           return 0;<br />    }<br /><br />    delete $client->{Lists}->{$list}->{$email};<br />    $client->send( "REM", "$list $email" );   <br />    return 1; <br />}<br /><br />sub _add_to_list {<br />    my ($self,$list, $email) = @_;<br />    my $client = $self->GetMaster();<br />    <br />    unless ($email) {<br />           carp "email address required to a";<br />           return 0;<br />    }<br />    <br />    $client->{Lists}->{$list}->{$email} = 1;<br />    $client->send( "ADC", "$list N=$email" ) if $self->isVer('MSNP10');<br />    $client->send( "ADD", "$list $email $email") if $self->isVer('MSNP9');<br />    <br />    return 1; <br />}<br /><br />}<br />

_________________
Eric256
Proud previous owner and current admin of Bot-depot.com
Back to top
Keenie
Almost An Agent
Almost An Agent


Joined: 31 Oct 2003
Posts: 1071

Reputation: 52.4

PostPosted: Wed Jan 28, 2004 1:09 am    Post subject: Reply with quote

looks good
but with that way you should take out then
$client = $self->getmaster() out of the top 2 since we wont need it anymore, but im sure this is just demo code anyways
Back to top
Mojave
Almost An Agent
Almost An Agent


Joined: 01 Nov 2003
Posts: 1434

Reputation: 66.4

PostPosted: Wed Jan 28, 2004 3:32 am    Post subject: Reply with quote

Went with Keenie's suggestion and tightened the code up a bit more...

Code:
sub addcontact {<br />   my ($self,$email) = @_;<br /><br />   return $self->_add_to_list('FL', $email);<br />}<br /><br />sub remcontact {<br />   my ($self,$email) = @_;<br />  <br />   return $self->_rem_from_list('FL', $email);    <br />}<br /><br />sub unblock {<br />   my ($self,$email) = @_;<br />   <br />   $self->_rem_from_list('AL', $email) || return 0;<br />   return $self->_add_to_list('BL', $email);  <br />}<br /><br />sub block {<br />   my ($self,$email) = @_;<br />   <br />   $self->_rem_from_list('AL', $email) || return 0;<br />   return $self->_add_to_list('BL', $email);  <br />}<br /><br /><br /><br />sub _rem_from_list {<br />   my ($self, $list, $email) = @_;<br />   my $client = $self->GetMaster();<br />   <br />   unless ($email) {<br />          carp "email address required to add to list $list";<br />          return 0;<br />   }<br /><br />   delete $client->{Lists}->{$list}->{$email};<br />   $client->send( "REM", "$list $email" );   <br />   return 1; <br />}<br /><br />sub _add_to_list {<br />   my ($self,$list, $email) = @_;<br />   my $client = $self->GetMaster();<br />   <br />   unless ($email) {<br />          carp "email address required to a";<br />          return 0;<br />   }<br />   <br />   $client->{Lists}->{$list}->{$email} = 1;<br />   $client->send( "ADC", "$list N=$email" ) if $self->isVer('MSNP10');<br />   $client->send( "ADD", "$list $email $email") if $self->isVer('MSNP9');<br />   <br />   return 1; <br />}
Back to top
eric256
The Keymaker
The Keymaker


Joined: 03 May 2006
Posts: 2292
Location: Colorado
Reputation: 47Reputation: 47Reputation: 47Reputation: 47Reputation: 47

PostPosted: Wed Jan 28, 2004 3:53 am    Post subject: Reply with quote

nice i like
_________________
Eric256
Proud previous owner and current admin of Bot-depot.com
Back to top
Keenie
Almost An Agent
Almost An Agent


Joined: 31 Oct 2003
Posts: 1071

Reputation: 52.4

PostPosted: Wed Jan 28, 2004 4:17 am    Post subject: Reply with quote

me too, just something ive noticed that still carried over

Quote:
unless ($email) {
         carp "email address required to a";
         return 0;
  }


should be

Code:
unless ($email) {<br />         carp "email address required to remove from list $list";<br />         return 0;<br />  }


also maybe a good idea would be to add into the unless

Code:
unless ($email && $list)


since you can't get far without a list, and checking for it wont hurt anything Smile
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> MSN.pm Development All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group