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?
Quote
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>,,","))),$char_r($replace($regml(1),<b>,,</b>,,",")))
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
}