How to make your own theme

From Scriptwiki
Revision as of 14:37, 22 May 2014 by Jay2k1 (talk | contribs) (Miscellaneous: grammar nazi strikes again)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This tutorial is going to give you an overview on how to create your own theme by modifying various events and aliases. I'm not making a theme-engine here, just showing how to get things going. There are several ways to make your own theme, hope you get some ideas from this tutorial.
At this point you should already know basics of mircscripting, if you are still having some difficulties, take a look at How to start

Start

We'll start with 2 aliases that returns colorcodes, and delimiters (ie < or > for <nick>). You can leave some of the returned values blank like ts_right and ts_right (in theme_delimiter, timestamp delimiters), so there won't be anything around the timestamp.

alias theme_color {
 ;color of timestamp
 if ($1 == timestamp) { return 03 }

 ;color of @-prefix
 if ($1 == prefix-op) { return 10 }

 ;color of +-prefix
 if ($1 == prefix-voice) { return 11 }

 ;color of %-prefix
 if ($1 == prefix-hop) { return 06 }

 ;color of nick 
 if ($1 == nick) { return 14 }

 ;color of link
 if ($1 == link) { return 07 }

 ;color of left and right delimiters ie: <nick> (the < and > in there)
 if ($1 == delimiter) { return 05 }

 ;color of event name
 if ($1 == sysmsg) { return 04 }

 ;color of system message delimiter ie: [highlight] (the [ and ] in there)
 if ($1 == sysdelimiter) { return 05 }
}

alias theme_delimiter {
 ;left delimiter of system messages ($chr(91) = [ and $chr(93) = ])
 if ($1 == sys_left) { return $chr(91) }

 ;right delimiter of system messages
 if ($1 == sys_right) { return $chr(93) }

 ;left delimiter of timestamp
 if ($1 == ts_left) { return ( }

 ;right delimiter of timestamp
 if ($1 == ts_right) { return ) }

 ;left delimiter of nick
 if ($1 == nick_left) { return ( }

 ;right delimiter of nick
 if ($1 == nick_right) { return ) }
}

Helpful aliases

These aliases are meant to make things easier with the theme. I chose to do a couple of aliases, that returns stuff we need several times, it would be pointless to do same things over and over again. This makes the theme more easily modified, since you only need to change things in one place.

$clr

First we have clr alias (short for color), so we don't have to use ctrl+k in the script, just $clr(control code), ie. $clr(03) is the same as ctrl+k 3, (works with background colors), zeropads the given number to 2, ie. 3 -> 03.

alias clr { return $+($chr(3),$base($1,10,10,2)) $+ $iif($2,$+($chr(44),$base($2,10,10,2)),) }

$urlc

This is an alias which underlines and colors links, i use this in several places, so if you don't want to use this, replace all $urlc($1-) with $1- in the future
You can find a complete version of this URL-logger & coloring system from here

alias urlc {
 ;assign $1- into a variable
 var %line = $1-

 ;check with regex if the line includes www. or http://
 if ($regex(%line,/(\b(www.?\.|https?:\/\/|ftp:\/\/).)/i)) {

   var %x = 1 

   ;loop through the line
   while (%x <= $numtok(%line,32)) { 

     ;check if a link is found
     if ($regex($gettok(%line,%x,32),/(\b(www.?\.|https?:\/\/|ftp:\/\/).)/i)) { 
       ;put some colors and underline to the link, $chr(31) is the underline
       var %l2 = $+($clr($theme_color(link)),$chr(31),$gettok(%line,%x,32),$chr(31),$clr)

       ;replace the old link with the new, colored one
       %line = $puttok(%line,%l2,%x,32)
     } 
     inc %x 
   }
 }
 return %line
}

$modeprefix

An alias to return colored modeprefix of a nick, usage: $modeprefix($nick,$chan), you shouldn't modify this (except $chr(160) to $chr(32), read below) since the colors are in variables that we set earlier

