Need Perl Help

BlackMageBlackMage [citation needed] Join Date: 2003-06-18 Member: 17474Members, Constellation
edited March 2004 in Off-Topic
<div class="IPBDescription">because bm is nub</div> first, source available <a href='http://www.r1ch.net/projects/bitchbot/' target='_blank'>here</a>

my problem:
the bot seems to just drop all | charachters from text, names, commands etc

this is a problem because several people have |'s in their names

i've traced the problem to this chunk:
<!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->
my ($remote, $port, $iaddr, $paddr, $proto, $line, $spoken, $bitchcmds, $newfacts);
...
$line =~ s/\027-\036\004-\025\376\377//gi; <-- no clue
print "$line: " . $line . "\n";
...
undef $nickname;
undef $command;
undef $mtext;
undef $hostmask;

$hostmask = substr($line,index($line,":"));
$mtext = substr($line,index($line,":",index($line,":")+1)+1);
($hostmask, $command) = split(" ",substr($line,index($line,":")+1));
($nickname) = split("!",$hostmask);

@spacesplit = split(" ",$line);
$mtext =~ s/[\r|\n]//g;

print "mtext: " . $mtext . "\n";
<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->

output:

: :BlackMage|debuggin!~user@adsl-ip-ip-ip-ip.dsl.kscymo.swbell.net PRIVMSG #magebotdebug :test|string


mtext: teststring
<BlackMage|debuggin> teststring

help, please?

oh, and when it sends text (like kick commands or privmsgs) it drops the | from names. it would try to pm a guy called BlackMagedebuggin in the example above

Comments

  • BlackMageBlackMage [citation needed] Join Date: 2003-06-18 Member: 17474Members, Constellation
    someone? anyone?
    whoever helps me fix it gets high-level commands on the bot

    oh, *bump*
  • DOOManiacDOOManiac Worst. Critic. Ever. Join Date: 2002-04-17 Member: 462Members, NS1 Playtester
    I only know a little bit of Perl but it seems obvious you're dealing with regular expressions, which I am also only vaguley familiar with.

    What are you trying to do exactly? The problem is that it drops the pipe ( | ) character?

    A rough guess would be that the offending line is:

    <!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->$line =~ s/\027-\036\004-\025\376\377//gi;<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->

    Look up a guide on regular expressions, and find out WTH those escape codes are, I bet one of em is to filter out the pipe.


    [edit]
    Upon second inspection, I now think that this line is probably the culpurit:
    <!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->$mtext =~ s/[\r|\n]//g;<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
    Seems you're filtering out Carriage Return, New Line, and for some reason, Pipe. Try making the line this instead:
    <!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->$mtext =~ s/[\r\n]//g;<!--c2--></td></tr></table><div class='postcolor'><!--ec2--> (all I did was remove the pipe). I'd also take some effort to find out WHY the pipe was removed from this part, because its probably something significant and/or important.
  • BlackMageBlackMage [citation needed] Join Date: 2003-06-18 Member: 17474Members, Constellation
    edited March 2004
    the pipe is 'or' methinks, worth a shot anyways. we see what comes from it

    edit: hole-e-hell it works <3 doom, drop by our chan (in sig) if you want bot-stuff

    oh, doom is my hero
  • DOOManiacDOOManiac Worst. Critic. Ever. Join Date: 2002-04-17 Member: 462Members, NS1 Playtester
    edited March 2004
    Pipe isn't OR in regular expressions. Pipe is either Pipe or something else.

    If you want "a or h" in a regular expression you do <!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->[ah]<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->

    The brackets mean "any one of whatever is in between me"

    Glad I could be of some help. :D
Sign In or Register to comment.