Skip to content

Commit

Permalink
add magic comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Sixeight committed Jan 31, 2009
1 parent 31cbec2 commit 1e5522c
Show file tree
Hide file tree
Showing 78 changed files with 3,597 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/filter/en2ja.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# -*- coding: utf-8 -*-

plugin 'translation'



Termtter::Client.add_filter do |statuses|

statuses.each do |s|

if s.english?

s.text = translate(s.text, 'en|ja')

end

end

end
23 changes: 23 additions & 0 deletions lib/filter/expand-tinyurl.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,45 @@
# -*- coding: utf-8 -*-

module Termtter::Client

add_filter do |statuses|

statuses.each do |s|

s.text.gsub!(%r'(http://tinyurl\.com(/[\w/]+))') do |m|

expand_tinyurl($2) || $1

end

end

statuses

end

end



def expand_tinyurl(path)

http_class = Net::HTTP

unless configatron.proxy.host.empty?

http_class = Net::HTTP::Proxy(configatron.proxy.host,

configatron.proxy.port,

configatron.proxy.user_name,

configatron.proxy.password)

end

res = http_class.new('tinyurl.com').head(path)

res['Location']

end
14 changes: 14 additions & 0 deletions lib/filter/fib.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
# -*- coding: utf-8 -*-

def fib(n)i=0;j=1;n.times{j=i+i=j};i end

module Termtter::Client

add_filter do |statuses|

statuses.each do |s|

s.text.gsub!(/(\d+)/) do |m|

n = $1.to_i

n < 1000000000 ? fib(n) : n # not to calc fib(id)

end

end

statuses

end

end


18 changes: 18 additions & 0 deletions lib/filter/ignore.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
# -*- coding: utf-8 -*-



configatron.filters.ignore.set_default(:words, [])



module Termtter::Client

add_filter do |statuses|

ignore_words = configatron.filters.ignore.words

statuses.delete_if do |s|

ignore_words.any? {|i| i =~ s.text }

end

end

end



# filter/ignore.rb

# ignore words

# setting

# configatron.filters.ignore.words = [ /ignore/, /words/ ]


12 changes: 12 additions & 0 deletions lib/filter/reverse.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
# -*- coding: utf-8 -*-

module Termtter::Client

add_filter do |statuses|

statuses.map do |s|

s.text = s.text.split(//).reverse.to_s

s

end

end

end



# filter-reverse.rb

# reverse texts
14 changes: 14 additions & 0 deletions lib/plugin/april_fool.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
# -*- coding: utf-8 -*-

def april_fool?;true;end

def april_fool;april_fool? ? "今日はエイプリルフールではありません。" : "今日はエイプリルフールです。";end



Termtter::Client.register_command(

:name => :april_fool, :aliases => [:af],

:exec_proc => proc {|arg|

if arg =~ /^\?you\s(\w+)/

puts "=> #{Termtter::Client.update_status("@#{$1} #{april_fool}")}"

else

puts "=> #{Termtter::Client.update_status(april_fool)}"

end

}

)
28 changes: 28 additions & 0 deletions lib/plugin/bomb.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,55 @@
# -*- coding: utf-8 -*-

module Termtter

class Status

def bomb?

/爆発|bomb/ =~ self.text

end

end



module Client

register_command(

:name => :bomb, :aliases => [],

:exec_proc => proc {|arg|

text = "#{arg.strip} 爆発しろ!"

Termtter::API::twitter.update_status(text)

puts "=> #{text}"

},

:help => ['bomb WORD', 'Bomb it']

)

end

end



# bomb.rb

# Bomb it!

#

# See http://gyazo.com/4b33517380673d92f51a52e675ecdb02.png .

# configatron.plugins.stdout.timeline_format =

# '<%= color(time, 90) %> <%= s.bomb? ? color(color(status, 41), 37) : color(status, status_color) %> <%= color(id, 90) %>'

# vim: fenc=utf8
8 changes: 8 additions & 0 deletions lib/plugin/confirm.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# -*- coding: utf-8 -*-

Termtter::Client.register_hook(

:name => :confirm,

:points => [:pre_exec_update],

:exec_proc => proc {|cmd, arg|

false if arg.empty? || /^y?$/i !~ Readline.readline("update? #{arg} [Y/n] ", false)

}

)
9 changes: 9 additions & 0 deletions lib/plugin/cool.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
# -*- coding: utf-8 -*-

module Termtter::Client

register_macro(:cool, "update @%s cool.",

:help => ['cool {SCREENNAME}', 'update "@{SCREENNAME} cool."'],

:completion_proc => proc {|cmd, args|

find_user_candidates args, "#{cmd} %s"

}

)

end
58 changes: 58 additions & 0 deletions lib/plugin/english.rb
Original file line number Diff line number Diff line change
@@ -1,57 +1,115 @@
# -*- coding: utf-8 -*-

require 'erb'



module Termtter

Client.clear_hooks # FIXME: not to clear all but to clear just stdout.rb



configatron.set_default(

:timeline_format,

'<%= color(time, 90) %> <%= color(status, status_color) %> <%= color(id, 90) %>')



def color(str, num)

"\e[#{num}m#{str}\e[0m"

end



# FIXME: The code below is a copy from stdout.rb so it's not DRY. DRY it.



Client.add_hook do |statuses, event|

colors = %w(0 31 32 33 34 35 36 91 92 93 94 95 96)



case event

when :update_friends_timeline, :list_friends_timeline, :list_user_timeline, :show, :replies

unless statuses.empty?

statuses.reverse! if event == :update_friends_timeline

statuses.each do |s|

text = s.text.gsub("\n", '')

next unless Status.english?(text) # if you substitute "if" for "unless", this script will be "japanese.rb"

status_color = colors[s.user_screen_name.hash % colors.size]

status = "#{s.user_screen_name}: #{text}"

if s.in_reply_to_status_id

status += " (reply to #{s.in_reply_to_status_id})"

end



time_format = case event

when :update_friends_timeline, :list_friends_timeline

'%H:%M:%S'

else

'%m-%d %H:%M'

end

time = "(#{s.created_at.strftime(time_format)})"



id = s.id



puts ERB.new(configatron.timeline_format).result(binding)

end

end

when :search

statuses.each do |s|

text = s.text.gsub("\n", '')

status_color = colors[s.user_screen_name.hash % colors.size]



status = "#{s.user_screen_name}: #{text}"

time = "(#{s.created_at.strftime('%m-%d %H:%M')})"

id = s.id

puts ERB.new(configatron.timeline_format).result(binding)

end

end

end

end
Loading

0 comments on commit 1e5522c

Please sign in to comment.