alias modeprefix {
 ;we will use $matchtok to find out if modeprefix is one of @,+ or % and then replace them with colored ones
 ;if you don't like the space between left delimiter and nick when there's no mode, change the $chr(160) to $chr(32) or leave it blank

 return $iif( $&
   $matchtok(@.+.%,$left($nick($2,$1).pnick,1),1,46), $&
   $replace($ifmatch, $&
   @,$+($clr($theme_color(prefix-op)),@,$clr), $&
   +,$+($clr($theme_color(prefix-voice)),+,$clr), $&
   %,$+($clr($theme_color(prefix-hop)),%,$clr) $&
   ),$chr(160))
}

$theme_nick

An alias to return nick with modeprefix and delimiters, ie. (@Cail) This alias is used everytime someone says something/you do something. The purpose of this alias is to use it in events, and everytime you wish to change how your nick looks like, you only need to change it in one place.

alias theme_nick {
 ;this alias return colored timestamp, modeprefix, nick
 ;with custom delimiters


 return $+( $&
   $clr($theme_color(delimiter)),$theme_delimiter(nick_left), $&
   $modeprefix($1,$chan), $&
   $clr($theme_color(nick)),$1, $&
   $clr($theme_color(delimiter)),$theme_delimiter(nick_right), $&
   $clr $&
   )
}

$theme_system

Same purpose as $theme_nick, but used to return event names, ie. [join] with colors

alias theme_system {
 ;this alias returns colored system messages. ie: highlight, topic, etc.
 ;with custom delimiter


 return $+( $&
   $clr($theme_color(sysdelimiter)),$theme_delimiter(sys_left), $&
   $clr($theme_color(sysmsg)),$1, $&
   $clr($theme_color(delimiter)),$theme_delimiter(sys_right), $&
   $clr $&
   )
}

Events

These are the modified events to prevent mIRC from showing default text, and echo messages the way we want. Here are only a few common events, some of them even are a bit repetitive, but should give you an expression on how to handle the events.

On Start

For on start event, i only set the timestamp at this point.

on *:start:{ 
 ;we'll set this timestamp everytime when you start mirc, so the colors won't disappear
 ;i'm using timestamp format HH:nn:ss in here, you can ofcourse change it to whatever you like (/help time and date identifiers for format) 
 ;note that you shouldn't add ( and ) around the timestamp, since they are already in a variable (which you can change).
 .timestamp -f $+( $&
   $clr($theme_color(timestamp)),$theme_delimiter(ts_left), $&
   HH:nn:ss, $&
   $theme_delimiter(ts_right), $&
   $clr) 
}

On Input

Replacing our own input. We will be sending the same line we input, but echo a modified line. Note that on input event won't need ^ to trigger before default actions.

on *:INPUT:*: {
 ;we will check that ctrl wasn't pressed while pressing enter, and that it's not a command
 if ($left($1,1) === $readini(mirc.ini,text,commandchar)) && (!$ctrlenter) { return }

 ;halt the default actions
 haltdef

 ;we'll put the line into a variable, in case we want to modify it for the echo
 ;in this case i have an alias called urlc to underline and color links
 var %line = $urlc($1-)

 ;here is the part what we send as msg, we want to send $1- and not the modified variable
 .msg $target $1-

 ;then we have the echo, where we get to use $theme_nick, which returns
 ;modeprefix, and the brackets around the nick (see above)
 echo $color(own text) -at $theme_nick($nick) %line 
}

On Text (channel)

Replacing incoming text from a channel. Here we also make our own highlight system.

on ^*:TEXT:*:#: {
 ;again halt the default actions and assign $1- into a variable
 haltdef
 var %line = $urlc($1-)

 ;a regular expression to check if the line contains your nick
 ;triggers for Cail, Caili, Cail:, Caili: basically nick + 2 characters 
 ;('i' in [i,$chr(44),:] is 'cause i'm sometimes referred to Caili, you can ofcourse remove it, or change it/add other characters)

 var %hlpattern = $+(/(^|\s),$me,([i,$chr(44),:]{0,2})?\b/i)
 if ($regex($1-,%hlpattern)) {

   ;if the active window isn't the same as the window where the highlight was; echo it to the active
   if ($active != $chan) { echo -at $theme_system(highlight,highlight) $+($chan,/,$nick,:) %line }

   echo $color(highlight) -mt $chan $theme_nick($nick) %line
 }
 else {
   echo $color(normal text) -mt $chan $theme_nick($nick) %line
 }
} 

