This script uses twitters search engine to search tweets for matches. It returns the top 3 matches along with usernames.
Setup:
Basic Syntax is !tsearch search words or @tsearch search words or /tsearch search words.
!tsearch or @tsearch or /tsearch will render no results. You must provide search words.
The !tsearch, public trigger and will notice the user. The @tsearch trigger will message the channel if you are an op. Triggers can be turned off from the right click channel menu.
Advanced Syntax:
Screen Shot:
;Twitter search by Ford_Lawnmower irc.geekshed.net #Script-Help
alias -l Gettsearch {
if ($sslready) {
$1-2 Searching........
var %sockname $+(tsearch,$network,$2,$ticks)
sockopen -e %sockname twitter.com 443
;The three lines below set the number of results and the colors.
Svar %sockname maxresults 3
Svar %sockname namecolor $+($chr(3),14,$chr(2))
Svar %sockname textcolor $+($chr(15),$chr(3),04)
Svar %sockname output $1-2
Svar %sockname url $+(/i/search/timeline?type=relevance&include_available_features=1&include_entities=1&q=,$urlencode($3-))
}
else $1-2 You must install openssl for this script to run: http://www.mirc.com/download/openssl/openssl-0.9.8r-setup.exe
}
menu Channel,Status {
.$iif($group(#tsearch) == On,$style(1)) tsearch Trigger
..$iif($group(#tsearch) == On,$style(2)) On: .enable #tsearch
..$iif($group(#tsearch) == Off,$style(2)) Off: .disable #tsearch
}
#tsearch on
On $*:Text:/^(\+|-|!|@)tsearch.*/Si:#: {
var %action $regml(1)
if (%action isin +-) && ($regex($nick($chan,$nick).pnick,/(!|~|&|@)/)) {
if (%action == +) {
if ($istok(%tsearchChanList,$+($network,$chan),32)) { .msg $chan $nick $chan is already running the tsearch script }
else {
.enable #tsearch
Set %tsearchChanList $addtok(%tsearchChanList,$+($network,$chan),32)
.msg $chan $nick has activated the tsearch script for $chan .
}
}
else {
if (!$istok(%tsearchChanList,$+($network,$chan),32)) { .msg $chan $nick $chan is not running the tsearch script }
else {
Set %tsearchChanList $remtok(%tsearchChanList,$+($network,$chan),1,32)
.msg $chan $nick has deactivated the tsearch script for $chan .
}
}
}
elseif (!$timer($+(tsearch,$network,$nick))) && ($istok(%tsearchChanList,$+($network,$chan),32)) {
.timer $+ $+(tsearch,$network,$nick) 1 6 noop
var %method $iif(%action == !,.notice $nick,$iif($regex($nick($chan,$nick).pnick,/(!|~|&|@|%|\+)/),.msg $chan,.notice $nick))
Gettsearch %method $2-
}
}
#tsearch end
alias tsearch { Gettsearch echo -gta $1- }
On *:sockopen:tsearch*: {
if (!$sockerr) {
sockwrite -nt $sockname GET $svar($sockname,url) HTTP/1.0
sockwrite -n $sockname Host: twitter.com
sockwrite -n $sockname Connection: close
sockwrite -n $sockname $crlf
}
else {
$svar($sockname,output) $svar($sockname,textcolor) Twitter Search is currently overloaded or ignoring your request. Please wait a few moments and try again.
sockclose $sockname
return
}
}
On *:sockread:tsearch*: {
if ($sockerr) {
$svar($sockname,output) $svar($sockname,textcolor) Twitter Search is currently overloaded or ignoring your request. Please wait a few moments and try again.
sockclose $sockname
return
}
else {
sockread -fn 2000048 &tsearch
write -n $sockname $bvar(&tsearch,1-).text
}
}
On *:sockclose:tsearch*: {
bread $sockname 1 $int($calc($file($sockname).size / 1.7)) &tsearch
.remove $sockname
var %count 1
;noop $bstringmap(&tsearch,\u003c,<,\u003e,>,<,<,>,>,\n,$chr(32),\/,/,",", ,$chr(32))
while ($bintween(&tsearch,\u003cp class=\"js-tweet-text tweet-text\"\u003e,\u003c\/p\u003e,%count)) {
var %match $replace($v1,\u003c,<,\u003e,>,<,<,>,>,\n,$chr(32),\/,/,",", ,$chr(32))
$svar($sockname,output) $+($svar($sockname,namecolor),$remove($bintween(&tsearch,js-user-profile-link js-nav\" href=\",\",%count),$chr(13),$chr(10),\/),:) $&
$+($svar($sockname,textcolor),$httpstrip($fix&#(%match)))
if (%count >= $svar($sockname,maxresults)) break
inc %count
}
if (!$bintween(&tsearch,\u003cp class=\"js-tweet-text tweet-text\"\u003e,\u003c\/p\u003e,1)) $svar($sockname,output) $svar($sockname,textcolor) Nothing found!
;bwrite $sockname -1 -1 $bstringmap(&tsearch,\u003c,<,\u003e,>,<,<,>,>,\n,$chr(32),\/,/,",", ,$chr(32))
}
;syntax $binreplace(&binvar,$textfrom,$textto)
alias -l binreplace {
if ($bvar($1,0)) {
if ($3) bset -t &to 1 $3
var %start 1
while ($bfind($1,%start,$2).text) {
%start = $v1
var %end $calc($v1 + $len($2))
bcopy &left 1 $1 1 $calc(%start - 1)
if ($bvar($1,$calc(%end + 1))) bcopy &right 1 $1 %end $bvar($1,0)
bunset $1
if ($bvar(&left,0)) bcopy $1 1 &left 1 $bvar(&left,0)
if ($bvar(&to,0)) bcopy $1 $calc($bvar($1,0) + 1) &to 1 $bvar(&to,0)
%start = $calc($bvar($1,0) + 1)
if ($bvar(&right,0)) bcopy $1 $calc($bvar($1,0) + 1) &right 1 $bvar(&right,0)
bunset &right
bunset &left
}
return $1
}
return $1
}
;syntax $bstringmap(&binvar,$find,$replace,$find,$replace,$etc,$etc)
alias -l bstringmap {
var %next 2
while ($($+($,$calc(%next + 1)),2)) {
binreplace $1 $($+($,%next),2) $($+($,$calc(%next + 1)),2)
inc %next 2
}
return $1
}
alias -l bintween {
var %count = 1, %mark = 0, %mark2 = 0
while (%count <= $4) {
if ($bfind($1, %mark2, $2).text) {
%mark = $calc($bfind($1, %mark2, $2).text + $len($2))
if ($bfind($1, %mark, $3).text) {
%mark2 = $bfind($1, %mark, $3).text
}
else { return 0 }
}
else { return 0 }
inc %count
}
return $bvar($1, $iif(%mark > 0,%mark,1), $calc(%mark2 - %mark)).text
}
alias -l httpstrip { var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x) | return $remove($replace(%x,&,&), ,$chr(10),$chr(13),$crlf) }
alias -l Put {
if (!$regex($1,/(\.|^)(msg|notice|echo)$/Si)) || (!$3) { echo -st **Put error** Syntax /Put msg #channel text - or - /Put notice nickname text | return }
tokenize 32 $regsubex($1-,/([$\|%\[\]][^\s]*)/g,$+($chr(2),$chr(2),\t))
var %tokens $0, %Tstart 3, %Dtimer 1500
if ($timer($+(Put,$2,$network)).secs) { %Dtimer = $calc($v1 * 1000) }
while ($len($($+($,%Tstart,-,%tokens),2)) > 430) {
dec %tokens
if ($len($($+($,%Tstart,-,%tokens),2)) <= 430) {
.timer -m 1 %Dtimer $1-2 $($+($,%Tstart,-,%tokens),2))
inc %Dtimer 1500
%Tstart = $calc(%tokens + 1)
%tokens = $0
}
}
.timer -m 1 %Dtimer $1-2 $($+($,%Tstart,-,%tokens),2))
.timer $+ $+(Put,$2,$network) -m 1 $calc(%Dtimer + 1500) noop
}
alias -l urlencode return $regsubex($1-,/([^a-z0-9])/ig,% $+ $base($asc(\t),10,16,2))
alias -l Svar {
var %sockname $1, %item $2
if ($isid) {
if ($regex($sock(%sockname).mark,/ $+ %item $+ \x01([^\x01]*)/i)) return $regml(1)
}
else {
tokenize 44 $2-
var %count 1
while (%count <= $0) {
var %record $($+($,%count),2), %item $gettok(%record,1,32), %value $gettok(%record,2-,32)
if (!$regex($sock(%sockname).mark,/ $+ %item $+ \x01/i)) sockmark %sockname $+($sock(%sockname).mark,$chr(1),%item,$chr(1),%value)
else sockmark %sockname $regsubex($sock(%sockname).mark,/( $+ %item $+ \x01[^\x01]*)/i,$+(%item,$chr(1),%value))
inc %count
}
}
}
alias -l fix&# {
var %fix $regsubex($charMap($1-),/\&\#([0-9]{1,4});/ig,$UTF8(\t))
return $regsubex(%fix,/\\u([0-9a-f]{4})/gi,$h2u(\t))
}
alias -l charMap {
var %map $remove(€|¬a;|‚|ƒ|„|…|†|‡|ˆ|‰|Š|‹|Œ|¬a;|¬a;|¬a;|¬a;|$&
‘|’|“|”|•|–|—|˜|™|š|›|œ|¬a;|¬a;|Ÿ| |¡|¢|£|$&
¤|¥|¦|§|¨|©|ª|«|¬|­|®|¯|°|±|²|³|´|µ|¶|·|$&
¸|¹|º|»|¼|½|¾|¿|À|Á|Â|Ã|Ä|Å|Æ|Ç|È|$&
É|Ê|Ë|Ì|Í|Î|Ï|Ð|Ñ|Ò|Ó|Ô|Õ|Ö|×|Ø|Ù|$&
Ú|Û|Ü|Ý|Þ|ß|à|á|â|ã|ä|å|æ|ç|è|é|ê|ë|$&
ì|í|î|ï|ð|ñ|ò|ó|ô|õ|ö|÷|ø|ù|ú|û|ü|ý|$&
þ|ÿ|,$chr(32))
var %char $regsubex($str(.,128),/(.)/g,$+($chr($calc(\n + 127)),|))
return $regsubex($1-,/( $+ %map $+ )/g,$gettok(%char,$findtokcs(%map,\t,124),124))
}
alias -l UTF8 {
if ($version >= 7) return $chr($1)
else {
if ($1 < 255) { return $chr($1) }
if ($1 >= 256) && ($1 < 2048) { return $+($chr($calc(192 + $div($1,64))),$chr($calc(128 + $mod($1,64)))) }
if ($1 >= 2048) && ($1 < 65536) { return $+($chr($calc(224 + $div($1,4096))),$chr($calc(128 + $mod($div($1,64),64))),$chr($calc(128 + $mod($1,64)))) }
if ($1 >= 65536) && ($1 < 2097152) {
return $+($chr($calc(240 + $div($1,262144))),$chr($calc(128 + $mod($div($1,4096),64))),$chr($calc(128 + $mod($div($1,64),64))),$&
$chr($calc(128 + $mod($1,64))))
}
}
}
alias -l div { return $int($calc($1 / $2)) }
alias -l mod {
var %int $int($calc($1 / $2))
return $calc($1 - (%int * $2))
}
alias -l H2U { return $utf8($base($1,16,10)) }
The script is stucking the mIRC i use to break it!
Also when i an VAILD command to search and the bot starting searching then the mIRC stucks for 10-15 seconds and then output the results
mIRC Version: 7.32
OpenSSL version: 1.0.1e
(11/Oct/2013 17:07:53) <@westor> !tsearch google
(11/Oct/2013 17:07:54) -RafaeLLa-v2- Searching........
(11/Oct/2013 17:09:35) <@westor> !tsearch @google
(11/Oct/2013 17:09:35) -RafaeLLa-v2- Searching........
That's not very many variables for a socket script kirby. It can be done with less, but it's much more understandable this way. Besides they are all unset at the end ;/
I hate the use of tokenize for this, it's just not in my scripting style. I like to write code that is very easy to read and follow. Tokenize just muddy's the water, with a bunch of $* crap. I knew the menu was very basic. You are correct, your code is much more functional for the menu. By the way, I posted this several other places, some longer than a month ago. Thanks for the comments :)
Thank you uneek :)
Looks nice.
Except the screenshot is a little blurry; makes it a little hard to see. =/
I'm a little obsessed with using as few variables as possible, even though they are priceless at times, but you can certainly do so in this script.
set %twitter.inuse 1
set %twitter.nick $me
set %twitter.chan ECHO
sockclose twitter
set %twitterurl /search?q= $+ $replace($1-,$chr(32),+)
set %twittersite search.twitter.com
set %twitter.max 5
Although yes, you can **/unset %twitter* at the end, but you can also use /sockmark and then /tokenize later on.
If you are not familiar with them, /help /tokenize and /help /sockmark**.
Basically, you can store multiple items into the socket mark (up to 512 bytes, or half a kilobyte) and then tokenize them to make identifiers ($1,$2,$3,.., so on).
If done correctly, you can possibly use one (at most) variable in the whole script.
What I would also encourage is to change your menu layout slightly (the way you used groups was nice).
menu channel {
.Twitter
.Trigger On:enable #TwitterTrigger
.Trigger Off:disable #TwitterTrigger
}
menu * {
$iif($group(#TwitterTrigger) == On,$style(1)) Twitter
.$iif($group(#TwitterTrigger) == On,$style(2)) On: .enable #TwitterTrigger
.$iif($group(#TwitterTrigger) == Off,$style(2)) Off: .disable #TwitterTrigger
}
What I personally like about this layout is that it displays the status (if the group is enabled or disabled). If the group were to be disabled, then the 'Off' part would be grayed out, and only the 'On' part could be selected--vice-versa with if groups were to be enabled.
It also makes a 'check' mark if the group is enabled.
Otherwise, nice work.
@^WeSt Yea, I see that the page is about 30 times larger than it was when I first wrote this.
It's way too big to parse the entire page without freezing mIRC.
I made some adjustments and removed most of the parsing. Try the updated code and let me know how it works.