本文整理汇总了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);
}
});
};
示例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];
});
};
示例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()
})
示例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'))
})
})
})
示例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);
});
示例6: onResponse
export = (robot: Robot) => robot.respond(/(jerk)( me)?/i, async res => {
try {
await onResponse(res);
} catch (e) {
console.error(e);
}
});
示例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);
}
});
示例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]`)
})
}
示例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");
});
}
示例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}`);
}
});
};