-
Notifications
You must be signed in to change notification settings - Fork 1
/
irc.coffee
95 lines (72 loc) · 2.19 KB
/
irc.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
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
# Add ./lib to the require paths for easy extending
require.paths.unshift './lib'
# Utilities
sys = require 'sys'
http = require 'http'
_ = require 'underscore'
# Express framework
express = require 'express'
# Socket.io
io = require 'socket.io'
# IRC client
irc = require 'irc'
# channel = process.argv[3]
# channel ?= '#naneautest'
channels = ['#naneautest', '#naneautest2','#naneautest3']
nick = 'naneaubot';
server = 'irc.freenode.net';
# Instantiate the IRC Client
# ircClient = new irc.Client server, nick, channels: channels
# Quick 'n dirty error handler
# ircClient.addListener 'error', (error) ->
# console.log error
# # Create the insulting bot
# bot = new Bot ircClient, nick
# Express server
app = express.createServer()
# Set static files directory
app.use express.staticProvider __dirname + '/static'
# Use CoffeeKup templating
app.register '.coffee', require 'coffeekup'
app.set 'view engine', 'coffee'
# Root request triggers a simple render (App is all in Backbone.js through Socket.io)
app.get '/', (request, response) ->
response.render 'index'
# Listen on port that is given (or use default)
port = process.argv[2]
port ?= 8080
app.listen parseInt port, 10
# Socket.io config
socket = io.listen app
# Log new connections
socket.on 'connection', (client) ->
sys.puts 'socket.io client connected'
client.on 'message', (data) ->
# if data.message is 'channelMessage'
# ircClient.say data.channel, data.text
# Send the channel list
client.send
message: 'channelList'
channels: channels
# Broadcast a received message
sendMessage = (from, to, message) ->
socket.broadcast
message: 'channelMessage',
from: from
to: to,
text: message
# Broadcast messages received from IRC
# ircClient.addListener 'message', sendMessage
# manage a backlog
backlogs = {}
# ircClient.addListener 'message', (from, to, message) ->
# backLog.push [from, to, message]
# # For last 10 message, do a broadcast
# for message in backLog[backLog.length - 10 ... backLog.length]
# do (message) ->
# [from, to, message] = message
# sendMessage from, to, message
#
#
#
# # backLog = []