Project

General

Profile

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

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

 
1
´╗┐alias converttheme {
2
  var %colorfile $adiircdircolors.conf
3
  var %eventfile $adiircdirpevents.conf
4
  
5
  ; Set theme name
6
  var %themename HexTheme
7
  
8
  var %themefolder $adiircdirThemes\ $+ %themename
9
  
10
  if (!$exists(%themefolder)) {
11
    mkdir %themefolder
12
  }
13

    
14
  set %themepath $qt(%themefolder $+ \ $+ %themename $+ .mts)
15
  
16
  write -c %themepath [mts]
17
  write -a %themepath Name HexTheme
18
  write -a %themepath FontDefault Consolas,10  
19
  write -a %themepath NickColumn ON
20
  write -a %themepath Timestamp ON
21
  
22
  if ($hget(themecolors)) {
23
    hfree themecolors
24
  }
25
  
26
  hmake themecolors
27
  var %s 0, %c = $lines(%colorfile)
28
  
29
  while (%s < %c) {
30
    inc %s
31
    var %text = $read(%colorfile, %s)
32
    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)))
33
  }
34
  
35
  var %s 0, %rgbcolors
36
  
37
  ; Add mirc colors (0-15)
38
  while (%s < 16) {
39
    inc %s
40
    
41
    %rgbcolors = %rgbcolors $rgb($hget(themecolors, color_ $+ $calc(%s - 1)))
42
  } 
43
  
44
  ; Add messages forecolor
45
  %rgbcolors = %rgbcolors 17= $+ $rgb($hget(themecolors, color_258))
46
  
47
  ; Add messages backcolor
48
  %rgbcolors = %rgbcolors 22= $+ $rgb($hget(themecolors, color_259))
49
  
50
  ; Add unread line marker color
51
  %rgbcolors = %rgbcolors 78= $+ $rgb($hget(themecolors, color_260))
52
  
53
  ; Add selected messages forecolor
54
  %rgbcolors = %rgbcolors 121= $+ $rgb($hget(themecolors, color_256))
55
  
56
  ; Add selected messages backcolor
57
  %rgbcolors = %rgbcolors 120= $+ $rgb($hget(themecolors, color_257))
58
  
59
  ; Add selected nicklist forecolor
60
  %rgbcolors = %rgbcolors 123= $+ $rgb($hget(themecolors, color_256))
61
  
62
  ; Add selected nicklist backcolor
63
  %rgbcolors = %rgbcolors 122= $+ $rgb($hget(themecolors, color_257))
64
  
65
  writeline RGBColors %rgbcolors
66
  
67
  ; Messages colors
68
  ; 16 forecolor/normal (because N + 1)
69
  ; 21 backcolor (because N + 1)
70
  var %s 0, %colors = 21,
71
  while (%s < 20) {
72
    inc %s
73
    
74
    %colors = %colors $+ 16 $+ ,
75
  }
76
  
77
  ; Topicbox/Editbox back color
78
  %colors = %colors $+ 21 $+ ,
79
  
80
  ; Topicbox/Editbox fore color
81
  %colors = %colors $+ 16 $+ ,
82

    
83
  ; Nicklist back color
84
  %colors = %colors $+ 21 $+ ,
85

    
86
  ; Nicklist fore color
87
  %colors = %colors $+ 16 $+ ,
88
      
89
  writeline Colors %colors
90
  
91
  var %s 0, %c = $lines(%eventfile)
92
  
93
  ; Convert events to MTS format
