Skip to content

Commit

Permalink
Merge branch 'master' into work
Browse files Browse the repository at this point in the history
Conflicts:
	lib/plugins/defaults/stdout.rb
  • Loading branch information
nanki committed Aug 13, 2010
2 parents 358e272 + 8fb3337 commit 49baed1
Show file tree
Hide file tree
Showing 104 changed files with 1,356 additions and 384 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -11,7 +11,7 @@ begin
gem.add_dependency("json", ">= 1.1.3")
gem.add_dependency("highline", ">= 1.5.0")
gem.add_dependency("termcolor", ">= 1.0.0")
gem.add_dependency("rubytter", ">= 0.11.0")
gem.add_dependency("rubytter", ">= 1.4.0")
gem.add_dependency("notify", ">= 0.2.1")
gem.authors = %w(jugyo ujihisa)
gem.email = 'jugyo.org@gmail.com'
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
1.7.2
1.8.0
2 changes: 1 addition & 1 deletion lib/plugins/aa.rb
Expand Up @@ -34,11 +34,11 @@ def self.make

Termtter::Client.register_command(
:name => :aa,
:author => 'hitode909',
:exec_proc => lambda {|arg|
name = Termtter::Client.normalize_as_user_name(arg)
command = name.length > 0 ? "u @#{name} #{AAMaker.make}" : "u #{AAMaker.make}"
Termtter::Client.execute command
},
:help => ["aa [(Optinal) USER]", "Post a AA"]
)

17 changes: 5 additions & 12 deletions lib/plugins/appendtitle.rb
Expand Up @@ -9,33 +9,26 @@
module Termtter::Client
config.plugins.appendtitle.set_default(:timeout, 30)
config.plugins.appendtitle.set_default(:cache_expire, 3600 * 24 * 7)
config.plugins.appendtitle.set_default(:memcached_server, 'localhost:11211')

def self.memcache_client
@memcache_client ||= MemCache.new(config.plugins.appendtitle.memcached_server)
end

def self.fetch_title(uri)
return unless uri
key = %w{ termtter plugins appendtitle title}.push(Digest::SHA1.hexdigest(uri)).join('-')
if v = memcache_client.get(key)
key = %w{ plugins appendtitle title}.push(Digest::SHA1.hexdigest(uri)).join('-')
if v = memory_cache.get(key)
logger.debug "appendtitle: cache hit for #{uri}"
return v
end

memcache_client.set(key, '', config.plugins.appendtitle.cache_expire) # to avoid duplicate fetch
memory_cache.set(key, '', config.plugins.appendtitle.cache_expire) # to avoid duplicate fetch
begin
logger.debug "appendtitle: fetching title for #{uri}"
source = Nokogiri(open(uri).read)
if source and source.at('title')
title = source.at('title').text
memcache_client.set(key, title, config.plugins.appendtitle.cache_expire)
memory_cache.set(key, title, config.plugins.appendtitle.cache_expire)
return title
end
nil
rescue Timeout::Error
nil
rescue
rescue Timeout::Error, StandardError
nil
end
end
Expand Down
25 changes: 25 additions & 0 deletions lib/plugins/basic.rb
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
config.access_token = ''
config.access_token_secret = ''

module OAuth
class AccessToken
def initialize(consumer, access_token, access_token_secret)
end
end
end
module Termtter
class RubytterProxy
def initialize(access_token, twitter_option)
user_name = config.plugins.basic.user_name
password = config.plugins.basic.password
@rubytter = Rubytter.new(user_name, password, twitter_option)
end
end
end

# basic.rb
# Use Basic Auth instead of OAuth
#
# config.plugins.basic.user_name = 'your_name'
# config.plugins.basic.password = 'the secret'
32 changes: 32 additions & 0 deletions lib/plugins/copy.rb
@@ -0,0 +1,32 @@
config.plugins.copy.set_default(:style, "@<%= t.user.screen_name %>: <%= t.text %> [ <%= url %> ]")

def copy_to_clipboard(str)
if /darwin/i =~ RUBY_PLATFORM
IO.popen("pbcopy", "w") do |io|
io.print str
end
else
puts "Sorry, this plugin is only in Mac OS X."
end
str
end

