Comparing version 3.0.1 to 3.0.2
322
index.js
const events = require('events'); | ||
const debug = require('debug')('irc2as'); | ||
const ASEmitter = require('./as-emitter'); | ||
const EVENT_INCOMING = 'incoming', | ||
EVENT_ERROR = 'error', | ||
// EVENT_ERROR = 'error', | ||
EVENT_PONG = 'pong', | ||
@@ -28,3 +29,3 @@ EVENT_PING = 'ping', | ||
NAMES = "353", | ||
NAMES_END = "366", | ||
// NAMES_END = "366", | ||
NICK = "NICK", | ||
@@ -41,4 +42,4 @@ NOTICE = "NOTICE", | ||
WHO = "352", | ||
WHO_OLD = "354", | ||
WHO_END = "315"; | ||
WHO_OLD = "354"; | ||
// WHO_END = "315"; | ||
@@ -57,8 +58,8 @@ const ROLE = { | ||
function getNickFromServerString(server) { | ||
function getNickFromServer(server) { | ||
return server.split(/^:/)[1].split('!')[0]; | ||
} | ||
function IrcToActivityStreams(cfg) { | ||
class IrcToActivityStreams { | ||
constructor(cfg) { | ||
const config = cfg || {}; | ||
@@ -69,39 +70,15 @@ this.server = config.server; | ||
this.__buffer[NAMES] = {}; | ||
return this; | ||
} | ||
} | ||
IrcToActivityStreams.prototype._sendPresence = function (username, role, channel, time) { | ||
this.events.emit(EVENT_INCOMING, { | ||
'@type': 'update', | ||
actor: { | ||
'@type': 'person', | ||
'@id': `${username}@${this.server}`, | ||
'displayName': username, | ||
}, | ||
target: { | ||
'@type': 'room', | ||
'@id': this.server + '/' + channel, | ||
displayName: channel | ||
}, | ||
object: { | ||
'@type': 'presence', | ||
role: role | ||
}, | ||
published: time | ||
}); | ||
}; | ||
IrcToActivityStreams.prototype.input = function (string) { | ||
debug(string); | ||
if (typeof string !== 'string') { | ||
input(incoming) { | ||
debug(incoming); | ||
if (typeof incoming !== 'string') { | ||
debug('unable to process incoming message as it was not a string.'); | ||
return false; | ||
} | ||
if (string.length < 3) { | ||
} else if (incoming.length < 3) { | ||
debug('unable to process incoming string, length smaller than 3.'); | ||
return false; | ||
} | ||
string = string.trim(); | ||
const time = '' + Date.now(); | ||
const [metadata, content] = string.split(' :'); | ||
incoming = incoming.trim(); | ||
const [metadata, content] = incoming.split(' :'); | ||
const [server, code, pos1, pos2, pos3, ...msg] = metadata.split(" "); | ||
@@ -111,11 +88,14 @@ const channel = ((typeof pos1 === "string") && (pos1.startsWith('#'))) ? pos1 : | ||
((typeof pos3 === "string") && (pos3.startsWith('#'))) ? pos3 : undefined; | ||
let nick, type, message, role; | ||
if (metadata === PING) { | ||
this.events.emit(EVENT_PING, time); | ||
this.events.emit(EVENT_PING, `${Date.now()}`); | ||
return true; | ||
} | ||
debug(`[${code}] server: ${server} channel: ${channel} 1: ${pos1}, 2: ${pos2}, 3: ${pos3}.` + | ||
` content: `, content); | ||
this.__processIRCCodes(code, server, channel, pos1, pos2, pos3, content, msg, incoming); | ||
} | ||
__processIRCCodes(code, server, channel, pos1, pos2, pos3, content, msg, incoming) { | ||
const ase = new ASEmitter(this.events, this.server); | ||
let nick, type, role; | ||
switch (code) { | ||
@@ -132,18 +112,3 @@ /** */ | ||
case ERR_BANLISTFULL: | ||
this.events.emit(EVENT_ERROR, { | ||
'@type': 'send', | ||
actor: { | ||
'@type': 'room', | ||
'@id': this.server + '/' + channel | ||
}, | ||
target: { | ||
'@type': 'person', | ||
'@id': pos1 + '@' + this.server | ||
}, | ||
object: { | ||
'@type': 'error', | ||
content: content | ||
}, | ||
published: time | ||
}); | ||
ase.channelError(channel, pos1, content) | ||
break; | ||
@@ -154,19 +119,3 @@ | ||
case ERR_BAD_NICK: | ||
this.events.emit(EVENT_ERROR, { | ||
'@type': 'update', | ||
actor: { | ||
'@type': 'service', | ||
'@id': this.server | ||
}, | ||
object: { | ||
'@type': 'error', | ||
content: content | ||
}, | ||
target: { | ||
'@type': 'person', | ||
'@id': pos2 + '@' + this.server, | ||
displayName: pos2 | ||
}, | ||
published: time | ||
}); | ||
ase.serviceError(pos2, content) | ||
break; | ||
@@ -176,18 +125,3 @@ | ||
case ERR_NO_CHANNEL: // no such channel | ||
this.events.emit(EVENT_ERROR, { | ||
'@type': 'join', | ||
actor: { | ||
'@id': this.server, | ||
'@type': 'service' | ||
}, | ||
object: { | ||
'@type': 'error', | ||
content: 'no such channel ' + pos2 | ||
}, | ||
target: { | ||
'@id': pos2 + '@' + this.server, | ||
'@type': 'person' | ||
}, | ||
published: time | ||
}); | ||
ase.joinError(pos2) | ||
break; | ||
@@ -197,19 +131,3 @@ | ||
case ERR_TEMP_UNAVAIL: // nick conflict | ||
this.events.emit(EVENT_ERROR, { | ||
'@type': 'update', | ||
actor: { | ||
'@type': 'service', | ||
'@id': this.server | ||
}, | ||
object: { | ||
'@type': 'error', | ||
content: content | ||
}, | ||
target: { | ||
'@type': 'person', | ||
'@id': pos2 + '@' + this.server, | ||
displayName: pos2 | ||
}, | ||
published: time | ||
}); | ||
ase.nickError(pos2, content); | ||
break; | ||
@@ -219,25 +137,9 @@ | ||
case JOIN: // room join | ||
nick = getNickFromServerString(server); | ||
this.events.emit(EVENT_INCOMING, { | ||
'@type': 'join', | ||
actor: { | ||
'@type': 'person', | ||
'@id': nick + '@' + this.server, | ||
displayName: nick | ||
}, | ||
target: { | ||
'@type': 'room', | ||
'@id': this.server + '/' + channel, | ||
displayName: channel | ||
}, | ||
object: {}, | ||
published: time | ||
}); | ||
ase.joinRoom(channel, getNickFromServer(server)) | ||
break; | ||
case MODE: // custom event indicating a channel mode has been updated, used to re-query user or channel | ||
user_mode = pos2 || content; | ||
let user_mode = pos2 || content; | ||
if (! channel) { break; } // don't handle cases with no channel defined | ||
if (! pos3) { break; } // we need target user | ||
nick = getNickFromServerString(server); | ||
role = MODES[user_mode[1]] || 'member'; | ||
@@ -248,29 +150,3 @@ type = 'add'; | ||
} | ||
this.events.emit(EVENT_INCOMING, { | ||
'@type': type, | ||
actor: { | ||
'@type': 'person', | ||
'@id': nick + '@' + this.server, | ||
displayName: nick | ||
}, | ||
target: { | ||
'@type': 'person', | ||
'@id': pos3 + '@' + this.server, | ||
displayName: pos3 | ||
}, | ||
object: { | ||
"@type": "relationship", | ||
"relationship": 'role', | ||
"subject": { | ||
'@type': 'presence', | ||
role: role | ||
}, | ||
"object": { | ||
'@type': 'room', | ||
'@id': this.server + '/' + channel, | ||
displayName: channel | ||
} | ||
}, | ||
published: time | ||
}); | ||
ase.role(type, getNickFromServer(server), pos3, role, channel) | ||
break; | ||
@@ -291,4 +167,3 @@ | ||
content: [ content ] | ||
}, | ||
published: time | ||
} | ||
} | ||
@@ -301,3 +176,3 @@ } else { | ||
if (! this.__buffer[MOTD]) { break; } | ||
this.events.emit(EVENT_INCOMING, this.__buffer[MOTD]); | ||
ase.emitEvent(EVENT_INCOMING, this.__buffer[MOTD]); | ||
delete this.__buffer[MOTD]; | ||
@@ -315,3 +190,3 @@ break; | ||
} | ||
this._sendPresence(username, role, channel, time); | ||
ase.presence(username, role, channel); | ||
} | ||
@@ -322,21 +197,4 @@ break; | ||
case NICK: // nick change | ||
nick = getNickFromServerString(server); | ||
debug(`- 2 nick: ${nick} from content: ${content}`); | ||
this.events.emit(EVENT_INCOMING, { | ||
'@type': 'update', | ||
actor: { | ||
'@type': 'person', | ||
'@id': nick + '@' + this.server, | ||
displayName: nick | ||
}, | ||
target: { | ||
'@type': 'person', | ||
'@id': content + '@' + this.server, | ||
displayName: content | ||
}, | ||
object: { | ||
'@type': 'address' | ||
}, | ||
published: time | ||
}); | ||
// debug(`- 2 nick: ${nick} from content: ${content}`); | ||
ase.nickChange(getNickFromServer(server), content); | ||
break; | ||
@@ -346,19 +204,3 @@ | ||
case NOTICE: // notice | ||
this.events.emit(EVENT_INCOMING, { | ||
'@type': 'update', | ||
actor: { | ||
'@type': 'service', | ||
'@id': this.server | ||
}, | ||
object: { | ||
'@type': 'error', | ||
content: content | ||
}, | ||
target: { | ||
'@type': 'person', | ||
'@id': pos1 + '@' + this.server, | ||
displayName: pos1 | ||
}, | ||
published: time | ||
}); | ||
ase.notice(pos1, content); | ||
break; | ||
@@ -368,21 +210,3 @@ | ||
case PART: // leaving | ||
nick = getNickFromServerString(server); | ||
this.events.emit(EVENT_INCOMING, { | ||
'@type': 'leave', | ||
actor: { | ||
'@type': 'person', | ||
'@id': nick + '@' + this.server, | ||
displayName: nick | ||
}, | ||
target: { | ||
'@type': 'room', | ||
'@id': this.server + '/' + channel, | ||
displayName: channel | ||
}, | ||
object: { | ||
'@type': 'message', | ||
content: 'user has left the channel' | ||
}, | ||
published: time | ||
}); | ||
ase.userPart(channel, getNickFromServer(server)); | ||
break; | ||
@@ -392,3 +216,3 @@ | ||
case PONG: // ping response received | ||
this.events.emit(EVENT_PONG, time); | ||
this.events.emit(EVENT_PONG, `${Date.now()}`); | ||
break; | ||
@@ -398,27 +222,3 @@ | ||
case PRIVMSG: // msg | ||
nick = getNickFromServerString(server); | ||
if (content.startsWith('+\u0001ACTION ')) { | ||
type = 'me'; | ||
message = content.split(/^\+\u0001ACTION\s+/)[1].split(/\u0001$/)[0]; | ||
} else { | ||
type = 'message'; | ||
message = content; | ||
} | ||
this.events.emit(EVENT_INCOMING, { | ||
'@type': 'send', | ||
actor: { | ||
'@type': 'person', | ||
'@id': nick + '@' + this.server, | ||
displayName: nick | ||
}, | ||
target: { | ||
displayName: pos1 | ||
}, | ||
object: { | ||
'@type': type, | ||
content: message | ||
}, | ||
published: time | ||
}); | ||
ase.privMsg(getNickFromServer(server), pos1, content); | ||
break; | ||
@@ -428,20 +228,3 @@ | ||
case QUIT: // quit user | ||
nick = getNickFromServerString(server); | ||
this.events.emit(EVENT_INCOMING, { | ||
'@type': 'leave', | ||
actor: { | ||
'@type': 'person', | ||
'@id': nick + '@' + this.server, | ||
displayName: nick | ||
}, | ||
target: { | ||
'@type': 'service', | ||
'@id': this.server | ||
}, | ||
object: { | ||
'@type': 'message', | ||
content: 'user has quit' | ||
}, | ||
published: time | ||
}); | ||
ase.userQuit(getNickFromServer(server)) | ||
break; | ||
@@ -451,21 +234,3 @@ | ||
case TOPIC_CHANGE: // topic changed now | ||
nick = getNickFromServerString(server); | ||
this.events.emit(EVENT_INCOMING, { | ||
'@type': 'update', | ||
actor: { | ||
'@type': 'person', | ||
'@id': nick + '@' + this.server, | ||
displayName: nick | ||
}, | ||
target: { | ||
'@type': 'room', | ||
'@id': this.server + '/' + channel, | ||
displayName: channel | ||
}, | ||
object: { | ||
'@type': 'topic', | ||
topic: content | ||
}, | ||
published: time | ||
}); | ||
ase.topicChange(channel, getNickFromServer(server), content); | ||
break; | ||
@@ -498,3 +263,3 @@ | ||
this.__buffer[TOPIC_IS].published = msg[0]; | ||
this.events.emit(EVENT_INCOMING, this.__buffer[TOPIC_IS]); | ||
ase.emitEvent(EVENT_INCOMING, this.__buffer[TOPIC_IS]); | ||
delete this.__buffer[TOPIC_IS]; | ||
@@ -509,3 +274,3 @@ break; | ||
role = MODES[pos2[1]] || 'member'; | ||
this._sendPresence(nick, role, channel, time); | ||
ase.presence(nick, role, channel); | ||
break; | ||
@@ -515,7 +280,8 @@ | ||
default: | ||
this.events.emit(EVENT_UNPROCESSED, string); | ||
this.events.emit(EVENT_UNPROCESSED, incoming); | ||
break; | ||
} | ||
} | ||
}; | ||
module.exports = IrcToActivityStreams; |
{ | ||
"name": "irc2as", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "IRC to ActivityStreams objects", | ||
@@ -10,7 +10,7 @@ "main": "index.js", | ||
"dependencies": { | ||
"debug": "^4.1.1", | ||
"debug": "^4.3.1", | ||
"fast-deep-equal": "^3.1.1" | ||
}, | ||
"devDependencies": { | ||
"jaribu": "^2.2.2" | ||
"jaribu": "^2.2.3" | ||
}, | ||
@@ -36,3 +36,4 @@ "scripts": { | ||
}, | ||
"homepage": "https://github.com/silverbucket/irc2as#readme" | ||
"homepage": "https://github.com/silverbucket/irc2as#readme", | ||
"gitHead": "a1a1339697d1af35f6d5a05b6a2fba2499bc1bdb" | ||
} |
@@ -27,2 +27,3 @@ const fs = require('fs'); | ||
} | ||
define(['require'], function (require, IRC2AS) { | ||
@@ -37,12 +38,12 @@ let suites = []; | ||
env.validStreams = [ | ||
{ | ||
{ | ||
'@type': 'update', | ||
actor: { | ||
actor: { | ||
'@type': 'service', | ||
'@id': 'localhost', | ||
displayName: 'localhost' | ||
displayName: 'localhost' | ||
}, | ||
object: { | ||
'@type': 'topic', | ||
content: [ '-', '-' ] | ||
object: { | ||
'@type': 'topic', | ||
content: [ '-', '-' ] | ||
} | ||
@@ -52,10 +53,10 @@ }, | ||
'@type': 'update', | ||
actor: { | ||
actor: { | ||
'@type': 'service', | ||
'@id': 'localhost', | ||
displayName: 'localhost' | ||
displayName: 'localhost' | ||
}, | ||
object: { | ||
object: { | ||
'@type': 'topic', | ||
content: [ | ||
content: [ | ||
'- on the https://freenode.live website for our call for volunteers and call for', | ||
@@ -67,38 +68,38 @@ '- participation. If you are interested in sponsoring next year\'s event, please', | ||
'-', | ||
'-' | ||
] | ||
'-' | ||
] | ||
} | ||
}, | ||
{ '@type': 'update', | ||
actor: | ||
actor: | ||
{ '@type': 'person', | ||
'@id': 'donkey2018@localhost', | ||
displayName: 'donkey2018' }, | ||
target: | ||
target: | ||
{ '@type': 'person', | ||
'@id': 'slvrbckt@localhost', | ||
displayName: 'slvrbckt' }, | ||
object: { '@type': 'address' } | ||
object: { '@type': 'address' } | ||
}, | ||
{ '@type': 'update', | ||
actor: | ||
actor: | ||
{ '@type': 'person', | ||
'@id': 'slvrbckt@localhost', | ||
displayName: 'slvrbckt' }, | ||
target: | ||
target: | ||
{ '@type': 'person', | ||
'@id': 'donkey2018@localhost', | ||
displayName: 'donkey2018' }, | ||
object: { '@type': 'address' } | ||
object: { '@type': 'address' } | ||
}, | ||
{ '@type': 'leave', | ||
actor: | ||
actor: | ||
{ '@type': 'person', | ||
'@id': 'slvrbckt@localhost', | ||
displayName: 'slvrbckt' }, | ||
target: | ||
target: | ||
{ '@type': 'room', | ||
'@id': 'localhost/#debian', | ||
displayName: '#debian' }, | ||
object: { '@type': 'message', content: 'user has left the channel' } | ||
object: { '@type': 'message', content: 'user has left the channel' } | ||
}, | ||
@@ -182,3 +183,3 @@ {"@type":"leave",actor:{"@type":"person","@id":"jarlaxl_@localhost",displayName:"jarlaxl_"},target:{"@type":"service","@id":"localhost"},object:{"@type":"message",content:"user has quit"}}, | ||
{ | ||
desc: "verify ping count", | ||
desc: "verify ping count", | ||
run: function (env, test) { | ||
@@ -189,3 +190,3 @@ test.assert(env.pings, 2); | ||
{ | ||
desc: "verify pong count", | ||
desc: "verify pong count", | ||
run: function (env, test) { | ||
@@ -192,0 +193,0 @@ test.assert(env.pongs, 3); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8
685
39954
Updateddebug@^4.3.1