Hey...I have some lazy people talking to my bot who want it to work kind of like smarterchild. They asked if I could have it do "searches" for them...as if they couldn't search google themselves. As it currently stands, my bot replies to those who ask to "search", that they should go to google and do it themselves.
However, is there a way that I could get the bot to retrieve search results?
Right now I'm having a little trouble having the bot respond with a link to a page of results.
Code:
sub search {<br /><br /> #Asks if this is an admin-only command? (1 for yes, 0 for no).<br /> $adminonly = 0;<br /><br /> #Retrieves the admin's screenname.<br /> open (FILE, "commands/admin.txt");<br /> @admin = <FILE>;<br /> close(FILE);<br /> chomp(@admin);<br /> <br /> #Retrieves the message and the victim.<br /> my $victim = shift;<br /> my $msg = shift;<br /> my $aim = shift;<br /><br /> #Take the prefix off of the message.<br /> $msg =~ s/\/search //ig;<br /><br /> #Assigns the message & creator<br /> my $search = $msg;<br /> my $link = "<a href='http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=$search'>Click here for Results</a>";<br /><br /> #If the message is in an improper format...<br /> if ($search eq "") {<br /> #Replies improper format.<br /> $reply = "Your command was in an improper format. The proper format is:"<br /> . " /search what\n"<br /> . " what = what you are actually searching for";<br /> #Otherwise, continue.<br /> } else {<br /> #Send the search.<br /> $reply = "Searching!...$link";<br /> }<br /><br /> #Return the reply.<br /> return $reply; <br />}<br />1;
The bot respods with the $reply (from above)...and $link actually appears in the response, as a link....but there is no url that it links to. The link is a dead link, that when clicked does nothing.
When I use the following for my $link...
Code:
"<a href="http://www.google.com/search?hl=en&lr=&ie=UTF-8&oe=UTF-8&q=$search">Click here for Results</a>";
...I can't even get the bot to run, because it doesn't like having the "" appear more than once in $link _________________ Anthony Arslan
@-Squared Enterprises
MacroHard Corporation
The first thing you should do for all of your non-admin commands, is remove the admin code at the top. Since you are not using the variable $adminonly and you're not checking against the list of admins, there's no reason to open the file and read them in. It's not all that inefficient, but it is completely useless and increases the size of your code by 7 lines for no reason.
Now, to solve your problem, simply escape the double quotes inside your $link variable. If you want to have double quotes inside a string, do this:
Code:
my $string = "The girl said \"hello\".";
p.s Which bot are you using? I might write a simple tutorial on how to fix the code so that the list of admins is read in only once, not every single time an admin command is executed.
You can also use a Google mod which will be able to return the first 5 search results or so right in the IM window. I think it's called Net::Google or something. There's also one for Yahoo! search.
programmers package manager.. open /perl/bin/ppm.bat or go to run and type ppm, or type ppm at the command prompt.. then you can type search some::file
did that got an error: C:\ActivePerl\Perl\bin>ppm.bat Error: neither 'HKEY_LOCAL_MACHINE/SOFTWARE/ActiveState/PPM//InstallLocation' no *lazy* 'HKEY_CURRENT_USER/SOFTWARE/ActiveState/PPM//InstallLocation' found in registr *lazy* at ppm.bat line 29.