On Text (query)

Replacing incoming text from query.

on ^*:TEXT:*:?: {
 ;halt default actions, and set $1- into a variable
 haltdef
 var %line = $urlc($1-)

 echo $color(normal text) -mt $nick $theme_nick($nick) %line
}

On Action

Replacing action texts.

on ^*:ACTION:*:*: {
 haltdef

 ;if you like to see actions like: timestamp * nick does stuff, you can add ; in front of the 1st line and
 ;take it off from the 2nd

 echo $color(action text) -mt $iif($chan,$chan,$nick) $theme_system(action) $nick $1-
 ;echo $color(action text) -mt $iif($chan,$chan,$nick) * $nick $1-
}

On Join

Replacing join event. Also modified to show "Nick sets usermode +x", so you don't have to see the quit and join when a user sets mode +x.

Before:

(1359 04) [quit] Cail ~user@dsl-xx-xx-xx-xx.dhcp.inet.fi Registered
(1359 04) [join] Cail ~user@Cail.users.quakenet.org

After:

(1400 46) [usermode] Cail sets usermode +x

On to the script:

on ^*:JOIN:#: { 
 haltdef

 ;if it's you who joins the chan, echo "You have entered #channel"
 if ($nick == $me) {
   echo $color(join) -t $chan $theme_system(join) You have entered $chan
 }

 ;else if the nick has quit setting usermode +x
 ;show "Nick sets usermode +x" instead of quit and join
 elseif ($($+($(%registered.,0),$cid,.,$nick),2)) {
   echo $color(join) -t $chan $theme_system(usermode) $nick sets usermode +x
 } 

 ;else show the normal join
 else {
   echo $color(join) -t $chan $theme_system(join) $nick $site 
 }
}

On Part

Replacing part event (! means it won't trigger if you part).

on !^*:PART:#: {
 ;this event only triggers if someone else parts
 haltdef
 var %message = $1-
 echo $color(part) -t $chan $theme_system(part) $nick $site %message
}

On Quit

Replacing quit event, "Registered quits" aren't shown. This event works in conjunction with on join event to hide the quit and join when a user sets mode +x (see above). We have to use $comchan in here, since $chan doesn't exist in on quit event

on ^*:QUIT: {
 haltdef

 ;check if the quit message is "registered", this means the user is setting usermode +x
 ;we don't show the quit here, we only show "Nick sets usermode +x" when the user joins back

 if ($1 == registered) { 
   ;set a variable for ConnectionID and nick that unsets after 5 seconds.
   set -u5 $($+($(%registered.,0),$cid,.,$nick),1) $true
 } 

 ;else the quit is normal, and is looped through $comchans
 ;and echoed into each channel

 else { 
   var %message = $1-
   var %x = 1
   while ($comchan($nick,%x)) {
     echo $color(quit) -t $comchan($nick,%x) $theme_system(quit) $nick $address %message 
     inc %x 
   }
 }
}

On Kick

Replacing kick event, "you kicked", "you were kicked" and "someone was kicked by somebody".

on ^*:KICK:#: {
 ;halt default actions and assign kick message into a variable
 haltdef
 var %message = $1-

 ;check if you were kicked
 if ($knick == $me) { 
   echo $color(kick) -t $chan $theme_system(kick) You were kicked from $chan by $nick $+ : %message  
 }

 ;else if you kicked someone
 elseif ($nick == $me) { 
   echo $color(kick) -t $chan $theme_system(kick) You kicked $knick from $chan $+ : %message 
 }

 ;else someone else kicked someone else
 else {
   echo $color(kick) -t $chan $theme_system(kick) $knick was kicked from $chan by $nick $+ : %message
 }
}

On Nick

Replacing nick event, "you morphed to Somenick" and "Someone morphed to Someguy". Another place to use $comchan.

