Ask.com

Platform:  mIRC
Published  Nov 02, 2011
Updated  Mar 30, 2012
Well this is a snippet I found that I've done before... It's still in *beta* stage and any opinion or (constructive) criticism is of course welcome.
The usage is /ask Question here.
Also, /askd will open a dialog which is pretty self-explanatory. Rightclicking in an active window will open it too.
Example /ask Who created The Simpsons?
The Simpsons was created by Matt Groening.

And also, I should probably mention, neither the $urlencode or $chr_r aliases were made by me.

Small update: Added an output if no result was found. Thank you _Dean_.

Update December 15th: Added a dialog (My first ever made!) with the command /askd to open it ut. Right clicking in an active window and pressing "Ask" will open it too. alias askd {
if !$dialog(ask) {
dialog -mt ask ask
}
else {
echo -a Dialog already active!
}
}
dialog ask {
title "Ask.com"
size -1 -1 400 180
text "Ask something:", 1, 5 5 500 500
edit "", 2, 5 20 250 20, autohs
button "Ask!", 3, 260 15 30 30
box "Answer", 4, 5 40 370 130
edit "", 5, 10 60 350 100, read multi vsbar
}
on *:dialog:ask:sclick:3:{
if $did(2).text {
ask $v1
}
else {
noop $input(You must specify a question in the editbox!,o,!!!)
}
}
alias ask {
if $1 {
if $sock(ask) {
sockclose $v1
}
sockopen ask www.ask.com 80
sockmark ask $1-
}
else {
echo -a 04Error! Incorrect syntax.
}
}
on *:sockopen:ask:{
var %x = sockwrite -nt $sockname
%x GET /web?qsrc=1&o=0&l=dir&q= $+ $urlencode($sock($sockname).mark) HTTP/1.1
%x Host: www.ask.com
%x Connection: close
%x
}
on *:sockread:ask:{
var %askreader
sockread %askreader
if $regex(%askreader,/<div\s(?:id="r\d+_a"|class="txt3 abstract")\s(?:class="txt3 abstract"|id="r\d+_a")>(.+)(?:<\/div>|<\/span>)|<span class="answers_ui_t\d+">(.+)<\/span>/U) {
$iif($dialog(ask),did -ri ask 5 1,echo -a 03 $+ ) $iif($dialog(ask),$strip($char_r($replace($regml(1),<b>,,</b>,,&quot;,"))),$char_r($replace($regml(1),<b>,,</b>,,&quot;,")))
sockclose $sockname
}
if (*did not match* iswm %askreader) {
$iif($dialog(ask),did -ri ask 5 1,echo -a 04 $+ ) No result for your query $qt($sock($sockname).mark) was found.
sockclose $sockname
}
}
alias urlencode return $regsubex($1,/(\W)/gS,% $+ $base($asc(\1),10,16,2)))
alias char_r return $regsubex($1-,/&#(\d+);/g,$chr(\1))
menu * {
Ask:askd
}

Comments

Sign in to comment.
Kiddo96   -  Dec 15, 2011
Updated the script with a dialog! First dialog I've ever made, I'd be thankful for comments :-)
 Respond  
