Module: Joggle::Commands
- Included in:
- Engine
- Defined in:
- lib/joggle/commands.rb
Overview
Mixin to handle commands.
Constant Summary collapse
- HELP =
String constant for .help command.
[ "Joggle Help:", "Available commands:", " .help - Display this help screen.", " .register <user> <pass> - Register Twitter username and password.", " .unregister - Forget Twitter username and password.", # TODO: " .force <msg> - Force tweet.", # TODO: " .list - List recent tweets.", "Any other message with two words or more is sent as a tweet. See the Joggle home page at http://pablotron.org/software/joggle/ for additional information", ].join("\n")
- EGGS =
[ # movie quotes "This is what happens, Larry!", "Got a package, people!", "Billy, do you like wrestling?", "NO AND DEN!", "I'm the dude playing the dude disguised as another dude.", "Hey, want to hear the most annoying sound in the world?", "Bueller?", "Inconcievable!", # non-movie quotes "You are in a maze of twisty compiler features, all different.", "You can tune a filesystem, but you can't tuna fish.", "Never attribute to malice that which can adequately explained by stupidity.", "The first thing to do when you find yourself in a hole is to stop digging.", "I once knew a man who had a dog with only three legs, and yet that man could play the banjo like anything.", "The needs of the many outweigh the needs of the guy who can't run fast.", "It may look like I'm doing nothing, but I'm actively waiting for my problems to go away.", "Nobody ever went broke underestimating the intelligence of the American people.", "There are only two things wrong with C++: The initial concept and the implementation.", "There are only two kinds of people, those who finish what they start, and so on.", # exclamations "I'LL SAY!!!", "AND HOW!!!", "Cha-ching!", "Crikey!", "Nope.", "Sweet!", "Blimey!", # emoticons ":-D", "^_^", ":(", ":-)", ":')-|-<", # misc "http://pablotron.org/offended", "<INSERT WITTY REMARK HERE>", "0xBEEFCAFE", ]
Instance Method Summary collapse
- #do_easteregg(who, arg) ⇒ Object
-
#do_help(who, arg) ⇒ Object
Handle .help command.
-
#do_list(who, arg) ⇒ Object
Handle .list command.
-
#do_register(who, arg) ⇒ Object
Handle .register command.
-
#do_unregister(who, arg) ⇒ Object
Handle .unregister command.
Instance Method Details
#do_easteregg(who, arg) ⇒ Object
159 160 161 |
# File 'lib/joggle/commands.rb', line 159 def do_easteregg(who, arg) reply(who, EGGS[rand(EGGS.size)]) end |
#do_help(who, arg) ⇒ Object
Handle .help command.
110 111 112 |
# File 'lib/joggle/commands.rb', line 110 def do_help(who, arg) reply(who, HELP) end |
#do_list(who, arg) ⇒ Object
Handle .list command.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/joggle/commands.rb', line 62 def do_list(who, arg) # see if user is registered if @tweeter.registered?(who) # user is registerd, so unregister them begin msgs = [] # build list @tweeter.list(who) do |id, time, from, msg| msgs << make_response(id, time, from, msg) end # build response if msgs.size > 0 msg = msgs.join("\n") else msg = 'No tweets.' end rescue Exception => err msg = "Couldn't list tweets: #{err}" end else # user isn't registered, send error msg = "Not registered." end # reply to request reply(who, msg) end |
#do_register(who, arg) ⇒ Object
Handle .register command.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/joggle/commands.rb', line 9 def do_register(who, arg) # see if user is registered if user = @tweeter.registered?(who) # user is registered, return error msg = "Already registered as #{user}" else # user isn't registered, so add them # get twitter username and password from argument user, pass = arg.split(/\s+/, 2) # register user begin @tweeter.register(who, user, pass) msg = "Registered as #{user}" rescue Exception => err msg = "Couldn't register: #{err}" end end # reply to request reply(who, msg) end |
#do_unregister(who, arg) ⇒ Object
Handle .unregister command.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/joggle/commands.rb', line 36 def do_unregister(who, arg) # see if user is registered if @tweeter.registered?(who) # user is registerd, so unregister them begin # unregister user @tweeter.unregister(who) # send success msg = "Unregistered." rescue Exception => err msg = "Couldn't unregister: #{err}" end else # user isn't registered, send error msg = "Not registered." end # reply to request reply(who, msg) end |