]>
Commit | Line | Data |
---|---|---|
9e769c12 CP |
1 | var ThemeControlCodeMap = { |
2 | "C": "\x03", | |
3 | "B": "\x02", | |
4 | "U": "\x1F", | |
5 | "O": "\x0F", | |
6 | "$": "$" | |
7 | }; | |
8 | ||
9 | var DefaultTheme = { | |
10 | "PREFIX": ["$C4==$O "], | |
11 | "SIGNON": ["Signed on!", true], | |
12 | "CONNECT": ["Connected to server.", true], | |
13 | "RAW": ["$m", true], | |
8dc46dfa | 14 | "DISCONNECT": ["Disconnected from server: $m", true], |
9e769c12 CP |
15 | "ERROR": ["ERROR: $m", true], |
16 | "SERVERNOTICE": ["$m", true], | |
17 | "JOIN": ["$n [$h] has joined $c", true], | |
18 | "PART": ["$n [$h] has left $c [$m]", true], | |
19 | "KICK": ["$v was kicked from $c by $n [$m]", true], | |
20 | "MODE": ["mode/$c [$m] by $n", true], | |
21 | "QUIT": ["$n [$h] has quit [$m]", true], | |
22 | "NICK": ["$n has changed nick to $w", true], | |
23 | "TOPIC": ["$n changed the topic of $c to: $m", true], | |
24 | "UMODE": ["MODE $n $m", true], | |
25 | "INVITE": ["$n invites you to join $c", true], | |
26 | "CHANMSG": ["<$n> $m"], | |
27 | "PRIVMSG": ["<$n> $m"], | |
28 | "CHANNOTICE": ["-$n:$c- $m"], | |
29 | "PRIVNOTICE": ["-$n- $m"], | |
30 | "OURCHANMSG": ["<$n> $m"], | |
31 | "OURPRIVMSG": ["<$n> $m"], | |
32 | "OURTARGETEDMSG": ["*$t* $m"], | |
33 | "OURTARGETEDNOTICE": ["[notice($t)] $m"], | |
34 | "OURCHANNOTICE": ["-$n:$t- $m"], | |
35 | "OURPRIVNOTICE": ["-$n- $m"], | |
36 | "OURCHANACTION": [" * $n $m"], | |
37 | "OURPRIVACTION": [" * $n $m"], | |
38 | "CHANACTION": [" * $n $m"], | |
39 | "PRIVACTION": [" * $n $m"], | |
40 | "CHANCTCP": ["$n [$h] requested CTCP $x from $c: $m"], | |
41 | "PRIVCTCP": ["$n [$h] requested CTCP $x from $-: $m"], | |
42 | "CTCPREPLY": ["CTCP $x reply from $n: $m"], | |
43 | "OURCHANCTCP": ["[ctcp($t)] $x $m"], | |
44 | "OURPRIVCTCP": ["[ctcp($t)] $x $m"], | |
45 | "OURTARGETEDCTCP": ["[ctcp($t)] $x $m"] | |
46 | }; | |
47 | ||
48 | var Theme = new Class({ | |
49 | initialize: function(themeDict) { | |
50 | this.__theme = {}; | |
51 | ||
52 | for(var k in DefaultTheme) | |
53 | this.__theme[k] = DefaultTheme[k]; | |
54 | ||
55 | if(themeDict) | |
56 | for(var k in themeDict) | |
57 | this.__theme[k] = themeDict[k]; | |
58 | ||
59 | for(var k in this.__theme) { | |
60 | if(k == "PREFIX") | |
61 | continue; | |
62 | ||
63 | var data = this.__theme[k]; | |
64 | if(data[1]) { | |
65 | this.__theme[k] = this.__theme["PREFIX"] + data[0]; | |
66 | } else { | |
67 | this.__theme[k] = data[0]; | |
68 | } | |
69 | } | |
70 | }, | |
71 | __dollarSubstitute: function(x, h) { | |
72 | var msg = []; | |
73 | ||
74 | var n = x.split(""); | |
75 | for(var i=0;i<n.length;i++) { | |
76 | var c = n[i]; | |
77 | if(c == "$" && (i <= n.length - 1)) { | |
78 | var c2 = n[++i]; | |
79 | ||
80 | var o = ThemeControlCodeMap[c2]; | |
81 | if(!o) | |
82 | o = h[c2]; | |
83 | if(o) | |
84 | msg.push(o); | |
85 | } else { | |
86 | msg.push(c); | |
87 | } | |
88 | } | |
89 | ||
90 | return msg.join(""); | |
91 | }, | |
92 | message: function(type, data) { | |
93 | var msg = this.__theme[type]; | |
94 | ||
95 | msg = this.__dollarSubstitute(msg, data); | |
96 | ||
97 | return msg; | |
98 | } | |
99 | }); |