This repository was archived by the owner on May 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.ts
More file actions
57 lines (45 loc) · 1.75 KB
/
sample.ts
File metadata and controls
57 lines (45 loc) · 1.75 KB
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
import net = require('net');
import tls = require('tls');
import {ParserServer} from 'dab.irc.parser/src/ParserServer';
import * as Core from 'dab.irc.core/src';
import {ConversationMessage} from 'dab.irc.parser/src/MessageTypes/ConversationMessage';
import * as Manager from './src';
class SampleIRCContext implements Core.IConnectionContext {
connection: Core.Connection;
me: Core.User = new Core.User("dabirc", "dabitp", null);
host: string = "irc.dab.biz";
port: number = 6697;
ssl: boolean = true;
rejectUnauthedCerts: boolean = false;
constructor() {
this.me.name = "David";
}
dataCallback: (d: Core.Message) => any;
createConnection(cb:() => any): Core.ISocket {
if (this.ssl) {
return new Core.NodeSocket(tls.connect(this.port, this.host, {rejectUnauthorized: this.rejectUnauthedCerts}, cb));
}
else {
return new Core.NodeSocket(net.createConnection(this.port, this.host, cb));
}
}
connectionEstablishedCallback: (c:Core.Connection) => any = (c:Core.Connection) => {
c.write("NICK " + this.me.nick);
c.write("USER " + this.me.ident + " 8 * :" + this.me.name);
}
logSentMessages: boolean = true;
logReceivedMessages: boolean = true;
channelPrefixes:string[];
}
var ctx = new SampleIRCContext();
var con = new Core.Connection();
var server = new Manager.ManagedServer("test", ctx, con);
server.on("PRIVMSG", (s:ParserServer, m:Core.Message) => {
var msg = <ConversationMessage>m;
console.log(msg);
if (msg.firstWord == "test") {
s.connection.write("PRIVMSG " + msg.destination.target + " :Found: From:" + msg.from.target);
}
});
ctx.dataCallback = server.dataReceived;
con.init(ctx);