This repository has been archived by the owner on Dec 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtomSlackBot.js
88 lines (77 loc) · 2.6 KB
/
tomSlackBot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const Botkit = require('botkit');
const request = require('request');
let controller = Botkit.slackbot({
debug: false
//include "log: false" to disable logging
//or a "logLevel" integer from 0 to 7 to adjust logging verbosity
});
// connect the bot to a stream of messages
controller.spawn({
token: process.env.BOTTOKEN,
}).startRTM();
controller.hears('salam',['direct_message','direct_mention','mention'],(bot,message) => {
bot.reply(message,`wa Alikom Salam <@${message.user}> :smiley:`);
});
controller.hears('kech jdid', ['direct_message','direct_mention','mention'], (bot, message) => {
let jdid = [];
request.get('https://boiling-inlet-40180.herokuapp.com/news', (err,res,body) => {
if (!err && res.statusCode == 200) {
jdid = JSON.parse(body);
}
let thenews = "";
for (let variable in jdid) {
thenews += "* " + jdid[variable].text + "\n";
}
if (jdid.length>0) {
bot.reply(message, "wah kayan, please check:\n" + thenews);
}else {
bot.reply(message, "walo :confused:");
}
});
});
controller.hears('tu sais, je suis', ['direct_message','direct_mention','mention'], (bot, message) => {
request.post({
url: 'http://text-processing.com/api/sentiment/',
form: {
language: 'french',
text: message.text
}
},
function(error, response, body){
let answerLabel = JSON.parse(body)["label"];
if (answerLabel==='neg') {
return bot.reply(message, "Oh :confused:, Ghi lkhir ?");
} else {
return bot.reply(message, "Ah :smiley: Glad to hear that !");
}
}
);
});
controller.hears('you know, I\'m', ['direct_message','direct_mention','mention'], (bot, message) => {
request.post({
url: 'http://text-processing.com/api/sentiment/',
form: {
text: message.text
}
},
function(error, response, body){
let answerLabel = JSON.parse(body)["label"];
if (answerLabel==='neg') {
return bot.reply(message, "Oh :confused:, Ghi lkhir ?");
} else {
return bot.reply(message, "Ah :smiley: Glad to hear that !");
}
}
);
});
controller.hears('golah bsa7tek', ['direct_mention','mention'], (bot, message) => {
bot.reply(message, "bsa7tek");
});
controller.hears('say hi to (.)*', ['direct_message','direct_mention','mention'], (bot, message) => {
let theName = message.text.split('@')[1];
bot.reply(message, "Hello <@" + theName + ", marhba biik :smiley_cat:");
});
controller.on('direct_message', (bot, message) => {
bot.reply(message, "3lach rak tgoli \""+ message.text +"\" ?");
});
module.exports = controller;