Skip to content

Commit

Permalink
add lib/plugin.rb and use the module
Browse files Browse the repository at this point in the history
  • Loading branch information
ujihisa committed Jan 5, 2009
1 parent a5d559e commit 3c2e007
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
2 changes: 2 additions & 0 deletions lib/plugin.rb
@@ -0,0 +1,2 @@
module Termtter::Plugin
end
10 changes: 6 additions & 4 deletions lib/plugin/english.rb
@@ -1,8 +1,10 @@
Termtter::Client.clear_hooks # FIXME: not to clear all but to clear just stdout.rb

# english? :: String -> Boolean
def english?(message)
/[一-龠]+|[ぁ-ん]+|[ァ-ヴー]+|[a-zA-Z0-9]+/ !~ message
module Termtter::Plugin
# english? :: String -> Boolean
def self.english?(message)
/[一-龠]+|[ぁ-ん]+|[ァ-ヴー]+|[a-zA-Z0-9]+/ !~ message
end
end

# FIXME: The code below is a copy from stdout.rb so it's not DRY. DRY it.
Expand All @@ -15,7 +17,7 @@ def english?(message)
if event == :update_friends_timeline then statuses = statuses.reverse end
statuses.each do |s|
text = s.text.gsub("\n", '')
next unless english?(text) # if you substitute "if" for "unless", this script will be "japanese.rb"
next unless Termtter::Plugin.english?(text) # if you substitute "if" for "unless", this script will be "japanese.rb"
color_num = colors[s.user_screen_name.hash % colors.size]
status = "#{s.user_screen_name}: #{text}"
if s.in_reply_to_status_id
Expand Down
14 changes: 8 additions & 6 deletions lib/plugin/say.rb
@@ -1,18 +1,20 @@
raise 'say.rb runs only in OSX Leopard' if /darwin9/ !~ RUBY_PLATFORM

# say :: String -> String -> IO ()
def say(who, what)
voices = %w(Alex Bruce Fred Junior Ralph Agnes Kathy Princess Vicki Victoria Albert Bad\ News Bahh Bells Boing Bubbles Cellos Deranged Good\ News Hysterical Pipe\ Organ Trinoids Whisper Zarvox)
voice = voices[who.hash % voices.size]
system 'say', '-v', voice, what
module Termtter::Plugin
# say :: String -> String -> IO ()
def self.say(who, what)
voices = %w(Alex Bruce Fred Junior Ralph Agnes Kathy Princess Vicki Victoria Albert Bad\ News Bahh Bells Boing Bubbles Cellos Deranged Good\ News Hysterical Pipe\ Organ Trinoids Whisper Zarvox)
voice = voices[who.hash % voices.size]
system 'say', '-v', voice, what
end
end

module Termtter::Client
add_hook do |statuses, event, t|
if !statuses.empty? && event == :update_friends_timeline
statuses.reverse.each do |s|
text_without_uri = s.text.gsub(%r|https?://[^\s]+|, 'U.R.I.')
say s.user_screen_name, text_without_uri
Termtter::Plugin.say s.user_screen_name, text_without_uri
end
end
end
Expand Down
6 changes: 4 additions & 2 deletions lib/plugin/stdout.rb
@@ -1,5 +1,7 @@
def color(str, num)
"\e[#{num}m#{str}\e[0m"
module Termtter::Plugin
def color(str, num)
"\e[#{num}m#{str}\e[0m"
end
end

Termtter::Client.add_hook do |statuses, event|
Expand Down

0 comments on commit 3c2e007

Please sign in to comment.