4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ฅ(・ω・ฅ){ Ruboty の脳を辞書化する ruboty-brain_dictionary を作ったよ } #ruboty

Posted at

概要

Ruboty の脳を辞書化する ruboty-brain_dictionary を作ったよ

用途

定型文を登録したい時。
辞書ツールでもいいのかもしれないが、 Slack など Ruboty がいる場所だけで使いたい場合に使う。
また、辞書を Ruboty で管理することで、辞書の内容を共有したい。

例えば、「日光東照宮」というキーに対して以下の Emoji を返す。
:see_no_evil::speak_no_evil::hear_no_evil:

「ぬるぽ」というキーに対して以下の顔文字を返す。
(#゚Д゚)ノ┌┛)д)゚゚ガッ

ちょっとした キーワード に反応して 固定メッセージ を返すだけなら、この gem があれば
Plugin を作るまでもない。

Installation

Add this line to your application's Gemfile:

gem 'ruboty-brain_dictionary'

And then execute:

$ bundle

Commands

Command Pattern Description
learn /learn\s{1}?(?<key>.+)?\s{\1}(?<value>.+)?\z/ learn key-value
remember /remember\s{0,1}?(?<key>.+)?\z/ remember your ruboty brain_dictionary that match your keys.
dict /dict\s{1}?(?<key>.+)?\z/ show your value from brain.
forget /forget\s{0,1}?(?<key>.+)?\z/ forget your ruboty brain_dictionary that match your key.

Usage

learn

  • learn key-value
>ruboty learn tu ka
>ruboty remember tu
tu,ka

remember

  • remember your ruboty brain_dictionary that match with your keys.
>ruboty learn hoge hoge-value
>ruboty learn hige hige-value
>ruboty learn hage hage-value
>ruboty learn hoo bar

# remember all
>ruboty remember
hage,hage-value
hige,hige-value
hoge,hoge-value
hoo,bar

# remember match keys
>ruboty remember ge
hage,hage-value
hige,hige-value
hoge,hoge-value

# remember match key
>ruboty remember hoo
hoo,bar

dict

>ruboty learn hoge hoge-value
>ruboty learn hige hige-value
>ruboty learn hage hage-value
>ruboty learn hoo bar
>dict hoge
hoge-value
>dict hoo
hoo-value
>dict hogea
>

forget

  • forget your ruboty brain_dictionary that match with your key.
>ruboty learn hoge hoge-value
>ruboty learn hige hige-value
>ruboty learn hage hage-value
>ruboty learn hoo bar

# remember all
>ruboty remember
hage,hage-value
hige,hige-value
hoge,hoge-value
hoo,bar

# forget hoo & confirm
>ruboty forget hoo
success delete key 'hoo'

>ruboty remember
hage,hage-value
hige,hige-value
hoge,hoge-value

# forget hoo ( not exist )
>ruboty forget hoo
no key 'hoo'

ENV

Name Description
-- --

Dependency

Name Description
-- --

:pencil: Memo

  • Ruboty の brain を利用しています。デフォルトだとメモリ保存なので再起動すると値は消えます
  • ruboty-redis を利用していれば、永続化されます

参照

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?