本文整理汇总了TypeScript中hubot.Robot.respond方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Robot.respond方法的具体用法?TypeScript Robot.respond怎么用?TypeScript Robot.respond使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hubot.Robot
的用法示例。
在下文中一共展示了Robot.respond方法的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: onResponse
export = (robot: Robot) => robot.respond(/(jerk)( me)?/i, async res => {
try {
await onResponse(res);
} catch (e) {
console.error(e);
}
});
示例4:
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);
});
示例5: 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);
}
});
示例6: 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]`)
})
}
示例7: 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");
});
}
示例8: default
export default (robot: Robot, appVeyor: IAppVeyor, secureBrain: ISecureBrain) => {
robot.respond(/start build (.*)/i, res => {
const projectSlug = res.match[1]
res.reply('One moment please...');
const userSettings = secureBrain.get(`appveyor.settings.${res.message.user.id}`);
if (userSettings == null)
return res.reply(`You must whisper me your AppVeyor API token with "/msg @${robot.name} set token <token>" first`);
appVeyor.build(projectSlug, userSettings.token)
.then((data) => {
if (!data.ok) return res.reply(`Could not start build. Got status code ${data.statusCode}`);
const msgData: ICustomMessageData = {
channel: res.message.room,
text: 'Build started',
attachments: [
{
fallback: `Started build of '${projectSlug}' v${data.body.version}: ${data.body.link}`,
title: `Started build of '${projectSlug}'`,
title_link: data.body.link,
text: `v${data.body.version}`,
color: '#7CD197'
}
]
};
const slackAdapter = robot.adapter as ISlackAdapter;
slackAdapter.customMessage(msgData);
robot.brain.set(`appveyor.build.${projectSlug}-${data.body.version}`, { username: res.message.user.name });
})
.catch((reason) => robot.emit('error', reason, res));
});
robot.router.post('/hubot/appveyor/webhook', (req, res) => {
const auth = req.headers['authorization'];
if (auth !== Config.appveyor.webhook.token) return res.send(403);
const data = req.body.payload ? JSON.parse(req.body.payload) : req.body;
const outcome = data.eventName === 'build_success' ? 'succeeded' : 'failed';
let msg = `Build v${data.eventData.buildVersion} of '${data.eventData.projectName} ${outcome}.`;
const value = robot.brain.get(`appveyor.build.${data.eventData.projectName}-${data.eventData.buildVersion}`);
if (value) {
msg += ` @${value.username}`;
}
robot.messageRoom(Config.announce_channel, msg);
res.send(200);
});
}
示例9: default
export default (robot: Robot, appVeyor: IAppVeyor, secureBrain: ISecureBrain) => {
const getColour = (status: string) => {
switch (status) {
case 'success': return '#7CD197';
case 'failed': return '#D17C8C';
}
return '#CCCCCC';
}
robot.respond(/list (\d+ )?builds of (.*)/i, res => {
const buildCount = res.match[1] !== undefined ? Number(res.match[1]) : 3;
const projectSlug = res.match[2];
res.reply('One moment please...');
const userSettings = secureBrain.get(`appveyor.settings.${res.message.user.id}`);
if (userSettings == null)
return res.reply(`You must whisper me your AppVeyor API token with "/msg @${robot.name} set token <token>" first`);
appVeyor.builds(projectSlug, buildCount, userSettings.token)
.then((data) => {
let msgData: ICustomMessageData = {
channel: res.message.room,
attachments: data.body.builds.map((build) => {
return {
fallback: `Build v${build.version}: ${build.status} ${build.link}`,
title: `Build v${build.version}`,
title_link: build.link,
color: getColour(build.status),
fields: [
{
title: build.branch,
short: true
},
{
value: build.committer,
short: true
}
]
}
})
};
const slackAdapter = robot.adapter as ISlackAdapter;
slackAdapter.customMessage(msgData);
})
.catch(res.reply);
});
}
示例10: default
export default (robot: Robot, appveyor: IAppVeyor, secureBrain: ISecureBrain) => {
robot.respond(/deploy (.+) v(.+) to (.+)/i, res => {
const project = res.match[1];
const version = res.match[2];
const environment = res.match[3];
const userSettings = secureBrain.get(`appveyor.settings.${res.message.user.id}`);
if (userSettings == null)
return res.reply(`You must whisper me your AppVeyor API token with "/msg @${robot.name} set token <token>" first`);
res.reply(`Starting deploy of '${project}' to '${environment}'...`);
appveyor.deploy(project, version, environment, userSettings.token)
.then((data) => {
if (!data.ok) return res.reply(`Could not deploy. Got status code ${data.statusCode}`);
let msgData: ICustomMessageData = {
channel: res.message.room,
text: 'Deploy started',
attachments: [
{
fallback: `Started deploy of '${project}' v${version} to '${environment}': ${data.body.link}`,
title: `Started deploy of '${project}' v${version}`,
title_link: data.body.link,
text: `v${version}`,
color: '#2795b6'
}
]
};
const slackAdapter = robot.adapter as ISlackAdapter;
slackAdapter.customMessage(msgData);
})
.catch((reason) => robot.emit('error', reason, res));
});
}