PageRenderTime 38ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/plugins/hi.rb

https://github.com/Epictetus/termtter
Ruby | 36 lines | 34 code | 0 blank | 2 comment | 0 complexity | 37d1be3cf91bd37adb1886c3c7011f61 MD5 | raw file
  1. # -*- coding: utf-8 -*-
  2. # あいうえお
  3. module Termtter::Client
  4. {
  5. :english => ['hi', 'hey', 'hello', 'How are you?', "How's going?"],
  6. :spanish => ['¡Hola!', '¿Cómo estás?'],
  7. :german => ['Guten Tag!'],
  8. }.each do |language, greetings|
  9. greetings.each do |greeting|
  10. # '¿Cómo estás?' -> 'como_estas'
  11. # MEMO:
  12. # command_name = greeting.tr('áó', 'ao').scan(/\w+/).join('_').downcase
  13. # works only on ruby 1.9
  14. command_name = greeting.
  15. gsub('á', 'a').
  16. gsub('ó', 'o').
  17. scan(/[a-zA-Z]+/).
  18. join('_').
  19. downcase
  20. register_command(
  21. :name => command_name,
  22. :author => 'ujihisa',
  23. :help => ["#{command_name} [(Optinal) USER]", "Post a greeting message in #{language.to_s.capitalize}"],
  24. :exec_proc => lambda {|arg|
  25. result =
  26. if arg.empty?
  27. Termtter::API.twitter.update(greeting)
  28. else
  29. name = normalize_as_user_name(arg)
  30. Termtter::API.twitter.update("@#{name} #{greeting}")
  31. end
  32. puts "=> " << result.text
  33. })
  34. end
  35. end
  36. end