94
  while (%s < %c) {
95
    inc %s
96
    var %text = $read(%eventfile, n, %s)
97
    
98
    if (event_name=Change Nick == %text) {
99
      inc %s
100
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
101
      
102
      writeline Nick $replace_control_codes(%text2, <nick>, <newnick>)
103
    }
104
    else if (event_name=Your Nick Changing == %text) {
105
      inc %s
106
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
107
      
108
      writeline NickSelf $replace_control_codes(%text2, <nick>, <newnick>)
109
    }
110
    else if (event_name=Channel Action == %text) {
111
      inc %s
112
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
113
      
114
      writeline ActionChan $replace_control_codes(%text2, <nick>, <text>)
115
      
116
      ; No equal in hex, use Channel Action syntax instead
117
      writeline ActionChanSelf $replace_control_codes(%text2, <me>, <text>)
118
    }
119
    else if (event_name=Channel Message == %text) {
120
      inc %s
121
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
122
      
123
      writeline TextChan $replace_control_codes(%text2, <nick>, <text>)
124
    }
125
    else if (event_name=Private Message to Dialog == %text) {
126
      inc %s
127
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
128
      
129
      writeline TextQuery $replace_control_codes(%text2, <nick>, <text>)
130
    }
131
    else if (event_name=Your Message == %text) {
132
      inc %s
133
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
134
      
135
      writeline TextChanSelf $replace_control_codes(%text2, <me>, <text>)
136
    }
137
    else if (event_name=Message Send == %text) {
138
      inc %s
139
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
140
      
141
      writeline TextQuerySelf $replace_control_codes(%text2, <me>, <text>)
142
    }
143
    else if (event_name=Part == %text) {
144
      inc %s
145
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
146
      
147
      writeline Part $replace_control_codes(%text2, <nick>, <address>, <chan>)
148
    }
149
    else if (event_name=Quit == %text) {
150
      inc %s
151
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
152
      
153
      writeline Quit $replace_control_codes(%text2, <nick>, <text>)
154
    }
155
    else if (event_name=Join == %text) {
156
      inc %s
157
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
158
      
159
      writeline Join $replace_control_codes(%text2, <nick>, <chan>, <address>)
160
    }
161
    else if (event_name=You Join == %text) {
162
      inc %s
163
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
164
      
165
      writeline JoinSelf $replace_control_codes(%text2, <nick>, <chan>, <address>)
166
    }
167
    else if (event_name=Topic == %text) {
168
      inc %s
169
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
170
      
171
      writeline RAW.332 $replace_control_codes(%text2, <chan>, <text>)
172
    }
173
    else if (event_name=Topic Creation == %text) {
174
      inc %s
175
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
176
      
177
      writeline RAW.333 $replace_control_codes(%text2, <chan>, <nick>, <text>)
178
    }
179
    else if (event_name=Topic Change == %text) {
180
      inc %s
181
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
182
      
183
      writeline Topic $replace_control_codes(%text2, <nick>, <text>, <address>)
184
    }
185
    else if (event_name=Kick == %text) {
186
      inc %s
187
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
188
      
189
      writeline Kick $replace_control_codes(%text2, <nick>, <knick>, <chan>, <text>, <address>)
190
    }
191
    else if (event_name=You Kicked == %text) {
192
      inc %s
193
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
194
      
195
      writeline KickSelf $replace_control_codes(%text2, <nick>, <chan>, <nick>, <text>)
196
    }
197
    else if (event_name=Channel Mode Generic == %text) {
198
      inc %s
199
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
200
      
201
      writeline Mode $replace_control_codes(%text2, <nick>, <modes>)
202
      
203
      ; Abusing this for user modes as well
204
      writeline ModeUser $replace_control_codes(%text2, <nick>, <modes>)
205
    }
206
    else if (event_name=CTCP Generic == %text) {
207
      inc %s
208
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
209
      
210
      writeline Ctcp $replace_control_codes(%text2, <ctcp>, <nick>)
211
    }
212
    else if (event_name=CTCP Send == %text) {
213
      inc %s
214
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
215
      
216
      writeline CtcpSelf $replace_control_codes(%text2, <target>, <ctcp> <text>)
217

    
218
      ; Abusing this for chan self as well
219
      writeline CtcpChanSelf $replace_control_codes(%text2, <target>, <ctcp> <text>)
220
    }
221
    else if (event_name=Channel Notice == %text) {
222
      inc %s
223
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
224
      
225
      writeline NoticeChan $replace_control_codes(%text2, <nick>, <chan>, <text>)
226
    }
227
    else if (event_name=Notice == %text) {
228
      inc %s
229
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
230
      
231
      writeline Notice $replace_control_codes(%text2, <nick>, <text>)
232
      
233
      ; Same syntax is used for ctcp replies
234
      writeline CtcpReply $replace_control_codes(%text2, <nick>, <ctcp> <text>)
235
    }
236
    else if (event_name=Server Notice == %text) {
237
      inc %s
238
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
239
      
240
      writeline NoticeServer $replace_control_codes(%text2, <text>)
241
    }
242
    else if (event_name=Notice Send == %text) {
243
      inc %s
244
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
245
      
246
      writeline NoticeSelf $replace_control_codes(%text2, <target>, <text>)
247
      
248
      ; No equal in hex, use Notice Send syntax instead
249
      writeline NoticeSelfChan $replace_control_codes(%text2, <target>, <text>)
250
    }
251
    else if (event_name=WhoIs Away Line == %text) {
252
      inc %s
253
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
254
      
255
      writeline RAW.301 $replace_control_codes(%text2, <nick>, <text>)
256
    }
257
    else if (event_name=WhoIs Channel/Oper Line == %text) {
258
      inc %s
259
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
260
      
261
      writeline RAW.313 $replace_control_codes(%text2, <nick>, <operline>)
262
      writeline RAW.319 $replace_control_codes(%text2, <nick>, <chan>)
263
    }
264
    else if (event_name=WhoIs End == %text) {
265
      inc %s
266
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
267
      
268
      writeline RAW.318 $replace_control_codes(%text2, <nick>)
269
    }
270
    else if (event_name=WhoIs Identified == %text) {
271
      inc %s
272
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
273
      
274
      writeline RAW.307 $replace_control_codes(%text2, <nick>, <text>)
275
      writeline RAW.320 $replace_control_codes(%text2, <nick>, <text>)
276
    }
277
    else if (event_name=WhoIs Authenticated == %text) {
278
      inc %s
279
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
280
      
281
      writeline RAW.330 $replace_control_codes(%text2, <nick>, <text>, <authnick>)
282
    }
283
    else if (event_name=WhoIs Idle Line with Signon == %text) {
284
      inc %s
285
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
286
      
287
      writeline RAW.317 $replace_control_codes(%text2, <nick>, <idletime>, <signontime>)
288
    }
289
    else if (event_name=WhoIs Name Line == %text) {
290
      inc %s
291
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
292
      
293
      writeline RAW.311 $replace_control_codes(%text2, <nick>, <userident>, <userhost>, <realname>)
294
      writeline RAW.314 $replace_control_codes(%text2, <nick>, <userident>, <userhost>, <realname>)
295
    }
296
    else if (event_name=WhoIs Server Line == %text) {
297
      inc %s
298
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
299
      
300
      writeline RAW.312 $replace_control_codes(%text2, <nick>, <text>)
301
    }
302
    else if (event_name=Channel Modes == %text) {
303
      inc %s
304
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
305
      
306
      writeline RAW.324 $replace_control_codes(%text2, <chan>, <modes>)
307
    }
308
    else if (event_name=Channel Creation == %text) {
309
      inc %s
310
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
311
      
312
      writeline RAW.329 $replace_control_codes(%text2, <chan>, <value>)
313
    }
314
    else if (event_name=Motd == %text) {
315
      inc %s
316
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
317
      
318
      writeline RAW.372 $replace_control_codes(%text2, <text>)
319
    }
320
    else if (event_name=MOTD Skipped == %text) {
321
      inc %s
322
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
323
      
324
      writeline RAW.376 $replace_control_codes(%text2, <text>)
325
      writeline RAW.422 $replace_control_codes(%text2, <text>)
326
    }
327
    else if (event_name=Connected == %text) {
328
      inc %s
329
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
330
      
331
      writeline Logon $replace_control_codes(%text2)
332
    }
333
    else if (event_name=Disconnected == %text) {
334
      inc %s
335
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
336
      
337
      writeline Disconnect $replace_control_codes(%text2)
338
    }
339
    else if (event_name=Server Error == %text) {
340
      inc %s
341
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
342
      
343
      writeline ServerError $replace_control_codes(%text2, <text>)
344
    }
345
    else if (event_name=Connection Failed == %text) {
346
      inc %s
347
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
348
      
349
      writeline ConnectError $replace_control_codes(%text2, <text>)
350
    }
351
    else if (event_name=Server Text == %text) {
352
      inc %s
353
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
354
      
355
      ; Hack, read up to $t to get "server prefix"          
356
      ; Look for the $T nick column variable
357
      var %pos $pos(%text2, $ $+ T, 1)
358
    
359
      if (%pos > 1) {
360
        %text2 = $left(%text2, $calc(%pos - 1))
361
        writeline PrefixSys $replace_control_codes(%text2)
362
      }
363
    }
364
    else if (event_name=Ban List == %text) {
365
      inc %s
366
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
367
      
368
      ; Uses same format for all list types
369
      writeline RAW.367 $replace_control_codes(%text2, <chan>, <address>, <nick>, <bantime>)
370
      writeline RAW.348 $replace_control_codes(%text2, <chan>, <address>, <nick>, <bantime>)
371
      writeline RAW.346 $replace_control_codes(%text2, <chan>, <address>, <nick>, <bantime>)
372
      writeline RAW.728 $replace_control_codes(%text2, <chan>, <address>, <nick>, <bantime>)
373
    }
374
    else if (event_name=Channel List == %text) {
375
      inc %s
376
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
377
      
378
      writeline RAW.321 $replace_control_codes(%text2)
379
    }
380
    else if (event_name=Receive Wallops == %text) {
381
      inc %s
382
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
383
      
384
      writeline Wallop $replace_control_codes(%text2, <nick>, <text>)
385
    }
386
    else if (event_name=Keyword == %text) {
387
      inc %s
388
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
389
      
390
      writeline RAW.475 $replace_control_codes(%text2, <chan>)
391
    }
392
    else if (event_name=Banned == %text) {
393
      inc %s
394
      var %text2 = $replace($read(%eventfile, n, %s), event_text=,)
395
      
396
      writeline RAW.474 $replace_control_codes(%text2, <chan>)
397
    }
398
  }
399
  
400
  hfree themecolors
401
  unset %themepath
402
  echo -ag $prefixsys Conversion done
403
}
404

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

    
409
alias -l writeline {
410
  ; echo -ag $1-
411
  write -a %themepath $1-
412
}
413

    
414
alias -l replace_control_codes {
415

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

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