This repository has been archived by the owner on Dec 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,32 @@ | ||
var _ = require("lodash"); | ||
var Msg = require("../models/msg"); | ||
|
||
module.exports = function(irc, client, network) { | ||
irc.on("topic", function(data) { | ||
var chan = _.findWhere(network.channels, {name: data.channel}); | ||
if (!chan) { | ||
return; | ||
} | ||
|
||
var from = data.nick || chan.name; | ||
var topic = data.topic; | ||
|
||
chan.topic = topic; | ||
|
||
var msg = new Msg({ | ||
type: Msg.Type.TOPIC, | ||
from: from, | ||
text: topic | ||
}); | ||
chan.messages.push(msg), | ||
client.emit("msg", { | ||
chan: chan.id, | ||
msg: msg | ||
}); | ||
|
||
client.emit("topic", { | ||
chan: chan.id, | ||
topic: _.escape(topic) | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,43 @@ | ||
var tape = require("tape"); | ||
var events = require("events"); | ||
var topic = require("../../src/irc-events/topic"); | ||
var Chan = require("../../src/models/chan"); | ||
|
||
tape("topic", function(t) { | ||
t.plan(2); | ||
|
||
var irc = new events.EventEmitter(); | ||
irc.me = "foo"; | ||
|
||
var client = {}; | ||
client.emit = function(e, msg) { | ||
switch(e) { | ||
case "msg": | ||
t.pass(); | ||
break; | ||
|
||
case "topic": | ||
if (msg.topic == "foo") { | ||
t.pass(); | ||
} | ||
break; | ||
} | ||
}; | ||
|
||
var network = { | ||
id: 0, | ||
channels: [new Chan({ | ||
name: "#bar" | ||
})] | ||
}; | ||
|
||
topic(irc, client, network); | ||
|
||
irc.emit("topic", { | ||
channel: "#bar", | ||
nick: "", | ||
topic: "foo" | ||
}); | ||
|
||
t.end(); | ||
}); |