Class: Atig::Command::Status

Inherits:
Command
  • Object
show all
Includes:
Twitter::Validation
Defined in:
lib/atig/command/status.rb

Instance Attribute Summary

Attributes inherited from Command

#api, #db, #gateway, #opts

Instance Method Summary collapse

Methods inherited from Command

#find_by_tid, #initialize

Constructor Details

This class inherits a constructor from Atig::Command::Command

Instance Method Details

#action(target, mesg, command, args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/atig/command/status.rb', line 12

def action(target, mesg, command, args)
  if args.empty?
    yield "/me #{command} blah blah"
    return
  end
  text = mesg.split(" ", 2)[1]
  previous,*_ = db.statuses.find_by_user( db.me, :limit => 1)
  if previous and
      ((::Time.now - ::Time.parse(previous.status.created_at)).to_i < 60*60*24 rescue true) and
      text.strip == previous.status.text.strip
    yield "You can't submit the same status twice in a row."
    return
  end
  q = gateway.output_message(:status => text)

  case tweet_invalid? q[:status]
  when :too_long
    yield "You can't submit the status over 140 chars"
    return
  when :invalid_characters
    yield "You can't submit the status invalid chars"
    return
  end

  api.delay(0, :retry=>3) do|t|
    ret = t.post("statuses/update", q)
    gateway.update_status ret,target
  end
end

#command_nameObject



10
# File 'lib/atig/command/status.rb', line 10

def command_name; %w(status) end