Last active
August 29, 2015 13:57
-
-
Save zakuroishikuro/9637890 to your computer and use it in GitHub Desktop.
ヒェーと対話
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# シェルで比叡と対話する (hieisay) | |
# http://qiita.com/manuluu/items/90d867025cc617a29f5a | |
require 'optparse' | |
Version = '214.6' | |
DEFAULT = :default | |
class Hiei | |
def initialize(aa) | |
@aa = aa | |
end | |
def speak(message="", type=DEFAULT) | |
type = @aa.include?(type) ? type : DEFAULT | |
@aa[type].sub(/\$message/, message.to_s) | |
end | |
def react(message="") | |
type = case message.to_s | |
when /可愛い*|かわい+|カワイ+|カワイ+|きゃわ+|キャワ+|キャワ+|天使/ | |
:tere | |
when /おい|オイ|作(れ|って)|買(え|って)/ | |
:f_ck | |
when /[し死](ね|んで)|[き消]え[ろて]/ | |
:cry | |
when /[ひヒヒ][えぇエェエェ]+/ | |
:ase | |
else | |
DEFAULT | |
end | |
speak "", type | |
end | |
attr_accessor :aa | |
end | |
hiei = Hiei.new (eval DATA.read) # ソースの途中にAAを入れたくなかったので、下に書いた。(1ファイルにまとめたかった) | |
type = DEFAULT | |
react = false | |
#オプションのパース | |
opt = OptionParser.new | |
opt.on('-l', '--list', '表示可能なヒェーとタイプを全表示'){ | |
hiei.aa.each{|type, aa| puts "[type: #{type}]", aa.sub(/[\\s ]*\$message/,""), "\n"} | |
exit | |
} | |
opt.on('-s', '--speak [TYPE]', 'ヒェーに喋ってもらう (デフォルト)', "TYPE: #{hiei.aa.keys.map{|v|v.to_s}*", "}"){|v| | |
type = v.to_sym | |
} | |
opt.on('-r', '--react', 'ヒェーに話しかける'){|v| | |
react = v | |
} | |
opt.on('-i', '--interactive', '対話モード (空白 or Control+dで終了)'){ | |
loop do | |
print "\n->" | |
msg = $stdin.gets | |
break if msg.to_s.strip.empty? | |
puts hiei.react(msg) | |
end | |
puts | |
exit | |
} | |
begin | |
opt.parse!(ARGV) | |
rescue OptionParser::InvalidOption | |
puts $!, opt.help | |
exit | |
end | |
msg = ARGV[0] | |
if react | |
puts hiei.react(msg) | |
else | |
puts hiei.speak(msg, type) | |
end | |
__END__ | |
{default:<<'AA', | |
,,.:≧=-=ミメ | |
//〈/>'7"⌒`ヾ、 | |
__i.://./:./\.:V | |
〔_}]:厶イ:/ / 、}ヘ | |
/./厶イ/ ● ● ト{_/ $message | |
厶/:人_ /`ー‐ 、 |i | |
厶イハ小:、 / / 八 | |
/V ト、`二 ´_,イ/ | |
/ ∧ ∨ ヽ//|⌒ \ | |
/⌒ \/ハ ∨ //.|、 /ス | |
AA | |
ase:<<'AA', | |
,,.:≧=-=ミメ | |
//〈/>'7"⌒`ヾ、 | |
__i.://./:./\.:V | |
〔_}]:厶イ:/し ー 、}ヘ | |
/./厶イ/ ● ● ト{_/ $message | |
厶/:人_ u /`ー‐ 、u |i | |
厶イハ小:、 / / U八 | |
/V ト、`二 ´_,イ/ | |
/ ∧ ∨ ヽ//|⌒ \ | |
/⌒ \/ハ ∨ //.|、 /ス | |
AA | |
tere:<<'AA', | |
,,.:≧=-=ミメ | |
//〈/>'7"⌒`ヾ、 | |
__i.://./:./\.:V | |
〔_}]:厶イ:/ \ 、}ヘ | |
/./厶イ/ ● ● ト{_/ $message | |
厶/:人_/// /`ー‐ 、//|i | |
厶イハ小:、 / ノ 八 | |
/V ト、`二 ´_,イ/ | |
/ ∧ ∨ ヽ//|⌒ \ | |
/⌒ \/ハ ∨ //.|、 /ス | |
AA | |
f_ck:<<'AA', | |
,,.:≧=-=ミメ | |
//〈/>'7"⌒`ヾ、 | |
__i.://./:./\.:V | |
〔_}]:厶イ:/ \ 、}ヘ | |
/./厶イ/ ●..:::.● ト{_/ $message | |
厶/:人_ /`ー‐ 、 |i ∩ | |
厶イハ小:、 / / 八 | | | |
/V ト、`二 ´_,イ/ ( ) | |
/ ∧ ∨ ヽ//|⌒ \ / / | |
/⌒ \/ハ ∨ //.|、 /ス/ / | |
AA | |
cry:<<'AA', | |
____ | |
_,:´.:.::.、 | |
,ィi「.:.:.:.:ヽ | |
、_,,.ノ:.V|:.:.:.:.:', | |
\.:.r┴┬‐r-=rz==rz=rミ | |
ヾーr‐≧''".:.:.:.:.', | |
<:./^i:/:.:イ:./.:.i | |
`ヽ} レ|//ヽ|/ヽ/| $message | |
/⌒ ヽ>、 /V ノ::/´7从 | |
i Vト| /_/ ノ | |
\:、 Vハ| |V_| | | |
/{二ニV| | V| | | |
/ ( >⌒ i 上>⌒ i | |
/ | /〉 \/ | | |
/ :| /| \ | | |
AA | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment