• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript hubot.Robot类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中hubot.Robot的典型用法代码示例。如果您正苦于以下问题:TypeScript Robot类的具体用法?TypeScript Robot怎么用?TypeScript Robot使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Robot类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: ilevelList

export = (robot: Robot) => {
    robot.respond(/(ilvl)( me)?/i, async res => {
        try {
            await ilevelList(res);
        } catch (e) {
            console.error(e);
        }
    });

    robot.respond(/(raider)?(io)( me)?/i, async res => {
        try {
            await raiderioScore(res);
        } catch (e) {
            console.error(e);
        }
    });

    robot.respond(/(affixes)( me)?/i, async res => {
        try {
            await affixes(res);
        } catch (e) {
            console.error(e);
        }
    });
};
开发者ID:mattvperry,项目名称:DonkeyBot,代码行数:25,代码来源:wow.ts


示例2: stats

export = (robot: Robot) => {
    robot.respond(/sniperino stats( me)?/i, res => {
        const { stats } = loadState(robot.brain);
        const message = Object.values(stats)
            .filter(<T>(x?: T): x is T => x !== undefined)
            .map(stat => ({ ...stat, winRate: calculateWinRate(stat) }))
            .sort((a, b) => b.winRate - a.winRate)
            .map(({ userId, winRate }) => `${robot.brain.userForId(userId).name}: ${winRate}%`)
            .join('\n');

        res.send(message);
    });

    robot.respond(/sniperino( me)?$/i, res => {
        const state = loadState(robot.brain);
        const { name, id } = res.message.user;
        if (state.games[id] !== undefined) {
            res.send(stringFns[GameEvent.Dupe]({ name }));
            return;
        }

        const snipe = Math.floor(Math.random() * 99) + 1;
        state.games[id] = snipe;
        res.send(stringFns[GameEvent.New]({ name, snipe }));
    });

    robot.on('roll', (res: Response, roll: number, max: number) => {
        // If someone rolled out of something other than 100, they are
        // either not playing sniperino or trying to cheat.
        if (max !== 100) {
            return;
        }

        // If there are no active games then this was just an ordinary roll
        const state = loadState(robot.brain);
        const { name, id } = res.message.user;
        const snipe = state.games[id];
        if (snipe === undefined) {
            return;
        }

        const {
            gamesPlayed = 0,
            gamesWon = 0
        } = state.stats[id] || {};

        // Play game
        const event = playGame(roll, snipe);
        state.stats[id] = {
            gamesPlayed: (event !== GameEvent.Draw ? gamesPlayed + 1 : gamesPlayed),
            gamesWon: (event === GameEvent.Win ? gamesWon + 1 : gamesWon),
            userId: id,
        };

        res.send(stringFns[event]({ name, roll }));

        delete state.games[id];
    });
};
开发者ID:mattvperry,项目名称:DonkeyBot,代码行数:59,代码来源:sniperino.ts


示例3: beforeEach

 beforeEach(done => {
   robot = new Robot(null, 'mock-adapter', false, 'TestHubot')
   robot.adapter.on('connected', () => {
     hello(robot)
     user = robot.brain.userForId('1', {
       name: 'mocha',
       room: '#general',
     })
     done()
   })
   robot.run()
 })
开发者ID:namikingsoft,项目名称:hubot-sandbox,代码行数:12,代码来源:hello.ts


示例4: describe

describe('hello', function() {

  let robot: Robot
  let user: any

  beforeEach(done => {
    robot = new Robot(null, 'mock-adapter', false, 'TestHubot')
    robot.adapter.on('connected', () => {
      hello(robot)
      user = robot.brain.userForId('1', {
        name: 'mocha',
        room: '#general',
      })
      done()
    })
    robot.run()
  })

  afterEach(() => robot.shutdown())

  context('when received hello', () => {
    it('should be send world ', done => {
      robot.adapter.on('reply', (envelope, strings) => {
        assert(envelope.user.name === 'mocha')
        assert(strings[0] === 'world')
        done()
      })
      robot.adapter.receive(new TextMessage(user, 'hello'))
    })
  })
})
开发者ID:namikingsoft,项目名称:hubot-sandbox,代码行数:31,代码来源:hello.ts


示例5:

export = (robot: Robot) => robot.respond(/roll( me)?( (\d+))?/i, res => {
    const max = Math.abs(Number(res.match[2])) || 100;
    const roll = Math.floor(Math.random() * max + 1);

    res.reply(`rolls a ${roll} !`);
    (robot as any).emit('roll', res, roll, max);
});
开发者ID:mattvperry,项目名称:DonkeyBot,代码行数:7,代码来源:roll.ts


示例6: onResponse

export = (robot: Robot) => robot.respond(/(jerk)( me)?/i, async res => {
    try {
        await onResponse(res);
    } catch (e) {
        console.error(e);
    }
});
开发者ID:mattvperry,项目名称:DonkeyBot,代码行数:7,代码来源:jerk.ts


示例7: getCats

export = (robot: Robot) => robot.respond(/(kitty|cat|meow)( me)? ?(\d+)? ?(\w+)?/i, async res => {
    try {
        const parsedCats = await getCats(Number(res.match[3]), res.match[4]);
        parsedCats.map(c => res.send(c));
    } catch (e) {
        console.error(e);
    }
});
开发者ID:mattvperry,项目名称:DonkeyBot,代码行数:8,代码来源:kitty.ts


示例8: default

export default (robot: Robot) => {

  robot.respond(/what are your prime directives\??/i, (response) => {
    response.reply(`1. Serve the public trust
2. Protect the innocent hackers
3. Uphold the Code of Conduct\n4. [Classified]`)
  })

}
开发者ID:Codesleuth,项目名称:hubot-hackbot,代码行数:9,代码来源:prime_directives.script.ts


示例9: default

export default (robot: Robot, secureBrain: ISecureBrain) => {
  robot.respond(/set token (.+)/i, (res) => {
    const token = res.match[1];
    if (token.length < 20)
      return res.reply('Token looks to be too short');

    secureBrain.set(`appveyor.settings.${res.message.user.id}`, { token: token });
    res.reply("Your token has been set");
  });
}
开发者ID:Codesleuth,项目名称:hubot-appveyor,代码行数:10,代码来源:settings.ts


示例10: resetHype

export = (robot: Robot) => {
    robot.hear(/hype/i, res => {
        resetHype();
        if (total < maxHype) {
            total += Math.min(hypeIncrement, maxHype - total);
            res.send(`${gettingHyped} : ${total}%`);
        } else {
            res.send(`${overHyped}`);
        }
    });
};
开发者ID:mattvperry,项目名称:DonkeyBot,代码行数:11,代码来源:hype.ts



注:本文中的hubot.Robot类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript hubot-slack.Robot类代码示例发布时间:2022-05-25
下一篇:
TypeScript hubot.Response类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap