Project

General

Profile

[Script] Convert hexchat theme to MTS theme (BETA) » convert_hexchat_theme.ini

Per Amundsen, 06/07/2018 06:50 AM

 
alias converttheme {
var %colorfile $adiircdircolors.conf
var %eventfile $adiircdirpevents.conf
; Set theme name
var %themename HexTheme
var %themefolder $adiircdirThemes\ $+ %themename
if (!$exists(%themefolder)) {
mkdir %themefolder
}

set %themepath $qt(%themefolder $+ \ $+ %themename $+ .mts)
write -c %themepath [mts]
write -a %themepath Name HexTheme
write -a %themepath FontDefault Consolas,10
write -a %themepath NickColumn ON
write -a %themepath Timestamp ON
if ($hget(themecolors)) {
hfree themecolors
}
hmake themecolors
var %s 0, %c = $lines(%colorfile)
while (%s < %c) {
inc %s
var %text = $read(%colorfile, %s)
hadd themecolors $gettok(%text, 1, 61) $rgb($getcolor($gettok($gettok(%text, 2, 61), 1, 32)), $getcolor($gettok($gettok(%text, 2, 61), 2, 32)), $getcolor($gettok($gettok(%text, 2, 61), 3, 32)))
}
var %s 0, %rgbcolors
; Add mirc colors (0-15)
while (%s < 16) {
inc %s
%rgbcolors = %rgbcolors $rgb($hget(themecolors, color_ $+ $calc(%s - 1)))
}
; Add messages forecolor
%rgbcolors = %rgbcolors 17= $+ $rgb($hget(themecolors, color_258))
; Add messages backcolor
%rgbcolors = %rgbcolors 22= $+ $rgb($hget(themecolors, color_259))
; Add unread line marker color
%rgbcolors = %rgbcolors 78= $+ $rgb($hget(themecolors, color_260))
; Add selected messages forecolor
%rgbcolors = %rgbcolors 121= $+ $rgb($hget(themecolors, color_256))
; Add selected messages backcolor
%rgbcolors = %rgbcolors 120= $+ $rgb($hget(themecolors, color_257))
; Add selected nicklist forecolor
%rgbcolors = %rgbcolors 123= $+ $rgb($hget(themecolors, color_256))
; Add selected nicklist backcolor
%rgbcolors = %rgbcolors 122= $+ $rgb($hget(themecolors, color_257))
writeline RGBColors %rgbcolors
; Messages colors
; 16 forecolor/normal (because N + 1)
; 21 backcolor (because N + 1)
var %s 0, %colors = 21,
while (%s < 20) {
inc %s
%colors = %colors $+ 16 $+ ,
}
; Topicbox/Editbox back color
%colors = %colors $+ 21 $+ ,
; Topicbox/Editbox fore color
%colors = %colors $+ 16 $+ ,

; Nicklist back color
%colors = %colors $+ 21 $+ ,

; Nicklist fore color
%colors = %colors $+ 16 $+ ,
writeline Colors %colors
var %s 0, %c = $lines(%eventfile)
; Convert events to MTS format
while (%s < %c) {
inc %s
var %text = $read(%eventfile, n, %s)
if (event_name=Change Nick == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline Nick $replace_control_codes(%text2, <nick>, <newnick>)
}
else if (event_name=Your Nick Changing == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline NickSelf $replace_control_codes(%text2, <nick>, <newnick>)
}
else if (event_name=Channel Action == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline ActionChan $replace_control_codes(%text2, <nick>, <text>)
; No equal in hex, use Channel Action syntax instead
writeline ActionChanSelf $replace_control_codes(%text2, <me>, <text>)
}
else if (event_name=Channel Message == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline TextChan $replace_control_codes(%text2, <nick>, <text>)
}
else if (event_name=Private Message to Dialog == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline TextQuery $replace_control_codes(%text2, <nick>, <text>)
}
else if (event_name=Your Message == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline TextChanSelf $replace_control_codes(%text2, <me>, <text>)
}
else if (event_name=Message Send == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline TextQuerySelf $replace_control_codes(%text2, <me>, <text>)
}
else if (event_name=Part == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline Part $replace_control_codes(%text2, <nick>, <address>, <chan>)
}
else if (event_name=Quit == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline Quit $replace_control_codes(%text2, <nick>, <text>)
}
else if (event_name=Join == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline Join $replace_control_codes(%text2, <nick>, <chan>, <address>)
}
else if (event_name=You Join == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline JoinSelf $replace_control_codes(%text2, <nick>, <chan>, <address>)
}
else if (event_name=Topic == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline RAW.332 $replace_control_codes(%text2, <chan>, <text>)
}
else if (event_name=Topic Creation == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline RAW.333 $replace_control_codes(%text2, <chan>, <nick>, <text>)
}
else if (event_name=Topic Change == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline Topic $replace_control_codes(%text2, <nick>, <text>, <address>)
}
else if (event_name=Kick == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline Kick $replace_control_codes(%text2, <nick>, <knick>, <chan>, <text>, <address>)
}
else if (event_name=You Kicked == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline KickSelf $replace_control_codes(%text2, <nick>, <chan>, <nick>, <text>)
}
else if (event_name=Channel Mode Generic == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline Mode $replace_control_codes(%text2, <nick>, <modes>)
; Abusing this for user modes as well
writeline ModeUser $replace_control_codes(%text2, <nick>, <modes>)
}
else if (event_name=CTCP Generic == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline Ctcp $replace_control_codes(%text2, <ctcp>, <nick>)
}
else if (event_name=CTCP Send == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline CtcpSelf $replace_control_codes(%text2, <target>, <ctcp> <text>)

; Abusing this for chan self as well
writeline CtcpChanSelf $replace_control_codes(%text2, <target>, <ctcp> <text>)
}
else if (event_name=Channel Notice == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline NoticeChan $replace_control_codes(%text2, <nick>, <chan>, <text>)
}
else if (event_name=Notice == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline Notice $replace_control_codes(%text2, <nick>, <text>)
; Same syntax is used for ctcp replies
writeline CtcpReply $replace_control_codes(%text2, <nick>, <ctcp> <text>)
}
else if (event_name=Server Notice == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline NoticeServer $replace_control_codes(%text2, <text>)
}
else if (event_name=Notice Send == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline NoticeSelf $replace_control_codes(%text2, <target>, <text>)
; No equal in hex, use Notice Send syntax instead
writeline NoticeSelfChan $replace_control_codes(%text2, <target>, <text>)
}
else if (event_name=WhoIs Away Line == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline RAW.301 $replace_control_codes(%text2, <nick>, <text>)
}
else if (event_name=WhoIs Channel/Oper Line == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline RAW.313 $replace_control_codes(%text2, <nick>, <operline>)
writeline RAW.319 $replace_control_codes(%text2, <nick>, <chan>)
}
else if (event_name=WhoIs End == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline RAW.318 $replace_control_codes(%text2, <nick>)
}
else if (event_name=WhoIs Identified == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline RAW.307 $replace_control_codes(%text2, <nick>, <text>)
writeline RAW.320 $replace_control_codes(%text2, <nick>, <text>)
}
else if (event_name=WhoIs Authenticated == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline RAW.330 $replace_control_codes(%text2, <nick>, <text>, <authnick>)
}
else if (event_name=WhoIs Idle Line with Signon == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline RAW.317 $replace_control_codes(%text2, <nick>, <idletime>, <signontime>)
}
else if (event_name=WhoIs Name Line == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline RAW.311 $replace_control_codes(%text2, <nick>, <userident>, <userhost>, <realname>)
writeline RAW.314 $replace_control_codes(%text2, <nick>, <userident>, <userhost>, <realname>)
}
else if (event_name=WhoIs Server Line == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline RAW.312 $replace_control_codes(%text2, <nick>, <text>)
}
else if (event_name=Channel Modes == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline RAW.324 $replace_control_codes(%text2, <chan>, <modes>)
}
else if (event_name=Channel Creation == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline RAW.329 $replace_control_codes(%text2, <chan>, <value>)
}
else if (event_name=Motd == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline RAW.372 $replace_control_codes(%text2, <text>)
}
else if (event_name=MOTD Skipped == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline RAW.376 $replace_control_codes(%text2, <text>)
writeline RAW.422 $replace_control_codes(%text2, <text>)
}
else if (event_name=Connected == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline Logon $replace_control_codes(%text2)
}
else if (event_name=Disconnected == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline Disconnect $replace_control_codes(%text2)
}
else if (event_name=Server Error == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline ServerError $replace_control_codes(%text2, <text>)
}
else if (event_name=Connection Failed == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline ConnectError $replace_control_codes(%text2, <text>)
}
else if (event_name=Server Text == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
; Hack, read up to $t to get "server prefix"
; Look for the $T nick column variable
var %pos $pos(%text2, $ $+ T, 1)
if (%pos > 1) {
%text2 = $left(%text2, $calc(%pos - 1))
writeline PrefixSys $replace_control_codes(%text2)
}
}
else if (event_name=Ban List == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
; Uses same format for all list types
writeline RAW.367 $replace_control_codes(%text2, <chan>, <address>, <nick>, <bantime>)
writeline RAW.348 $replace_control_codes(%text2, <chan>, <address>, <nick>, <bantime>)
writeline RAW.346 $replace_control_codes(%text2, <chan>, <address>, <nick>, <bantime>)
writeline RAW.728 $replace_control_codes(%text2, <chan>, <address>, <nick>, <bantime>)
}
else if (event_name=Channel List == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline RAW.321 $replace_control_codes(%text2)
}
else if (event_name=Receive Wallops == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline Wallop $replace_control_codes(%text2, <nick>, <text>)
}
else if (event_name=Keyword == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline RAW.475 $replace_control_codes(%text2, <chan>)
}
else if (event_name=Banned == %text) {
inc %s
var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
writeline RAW.474 $replace_control_codes(%text2, <chan>)
}
}
hfree themecolors
unset %themepath
echo -ag $prefixsys Conversion done
}

alias -l getcolor {
return $int($calc($base($1,16,10) / 257))
}

alias -l writeline {
; echo -ag $1-
write -a %themepath $1-
}

alias -l replace_control_codes {

; Replace "local colors" 16 to 31 with direct rgb values instead
var %text = $regsubex($1, /%C(1[6-9]|2[0-9]|3[01])/, $chr(4) $+ $rgb($hget(themecolors, \1)).hex)
; Look for the $T nick column variable
var %pos $pos(%text, $ $+ T, 1)
if (%pos == 1) {
; Add a fake whitespace before nick column
%text = $chr(160) $replace(%text, $ $+ T,)
}
else if (%pos > 1) {
; Remove spaces with fake whitespace in the left of nick column text
%text = $replace($left(%text, $calc(%pos - 1)), $chr(32), $chr(160)) $right(%text, $calc($len(%text) - %pos - 1))
}

; Replace control codes variables and $N variables with similar MTS %::variables
%text = $replacex(%text, % $+ B, $chr(2), % $+ U, $chr(31),% $+ O, $chr(15),% $+ C, $chr(3), $ $+ 1, $2, $ $+ 2, $3, $ $+ 3, $4, $ $+ 4, $5)
return %text
}
    (1-1/1)