on ^*:NICK: {
 haltdef

 ;see if it's you who changed the nick and loop through all the channels
 if ($nick == $me) { 
   var %chans = 1
   while ($chan(%chans)) {
     echo $color(nick) -t $chan(%chans) $theme_system(nick) You morphed to $newnick
     inc %chans 
   }
 }

 ;else it's someone else who changed the nick, now we have to loop through $comchans
 else {
   var %chans = 1
   while ($comchan($newnick,%chans) ) {
     echo $color(nick) -t $comchan($newnick,%chans) $theme_system(nick) $nick morphed to $newnick
     inc %chans 
   }
 }
}

On Notice

Replacing notice event.

on ^*:NOTICE:*:?: {
 ;halt default actions, assign $1- into a var and acho notice into active window
 haltdef
 var %line = $urlc($1-)

 echo $color(notice) -at $theme_system(notice) $nick $+ : %line
}

On Open (Query)

Adding irssi-style "session started with $nick" to on open event.

on *:open:?:*:{ 
 ;we're gonna echo irssi-style "session started with $nick" when someone querys you

 echo $color(info text) -t $nick $theme_system(query) session started with $nick
}

On Rawmode

We're using rawmode to affect all the mode changes at the same, you can ofcourse do ON OP, ON VOICE, and other events if you wish to do them differently.

on ^*:RAWMODE:#: {
 haltdef

 ;we'll check if you are affected by the mode change, and highlight the text if so
 if ($me isin $1-) {
   echo $color(highlight) -t $chan $theme_system(chan mode) $nick sets mode: $1- on $chan

   ;if the active window isn't the same as the window where the highlight was; echo it to the active
   ;you can take this off if you don't like to see it coming into active window
   if ($active != $chan) { echo $color(highlight) -at $theme_system(chan mode) $nick sets mode: $1- on $chan }
 }

 ;else, it doesn't affect you
 else {
   echo $color(mode) -t $chan $theme_system(chan mode) $nick sets mode: $1- on $chan
 }
}

On Topic

We'll handle topic in 2 different places now, the other is on topic to see the topic changes, and other is raw's 331, 332 and 333, which are returned by /topic #channel when joining a channel.

on ^*:TOPIC:#: {
 haltdef 

 ;check if there are no words, ($0 returns tokens seperated by $chr(32)), if this happens, the topic has been cleared
 if ($0 == 0) { 
   echo $color(topic) -mt $chan $theme_system(topic) $chan $+ : $nick clears the topic
 }

 ;else the topic is set or changed
 else { 
   echo $color(topic) -mt $chan $theme_system(topic) $chan $+ : $nick changes topic to $chr(34) $+ $1- $+ $chr(15) $+ $chr(34)
 }
}


Raws

I'm not gonna add all of the raw events here, only a few common ones, like whois and topic. You should check Raws-section for more information on raws.

Whois

;raw 311 returns name and host after /whois
raw 311:*:{ 
 haltdef

 ;we'll echo a system message "whois Nick", name and host into seperate lines 
 echo $color(whois) -at $theme_system(whois $2) 
 echo $color(whois) -at - name: $6- 
 echo $color(whois) -at - host: $3 $+ @ $+ $4
}

;raw 319 returns channels where the user is
raw 319:*:{
 haltdef 
 var %x = 1,%chans

 ;we loop through the channels and put some colors to modeprefix and comchans
 while (%x <= $numtok($3-,32)) {
   %chan = $gettok($3-,%x,32)
   %mode = $iif($left(%chan,1) != $chr(35),$+($clr(3),$left(%chan,1),$clr),)
   %chan = $iif($left(%chan,1) != $chr(35),$right(%chan,-1),%chan)
   %chan = %mode $+ $iif($me ison %chan,$+($clr(12),%chan,$clr),%chan)
   %chans = %chans %chan
   inc %x
 }

 ;we also echo how many channels the user is seen on
 echo $color(whois) -at - chans $+($chr(40),$numtok($3-,32),$chr(41),) %chans
}

;raw 312 returns the server that the user is connected to
raw 312:*:{ 
 haltdef
 echo $color(whois) -at - using $3- 
}

