Hello !
Thank you in advance for being patient. I'm not familiar with javascript and I've just started the node-red world.
About my project: i'm developing a bot for telegram with the powerful Red-bot:
GitHub - guidone/node-red-contrib-chatbot: Visually build a full featured chat bot for Telegram, Facebook Messenger and Slack with Node-RED. Almost no coding skills required. (take a look, it is an AMAZING job)
Here the flows:
The sense of the bot is that it must intercept the blasphemies and scold the blasphemer (this he does).
What I want is to know for each user how many blasphemies he said and make a ranking among the members of the group.
I realize it sounds very silly, but I'm working hard to practice of course, and i can't store this information.
Here my attempt of a function node,
var nB = { //an object and it's 3 parameters
name: msg.payload.userN,
sur: msg.payload.userS,
count: 1
};
//If not define the array notBless, create a empty array and simply add the nB
if (context.get("notBless") === undefined) {
context.set("notBless", []);
notBless.push(nB);
}
console.log(notBless.lenght);
//if the array is define, i look if the guy is a new blasphemous add it, if he is recidivist increase the count of profanity.
for(var i=0; i<notBless.lenght; i++){
if(notBless[i].name == msg.payload.userN){
notBless[i].count +=1;
console.log(notBless[i].count);
context.set("notBless",notBless,"notBless");
return msg;
}
}
notBless.push(nB);
context.set("notBless",notBless,"notBless");
console.log(notBless);
return msg;
Any suggestion for a fool who hasn't slept much since last night?
thank you for your time.