Wims   -  Nov 08, 2011
he already did (although '\v' shouldn't be included there)
Indeed! I quickly pasted something from wikipedia, but it was about POSIX character class, my bad, here is a quote from pcre.txt:
For compatibility with Perl, \s does not match the VT character (code
11). This makes it different from the the POSIX "space" class. The \s
characters are HT (9), LF (10), FF (12), CR (13), and space (32). If
"use locale;" is included in a Perl script, \s may match the VT charac-
ter. In PCRE, it never does.
 Respond  
Jethro   -  Nov 08, 2011
I'm under jaytea's influence right about now. He's intoxicating and sort of elating my sense of understanding.
 Respond  
jaytea   -  Nov 07, 2011

why not share your know-how in \s so everybody can learn from what you've learned?


he already did (although '\v' shouldn't be included there):


\s match a white space, same as [:space:] or [ \t\r\n\v\f] not just a $chr(32)


from there, you should be expected to realize that an IRC message may include \t and \f, therefore using \s in place of a regular space, when you mean to match a space and only a space, is incorrect.
 Respond  
Jethro   -  Nov 07, 2011
Sarcasm aside, Wims, why not share your know-how in \s so everybody can learn from what you've learned? I've been a veteran in so many flaming posts to know better, and those were a waste of time really thinking back. Make you post worth your while and be remembered by.
 Respond  
Wims   -  Nov 07, 2011
Sure, but the question wasn't specific to that regex _Dean_.
Jethro: it was sarcastic, and the truth, i've read enough posts to know that
Note that you answered my post by saying the same mistake again "use \s to indicate a space", again if people want a space, they should use a space, there's no "I like to", everyone likes to use the proper code they need lol
 Respond  
_Dean_   -  Nov 07, 2011
in fact wims, the \s in that regex match, really means the space character, since on that match, it will only match a space... in fact, \s will match for a white character, but in that case there are no \t \n \v or \f
 Respond  
Jethro   -  Nov 07, 2011
Wims, why wrote this:
you guys are too busy to show to hawkee's users who knows more than the other :)
This sounds sarcastic. We're here to help as much as we can, not to show arrogant attitude toward one another. While some info may be misleading based on our learning, you're always welcome to come forward and correct it with a humble courtesy.
 Respond  
Wims   -  Nov 07, 2011
??
I don't feel uncomfortable with anything here and i use a space to indicate a space, \s isn't a space.
Someone asked what was \s in regex, someone else said it was the space character, this is simply not true and i'm correcting what the person said before anyone start believing it, you know, you guys are too busy to show to hawkee's users who knows more than the other :)
 Respond  
Kiddo96   -  Nov 06, 2011
Didn't have the opportunity to log in yesterday.
Dean, updated with replace on &quot;
 Respond  
Jethro   -  Nov 05, 2011
Yes Wims, I like to leave an empty space as is, but for those of you who feel uncomfortable doing so, use \s to indicate a space. No harm, no foul.
 Respond  
Wims   -  Nov 04, 2011
\s match a white space, same as [:space:] or [ \t\r\n\v\f] not just a $chr(32)
 Respond  
Jethro   -  Nov 04, 2011
You can use the look-behind or look-ahead assertions to demand a targeted match to be met (you may want to read up on those assertions to gain understanding of how they work) , while the
Code
 
,
Code
 
and
Code
 
are telling regex to match as few strings as possible, being less greedy. Regex by design is greedy and case-sensitive.
 Respond  
_Dean_   -  Nov 04, 2011
sorry so, but i think we can improve regex a little bit more, and not use the (.*?) or /U
i just didnt go ahead with the code

by the way Kiddo96, you forgot to replace &quot; to "
 Respond  
Jethro   -  Nov 04, 2011
Before you called me a name, I was speaking in general, pointing out the sameness between (.*?) and /U.
 Respond  
_Dean_   -  Nov 04, 2011
in fact not Mr. idiot
he used the (.*?) so i didnt change his code, and i kept it in the same as he wants
so instead use 2 (.*?) i just used /U for all them
 Respond  
Jethro   -  Nov 04, 2011
Kidd96, you can leave an actual space rather than use \s. What you have done for (.*?) is the same as using /U. Mr. Dean is just giving you an "interchangeable" alternative is all.
 Respond  
_Dean_   -  Nov 04, 2011
its the space character
 Respond  
_Dean_   -  Nov 04, 2011
its the character space
 Respond  
Kiddo96   -  Nov 04, 2011
I think I'm following you, just wondering what \s means?
 Respond  
_Dean_   -  Nov 04, 2011
i just mixed both regex match, and i used ?: wich will not save the reference to the $regml so in this case, it will have only $regml(1) and not $regml(2) and $regml(3) as in your case
since you have used (.*?) so i used the /U modifier, which will make all the references not greedy

if you have any doubt ask me

Code
 
 Respond  
Kiddo96   -  Nov 04, 2011
Alright Dean I must say I like yours really much :) If you'd have time, could you please explain the regex pattern for me?. I'm still new to this and any kind of help is highly appreciated. Also added the "No result found" part to my script. Thank you for spotting that.
 Respond  
Kiddo96   -  Nov 03, 2011
Interesting Dean. I'll have a look at your code tomorrow, right now my eyeballs are about to pop out lol. :)
 Respond  
_Dean_   -  Nov 03, 2011
since you have asked it Kiddo96, i think you can use one regex match instead 2

this is a simple example, and i added the $replace for &quot; to "
and a check to check if the results match

Code
 


i didnt tried another thing, but i think we can improve a lot
if i think in something i will post it
 Respond  
Kiddo96   -  Nov 03, 2011
I'm glad to hear that, Jethro :)
 Respond  
Jethro   -  Nov 03, 2011
The regex you've been given to is as good as it gets. No improvement needed.
 Respond  
Kiddo96   -  Nov 03, 2011
I'd like to ask, could the regex pattern be improved anyhow?
 Respond  
PuNkTuReD   -  Nov 02, 2011
how could you not?
 Respond  
Frenetic   -  Nov 02, 2011
I didn't realize hawkee was a drama show.
 Respond  
PuNkTuReD   -  Nov 02, 2011
now, i by no means enjoy deans posts... but his post, while sounding serious, does have its humour...


- who is the most spammer in the world
and
- who is the president of the idiots academy
and it didnt return Jethro


he sounds shocked doesnt he... lmao...
 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.