;raw 330 returns authname of the user (only in Quakenet)
raw 330:*: {
 haltdef
 echo $color(whois) -at - authed as $3 
}

;raw 317 returns idletime and signontime of the user
raw 317:*:{ 
 haltdef

 ;we will use $duration to calculate users idle and how long he has been connected to server
 echo $color(whois) -at - idle: $duration($3) $+ ,  irc: $duration($calc( $ctime - $4 )) $+ , signon: $date($4) $time($4)
}

;raw 313 returns if the user is an IRC operator on network
raw 313:*:{ 
 haltdef
 echo $color(whois) -at - $2 is an IRC operator on $network
}

;raw 318 is the "end of whois", i usually like to hide it, but you can take the ; off from the echo.
raw 318:*:{
 haltdef
 ;echo $color(whois) -at $theme_system(whois $2) 
}

Topic

This is the other modification we make to affect the topic. These raws are sent to you when you join a channel or do /topic #channel.

;raw 331 is returned when you join a channel, or when you do /topic #channel, you'll get this raw instead of raw 332 if there is no topic on the channel
raw 331:*: {
 haltdef
 echo $color(topic) -t $2 $theme_system(topic,topic) No topic is set for $2
}

;raw 332 is the same as raw 331, but returns the topic if it's set
raw 332:*: {
 haltdef
 echo $color(topic) -t $2 $theme_system(topic,topic) Topic is " $+ $3- $+ $chr(15) $+ "
}

;raw 333 returns who set the topic and when, after joining a channel or by /topic #channel
raw 333:*: {
 haltdef
 echo $color(topic) -t $2 $theme_system(topic,topic) Topic set by $gettok($3,1,33) on $asctime($4)
}


Own input

These are just modified aliases to match the theme, you can modify other aliases the same way.

/query

Here we also add the irssi-style "session started with Someone", this can be used /query nick blaa blaa, or by doubleclicking a nick in nicklist or channel (if you have doubleclick action set to /query $$1 in options, alt+o -> mouse)

alias query {
 ;first, a silent query to open the chatwindow, we don't want to send anything yet
 .query $$1

 ;we're adding the irssi-style "session started with Someone"
 echo $color(info) -t $$1 $theme_system(query) session started with $$1

 ;now we check if we had anything to send, if so, we'll do a silent msg for the nick
 if ($2) { 
   .msg $$1 $2-
   echo $color(own text) -t $$1 $theme_nick($me) $2- 
 }
}

/me

This is quite a simple modification, pretty much all the aliases are modified the same way.

alias me { 
 ;silent /me $1- and echo, here you can also choose to show it like: * Nick does some action
 ;or by the theme

 .me $1- 
 echo $color(action) -at $theme_system(action) $me $1- 
 ;echo $color(action) -at * $me $1-
}

/notice

Yet one simple modification.

alias notice { 
 ;same goes for notice, we don't need to add haltdef's here since we do the commands silent
 .notice $$1 $2-
 echo $color(notice) -t $theme_system(notice) $$1 $+ : $2- 
}

Miscellaneous

Now you should be able to continue modifying other events and aliases on your own, here are just a few tips what you can do.

How to pad text, example:

1717 48           Cail@ » hello
1718 01            Anu+ » hello
1718 03           Cail@ » ahii
1718 32       chan mode » @Cail sets mode: +o Anu: #channel

Since you cannot do that with $chr(32), you'll need to use $chr(160), and calculate how many of those you need to put before the nick:

$str($chr(160),$calc(15 - $len($nick))) $nick

15 is the maximum nickname length in Quakenet (you might set this into a variable when you connect to a server).

This way, all the nicknames will end in same place. Of course you can do variations of this method like:

1717 48 @Cail           » hello
1718 01 +Anu            » hello
1718 03 @Cail           » ahii
1718 32 chan mode       » @Cail sets mode: +o Anu: #channel

This is a basic example so you get the idea. Ideally you would use $nick($chan,$nick).pnick instead of $nick and increase the maximum nick length number (15 in this example) by 1 to account for a possible mode prefix like @ or +. You should only do this for channel text though, since there is no mode prefix on queries.