Home
Documentation
Download
JISIRC
Version 1.0 Documentation
Objects
ircclient
dccchat
dccsend
Methods
connect
process
msg (AKA messsage)
ctcp
disconnect
sendCommand
addHandler
Properties
nick
alternateNick
userName
realName
hostName
port
status
connected
connectStartTime
Objects
ircclient
The ircclient object represents a connection to an IRC network.
The first step to connecting to IRC is creating a new
ircclient
object. The arguments to the object are the nickname, an array of alternate nicknames, the username, and the real name.
var oIRC = new ircclient(f.Nickname.value,
[f.AlternateNickname.value, f.Nickname.value + "-"],
"EasyTMD111",
"EasyTMD 2");
Alternatively, the object can be created with no arguments, and then the properties set.
var oIRC = new ircclient();
oIRC.nick = f.Nickname.value;
oIRC.alternateNick = [f.AlternateNickname.value, f.Nickname.value + "-"];
...
Once the object is created and properties set, the
addHandler
method sets up which events your connection will be responding to.
oIRC.addHandler("onconnect", ircconnected);
oIRC.addHandler("ondisconnect", ircdisconnected);
oIRC.addHandler("ontext", irctext);
oIRC.addHandler("ondccchat", ircdccchat);
oIRC.addHandler("ondccchatconnect", ircdccchatconnect);
oIRC.addHandler("ondccsend", ircdccsend);
oIRC.addHandler("ondccsendconnect", ircdccsendconnect);
oIRC.addHandler("onupdate", ircupdatenext);
Now the connect method can be called with the name of the server and port number:
oIRC.connect(f.elements["Server"].value, 6667);
The ircclient object functions based on its
process
function being called periodically, you may do this by setting a timer:
oIRC.timer = window.setTimeout("ircupdate();", 251);
function ircupdate() {
window.clearTimeout(oIRC.timer);
oIRC.process();
if (oDCCChat) oDCCChat.process();
}
The only event you are required to add a handler for and respond to in order for the ircclient object to function is the "onupdate" event, which fires after the process method completes, at which point you can add any reconnect on disconnect and retry connections features, and then the timer should be set again:
oIRC.addHandler("onupdate", ircupdatenext);
function ircupdatenext(iStatus) {
var iTimeout = 21;
switch (iStatus) {
case 1 : // connecting
if ((new Date()).valueOf() > oIRC.connectStartTime + (1000 * 5)) {
processmessage("Unable to connect to " + f.elements["Server"].value + "...");
outmessage("Unable to connect to " + f.elements["Server"].value +
" (" + oIRC.hostAddress + ")...\n");
}
break;
case 2 : // connected but not logged in
if ((new Date()).valueOf() > oIRC.connectStartTime + (1000 * 55)) {
oIRC.connect(f.elements["Server"].value, 6667);
processmessage("Retrying " + f.elements["Server"].value + "...");
outmessage("Retrying " + f.elements["Server"].value +
" (" + oIRC.hostAddress + ")...\n");
}
case 4 : // disconnecting
iTimeout = 102;
break;
}
oIRC.timer = window.setTimeout("ircupdate();", 21);
}
ircclient_dccchat
The ircclient_dccchat represents a DCC chat connection with another IRC client. It is initiated from the ircclient object's
ondccchat
event. Returning true when the event is fired accepts the DCC chat and creates a new object, which is then passed to the ondccchatconnect event handler. The DCC chat object also has events accessible by associating a function with them through the addHandler method.
oIRC.addHandler("ondccchat", ircdccchat);
oIRC.addHandler("ondccchatconnect", ircdccchatconnect);
...
function ircdccchat(sNick) {
if (parsenick(sNick)) return true;
}
function ircdccchatconnect(oNewDCCChat) {
inmessage("DCC chat connected: " + oNewDCCChat.nick + "\n");
if (oNewDCCChat.nick == aNickNames[iProcessNickIndex]) {
oDCCChat = oNewDCCChat;
oDCCChat.addHandler("ontext", ircdccchattext);
}
}
function ircdccchattext(sNick, sMessage) {
if (sNick == aNickNames[iProcessNickIndex]) {
//inmessage(sNick + ": " + sMessage + "\n");
aChatText[aChatText.length] = sMessage;
}
}
ircclient_dccsend
The ircclient_dccsend represents a DCC send connection with another IRC client. It is similar to the DCC chat object but has the "onpartreceived" event instead of the "ontext" event, and a new "oncomplete" event.
Methods
connect(sHost, iPort)
Connects to the specified IRC server, on the specified port. Sets the
connectStartTime
property.
process()
Reads from the connection's socket and triggers appropriate events. If there are DCC sends active, calls each sends process method. DCC chat's process methods must be called seperately.
messsage(sNick, sMsg)
Sends a private message to the specified user (this is a wrapper for the
sendCommand
method). Has the alias msg().
ctcp(sNick, sMsg)
Sends a private message as a CTCP command to the specified user (this is a wrapper for the
sendCommand
method).
disconnect(sMessage, bDCC)
Disconnects from IRC after sending the quit message sMessage. If bDCC is true, DCC chats and sends are also disconnected. If multiple ircclient objects are connected, DCC sends and chats for all of the objects will be disconnected, not just onces instantiated from the callee object.
sendCommand(sCommand, aParams, sMessage)
Sends the command sCommand with array of parameters aParams and message body sMessage.
addHandler(sEvent, oFunction)
Sets the function oFunction to be called when events of type sEvent are triggered.
Event types:
onconnect
ondisconnect
onupdate
ontext
onnotice
ondccchat
ondccchatconnect
ondccsend
ondccsendconnect
Properties
nick
alternateNick
userName
realName
hostName
port
connected
connectStartTime