Difference between revisions of "How to make your own theme"

From Scriptwiki
Jump to: navigation, search
m (added a space)
m (updated the regex on urlc alias)
Line 70: Line 70:
 
   
 
   
 
   ;check with regex if the line includes <nowiki>www. or http://</nowiki>
 
   ;check with regex if the line includes <nowiki>www. or http://</nowiki>
   if ($regex(%line,(<nowiki>\bwww\.|http:\/\/</nowiki>))) {
+
   if ($regex(%line,(<nowiki>/(\b(www.?\.|https?:\/\/|ftp:\/\/).)/i</nowiki>))) {
 
   
 
   
 
     var %x = 1  
 
     var %x = 1  

Revision as of 13:41, 10 January 2007

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 off with some variables, you can copy this alias, change the variables to whatever you like and run it by writing /setvars, you can leave some of the variables blank like %delimiter_timestamp_left and %delimiter_timestamp_right, so there won't be anything around the timestamp, the color variables should be set though. Everytime you change these, you'll need to run the alias again.

alias setvars {
 ;color of timestamp
 set %color_timestamp 03

 ;color of @-prefix
 set %color_op 10

 ;color of +-prefix
 set %color_voice 11

 ;color of %-prefix
 set %color_hop 06

 ;color of nick 
 set %color_nick 14

 ;color of link
 set %color_link 07

 ;color of left and right delimiters ie: <nick> (the < and > in there)
 set %color_delimiter 05

 ;color of event name
 set %color_sysmsg 04

 ;color of system message delimiter ie: [highlight] (the [ and ] in there)
 set %color_system_delimiter 05

 ;left delimiter of system messages ($chr(91) = [ and $chr(93) = ])
 set %delimiter_system_left $chr(91)

 ;right delimiter of system messages
 set %delimiter_system_right $chr(93)

 ;left delimiter of timestamp
 set %delimiter_timestamp_left (

 ;right delimiter of timestamp
 set %delimiter_timestamp_right )

 ;left delimiter of nick
 set %delimiter_left (

 ;right delimiter of nick
 set %delimiter_right )
}

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

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),(www\.|http:\/\/))) { 
       ;put some colors and underline to the link, $chr(31) is the underline
       var %l2 = $+($clr(%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(%color_op),@,$clr), $&
   +,$+($clr(%color_voice),+,$clr), $&
   %,$+($clr(%color_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

 ;use the mirc event colors for text color, we need to replace rawmode with mode to get the correct color, we also don't want to trigger for raws
 ;and we check if $2 is set, so we can set the event color if we want to; ie. $theme_nick(Nick,own text)

 if (($event) && ($event != text) && ($event !isnum)) || ($2) { var %event_color = $color($replace($iif($2,$2,$event),rawmode,mode)) }

 return $+( $&
   $clr(%color_delimiter),%delimiter_left, $&
   $modeprefix($1,$chan), $&
   $clr(%color_nick),$1, $&
   $clr(%color_delimiter),%delimiter_right, $&
   $clr(%event_color) $&
   )
}

$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

 ;this is the same if-statement as with the $theme_nick to set the text color.
 ;ie. $theme_system(topic) = in on topic event we can return [topic], $event will be topic, so the color will be "Topic text" from mirc color settings
 ;but in raw 332 (which returns the topic), $event will be "332", not "topic", so we have to use $theme_system(topic,topic) to set the right color

 if (($event) && ($event != text) && ($event !isnum)) || ($2) { var %event_color = $color($replace($iif($2,$2,$event),rawmode,mode)) }

 return $+( $&
   $clr(%color_system_delimiter),%delimiter_system_left, $&
   $clr(%color_sysmsg),$1, $&
   $clr(%color_system_delimiter),%delimiter_system_right, $&
   $clr(%event_color) $&
   )
}

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(%color_timestamp),%delimiter_timestamp_left, $&
   HH:nn:ss, $&
   %delimiter_timestamp_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 -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:, basically nick + 1 character (though some exceptions, like Cail:::)
 if ($regex($1-,$+(/\b,$me,.?\b/i))) {

   ;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 -mt $chan $theme_nick($nick,highlight) %line
 }
 else {
   echo -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 -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 -mt $iif($chan,$chan,$nick) $theme_system(action) $nick $1-
 ;echo -mt $iif($chan,$chan,$nick) $+($clr($color(Action text)),*) $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 -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 -t $chan $theme_system(usermode) $nick sets usermode +x
 } 

 ;else show the normal join
 else {
   echo -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 -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 -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 -t $chan $theme_system(kick) You were kicked from $chan by $nick $+ : %message  
 }

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

 ;else someone else kicked someone else
 else {
   echo -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 -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 -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 -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 -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 -t $chan $theme_system(chan mode,highlight) $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 -at $theme_system(chan mode,highlight) $nick sets mode: $1- on $chan }
 }

 ;else, it doesn't affect you
 else {
   echo -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 -mt $chan $theme_system(topic) $chan $+ : $nick clears the topic
 }

 ;else the topic is set or changed
 else { 
   echo -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 -at $theme_system(whois $2) 
 echo -at - name: $6- 
 echo -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 -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 -at - using $3- 
}

;raw 330 returns authname of the user (only in Quakenet)
raw 330:*: {
 haltdef
 echo -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 -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 (quite rare ;)
raw 313:*:{ 
 haltdef
 echo -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 -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 -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 -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 -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 -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 -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 -at $theme_system(action,action) $me $1- 
 ;echo -at $+($clr($color(Action text)),*) $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 -t $theme_system(notice,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 max. lenght of nickname 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. Ofcourse 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