♪ ♫ ♪ it’s a kind of magic, it’s a kind of magic! ♪ ♫ ♪
Updated: 26-Sept-2011: Fixed evaluation bug.
var %s = [ [ $replace($v1,,% $+ s) ] ]*
This is a fun little script for being a little bit silly . . .
A throwback to 1995 when IRC was bright with rainbow colors aNd aLtErNaTiNg tExT. :-)
The script allows you to repeat a line of text several times while modifying it in different ways.
Read the full instructions and command parameter definitions in the code comments.
Usage:
/magic [loop] [delay-ms] [$identifiers ...] [["]/command [params"]] <string to magicize!>
Examples:
/magic 5 Hello World!
This will say "Hello World!" to the active window 5 times.
/magic 5 250 Hello World!
This will do the same, but with a 1/4 second delay between lines.
/magic $camel Hello World!
This will say "hElLo wOrLd!", same as doing //say $camel(Hello World!)
/magic 5 $rcase Hello World!
Similar to above, except it will repeat 5 times with the letters randomly capitalized.
/magic 5 $rcase /me Hello World!
Same as above, but sent with the /me command instead of /say.
/magic 5 /me is really $me $+ !
This simply performs the action Raccoon is really Raccoon!, 5 times.
/magic 5 $upper "/echo -a" you are amazing!
If your command needs parameters, wrap the whole command in quotes.*
/magic 20 "/echo -a" ~ $read(versions.txt,n,%i)
[i]You can use %i to represent the current loop iteration, allowing for dynamic output!
This reads the first 20 lines from versions.txt and displays them.[/i]
!!! NOTE !!! Actively editing this Snippet as of tonight, 23-Sept-2011. Expect persistent changes and additions throughout the weekend.
Will add fun identifiers such as multiple $rainbow colorizors and other string manipulation fun things to use with /magic. You'll see. It's all quite random-ass fun. Remember Remember #mIRC-Rainbow. :D
;# a_magic.mrc by Raccoon 12-Sept-2011, last-updated 26-Sept-2011.
;# This is an Aliases file.
;#
;# ♪ ♫ ♪ I t ' s a k i n d o f M a g i c! ♫ ♪ ♫
;#
;# This script allows you to repeat a line of text several times while modifying it in different ways.
;#
;# Usage:
;# /magic [loop] [delay-ms] [$identifiers ...] [["]/command [params"]] <string to magicize!>
;#
;# Parameters:
;# - loop (optional) : A number "1" or greater. This creates more magic. Try 5 or 10.
;# - delay-ms (optional) : A delay in miliseconds between loops. Eg: 1000 equals 1 second.
;# : The first loop iteration will fire immediately, subsequent loops
;# : will create /timers with increasing incriments of the 'delay' value.
;#
;# - $identifiers (optional) : One or more $identifiers that will modify 'string'. Eg: $upper
;# : If the $identifier is blank with no (), the 'string' will be passed
;# "with magic sybols" : as the first and only parameter. If the $identifier requires
;# : multiple parameters, you can specify "*" to represent where 'string'
;# * = 'string' : should be inserted. Eg: $left(*,32) or $strip(*,c)
;# %i = 'loop iteration' : In addition, you can use "%i" which will be replaced with the
;# : current loop iteration. Eg: $rainbow(*,%i) or $str(*,%i)
;# : Nested identifiers should evaluate, but ") $" will break things.
;#
;# - /command (optional) : The command that will process the modified 'string'. The default
;# : command is /say. If your command requires parameters, you can
;# "can be quoted" : enclose the entire command in quotes. Eg: "/echo -a" or "/msg $me"
;#
;# - string (required) : Any old string you wish to make magical! Eg: Hello World! It's $me
;# : It can contain identifiers or variables which will be evaluated.
;# "will be evaluated, : To be exact, the string is evaluated once, then again each time it's
;# multiple times." : passed to an $identifier to modify it, and again when a 'delay' is
;# : used as the /timer will evaluate it. You can offset the evauluation
;# try $read(file.txt,%i) : by using tricks like $!me or $!!me or $!!!me or $!!!eval(%myvar)
;# : BTW, You can also use $read(file.txt,%i) to read lines from a file!
;#
;# Written by Raccoon on 22-Sept-2011
; Default Behavior. Modify if you like.
magic_default_loop return 1
magic_default_delay return 0
magic_default_funs return
magic_default_cmd return /say
;magic_default_str ** there cannot be a default string **
; /magic [loop] [delay] [$identifier[(*,%i)] {$iden...}] [["]/cmd [params"]] <evaluated string>
/magic { ; by Raccoon 12-Sept-2011, 22-Sept-2011
var %re = /^ $+ $&
([-]\S+|)\s? $+ $&
(\d+|)\s? $+ $&
(\d+|)\s? $+ $&
((?:\$[^(]+\([^)]*\)\s?|\$\S+\s?)+|)\s? $+ $&
("[^"]*"|\/\S*|)\s? $+ $&
(?<=\s|^)(.*)$/
noop $regex(_magic,$1-,%re)
if !$0 || !$regml(_magic,0) {
if ($0) echo -aic notice *** /magic : Invalid format.
echo -aic info *** Usage: /magic [loop] [delay-ms] [$id $!id(*,%i) $!...] [["]/cmd [params"]] <string to magicize>
echo -aic info *** Example: /magic 5 $!rcase $!rainbow /say The quick brown $!me jumps over the lazy $!network
return
}
var %switches = $regml(_magic,1)
var %loop = $regml(_magic,2)
if !%loop { var %loop = $magic_default_loop }
if !%loop { var %loop = 1 }
var %delay = $regml(_magic,3)
if !%delay { var %delay = $magic_default_delay }
var %funs = $regml(_magic,4)
if !%funs { var %funs = $magic_default_funs }
var %cmd = [ [ $noqt($regml(_magic,5)) ] ]
if !%cmd { var %cmd = [ [ $noqt($magic_default_cmd) ] ] }
if !%cmd { var %cmd = /say }
var %str = $regml(_magic,6)
; echo -a %switches , %loop , %delay , %funs , %cmd , %str
; convert only plain "$identifer"s to "$identifier(*)"
var %re = /(\$[^(\s]+)(?=\s|$)/g
var %funs = $regsubex(_magic_fun,%funs,%re,\1(*))
; array each $identifier to $regml(_magic_fun,%i)
var %re = /(\$.+?\))(?=\s\$|\s|$)/g | ; /(\$[^(]+\([^)]*\))/g | ; /(\$[^(]+\([^)]*\)|\$\S+)/g
noop $regex(_magic_fun,%funs,%re)
; echo -a $regml(_magic_fun,0) --- $regml(_magic_fun,1) $+ , $regml(_magic_fun,2) $+ , $regml(_magic_fun,3) $+ , $regml(_magic_fun,4) $+ , $regml(_magic_fun,5)
var %i = 1
WHILE %loop {
var %s = [ [ %str ] ]
var %j = 1
WHILE $regml(_magic_fun,%j) {
var %s = [ [ $replace($v1,*,% $+ s) ] ]
inc %j
}
if %cmd {
if %delay > 0 { .timer -md 1 $calc(%delay * (%i -1)) %cmd %s }
else { %cmd %s }
}
inc %i
dec %loop
}
} ; end of /magic
; Additional functions will follow...
; Camel Case -- tHe qUiCk bRoWn fOx jUmPs oVeR ThE LaZy dOg.
/camel { $iif($isid,return,editbox -a) $regsubex($1-,/(.)(.)|(.)/g,$lower(\1) $+ $upper(\2)) } ; by Raccoon 12-Aug-2011
; Random Case -- ThE QUICk bRown FoX JUmPS OVeR the lazY dOG.
/rcase { $iif($isid,return,editbox -a) $regsubex($1-,/(.)/g,$iif($r(0,1),$lower(\1),$upper(\1))) } ; by Raccoon 12-Sept-2011
; end of snippet
It seems since I wrote this script, I've been gaining more attention from ban hammers. So of course, I wrote another script that I feel like sharing.
Raccoon's Ban Rejoin @ http://www.hawkee.com/snippet/9627/
Nothing too special. Just neatly made, I think.
/magic 2 500 $camel /me "Hello, I like co,mm ,as! ,,,,, :)"
works the same as:
/timer -m 2 500 me $camel("Hello, I like co,mm ,as! ,,,,, :)")
I guess your way does save a few keystrokes when entered at the command line.
/timer 2 1 me $camel("Hello, I like co,mm ,as! ,,,,, :)")
Is shorter than both if you don't need the precision.
Seems easier for me to remember.
Jethro: Thanks. :) Hmm, I guess it may make me come off as stand-offish, but I'm really not. I just tend to elaborate in grave detail.
gooshie: To each their own, I guess. Feel free to modify my work any way you choose. I, personally, hate popups/menus and never ever use them. I can type an entire ascii art faster than navigating screwy popup menus to find the dang thing. :P
/magic $lines(hellokitty.txt) $rainbow $read(hellokitty.txt,%i)
i would never type all that in EVER... i would make it a popup... so i could use it more than once and NEVER have to do that again.. and if you miss type that its worse than never sending it at all..
...as for me i can always wait another 900 milliseconds to spew forth chat stuff... i would feel like i'm just kidding myself to think i needed that fine grain of control for such situations... i guess if you save 900 milliseconds often enuff at the end of the year you could have several days saved up to do with as you wish...
Here's another for example that /magic can do without having to write a whole new script to do it. Say you have an ASCII ART saved to a file and want to display it in rainbow colors. Just type:
/magic $lines(hellokitty.txt) $rainbow $read(hellokitty.txt,%i)
By the time you open the script editor to write your own custom script to do this, the opportunity may have already passed.
gooshie:
Q. "What if I forget the command syntax?"
A. The syntax is displayed with an example if you type "/magic" with no parameters.
Q. "Why set the delay in milliseconds instead of seconds?"
A. It is often only necessary to delay a flood of text by 100 to 250 milliseconds to keep the server from booting you off. That's 1/10th to 1/4th of a second, thus the finer grain delay.
Q. Can the text modifiers be used in other scripts or popups?
A. Yes. They can be used independently of /magic. /magic just helps you quickly combine and play with them without opening the script editor. The text modifiers themselves follow "standard coding practices".
I'm not in disagreement that you can approach this several different ways. What /magic was mainly designed to do is combine multiple identifiers quickly in a channel without all the layout and closing brackets while-loop initiation and error messages because your text string contains a comma. As you can see, 85% of my code is strictly parsing user input; while the guts are a simple little WHILE loop with optional /timer. :)
raccoon
Yeah, ok so for a couple of weeks after you make this you will remember how to type in your unique complex command string at the command line. Then after you get bored with it and dont use it for awhile you forget and it just sits there. There is NO REASON even in your snippet to have finer grain delay than in seconds OR to use the while loop when that section could be done with a simple timer of which you are already using one.
My chat habit is to type plain text but may employ these type text modifiers in popups or auto-reply events and as such I prefer to have them coded to be easy to use and I also like them to follow standard mIRC coding practices. I'm just trying to offer you ideas as you had asked. BTW, there may be a million ways to script something but some ways are more correct than others.
So, to wrap this up; I would code the texteffects as one alias then make another alias that would use a simple timer that could do your command line the way you like but when I needed it for an auto-reply or popup I would just put a timer where I needed it and just use the text effect so it actually easy to read. This way I only need to remember: $texteffect(string).rcase or camel etc
As a matter of fact I have made such an alias that does several color effects that I will post now.
gooshie: there are a million different approaches to scripting a function. What makes /magic useful is the specific approach of encapsulating a loop with multiple identifiers that modify a string, making it strictly for command-line input user-typed only. You could easily perform the same in scripting with a while loop and several nested identifiers around a string -- easy enough to write as a script, but tedious to type in a channel on demand. /magic just makes it easier to type.
Dani_l11: Like I said, it's just silly fun. Especially useful on small networks with no flood limits and lots of colors and ascii art scrolling by, or any channel that observes "ASCII Fridays". :)
I think the code is also a useful demonstration of interpreting a complex set of Alias parameters using regular expression patterns. Notice how almost every parameter is optional and may contain multiple words.
raccoon
Maybe try making it all one alias $magic(string,loop,delay).prop
so it is sorta standard mIRC format, can be easily extended,
and can then be used easily any where as in:
on *:TEXT:hi:?:msg $nick $magic(Hello $nick $+ !,3,2).rcase
OIC: The loop makes this difficult..
So what I would do is have the text effects separate from the loop in which
case you can replace the whole while loop delay section with a timer.
Thanks to raccoon's unintentional snippet title that reminds me of the good old song...though I have nothing on-topic to say about this snippet lol It does work like magic though to bring back the fond memories.
Ryan, that song is even older (the original from the 60s) than the one I sing, which is from the 70s. :P
Anyway, raccoon, excuse us for hijacking your thread for a casual chitchat.