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