-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
123 lines (87 loc) · 2.38 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
"use strict";
var irc = require('slate-irc');
var net = require('net');
var Brig = require('brig');
var brig = new Brig();
var curColor = 0;
var colors = [
'#A4C400', '#60A917',
'#008A00', '#00ABA9',
'#1BA1E2', '#0050EF',
'#6A00FF', '#AA00FF',
'#F472D0', '#D80073',
'#A20025', '#E51400',
'#FA6800', '#F0A30A',
'#E3C800', '#825A2C',
'#6D8764', '#647687',
'#76608A', '#87794E'
];
brig.on('ready', function(brig) {
function getUserColor() {
var color = colors[curColor];
curColor++;
if (curColor == colors.length)
curColor = 0;
return color;
}
brig.open('App.qml', function(err, window) {
var names = {};
window.on('readyForIRC', function() {
window.emit('updatedIRC', 'Connecting IRC Server...');
function _connect() {
var channelName = '#HackathonTaiwan';
var stream = net.connect({
port: 6667,
host: 'irc.freenode.org'
});
stream.on('close', function() {
window.emit('updatedIRC', 'Disconnected');
});
stream.on('error', function() {
window.emit('updatedIRC', 'Connection Refused');
window.emit('updatedIRC', 'Reconnecting...');
_connect();
});
stream.on('connect', function() {
var client = irc(stream);
client.nick('HackathonTaiwan');
client.user('HackathonTaiwan', 'Hackathon Taiwan');
client.join(channelName);
client.on('welcome', function(msg) {
console.log('Connected IRC server');
window.emit('updatedIRC', 'Connected Server');
});
client.on('notice', function(msg) {
console.log(msg.message);
window.emit('updatedIRC', msg.message);
});
client.on('message', function(e) {
if (e.to != channelName.toLowerCase())
return;
var msg = e.from + ': ' + e.message;
console.log(msg);
var color = names[e.from];
if (!color) {
color = getUserColor();
names[e.from] = color;
}
var msgRich = '< <font color="' + color + '">' + e.from + '</font> > ' + e.message;
window.emit('updatedIRC', msgRich);
});
client.on('join', function(msg) {
if (Object.keys(names).length == 0)
return;
names[msg.nick] = getUserColor();
});
client.names(channelName, function(err, list) {
for (var index in list) {
var name = list[index].name;
names[name] = getUserColor();
}
});
});
}
_connect();
});
});
});