Skip navigation

Quelques scripts mSL plus ou moins utiles.  barlogoscript

 

 

 

 

Dice generator

[script]
n0=on $*:TEXT:/^!dice (10|[1-9]) (\d+[0-9]|[1-9])$/:#: var %i = 0, %limit = $iif($2 > 10, 10, $2) | while %i < %limit { inc %i | .timer 1 $calc(%i * 2) msg $chan $nick rolled $3 $+ -sided die number %i of $2 $+ : Result $rand(1,$3) }
n1=on $*:TEXT:/^!dice (100|[1-9]) { inc %i | .timer 1 $calc(%i * 2) msg $chan $nick NOPE }

Quote system

[script]
n0=On *:text:!Quote*:#: {
n1= write Quote.txt " $+ $2- $+ "
n2= if (%quote != $null) {
n3= msg # Quote recorded as Quote %quote $+ .
n4= inc %quote 1
n5= }
n6= if (%quote == $null) {
n7= set %quote 1
n8= msg # Quote recorded as Quote %quote $+ .
n9= }
n10=}
n11=On *:text:!Read*:#: {
n12= msg # Quote $$2 : $read(Quote.txt,$$2)
n13=}
n14=On *:text:!Random:#: {
n15= msg # $read(Quote.txt)
n16=}
n17=On *:text:!Lines:#: {
n18= msg # $lines(Quote.txt) lines in Quote.txt

Imgur detect