Termtter::Client.plug 'url'

Termtter::Client.register_command(:name => :copy,
:exec => lambda do |arg|
t = Termtter::API.twitter.show(arg)
url = url_by_tweet(t)
erbed_text = ERB.new(config.plugins.copy.style).result(binding)

puts "Copied=> #{copy_to_clipboard(erbed_text)}"
end)

Termtter::Client.register_command(:name => :copy_url,
:exec => lambda do |arg|
t = Termtter::API.twitter.show(arg)
url = url_by_tweet(t)

puts "Copied=> #{copy_to_clipboard(url)}"

end)
1 change: 1 addition & 0 deletions lib/plugins/defaults/auto_reload.rb
Expand Up @@ -4,6 +4,7 @@
Termtter::Client.execute('reload -r')
rescue TimeoutError
# do nothing
rescue
rescue Exception => e
Termtter::Client.handle_error(e)
end
Expand Down
18 changes: 18 additions & 0 deletions lib/plugins/defaults/cache.rb
@@ -0,0 +1,18 @@
require 'pp'

module Termtter::Client
register_command(
:name => :"cache stats",
:help => ['cache stats', 'Show Memcached stats.'],
:exec_proc => lambda {|arg|
puts memory_cache.stats.pretty_inspect
})

register_command(
:name => :"cache flush",
:help => ['cache flush', 'Flush all caches.'],
:exec_proc => lambda {|arg|
memory_cache.flush_all
logger.info "cache flushed."
})
end
3 changes: 2 additions & 1 deletion lib/plugins/defaults/command_line.rb
Expand Up @@ -64,6 +64,7 @@ def start_input_thread
Client.handle_error(e)
end
end
Client.exit
end
@input_thread.join
end
Expand Down Expand Up @@ -113,7 +114,7 @@ def setup_readline

def trap_setting()
return if /mswin(?!ce)|mingw|bccwin/ =~ RUBY_PLATFORM

begin
stty_save = `stty -g`.chomp
trap("INT") do
Expand Down
21 changes: 15 additions & 6 deletions lib/plugins/defaults/fib.rb
@@ -1,7 +1,16 @@
def fib(n)i=0;j=1;n.times{j=i+i=j};i end
Termtter::Client.register_command(:fib) do |arg|
n = arg.to_i
text = "fib(#{n}) = #{fib n}"
Termtter::API.twitter.update(text)
puts "=> " << text
end
Termtter::Client.register_command(:name => :fib,
:aliases => [:f, :ho],
:exec => lambda do |arg|
case arg
when "ukumori"
puts 'Does it mean "Sora Harakami (@sora_h)"?'
when "ootsuite", "otsuite"
puts "NDA :D"
else
n = arg.to_i
text = "fib(#{n}) = #{fib n}"
Termtter::API.twitter.update(text)
puts "=> " << text
end
end)
7 changes: 5 additions & 2 deletions lib/plugins/defaults/retweet.rb
Expand Up @@ -8,10 +8,12 @@
:official_retweet, true)
config.plugins.retweet.set_default(
:quotetweet, false)
config.plugins.retweet.set_default(
:as_reply, false)

module Termtter::Client
def self.post_retweet(s, comment = nil)
s.user.protected and
s[:user][:protected] and
config.plugins.retweet.confirm_protected and
!confirm("#{s.user.screen_name} is protected! Are you sure?", false) and
return
Expand All @@ -33,7 +35,8 @@ def self.post_retweet(s, comment = nil)
comment += ' ' unless comment.nil?
rt_or_qt = (config.plugins.retweet.quotetweet and comment) ? 'QT' : 'RT'
text = ERB.new(config.plugins.retweet.format).result(binding)
Termtter::API.twitter.update(text)
params = config.plugins.retweet.as_reply ? {:in_reply_to_status_id => s.id} : {}
Termtter::API.twitter.update(text, params)
puts "=> #{text}"
end

Expand Down

0 comments on commit 49baed1

Please sign in to comment.