Skip to content
This repository has been archived by the owner on Oct 16, 2019. It is now read-only.

Add 575 #74

Merged
merged 2 commits into from
May 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
node_modules
.DS_Store*
.hubot_history
test.json
test.json

scripts/gj.coffee
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ gochiusa-bot is "Is the order a rabbit?" BOT.
## Feature

* ごちうさというフレーズに反応してアニメ画像をランダムで吐きます.
![ごちうさというフレーズに反応する](./assets/gochiusa.png)
![ごちうさというフレーズに反応する](./assets/gochiusa.png)
* chino / @chino でチノちゃんがランダムでつぶやきます.
![chinoとつぶやく](./assets/chino.png)
![chinoとつぶやく](./assets/chino.png)
* `$`で囲まれた部分をLaTeXと認識して数式を画像化したものを返します.
![LaTeX画像化](./assets/latex.png)
![LaTeX画像化](./assets/latex.png)
* 麻雀点数計算機能
* `3翻30符`とかで点数を返します. (Thanks to [@dorapon2000](https://github.com/dorapon2000))
![点数表示](./assets/mahjong-calc.png)
![点数表示](./assets/mahjong-calc.png)
* 麻雀役出力機能 (Thanks to [@index30](https://github.com/index30), [@sga0221](https://github.com/sga0221), [@ksepynoin](https://github.com/ksepynoin))
![麻雀役出力機能](./assets/mahjong.png)
* ごちうさ言語の利用 (詳細は`glang help`を参考のこと)
* マジカルシルクハットゲーム機能
* 遊戯王の「マジカルシルクハット」を元にしたゲーム機能です.マジカルシルクハットに隠れた「ブラック・マジシャン」を当てれば勝ち.
* 575通知機能
* 発言した文章が575だった場合にadd-reactionしてくれる機能
![575の文章にadd-reactionする](./assets/goshichigo.png)

## How to contribute

Expand Down
Binary file added assets/goshichigo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"hubot-scripts": "^2.5.16",
"hubot-slack": "^3.3.0",
"hubot-slack-attachment": "^1.0.1",
"hubot-youtube": "^0.1.2"
"hubot-youtube": "^0.1.2",
"request": "^2.72.0"
},
"engines": {
"node": ">= 0.8.x",
Expand Down
101 changes: 101 additions & 0 deletions scripts/575.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Description:
// 文章が575の場合、教えてくれます。
//
// Commands:
// hubot > 任意の575の文字列
// hubot > add-reaction :goshichigo:
//


(function(){
var url = "https://labs.goo.ne.jp/api/morph";
var app_ID = process.env.GOO_APP_ID;
if (!app_ID){
console.error("error: Set your GOO_APP_ID env variables.");
}
module.exports=function(robot){
//入力された文章の取得
return robot.hear(/.*/i,function(msg){
//APIに渡すためのデータ
var data;
data = JSON.stringify({
"app_id" : app_ID,
"sentence" : msg.match[0]
});
return robot.http(url).header("Content-type","application/json").post(data)(function(err, res, body){
var result = JSON.parse(body);
var sentence = result.word_list;
if(is575(sentence))
return addReactions(msg,"goshichigo");

});
});
};
}).call(this);

//575か判定するメソッド
function is575(sentence){
var count = [0,0,0];
var count_lim = [5,7,5];
var now_watch = 0;
for(i in sentence){ //行
for(j in sentence[i]){ //列
var word = sentence[i][j];
if(word[2] == "$") //読めない文字は無視
continue;

//575達成後に読める文字が存在してしまう場合
if(now_watch > 2)
return false;

var is_joshi = (word[1].indexOf("助") != -1); //助詞の判定
var is_hanteishi = (word[1].indexOf("判") != -1); //判定詞の判定

//575の最初が助詞、判定詞になってしまう場合、falseを返す
if((is_joshi || is_hanteishi) && count[now_watch] == 0)
return false;

var wordReading = word[2].replace(/ャ|ュ|ョ|ァ|ィ|ゥ|ェ|ォ/g, ""); //小さい文字の削除
count[now_watch] += wordReading.length;

//文字数の判定
if(count[now_watch] > count_lim[now_watch]){
return false;
}else if(count[now_watch] == count_lim[now_watch]){
now_watch++;
}
}
}
if(now_watch == 3)
return true;
else
return false;
}



/*
add-reactionするメソッド
参考記事:
HubotでSlackのEmoji Reactionを付ける
http://qiita.com/hiconyan/items/f2c37a10ac2c581693ce
*/
var request = require('request');

var addReactions = function(msg, name){
var options;
options = {
url: 'https://slack.com/api/reactions.add',
qs: {
'token': process.env.HUBOT_SLACK_TOKEN,
'name': name,
'channel': msg.message.rawMessage.channel,
'timestamp': msg.message.rawMessage.ts
}
};
return request.post(options, function(err, res, body) {
if ((err != null) || res.statusCode !== 200) {
return robot.logger.error("Failed to add emoji reaction " + (JSON.stringify(err)));
}
});
};
3 changes: 2 additions & 1 deletion scripts/data/meshi_shop.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
"はりけんラーメン",
"千香華味",
"くい亭",
"シェーキーズ"
"シェーキーズ",
"小寅"
]