draftcode-termtter 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +4 -0
- data/README.rdoc +100 -0
- data/Rakefile +55 -0
- data/bin/kill_termtter +22 -0
- data/bin/termtter +6 -0
- data/lib/plugins/addspace.rb +27 -0
- data/lib/plugins/april_fool.rb +15 -0
- data/lib/plugins/bomb.rb +39 -0
- data/lib/plugins/clear.rb +14 -0
- data/lib/plugins/command_plus.rb +47 -0
- data/lib/plugins/confirm.rb +33 -0
- data/lib/plugins/cool.rb +10 -0
- data/lib/plugins/countter.rb +23 -0
- data/lib/plugins/devel.rb +18 -0
- data/lib/plugins/direct_messages.rb +36 -0
- data/lib/plugins/en2ja.rb +11 -0
- data/lib/plugins/english.rb +25 -0
- data/lib/plugins/erb.rb +17 -0
- data/lib/plugins/exec.rb +17 -0
- data/lib/plugins/exec_and_update.rb +14 -0
- data/lib/plugins/expand-tinyurl.rb +34 -0
- data/lib/plugins/fib.rb +28 -0
- data/lib/plugins/fib_filter.rb +14 -0
- data/lib/plugins/filter.rb +69 -0
- data/lib/plugins/graduatter.rb +8 -0
- data/lib/plugins/grass.rb +27 -0
- data/lib/plugins/group.rb +64 -0
- data/lib/plugins/growl.rb +52 -0
- data/lib/plugins/growl2.rb +143 -0
- data/lib/plugins/hatebu.rb +59 -0
- data/lib/plugins/hatebu_and_update.rb +58 -0
- data/lib/plugins/history.rb +93 -0
- data/lib/plugins/ignore.rb +19 -0
- data/lib/plugins/keyword.rb +18 -0
- data/lib/plugins/l2.rb +25 -0
- data/lib/plugins/log.rb +73 -0
- data/lib/plugins/me.rb +10 -0
- data/lib/plugins/modify_arg_hook_sample.rb +7 -0
- data/lib/plugins/msagent.rb +38 -0
- data/lib/plugins/multi_reply.rb +27 -0
- data/lib/plugins/notify-send.rb +22 -0
- data/lib/plugins/notify-send2.rb +52 -0
- data/lib/plugins/notify-send3.rb +45 -0
- data/lib/plugins/open_url.rb +59 -0
- data/lib/plugins/otsune.rb +21 -0
- data/lib/plugins/outputz.rb +33 -0
- data/lib/plugins/pause.rb +3 -0
- data/lib/plugins/post_exec_hook_sample.rb +9 -0
- data/lib/plugins/pre_exec_hook_sample.rb +9 -0
- data/lib/plugins/primes.rb +30 -0
- data/lib/plugins/quicklook.rb +41 -0
- data/lib/plugins/random.rb +23 -0
- data/lib/plugins/reblog.rb +40 -0
- data/lib/plugins/reload.rb +3 -0
- data/lib/plugins/reply.rb +8 -0
- data/lib/plugins/retweet.rb +46 -0
- data/lib/plugins/reverse.rb +13 -0
- data/lib/plugins/say.rb +26 -0
- data/lib/plugins/scrape.rb +41 -0
- data/lib/plugins/screen-notify.rb +20 -0
- data/lib/plugins/screen.rb +24 -0
- data/lib/plugins/shell.rb +14 -0
- data/lib/plugins/sl.rb +48 -0
- data/lib/plugins/spam.rb +16 -0
- data/lib/plugins/standard_plugins.rb +525 -0
- data/lib/plugins/stdout.rb +220 -0
- data/lib/plugins/storage.rb +55 -0
- data/lib/plugins/storage/DB.rb +37 -0
- data/lib/plugins/storage/status.rb +83 -0
- data/lib/plugins/storage/status_mook.rb +30 -0
- data/lib/plugins/switch_user.rb +22 -0
- data/lib/plugins/system_status.rb +33 -0
- data/lib/plugins/timer.rb +18 -0
- data/lib/plugins/tinyurl.rb +20 -0
- data/lib/plugins/translation.rb +38 -0
- data/lib/plugins/typable_id.rb +94 -0
- data/lib/plugins/update_editor.rb +53 -0
- data/lib/plugins/uri-open.rb +66 -0
- data/lib/plugins/wassr_post.rb +22 -0
- data/lib/plugins/yhara.rb +148 -0
- data/lib/plugins/yhara_filter.rb +8 -0
- data/lib/plugins/yonda.rb +21 -0
- data/lib/termtter.rb +38 -0
- data/lib/termtter/api.rb +57 -0
- data/lib/termtter/client.rb +324 -0
- data/lib/termtter/command.rb +80 -0
- data/lib/termtter/config.rb +68 -0
- data/lib/termtter/config_setup.rb +38 -0
- data/lib/termtter/connection.rb +41 -0
- data/lib/termtter/hook.rb +31 -0
- data/lib/termtter/optparse.rb +14 -0
- data/lib/termtter/system_extensions.rb +115 -0
- data/lib/termtter/task.rb +17 -0
- data/lib/termtter/task_manager.rb +116 -0
- data/lib/termtter/version.rb +4 -0
- data/spec/plugins/cool_spec.rb +10 -0
- data/spec/plugins/english_spec.rb +19 -0
- data/spec/plugins/fib_spec.rb +15 -0
- data/spec/plugins/filter_spec.rb +18 -0
- data/spec/plugins/pause_spec.rb +8 -0
- data/spec/plugins/primes_spec.rb +15 -0
- data/spec/plugins/shell_spec.rb +10 -0
- data/spec/plugins/sl_spec.rb +8 -0
- data/spec/plugins/spam_spec.rb +4 -0
- data/spec/plugins/standard_plugins_spec.rb +23 -0
- data/spec/plugins/storage/DB_spec.rb +12 -0
- data/spec/plugins/storage/status_spec.rb +24 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/termtter/client_spec.rb +255 -0
- data/spec/termtter/command_spec.rb +107 -0
- data/spec/termtter/config_spec.rb +111 -0
- data/spec/termtter/hook_spec.rb +78 -0
- data/spec/termtter/task_manager_spec.rb +78 -0
- data/spec/termtter/task_spec.rb +22 -0
- data/spec/termtter_spec.rb +29 -0
- data/test/friends_timeline.json +5 -0
- data/test/search.json +8 -0
- metadata +211 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
require 'erb'
|
|
4
|
+
|
|
5
|
+
config.plugins.system_status.set_default(:default_status_proc, lambda { Time.now.strftime("%x %X") })
|
|
6
|
+
config.plugins.system_status.set_default(:interval, 1)
|
|
7
|
+
config.plugins.system_status.set_default(:default_color, :on_blue)
|
|
8
|
+
config.plugins.system_status.set_default(:format, '<%= status %>')
|
|
9
|
+
|
|
10
|
+
def out_put_status(status, color)
|
|
11
|
+
formatted_status = ERB.new(config.plugins.system_status.format).result(binding)
|
|
12
|
+
colored_status = color(formatted_status, color)
|
|
13
|
+
print "\e[s\e[1000G\e[#{status.size - 1}D#{colored_status}\e[u"
|
|
14
|
+
$stdout.flush
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
module Termtter::Client
|
|
18
|
+
add_task(:name => :system_status, :interval => config.plugins.system_status.interval) do
|
|
19
|
+
status = (@@task_manager.get_task(:update_timeline).exec_at - Time.now).to_i.to_s
|
|
20
|
+
color = public_storage[:system_status_color] ||
|
|
21
|
+
config.plugins.system_status.default_color
|
|
22
|
+
out_put_status(status, color)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# system_status.rb
|
|
27
|
+
# show system status on left side.
|
|
28
|
+
# output public_storage[:system_status] or Time.now.strftime("%x %X") if nil
|
|
29
|
+
# example config
|
|
30
|
+
# config.plugins.system_status.default_status_proc = lambda { Time.now.strftime("%x %X") }
|
|
31
|
+
# config.plugins.system_status.interval = 1
|
|
32
|
+
# config.plugins.system_status.default_color = :on_blue
|
|
33
|
+
# config.plugins.system_status.format = '<%= status %>'
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
module Termtter::Client
|
|
4
|
+
register_command(
|
|
5
|
+
:name => :timer,
|
|
6
|
+
:exec_proc => lambda{|arg|
|
|
7
|
+
# argをparseする
|
|
8
|
+
return unless arg =~ /^\d+$/
|
|
9
|
+
after = arg.to_i
|
|
10
|
+
Termtter::Client.add_task(:after => after) do
|
|
11
|
+
text = "@#{config.user_name} 時間ですよ!!"
|
|
12
|
+
Termtter::API.twitter.update text
|
|
13
|
+
puts "=> " << text
|
|
14
|
+
end
|
|
15
|
+
},
|
|
16
|
+
:help => ['timer SEC', 'post reminder after SEC.']
|
|
17
|
+
)
|
|
18
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
Termtter::Client.register_hook(
|
|
4
|
+
:name => :tinyurl,
|
|
5
|
+
:points => [:modify_arg_for_update],
|
|
6
|
+
:exec_proc => lambda {|cmd, arg|
|
|
7
|
+
arg = arg.gsub(URI.regexp) do |url|
|
|
8
|
+
if url =~ %r!^https?:!
|
|
9
|
+
Termtter::API.connection.start('tinyurl.com', 80) do |http|
|
|
10
|
+
http.get('/api-create.php?url=' + URI.escape(url)).body
|
|
11
|
+
end
|
|
12
|
+
else
|
|
13
|
+
url
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
}
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
# tinyuri.rb
|
|
20
|
+
# make URLs in your update to convert tinyurl.com/XXXXXXX.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
require 'nokogiri'
|
|
4
|
+
require 'net/http'
|
|
5
|
+
require 'kconv'
|
|
6
|
+
require 'uri'
|
|
7
|
+
|
|
8
|
+
def translate(text, langpair)
|
|
9
|
+
req = Net::HTTP::Post.new('/translate_t')
|
|
10
|
+
req.add_field('Content-Type', 'application/x-www-form-urlencoded')
|
|
11
|
+
req.add_field('User-Agent', 'Mozilla/5.0')
|
|
12
|
+
Net::HTTP.version_1_2 # Proxy に対応してない
|
|
13
|
+
Net::HTTP.start('translate.google.co.jp', 80) {|http|
|
|
14
|
+
response = http.request(req, "langpair=#{langpair}&text=#{URI.escape(text)}")
|
|
15
|
+
doc = Nokogiri::HTML.parse(response.body, nil, 'utf-8')
|
|
16
|
+
return doc.css('#result_box').text
|
|
17
|
+
}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
Termtter::Client.register_command(
|
|
21
|
+
:name => :en2ja,
|
|
22
|
+
:exec_proc => lambda{|arg|
|
|
23
|
+
puts "translating..."
|
|
24
|
+
puts "=> #{translate(arg, 'en|ja')}"
|
|
25
|
+
}
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
Termtter::Client.register_command(
|
|
29
|
+
:name => :ja2en,
|
|
30
|
+
:exec_proc => lambda{|arg|
|
|
31
|
+
puts "translating..."
|
|
32
|
+
puts "=> #{translate(arg, 'ja|en')}"
|
|
33
|
+
}
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
# This plugin does not work yet.
|
|
37
|
+
# requirements
|
|
38
|
+
# nokogiri (sudo gem install nokogiri)
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
config.plugins.typable_id.set_default(:typable_keys, %w[ a i u e o
|
|
4
|
+
ka ki ku ke ko
|
|
5
|
+
ga gi gu ge go
|
|
6
|
+
sa si su se so
|
|
7
|
+
za zi zu ze zo
|
|
8
|
+
ta ti tu te to
|
|
9
|
+
da di du de do
|
|
10
|
+
na ni nu ne no
|
|
11
|
+
ha hi hu he ho
|
|
12
|
+
ba bi bu be bo
|
|
13
|
+
pa pi pu pe po
|
|
14
|
+
ma mi mu me mo
|
|
15
|
+
ya yu yo
|
|
16
|
+
ra ri ru re ro
|
|
17
|
+
wa wo
|
|
18
|
+
nn ])
|
|
19
|
+
|
|
20
|
+
module Termtter::Client
|
|
21
|
+
public_storage[:typable_id] = []
|
|
22
|
+
config.plugins.typable_id.typable_keys.each {|key|
|
|
23
|
+
public_storage[:typable_id].push([key, '', ''])
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
register_hook(
|
|
27
|
+
:name => :typable_id,
|
|
28
|
+
:points => [:post_filter],
|
|
29
|
+
:exec_proc => lambda {|filtered, event|
|
|
30
|
+
filtered.each do |s|
|
|
31
|
+
current_id = public_storage[:typable_id].shift
|
|
32
|
+
current_id[1] = s.id.to_s
|
|
33
|
+
current_id[2] = s
|
|
34
|
+
public_storage[:typable_id].push(current_id)
|
|
35
|
+
end
|
|
36
|
+
}
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
def self.typable_id_convert(id)
|
|
40
|
+
if current_id = public_storage[:typable_id].assoc(id.to_s)
|
|
41
|
+
return current_id[1]
|
|
42
|
+
elsif current_id = public_storage[:typable_id].rassoc(id.to_s)
|
|
43
|
+
return current_id[0]
|
|
44
|
+
else
|
|
45
|
+
return nil
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def self.typable_id_status(id)
|
|
50
|
+
if current_id = (public_storage[:typable_id].assoc(id.to_s)||\
|
|
51
|
+
public_storage[:typable_id].rassoc(id.to_s))
|
|
52
|
+
return current_id[2]
|
|
53
|
+
else
|
|
54
|
+
return nil
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def self.typable_id?(id)
|
|
59
|
+
if public_storage[:typable_id].assoc(id.to_s)
|
|
60
|
+
return true
|
|
61
|
+
else
|
|
62
|
+
return false
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
#Setting
|
|
68
|
+
# ex)
|
|
69
|
+
# config.plugins.stdout.timeline_format = '<90><%=time%></90> <<%=status_color%>><%=status%></<%=status_color%>> <90><%=id%>>[<%=Termtter::Client.typable_id_convert(id)%>]</90>
|
|
70
|
+
#Optional Settng
|
|
71
|
+
# ex) Like hepburn system
|
|
72
|
+
# config.plugins.typable_id.typable_keys = %w[ a i u e o
|
|
73
|
+
# ka ki ku ke ko ga gi gu ge go
|
|
74
|
+
# sa shi su se so za ji zu ze zo
|
|
75
|
+
# ta chi tsu te to da di du de do
|
|
76
|
+
# na ni nu ne no
|
|
77
|
+
# ha hi fu he ho ba bi bu be bo pa pi pu pe po
|
|
78
|
+
# ma mi mu me mo
|
|
79
|
+
# ya yu yo
|
|
80
|
+
# ra ri ru re ro
|
|
81
|
+
# wa wo
|
|
82
|
+
# nn ]
|
|
83
|
+
# ex) Hiragana
|
|
84
|
+
# config.plugins.typable_id.typable_keys = %w[あ い う え お
|
|
85
|
+
# か き く け こ が ぎ ぐ げ ご
|
|
86
|
+
# さ し す せ そ ざ じ ず ぜ ぞ
|
|
87
|
+
# た ち つ て と だ ぢ づ で ど
|
|
88
|
+
# な に ぬ ね の
|
|
89
|
+
# は ひ ふ へ ほ ば び ぶ べ ぼ ぱ ぴ ぷ ぺ ぽ
|
|
90
|
+
# ま み む め も
|
|
91
|
+
# や ゆ よ
|
|
92
|
+
# ら り る れ ろ
|
|
93
|
+
# わ を
|
|
94
|
+
# ん ]
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
require 'tempfile'
|
|
4
|
+
|
|
5
|
+
module Termtter::Client
|
|
6
|
+
if ENV['EDITOR']
|
|
7
|
+
config.plugins.update_editor.set_default('editor', ENV['EDITOR'])
|
|
8
|
+
else
|
|
9
|
+
config.plugins.update_editor.set_default('editor', 'vi')
|
|
10
|
+
end
|
|
11
|
+
config.plugins.update_editor.set_default('add_completion', true)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def self.input_editor
|
|
15
|
+
file = Tempfile.new('termtter')
|
|
16
|
+
editor = config.plugins.update_editor.editor
|
|
17
|
+
if config.plugins.update_editor.add_completion
|
|
18
|
+
file.puts "\n"*100 + "__END__\n" + public_storage[:users].to_a.join(' ')
|
|
19
|
+
end
|
|
20
|
+
file.close
|
|
21
|
+
system("#{editor} #{file.path}")
|
|
22
|
+
result = file.open.read
|
|
23
|
+
file.close(false)
|
|
24
|
+
result
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
register_command(
|
|
28
|
+
:name => :update_editor, :aliases => [:ue],
|
|
29
|
+
:exec_proc => lambda{|arg|
|
|
30
|
+
pause
|
|
31
|
+
text = input_editor
|
|
32
|
+
unless text.empty?
|
|
33
|
+
text = ERB.new(text).result(binding)
|
|
34
|
+
text.split("\n").each do |post|
|
|
35
|
+
break if post =~ /^__END__$/
|
|
36
|
+
unless post.empty?
|
|
37
|
+
Termtter::API.twitter.update(post)
|
|
38
|
+
puts "=> #{post}"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
resume
|
|
43
|
+
},
|
|
44
|
+
:help => ["update_editor,ue", "Update status from editor."]
|
|
45
|
+
)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# update_editor.rb
|
|
49
|
+
# update status from editor.
|
|
50
|
+
# example:
|
|
51
|
+
# > update_editor
|
|
52
|
+
# (type your status, save, close the editor)
|
|
53
|
+
# => (your status)
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
module Termtter::Client
|
|
4
|
+
public_storage[:uris] = []
|
|
5
|
+
|
|
6
|
+
register_hook(
|
|
7
|
+
:name => :uri_open,
|
|
8
|
+
:points => [:output],
|
|
9
|
+
:exec_proc => lambda {|statuses, event|
|
|
10
|
+
statuses.each do |s|
|
|
11
|
+
public_storage[:uris] += s[:text].scan(%r|https?://[^\s]+|)
|
|
12
|
+
end
|
|
13
|
+
}
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
def self.open_uri(uri)
|
|
17
|
+
unless config.plugins.uri_open.browser.empty?
|
|
18
|
+
system config.plugins.uri_open.browser, uri
|
|
19
|
+
else
|
|
20
|
+
case RUBY_PLATFORM
|
|
21
|
+
when /linux/
|
|
22
|
+
system 'firefox', uri
|
|
23
|
+
when /mswin(?!ce)|mingw|bccwin/
|
|
24
|
+
system 'explorer', uri
|
|
25
|
+
else
|
|
26
|
+
system 'open', uri
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
register_command(
|
|
32
|
+
:name => :'uri-open', :aliases => [:uo],
|
|
33
|
+
:exec_proc => lambda{|arg|
|
|
34
|
+
case arg
|
|
35
|
+
when /^\s+$/
|
|
36
|
+
public_storage[:uris].each do |uri|
|
|
37
|
+
open_uri(uri)
|
|
38
|
+
end
|
|
39
|
+
public_storage[:uris].clear
|
|
40
|
+
when /^\s*list\s*$/
|
|
41
|
+
public_storage[:uris].each_with_index do |uri, index|
|
|
42
|
+
puts "#{index}: #{uri}"
|
|
43
|
+
end
|
|
44
|
+
when /^\s*delete\s+(\d+)\s*$/
|
|
45
|
+
puts 'delete'
|
|
46
|
+
public_storage[:uris].delete_at($1.to_i)
|
|
47
|
+
when /^\s*clear\s*$/
|
|
48
|
+
public_storage[:uris].clear
|
|
49
|
+
puts "clear uris"
|
|
50
|
+
when /^\s*(\d+)\s*$/
|
|
51
|
+
open_uri(public_storage[:uris][$1.to_i])
|
|
52
|
+
public_storage[:uris].delete_at($1.to_i)
|
|
53
|
+
end
|
|
54
|
+
},
|
|
55
|
+
:completion_proc => lambda{|cmd, arg|
|
|
56
|
+
%w(list delete clear).grep(/^#{Regexp.quote arg}/).map{|a| "#{cmd} #{a}"}
|
|
57
|
+
}
|
|
58
|
+
)
|
|
59
|
+
end
|
|
60
|
+
# ~/.termtter
|
|
61
|
+
# plugin 'uri-open'
|
|
62
|
+
#
|
|
63
|
+
# see also: http://ujihisa.nowa.jp/entry/c3dd00c4e0
|
|
64
|
+
#
|
|
65
|
+
# KNOWN BUG
|
|
66
|
+
# * In Debian, exit or C-c in the termtter kills your firefox.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
require 'uri'
|
|
4
|
+
require 'net/http'
|
|
5
|
+
|
|
6
|
+
Termtter::Client.register_hook(
|
|
7
|
+
:name => :wassr_post,
|
|
8
|
+
:points => [:modify_arg_for_update],
|
|
9
|
+
:exec_proc => lambda {|cmd, arg|
|
|
10
|
+
begin
|
|
11
|
+
Net::HTTP.version_1_2
|
|
12
|
+
req = Net::HTTP::Post.new("/statuses/update.json?")
|
|
13
|
+
req.basic_auth config.plugins.wassr_post.username, config.plugins.wassr_post.password
|
|
14
|
+
Net::HTTP.start('api.wassr.jp', 80) do |http|
|
|
15
|
+
res = http.request(req, "status=#{URI.escape(arg.strip)}&source=Termtter")
|
|
16
|
+
end
|
|
17
|
+
rescue
|
|
18
|
+
puts "RuntimeError: #{$!}"
|
|
19
|
+
end
|
|
20
|
+
return arg
|
|
21
|
+
}
|
|
22
|
+
)
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
if RUBY_VERSION < "1.8.7"
|
|
4
|
+
class Array
|
|
5
|
+
def choice
|
|
6
|
+
at(rand(size))
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# based on new-harizon.rb
|
|
12
|
+
module Yharian
|
|
13
|
+
|
|
14
|
+
VOICES =
|
|
15
|
+
%w(Agnes Albert Bad\ News Bahh Bells Boing Bruce Bubbles Cellos Deranged Fred Hysterical Junior Kathy Pipe\ Organ Princess Ralph Trinoids Vicki Victoria Whisper Zarvox)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class Speaker
|
|
19
|
+
attr_reader :name
|
|
20
|
+
def initialize(name)
|
|
21
|
+
@name = name
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def talk(context)
|
|
25
|
+
n = 7
|
|
26
|
+
words = (0..rand(n)).map { %w[y hara].choice }.
|
|
27
|
+
inject {|r, e| r + (rand < 0.97 ? ' ' : ', ') + e }
|
|
28
|
+
eos = %w(? ? . . . . . . . . !).choice
|
|
29
|
+
[Remark.new(self,words, eos)]
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def voice(context = nil)
|
|
33
|
+
@name
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class Alex < Speaker
|
|
40
|
+
def initialize
|
|
41
|
+
super 'Alex'
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
class Vicki < Speaker
|
|
46
|
+
def initialize
|
|
47
|
+
super 'Vicki'
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
class Yhara < Speaker
|
|
52
|
+
def initialize
|
|
53
|
+
super 'yhara'
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def voice(context = nil)
|
|
57
|
+
VOICES.choise
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
class Jenifer < Speaker
|
|
62
|
+
ARABIAN = %w[ايران نيست]
|
|
63
|
+
|
|
64
|
+
def initialize
|
|
65
|
+
super 'jenifer'
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def talk(context)
|
|
69
|
+
words = (0..rand(3)). map { ARABIAN.choice }.join(' ')
|
|
70
|
+
[Remark.new(self,words, '')]
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def voice(context = nil)
|
|
74
|
+
'Princess'
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
class Remark
|
|
79
|
+
attr_reader :speaker, :words, :eos, :pronounciation
|
|
80
|
+
|
|
81
|
+
def initialize(speaker, words, eos, options = {})
|
|
82
|
+
@speaker = speaker
|
|
83
|
+
@words = words
|
|
84
|
+
@eos = eos # end of text : "?" or "." or "!"
|
|
85
|
+
@pronounciation = options[:pronounciation] || text
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def text
|
|
89
|
+
@words + @eos
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def interrogative?
|
|
93
|
+
@eos == '?'
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def display
|
|
97
|
+
puts "#{@speaker.name}: #{text}"
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def say(context = nil)
|
|
101
|
+
Kernel.say pronounciation, :voice => @speaker.voice(context)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def correct?(s)
|
|
105
|
+
s.gsub(/[^yhar]/,'') == @words.gsub(/[^yhar]/,'')
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
@@context = []
|
|
110
|
+
@@speakers = [Alex.new, Vicki.new]
|
|
111
|
+
|
|
112
|
+
def self.text
|
|
113
|
+
if ( @@context.last && Yhara === @@context.last.speaker && rand < 0.25 ) || rand < 0.01
|
|
114
|
+
speaker = Jenifer.new
|
|
115
|
+
elsif @@context.last && @@context.last.words =~ /y hara/ and @@context.last.interrogative? and rand < 0.25
|
|
116
|
+
speaker = Yhara.new
|
|
117
|
+
else
|
|
118
|
+
speaker = @@speakers[rand(2)]
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
remark = speaker.talk(@@context).first
|
|
122
|
+
@@context.push remark
|
|
123
|
+
remark.text
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
module Termtter::Client
|
|
128
|
+
register_command(
|
|
129
|
+
:name => :yhara,
|
|
130
|
+
:exec_proc => lambda{|arg|
|
|
131
|
+
text = "#{'@' if arg[0..0] != '@'}#{arg} #{Yharian::text}"
|
|
132
|
+
Termtter::API.twitter.update(text)
|
|
133
|
+
puts "=> #{text}"
|
|
134
|
+
},
|
|
135
|
+
:completion_proc => lambda {|cmd, args|
|
|
136
|
+
if /(.*)@([^\s]*)$/ =~ args
|
|
137
|
+
find_user_candidates $2, "#{cmd} #{$1}@%s"
|
|
138
|
+
end
|
|
139
|
+
},
|
|
140
|
+
:help => ["yhara (USER)", 'Post a new Yharian sentence']
|
|
141
|
+
)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# yhara.rb
|
|
145
|
+
# post a new yharian sentence
|
|
146
|
+
# example:
|
|
147
|
+
# > yhara
|
|
148
|
+
# => hara y y hara.
|