本文整理汇总了TypeScript中irc.Client类的典型用法代码示例。如果您正苦于以下问题:TypeScript Client类的具体用法?TypeScript Client怎么用?TypeScript Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
constructor(server:string, name:string, options?:IClientOpts, ...plugins: PluginConstructor[]) {
this.client = new Client(server, name, options);
this.plugins = new Array<Plugin>();
this.commands = new Map<string, ICommandHandler>();
this.client.addListener("message", (from:string, to:string, text:string, message:string) => {
for(let p of this.plugins) {
if(Helpers.isMessageHandler(p)) {
p.handleMessage(this.client, from, to, text);
}
}
let parts = text.split(" ");
if(parts.length > 0) {
let cmd = parts[0];
if(this.commands.has(cmd)) {
let handler = this.commands.get(cmd);
if(handler) {
parts.splice(0, 1);
handler.handleCommand(this.client, from, to, cmd, parts.join(" "));
}
}
}
});
this.client.addListener("join", (channel:string, nick:string, messsage:string) => {
});
this.client.addListener("error", (message:string) => {
console.log('error: ', message);
});
for(let p of plugins) {
this.loadPlugin(p);
}
}
示例2: init
init(): IrcClient {
this.isRunning = false;
this.plugins = getPlugins();
const hooks: HookCollection = new HookCollection(this.plugins);
this.client.addListener('join', (channel: string, nick: string, message: IMessage) => {
const args: api.IrcJoin = { user: nick };
const context: IrcContext<api.IrcJoin> = new IrcContext<api.IrcJoin>(this.name, this.client, args);
hooks.getJoinHooks().forEach((hook: api.PluginHook<api.IrcJoin>) => hook(context));
});
this.client.addListener('message', (nick: string, to: string, text: string, message: IMessage) => {
const args: api.IrcMessage = { user: nick, text: text };
const context: IrcContext<api.IrcMessage> = new IrcContext<api.IrcMessage>(this.name, this.client, args);
hooks.getMessageHooks().forEach((hook: api.PluginHook<api.IrcMessage>) => hook(context));
});
this.client.addListener('names', (channel: string, nicks: string[]) => {
const args: api.IrcNames = { users: nicks };
const context: IrcContext<api.IrcNames> = new IrcContext<api.IrcNames>(this.name, this.client, args);
hooks.getNamesHooks().forEach((hook: api.PluginHook<api.IrcNames>) => hook(context));
});
this.client.addListener('part', (channel: string, nick: string, reason: string, message: IMessage) => {
const args: api.IrcPart = { user: nick };
const context: IrcContext<api.IrcPart> = new IrcContext<api.IrcPart>(this.name, this.client, args);
hooks.getPartHooks().forEach((hook: api.PluginHook<api.IrcPart>) => hook(context));
});
this.client.addListener('error', (message: IMessage) => {
const error: string = JSON.stringify(message);
debugIrc(`${this.name} error: ${error}`);
});
return this;
}
示例3: debugIrc
this.client.connect(() => {
this.client.send('CAP', 'REQ', 'twitch.tv/membership');
this.client.join(channel, () => {
this.client.say(channel, 'Chat moderation is started');
this.isRunning = true;
debugIrc(`${this.name} started successfully`);
typeof done === 'function' && done();
});
});
示例4: stop
stop(done?: () => void): void {
if (!this.getIsRunning()) {
typeof done === 'function' && done();
return;
}
const channel: string = '#' + this.name;
this.client.say(channel, 'Chat moderation is stopped');
this.client.part(channel, () => {
this.client.disconnect(() => {
this.isRunning = false;
debugIrc(`${this.name} stopped successfully`);
typeof done === 'function' && done();
});
});
}
示例5: start
start(done?: () => void): void {
if (this.getIsRunning()) {
typeof done === 'function' && done();
return;
}
const channel: string = '#' + this.name;
this.client.connect(() => {
this.client.send('CAP', 'REQ', 'twitch.tv/membership');
this.client.join(channel, () => {
this.client.say(channel, 'Chat moderation is started');
this.isRunning = true;
debugIrc(`${this.name} started successfully`);
typeof done === 'function' && done();
});
});
}
示例6: unban
unban(user: string): void {
this.client.say(this.channel, `/unban ${user}`);
}
示例7: emoteonlyoff
emoteonlyoff(): void {
this.client.say(this.channel, `/emoteonlyoff`);
}
示例8:
r9kbetaoff(): void {
this.client.say(this.channel, `/r9kbetaoff`);
}