-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.coffee
41 lines (32 loc) · 1.15 KB
/
bot.coffee
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
irc = require('./irc')
config = require('./config')
class Bot
constructor: ->
@connections = {}
for server of config
host = config[server].host
port = config[server].port
tls = config[server].tls
@add_connection server, host, port, tls
@connections[server].connect()
add_connection: (name, host, port) =>
@connections[name] = new irc.IRCConnection(host, port)
@connections[name].add_listener(new irc.ConnectionListener 'connect',
@get_handle_connect(name))
console.log "Loaded '#{ name }' connection"
get_handle_connect: (server) ->
return () => @_handle_connect(server)
_handle_connect: (server) =>
callback = () =>
console.log "Setting username on #{ server }"
nick = config[server].user.nick
@connections[server].write 'NICK ' + nick
user = config[server].user.user
real = config[server].user.real
@connections[server].write 'USER ' + user + ' 8 * :' + real
setTimeout callback, 2000
callback = () =>
for chan, pass of config[server].chans
@connections[server].write 'JOIN #' + chan + ' ' + pass
setTimeout callback, 5000
bot = new Bot