[script]
n0=on $*:TEXT:/((https?[\S]*imgur\.com[\S]*))/Si:#: {
n1= if (!$sock(ImgurLookup)) {
n2= noop $regex(imgururl,$1-,(https?[\S]*imgur\.com[\S]*))
n3= sockopen ImgurLookup imgur.com 80 | sockmark ImgurLookup $+(#,>,$gettok($gettok($regml(imgururl,1),3-,47),1,46))
n4= }
n5=}
n6=on *:sockopen:ImgurLookup: {
n7= var %a sockwrite -n $sockname
n8= %a GET $+(/,$gettok($sock(ImgurLookup).mark,2,62)) HTTP/1.1
n9= %a Host: imgur.com
n10= %a $crlf
n11=}
n12=on *:sockread:ImgurLookup: {
n13= var %x | sockread %x
n14= if ($left($gettok($soc`k(ImgurLookup).mark,2,62),2) == a/) {
n15= if ( isin %x) { set %z 1 | sockmark ImgurLookup $addmark(ImgurLookup,$remove($Xchr($nohtml(%x)),- Imgur),62) }
n16= if (isin %x) { sockmark ImgurLookup $addmark(ImgurLookup,$Xchr($nohtml(%x)),62) }
n17= if (class="textbox left"> isin %x) { sockmark ImgurLookup $addmark(ImgurLookup,$remove($Xchr($nohtml(%x)),Album:),62) }
n18= if (GMT"> isin %x) { sockmark ImgurLookup $addmark(ImgurLookup,$Xchr($nohtml(%x)),62) }
n19= if (class="stat"> isin %x) { sockmark ImgurLookup $addmark(ImgurLookup,$Xchr($nohtml(%x)),62) }
n20= }
n21= else {
n22= if ("hash" isin %x) {
n23= noop $regex(imgurtitle,%x,("title":".*?,))
n24= noop $regex(imgurviews,%x,("views"[\S]*,))
n25= noop $regex(imgurnsfw,%x,("nsfw"[\S]*,))
n26= noop $regex(imgurtime,%x,("timestamp"[\S]*\s[\S]*,)|("datetime"[\S]*\s[\S]*,))
n27= if ($remove($between($regml(imgurtitle,1),$chr(58),$chr(44),1),") == $null) { halt }
n28= else {
n29= msg $gettok($sock(ImgurLookup).mark,1,62) 9,1i0,1mgur » $+(",$remove($between($regml(imgurtitle,1),$chr(58),$chr(44),1),"),") $iif($between($regml(imgurviews,1),$chr(58),$chr(44),1),9· $remove($between($regml(imgurviews,1),$chr(58),$chr(44),1),") Views) $iif($remove($between($regml(imgurtime,1),$chr(58),$chr(44),1),"),9· Uploaded: $timeago($calc($timezone + $ctime - $ctime($remove($between($regml(imgurtime,1),$chr(58),$chr(44),1),"))))) $iif($between($regml(imgurnsfw,1),$chr(58),$chr(44),1) == true,9· 4NSFW)
n30= }
n31= }
n32= }
n33=}
n34=
n35=on *:sockclose:ImgurLookup: {
n36= if (%z == 1) {
n37= if ($left($gettok($sock(ImgurLookup).mark,2,62),2) == a/) {
n38= if ($numtok($sock(ImgurLookup).mark,62) == 6) { sockmark ImgurLookup $instok($sock(ImgurLookup).mark,fillertext,5,62) }
n39= msg $gettok($sock(ImgurLookup).mark,1,62) 9,1i0,1mgur 9» $gettok($sock(ImgurLookup).mark,3,62) $iif($gettok($sock(ImgurLookup).mark,5,62) != fillertext,$+($chr(40),$gettok($sock(ImgurLookup).mark,5,62),$chr(41))) 9· Album: $gettok($sock(ImgurLookup).mark,4,62) 9· $iif($gettok($sock(ImgurLookup).mark,6,62),Uploaded: $gettok($sock(ImgurLookup).mark,6,62)) 9· $iif($gettok($sock(ImgurLookup).mark,7,62),$gettok($sock(ImgurLookup).mark,7,62))
n40= }
n41= }
n42= unset %z
n43=}
n44=
n45=alias -l nohtml { var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x, ) | return %x }
n46=alias -l Xchr {
n47= var %return $regsubex($regsubex($1-,/([A-F0-9]{1,2});/g,$chr($base($regml(\n),16,10))),/&#([0-9]{2});/g,$chr(\1))
n48= return $replacecs(%return,–,,·,·,»,»,«,«,Ü,Ü,ü,ü,Á,Á,á,á,É,$&
n49= É,é,é,Í,Í,í,í,Ó,Ó,ó,ó,Ñ,Ñ,ñ,ñ,Ú,Ú,ú,ú, ,$chr(32),$&
n50= æ,æ,",",&,&,',')
n51=}
n52=alias -l addmark { return $+($sock($1).mark,$chr($3),$2) }
n53=alias -l between { noop $regex($1,/\Q $+ $2 $+ \E(.*?)\Q $+ $3 $+ \E/gi) | return $regml($4) }
n54=alias timeago {
n55= if ($1 <= 59) { Return $1 seconds ago }
n56= if (($1 <= 3599) && ($1 > 59)) { return $floor($calc($1 / 60)) minutes ago }
n57= if (($1 <= 86399) && ($1 > 3599)) { return $round($calc($1 / 3600),0) hours ago }
n58= if (($1 <= 2592000) && ($1 > 86399)) { return $floor($calc($1 / 86400)) $iif($floor($calc($1 / 86400)) > 1,days,day) $+ , $round($calc($calc($1 - $calc($floor($calc($1 / 86400))*86400)) / 3600),0) hour(s) ago }
n59= if (($1 <= 31540000) && ($1 > 2592000)) { return $floor($calc($1 / 2592000)) $iif($floor($calc($1 / 2592000)) > 1,months,months) $+ , $round($calc($calc($1 - $calc($floor($calc($1 / 2592000))*2592000)) / 86400),0) day(s) ago }
n60= if ($1 > 31104000) { return $floor($calc($1 / 31104000)) $iif($floor($calc($1 / 31104000)) > 1,years,year) $+ , $round($calc($calc($1 - $calc($floor($calc($1 / 31104000))*31104000)) / 2592000),0) month(s) ago }
n61=}

Vimeo detect

[script]
n0=alias readXML {
n1= var %tag = $+(<,$1,>), %closingTag = $+()
n2= bread vimeo 0 $file(vimeo).size &binVar
n3= var %open = $bfind(&binVar, 0, %tag), %close = $bfind(&binVar, 0, %closingTag)
n4=
n5= return $bvar(&binVar, $calc(%open + $len(%tag)), $calc(%close - (%open + $len(%tag)))).text
n6=}
n7=
n8=alias htmlencode {
n9= var %str = $replace($1-,&,&,<,<,>,>)
n10= var %str = $regsubex(%str,/&#(\d+?);/g,$chr(\1))
n11= var %str = $regsubex(%str,/([\dA-F][\dA-F]);/g,$chr($base(\1,16,10)))
n12= return %str
n13=}
n14=
n15=on $*:text:/vimeo.com/(\d+)/Si:#:{
n16= if ($sock(vimeo)) .sockclose vimeo
n17= var -g %id = $regml(1), %msg = msg $target
n18= sockopen -e vimeo vimeo.com 443
n19=}
n20=
n21=on *:input:*:{
n22= if ($regex($1, /vimeo.com/(\d+)/Si)) {
n23= if ($sock(vimeo)) .sockclose vimeo
n24= var -g %id = $regml(1), %msg = msg $target
n25= sockopen -e vimeo vimeo.com 443
n26= }
n27=}
n28=
n29=on *:SOCKOPEN:vimeo: {
n30= sockwrite -nt $sockname GET /api/v2/video/ $+ %id $+ .xml http/1.0
n31= sockwrite -nt $sockname Host: vimeo.com
n32= sockwrite $sockname $crlf
n33=}
n34=
n35=on *:SOCKREAD:vimeo: {
n36= if ($sock($sockname).mark) {
n37= while ($sock($sockname).rq) {
n38= sockread &download_file
n39= .bwrite vimeo -1 -1 &download_file
n40= }
n41= }
n42= else {
n43= var %a
n44= sockread %a
n45= if (!%a) sockmark $sockname 1
n46= }
n47=}
n48=
n49=on *:SOCKCLOSE:vimeo: {
n50= var %title = $readXML(title), %upload_date = $readXML(upload_date), %description = $readXML(description), %likes = $readXML(stats_number_of_likes), %uploader = $readXML(user_name), %duration = $readXML(duration), %plays = $readXML(stats_number_of_plays)
n51=
n52= %msg 8,1 -- Vimeo -- 9Title: 11 $+ $htmlencode(%title) 7 $+ $chr(124) 9By: 11 $+ %uploader 7 $+ $chr(124) 09On: 11 $+ $htmlencode(%upload_date) $iif(%description, 7 $+ $chr(124) 9Description: 11 $+ $v1,) $iif(%likes, 7 $+ $chr(124) 9Likes: 11 $+ $bytes($v1, b),) $&
n53= $iif(%plays, 7 $+ $chr(124) 9Plays: 11 $+ $bytes($v1, b),) 7 $+ $chr(124) 9Duration: 11 $+ $duration(%duration)
n54=
n55= .remove vimeo
n56=}

Youtube detect

[script]
n0=alias sockopenmark { sockopen -e $1-3 | sockmark $1 $4- }
n1=on $*:text:/(youtube\.com)\/.*v=([^&]+)|(youtu\.be)\/(.+)/Si:*: {
n2= sockopenmark $+(yt.,$ticks,$rand(1,99)) www.youtube.com 443 $regml(2) msg $iif($chan,$v1,$nick))
n3=}
n4=on *:sockopen:yt.*:{
n5= tokenize 32 $sock($sockname).mark
n6= sockwrite -n $sockname GET /watch?v= $+ $1 HTTP/1.0
n7= sockwrite -n $sockname HOST: www.youtube.com $+ $str($crlf,2)
n8=}
n9=on *:sockread:yt.*:{
n10= var %v | sockread %v
n11= if (%v) echo -ag %v
n12= if ($regex(%v,/"name" content="(.+)"/)) {
n13= tokenize 32 $sock($sockname).mark
n14= $2-4 $replace($regml(1),&amp;,$chr(38),&#39;,$chr(39),',$chr(39),&quot;,$chr(34),",$chr(34),&,$chr(38)) $5-
n15= sockclose $sockname
n16= }
n17=}

Wikipedia search

;Wikipedia Script (Snippet Search) v1.0
;Made by nick1
;View online and report bugs at http://hawkee.com/snippet/17017/
;Last edit May 7, 2016
;2DO -- You tell me

alias -l wikiVersion { return v1.0 }

on $*:text:/^[!@]w(iki|ikipedia)(\s|$)/Si:*: {
;$iif($istok(%youtubefetch,$chan,44),halt,noop)
;$iif($istok(%nolinks,$nick,44),halt,noop)
if ($($+(%,botflood.,$nick),2)) {
if ($($+(%,botflood.,$nick),2) >= 50) {
ignore -u60 $address($nick,2)
msg $chan $+($nick,$chr(44)) You have been put on ignore for 60secs for abusing the bot.
halt
}
elseif ($($+(%,botflood.,$nick),2) >= 40) {
msg $chan $+($nick,$chr(44)) Please do not flood the bot.
inc -z $+(%,botflood.,$nick) 20
halt
}
else {
inc -z $+(%,botflood.,$nick) 10
}
}
else { inc -z $+(%,botflood.,$nick) 10 }
var %ticks $ticks
set $+(%,wiki.,%ticks,.topic) $replace($strip($2-),$chr(32),_)
if ($chan) { set $+(%,wiki.,%ticks,.msgtype) $iif($left($strip($1),1) == @,msg $chan,notice $nick) }
else { set $+(%,wiki.,%ticks,.msgtype) msg $nick }
if ($($+(%,wiki.,%ticks,.topic),2) != $null) {
sockopen -e $+(wiki.,%ticks) en.wikipedia.org 443
}
else {
$($+(%,wiki.,%ticks,.msgtype),2) Please specify a topic to search wikipedia for.
.timerWikiVarDelete 1 1 unset $+(%,wiki.,%ticks,.*)
}
}

on *:input:*:{
if (($left($strip($1),1) == @) || ($left($strip($1),1) == !)) {
if (($remove($1,$left($strip($1),1)) == wiki) || ($remove($1,$left($strip($1),1)) == wikipedia)) {
if ($2) {
var %ticks $ticks
set $+(%,wiki.,%ticks,.topic) $replace($strip($2-),$chr(32),_)
set $+(%,wiki.,%ticks,.msgtype) $iif($chan,$iif($left($1,1) == @,msg $active,echo -a),msg $active)
if ($($+(%,wiki.,%ticks,.topic),2) != $null) {
sockopen -e $+(wiki.,%ticks) en.wikipedia.org 443
}
}
elseif ($2 == $null) {
echo -a 4Incorrect Syntax – Use10 $1 
}
}
}
}

alias wiki {
var %ticks $ticks
set $+(%,wiki.,%ticks,.topic) $replace($strip($1-),$chr(32),_)
set $+(%,wiki.,%ticks,.msgtype) echo -a
if ($($+(%,wiki.,%ticks,.topic),2) != $null) {
sockopen -e $+(wiki.,%ticks) en.wikipedia.org 443
}
else {
$($+(%,wiki.,%ticks,.msgtype),2) Please specify a topic to search wikipedia for.
.timerWikiVarDelete 1 1 unset $+(%,wiki.,%ticks,.*)
}

}

on *:sockopen:wiki*: {
;$iif(!$window(@Wiki- $+ $network),window -evn @Wiki- $+ $network,noop)
var %ticks $remove($sockname,wiki.)
var %x sockwrite -nt $sockname
%x GET $+(/w/api.php?format=xml&action=query&generator=search&gsrnamespace=0&gsrsearch=,$($+(%,wiki.,%ticks,.topic),2),&gsrlimit=1&prop=extracts&exintro&explaintext&exsentences=2&exlimit=max) HTTP/1.1
%x Host: en.wikipedia.org
%x $crlf
}

alias nohtml { return $regsubex($$1-,/^[^<]*>|<[^>]*>|<[^>]*$/g,) }

on *:SOCKREAD:wiki*: {
if ($sockerr) { echo -a SOCKET ERROR: $sockerr | halt }
else {
var %ticks $remove($sockname,wiki.)
sockread &t
bwrite temp $+ %ticks -1 -1 &t
bread temp $+ %ticks 0 $file(temp $+ %ticks).size &binvar2
var %pos1 $bfind(&binvar2,1,)
var %pos2 $bfind(&binvar2,%pos1,)
if (%pos1 != 0) && (%pos2 != 0) {
var %out $bvar(&binvar2,$+($calc(%pos1 +30),-,$calc(%pos2 – 1))).text
var %out $replace(%out, »,$chr(34))
if ($numtok(%out,32) < 30) {
var %out $gettok(%out,1-,32)
}
else {
var %out $gettok(%out,1-27,32) $+ …
}
var %pos1 $bfind(&binvar2,1,title= »)
var %pos2 $bfind(&binvar2,%pos1, » index)
var %link $bvar(&binvar2,$+(%pos1,-,%pos2)).text
var %link $replace($noqt($remove(%link,title=)),$chr(32),_)
var %link https://en.wikipedia.org/wiki/ $+ %link
$($+(%,wiki.,%ticks,.msgtype),2) $+(10,%out,12,$chr(32) $+ %link)
wikicleanup %ticks
.timerUnsetWiki 1 1 unset $+(%,wiki.,%ticks,*)
}
elseif (** iswm $bvar(&binvar2,1-).text) {
;echo @Wiki- $+ $network 4NO FOUND
$($+(%,wiki.,%ticks,.msgtype),2) 10No results found. View search page:12 https://en.wikipedia.org/wiki/Special:Search?search= $+ $($+(%,wiki.,%ticks,.topic),2)
wikicleanup %ticks
.timerUnsetWiki 1 1 unset $+(%,wiki.,%ticks,*)
halt
}
}
}
alias wikicleanup {
;echo @Wiki- $+ $network Cleaning up
.remove temp $+ $1
bunset &t
bunset &binvar2
sockclose wiki. $+ $1
}

on *:start: .timerWikiUpdate 1 60 WikiUpdate

alias WUpdate {
;echo -atc info 12[04Wiki Script12] Checking for updates…
sockopen wUpdate hawkee.com 80
}

on *:sockopen:wupdate: {
sockwrite -nt $sockname GET /snippet/17017/ HTTP/1.1
sockwrite -nt $sockname Host: hawkee.com
sockwrite -nt $sockname $crlf
}

on *:SOCKREAD:WUpdate: {
if ($sockerr) { echo -a SOCKET ERROR: $sockerr $sockname $asctime | halt }
sockread %sockreader
if (** iswm %sockreader) { tokenize 32 %sockreader if ($WikiVersion != $5) { echo -atc info 12[04Wiki Script12] Current: $WikiVersion Latest: $5 Status: Please update at http://hawkee.com/snippet/17017/ } unset %sockreader sockclose $sockname } }