Merge pull request #8222 from elisee/slate-irc

Add slate-irc.d.ts
This commit is contained in:
Masahiro Wakame
2016-02-26 20:22:54 +09:00
2 changed files with 159 additions and 0 deletions
+61
View File
@@ -0,0 +1,61 @@
/// <reference path="slate-irc.d.ts" />
import * as net from "net";
import * as SlateIRC from "slate-irc";
let socket: net.Socket;
const client = SlateIRC(socket);
client.on("welcome", (name) => {
console.log(client.me);
});
client.on("motd", (event) => {
console.log(event.motd);
});
client.on("join", (event) => {
console.log(`${event.nick} has joined ${event.channel}`);
});
client.on("part", (event) => {
console.log(`${event.nick} has parted ${event.channels.join(", ")}`);
});
client.on("nick", (event) => {
console.log(`${event.nick} is now known as ${event.new}`);
});
client.on("quit", (event) => {
console.log(`${event.nick} has quit (${event.message}).`);
});
client.on("data", (event) => {
console.log(`Got ${event.command} command: ${event.string}`);
});
client.on("message", (event) => {
console.log(`[${event.to}] ${event.from}: ${event.message}`);
});
client.on("notice", (event) => {
console.log(`[${event.to}] ${event.from}: ${event.message}`);
});
client.on("disconnect", () => {
console.log("Disconnected.");
});
client.pass("pass");
client.nick("tobi");
client.user("tobi", "Tobi Ferret");
client.join("#channel");
client.join("#channel", "password");
client.names("#channel", (err, names) => {
console.log(names);
});
client.part("#channel");
client.part("#channel", "Leaving...");
+98
View File
@@ -0,0 +1,98 @@
// Type definitions for slate-irc
// Project: https://github.com/slate/slate-irc
// Definitions by: Elisée MAURER <https://github.com/elisee/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
declare module "slate-irc" {
import * as net from "net";
function IRC(socket: net.Socket): IRC.Client;
namespace IRC {
interface DataEvent {
prefix: string;
command: string;
params: string;
trailing: string;
string: string;
}
interface MOTDEvent {
motd: string[];
}
interface MessageEvent {
from: string;
hostmask: any;
to: string;
message: string;
}
interface JoinEvent {
nick: string;
hostmask: string;
channel: string;
}
interface PartEvent {
nick: string;
hostmask: string;
channels: string[];
}
interface NickEvent {
nick: string;
hostmask: string;
new: string;
}
interface QuitEvent {
nick: string;
hostmask: string;
message: string;
}
class Client {
me: string;
write(str: string): void;
pass(pass: string): void;
nick(nick: string): void;
user(username: string, realname: string): void;
invite(name: string, channel: string): void;
send(target: string, msg: string): void;
action(target: string, msg: string): void;
notice(target: string, msg: string): void;
ctcp(target: string, msg: string): void;
join(channel: string, key?: string): void;
part(channel: string, msg?: string): void;
names(channel: string, callback: (error: Error, names: { name: string; mode: string; }[]) => void): void;
away(message: string): void;
topic(channel: string, topic: string): void;
kick(channels: string|string[], nicks: string|string[], msg: string): void;
oper(name: string, password: string): void;
mode(target: string, flags: string, params: string): void;
quit(msg: string): void;
whois(target: string, mask: string, callback: Function): void;
on(event: string, callback: Function): void;
on(event: "data", callback: (event: DataEvent) => void): void;
on(event: "welcome", callback: (name: string) => void): void;
on(event: "message", callback: (event: MessageEvent) => void): void;
on(event: "notice", callback: (event: MessageEvent) => void): void;
on(event: "motd", callback: (event: MOTDEvent) => void): void;
on(event: "join", callback: (event: JoinEvent) => void): void;
on(event: "part", callback: (event: PartEvent) => void): void;
on(event: "nick", callback: (event: NickEvent) => void): void;
on(event: "quit", callback: (event: QuitEvent) => void): void;
}
}
export = IRC;
}