add user stats 👏
This commit is contained in:
parent
feadb9ddd0
commit
032fff64e3
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
node_modules/
|
||||
data/
|
34
jonbot.js
34
jonbot.js
|
@ -1,5 +1,7 @@
|
|||
var Botkit = require('botkit');
|
||||
var controller = Botkit.slackbot();
|
||||
var controller = Botkit.slackbot({
|
||||
json_file_store: procss.argv[3]
|
||||
});
|
||||
var bot = controller.spawn({
|
||||
token: process.argv[2]
|
||||
})
|
||||
|
@ -8,7 +10,31 @@ bot.startRTM(function(err,bot,payload) {
|
|||
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(["jonbot","^pattern$"],["direct_message","direct_mention","mention","ambient"],function(bot,message) {
|
||||
console.log(message.user + " mentioned \"jonbot\"");
|
||||
|
||||
// Increment the logged amount of mentions
|
||||
incrementKey(message.user, "bot_mentions", 1);
|
||||
|
||||
// Reply properly
|
||||
bot.reply(message,':clap: JOOOOON! :clap:');
|
||||
bot.api.reactions.add({
|
||||
timestamp: message.ts,
|
||||
|
@ -22,6 +48,12 @@ controller.hears(["jonbot","^pattern$"],["direct_message","direct_mention","ment
|
|||
});
|
||||
|
||||
controller.hears(["jon","^pattern$"],["direct_message","direct_mention","mention","ambient"],function(bot,message) {
|
||||
console.log(message.user + " mentioned \"jon\"");
|
||||
|
||||
// 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,
|
||||
|
|
Loading…
Reference in New Issue
Block a user