Skip to content
Permalink
Browse files

Merge pull request #124 from terbooter/master

	показываем анекдот по спецкоманде gray! #123
  • Loading branch information...
umputun committed Nov 20, 2016
2 parents e1b3104 + da1d302 commit e8866c5cabf344675ac32cef604b59b8d287d260
Showing with 36 additions and 8 deletions.
  1. +1 −1 anek-bot/README.md
  2. +16 −4 anek-bot/app/Bot.js
  3. +19 −3 anek-bot/src/Bot.ts
@@ -33,5 +33,5 @@ curl \
-v \
-X POST \
-d '{"text":"Расскажи анекдот","username":123,"display_name":"login"}' \
-H 'content-type:application/json' http://192.168.0.30:8080/
-H 'content-type:application/json' http://192.168.0.30:8080/event
```
@@ -18,18 +18,30 @@ var Bot = (function () {
}
return selectedChannel.getAnekdot().description;
};
//TODO refactor to hasAllWords
Bot.prototype.hasTriggerPhrase = function (message) {
var text = message.text.toLowerCase();
if (text.indexOf('расскажи') != -1 && text.indexOf('анекдот') != -1) {
var greyCommands = ["!грей", "грей!", "!gray", "gray!"];
if (this.hasAnyWord(message, greyCommands)) {
return true;
}
if (this.hasAllWords(message, ["расскаж", "анекдот"])) {
return true;
}
return false;
};
Bot.prototype.hasAnyWord = function (message, words) {
Bot.prototype.hasAllWords = function (message, words) {
var text = message.text.toLowerCase();
for (var _i = 0, words_1 = words; _i < words_1.length; _i++) {
var word = words_1[_i];
if (text.indexOf(word) == -1) {
return false;
}
}
return true;
};
Bot.prototype.hasAnyWord = function (message, words) {
var text = message.text.toLowerCase();
for (var _i = 0, words_2 = words; _i < words_2.length; _i++) {
var word = words_2[_i];
if (text.indexOf(word) != -1) {
return true;
}
@@ -23,15 +23,31 @@ export class Bot {
return selectedChannel.getAnekdot().description;
}

//TODO refactor to hasAllWords
private hasTriggerPhrase(message: RequestData): boolean {
var text = message.text.toLowerCase();
if (text.indexOf('расскажи') != -1 && text.indexOf('анекдот') != -1) {

var greyCommands = ["!грей", "грей!", "!gray", "gray!"];
if (this.hasAnyWord(message, greyCommands)) {
return true;
}

if (this.hasAllWords(message, ["расскаж", "анекдот"])) {
return true;
}

return false;
}

private hasAllWords(message: RequestData, words: string[]): boolean {
var text = message.text.toLowerCase();
for (var word of words) {
if (text.indexOf(word) == -1) {
return false;
}
}

return true;
}

private hasAnyWord(message: RequestData, words: string[]): boolean {
var text = message.text.toLowerCase();
for (var word of words) {

0 comments on commit e8866c5

Please sign in to comment.
You can’t perform that action at this time.