termtter 0.8.3
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 +97 -0
- data/Rakefile +46 -0
- data/bin/kill_termtter +22 -0
- data/bin/termtter +7 -0
- data/lib/filter/en2ja.rb +11 -0
- data/lib/filter/english.rb +8 -0
- data/lib/filter/expand-tinyurl.rb +24 -0
- data/lib/filter/fib.rb +15 -0
- data/lib/filter/ignore.rb +19 -0
- data/lib/filter/reply.rb +8 -0
- data/lib/filter/reverse.rb +13 -0
- data/lib/filter/url_addspace.rb +16 -0
- data/lib/filter/yhara.rb +20 -0
- data/lib/plugin/april_fool.rb +15 -0
- data/lib/plugin/bomb.rb +29 -0
- data/lib/plugin/clear.rb +14 -0
- data/lib/plugin/confirm.rb +9 -0
- data/lib/plugin/cool.rb +10 -0
- data/lib/plugin/devel.rb +13 -0
- data/lib/plugin/english.rb +59 -0
- data/lib/plugin/erb.rb +17 -0
- data/lib/plugin/favorite.rb +75 -0
- data/lib/plugin/fib.rb +8 -0
- data/lib/plugin/filter.rb +69 -0
- data/lib/plugin/follow.rb +56 -0
- data/lib/plugin/graduatter.rb +9 -0
- data/lib/plugin/grass.rb +27 -0
- data/lib/plugin/group.rb +60 -0
- data/lib/plugin/growl.rb +62 -0
- data/lib/plugin/hatebu.rb +59 -0
- data/lib/plugin/history.rb +82 -0
- data/lib/plugin/keyword.rb +18 -0
- data/lib/plugin/log.rb +63 -0
- data/lib/plugin/modify_arg_hook_sample.rb +7 -0
- data/lib/plugin/msagent.rb +26 -0
- data/lib/plugin/multi_reply.rb +36 -0
- data/lib/plugin/notify-send.rb +17 -0
- data/lib/plugin/otsune.rb +21 -0
- data/lib/plugin/outputz.rb +35 -0
- data/lib/plugin/pause.rb +3 -0
- data/lib/plugin/plugin.rb +53 -0
- data/lib/plugin/post_exec_hook_sample.rb +9 -0
- data/lib/plugin/pre_exec_hook_sample.rb +9 -0
- data/lib/plugin/primes.rb +23 -0
- data/lib/plugin/quicklook.rb +38 -0
- data/lib/plugin/reblog.rb +40 -0
- data/lib/plugin/reload.rb +3 -0
- data/lib/plugin/say.rb +24 -0
- data/lib/plugin/scrape.rb +41 -0
- data/lib/plugin/screen.rb +24 -0
- data/lib/plugin/shell.rb +14 -0
- data/lib/plugin/sl.rb +48 -0
- data/lib/plugin/spam.rb +9 -0
- data/lib/plugin/standard_plugins.rb +269 -0
- data/lib/plugin/stdout.rb +62 -0
- data/lib/plugin/system_status.rb +33 -0
- data/lib/plugin/translation.rb +28 -0
- data/lib/plugin/update_editor.rb +53 -0
- data/lib/plugin/uri-open.rb +69 -0
- data/lib/plugin/wassr_post.rb +22 -0
- data/lib/plugin/yhara.rb +148 -0
- data/lib/plugin/yonda.rb +20 -0
- data/lib/termtter/api.rb +14 -0
- data/lib/termtter/client.rb +399 -0
- data/lib/termtter/command.rb +77 -0
- data/lib/termtter/connection.rb +39 -0
- data/lib/termtter/hook.rb +18 -0
- data/lib/termtter/status.rb +26 -0
- data/lib/termtter/task.rb +16 -0
- data/lib/termtter/task_manager.rb +116 -0
- data/lib/termtter/twitter.rb +173 -0
- data/lib/termtter/user.rb +13 -0
- data/lib/termtter/version.rb +3 -0
- data/lib/termtter.rb +157 -0
- data/spec/plugin/cool_spec.rb +10 -0
- data/spec/plugin/fib_spec.rb +16 -0
- data/spec/plugin/filter_spec.rb +18 -0
- data/spec/plugin/plugin_spec.rb +25 -0
- data/spec/plugin/shell_spec.rb +10 -0
- data/spec/plugin/spam_spec.rb +17 -0
- data/spec/plugin/standard_plugins_spec.rb +31 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/termtter/client_spec.rb +175 -0
- data/spec/termtter/command_spec.rb +161 -0
- data/spec/termtter/task_manager_spec.rb +78 -0
- data/spec/termtter/task_spec.rb +22 -0
- data/spec/termtter/user_spec.rb +27 -0
- data/spec/termtter_spec.rb +43 -0
- data/test/friends_timeline.json +5 -0
- data/test/search.json +8 -0
- data/test/test_termtter.rb +86 -0
- metadata +177 -0
@@ -0,0 +1,53 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
module Termtter::Client
|
6
|
+
if ENV['EDITOR']
|
7
|
+
configatron.plugins.update_editor.set_default('editor', ENV['EDITOR'])
|
8
|
+
else
|
9
|
+
configatron.plugins.update_editor.set_default('editor', 'vi')
|
10
|
+
end
|
11
|
+
configatron.plugins.update_editor.set_default('add_completion', false)
|
12
|
+
|
13
|
+
|
14
|
+
def self.input_editor
|
15
|
+
file = Tempfile.new('termtter')
|
16
|
+
editor = configatron.plugins.update_editor.editor
|
17
|
+
if configatron.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_status(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,69 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module Termtter::Client
|
4
|
+
public_storage[:uris] = []
|
5
|
+
|
6
|
+
add_hook do |statuses, event, t|
|
7
|
+
if !statuses.empty? && event == :update_friends_timeline
|
8
|
+
statuses.each do |s|
|
9
|
+
public_storage[:uris] += s.text.scan(%r|https?://[^\s]+|)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.open_uri(uri)
|
15
|
+
unless configatron.plugins.uri_open.browser.nil?
|
16
|
+
system configatron.plugins.uri_open.browser, uri
|
17
|
+
else
|
18
|
+
case RUBY_PLATFORM
|
19
|
+
when /linux/
|
20
|
+
system 'firefox', uri
|
21
|
+
when /mswin(?!ce)|mingw|bccwin/
|
22
|
+
system 'explorer', uri
|
23
|
+
else
|
24
|
+
system 'open', uri
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
add_command /^uri-open\s*$/ do |m, t|
|
30
|
+
public_storage[:uris].each do |uri|
|
31
|
+
open_uri(uri)
|
32
|
+
end
|
33
|
+
public_storage[:uris].clear
|
34
|
+
end
|
35
|
+
|
36
|
+
add_command /^uri-open\s+(\d+)$/ do |m, t|
|
37
|
+
if m[1]
|
38
|
+
index = m[1].to_i
|
39
|
+
open_uri(public_storage[:uris][index])
|
40
|
+
public_storage[:uris].delete_at(index)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
add_command /^uri-open\s+list\s*$/ do |m, t|
|
45
|
+
public_storage[:uris].each_with_index do |uri, index|
|
46
|
+
puts "#{index}: #{uri}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
add_command /^uri-open\s+delete\s+(\d+)$/ do |m, t|
|
51
|
+
public_storage[:uris].delete_at(m[1].to_i) if m[1]
|
52
|
+
end
|
53
|
+
|
54
|
+
add_command /^uri-open\s+clear\s*$/ do |m, t|
|
55
|
+
public_storage[:uris].clear
|
56
|
+
puts "clear uris"
|
57
|
+
end
|
58
|
+
|
59
|
+
add_completion do |input|
|
60
|
+
['uri-open ', 'uri-open list', 'uri-open delete', 'uri-open clear'].grep(/^#{Regexp.quote input}/)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
# ~/.termtter
|
64
|
+
# plugin 'uri-open'
|
65
|
+
#
|
66
|
+
# see also: http://ujihisa.nowa.jp/entry/c3dd00c4e0
|
67
|
+
#
|
68
|
+
# KNOWN BUG
|
69
|
+
# * 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 configatron.plugins.wassr_post.username, configatron.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
|
+
)
|
data/lib/plugin/yhara.rb
ADDED
@@ -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_status(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.
|
data/lib/plugin/yonda.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module Termtter::Client
|
4
|
+
register_command(
|
5
|
+
:name => :yonda, :aliases => [:y],
|
6
|
+
:exec_proc => proc{|arg|
|
7
|
+
public_storage[:unread_count] = 0
|
8
|
+
print "\033[2J\033[H" # FIXME
|
9
|
+
call_hooks [], :plugin_yonda_yonda
|
10
|
+
},
|
11
|
+
:help => ['yonda,y', 'Mark as read']
|
12
|
+
)
|
13
|
+
|
14
|
+
add_hook do |statuses, event|
|
15
|
+
case event
|
16
|
+
when :update_friends_timeline
|
17
|
+
public_storage[:unread_count] += statuses.size
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/termtter/api.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module Termtter
|
4
|
+
module API
|
5
|
+
class << self
|
6
|
+
attr_reader :connection, :twitter
|
7
|
+
def setup
|
8
|
+
@connection = Connection.new
|
9
|
+
@twitter = Termtter::Twitter.new(configatron.user_name, configatron.password, @connection)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
# Termtter::API.connection, Termtter::API.twitter can be accessed.
|