當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript irc.Client類代碼示例

本文整理匯總了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);
        }
    }
開發者ID:AdditionalPylons,項目名稱:KawaiiBot,代碼行數:32,代碼來源:bot.ts

示例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;
    }
開發者ID:jbuerkel,項目名稱:twitchr,代碼行數:37,代碼來源:ircClient.ts

示例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();
            });
        });
開發者ID:jbuerkel,項目名稱:twitchr,代碼行數:11,代碼來源:ircClient.ts

示例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();
            });
        });
    }
開發者ID:jbuerkel,項目名稱:twitchr,代碼行數:18,代碼來源:ircClient.ts

示例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();
            });
        });
    }
開發者ID:jbuerkel,項目名稱:twitchr,代碼行數:20,代碼來源:ircClient.ts

示例6: unban

 unban(user: string): void {
     this.client.say(this.channel, `/unban ${user}`);
 }
開發者ID:jbuerkel,項目名稱:twitchr,代碼行數:3,代碼來源:ircContext.ts

示例7: emoteonlyoff

 emoteonlyoff(): void {
     this.client.say(this.channel, `/emoteonlyoff`);
 }
開發者ID:jbuerkel,項目名稱:twitchr,代碼行數:3,代碼來源:ircContext.ts

示例8:

 r9kbetaoff(): void {
     this.client.say(this.channel, `/r9kbetaoff`);
 }
開發者ID:jbuerkel,項目名稱:twitchr,代碼行數:3,代碼來源:ircContext.ts


注:本文中的irc.Client類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。