tilføjede patternbot.js
This commit is contained in:
parent
8764898bcf
commit
4887b49018
66
patternbot.js
Normal file
66
patternbot.js
Normal file
|
@ -0,0 +1,66 @@
|
|||
var Botkit = require('botkit');
|
||||
var controller = Botkit.slackbot({
|
||||
json_file_store: process.argv[3]
|
||||
});
|
||||
var bot = controller.spawn({
|
||||
token: process.argv[2]
|
||||
})
|
||||
bot.startRTM(function(err,bot,payload) {
|
||||
if (err) {
|
||||
throw new Error('Could not connect to Slack');
|
||||
}
|
||||
});
|
||||
|
||||
function createUserData(id) {
|
||||
return {id: id, jon_mentions: 0, bot_mentions: 0};
|
||||
};
|
||||
|
||||
function incrementKey(id, key, amount) {
|
||||
controller.storage.users.get(id, function(err,user_data) {
|
||||
if (!user_data) {
|
||||
console.log("Initializing user data");
|
||||
user_data = createUserData(id);
|
||||
}
|
||||
console.log("Current user data:",user_data);
|
||||
console.log("Incrementing mentions. Was " + user_data[key] + " will be " + (user_data[key] + amount));
|
||||
user_data[key] = user_data[key] + amount
|
||||
controller.storage.users.save(user_data);
|
||||
});
|
||||
}
|
||||
|
||||
controller.hears(["pattern","^pattern$"],["direct_message","direct_mention","mention","ambient"],function(bot,message) {
|
||||
console.log(message.user + " mentioned \"pattern\"");
|
||||
|
||||
// Increment the logged amount of mentions
|
||||
incrementKey(message.user, "bot_mentions", 1);
|
||||
|
||||
// Reply properly
|
||||
bot.reply(message,':clap: PAAATTERN! :clap:');
|
||||
bot.api.reactions.add({
|
||||
timestamp: message.ts,
|
||||
channel: message.channel,
|
||||
name: "clap",
|
||||
},function(err, res) {
|
||||
if (err) {
|
||||
bot.botkit.log('Failed to add reaction emoji');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
controller.hears(["pattern","^pattern$"],["direct_message","direct_mention","mention","ambient"],function(bot,message) {
|
||||
console.log(message.user + " mentioned \"pattern\"");
|
||||
|
||||
// Increment the logged amount of mentions
|
||||
incrementKey(message.user, "jon_mentions", 1);
|
||||
|
||||
// React with appropriate emoji
|
||||
bot.api.reactions.add({
|
||||
timestamp: message.ts,
|
||||
channel: message.channel,
|
||||
name: "clap",
|
||||
},function(err, res) {
|
||||
if (err) {
|
||||
bot.botkit.log('Failed to add reaction emoji');
|
||||
}
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user