Class: Atig::Command::Destroy

Inherits:
Command
  • Object
show all
Defined in:
lib/atig/command/destroy.rb

Instance Attribute Summary

Attributes inherited from Command

#api, #db, #gateway, #opts

Instance Method Summary collapse

Methods inherited from Command

#find_by_tid

Constructor Details

#initialize(*args) ⇒ Destroy

Returns a new instance of Destroy.



9
# File 'lib/atig/command/destroy.rb', line 9

def initialize(*args); super end

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
41
# File 'lib/atig/command/destroy.rb', line 12

def action(target, mesg, command, args)
  if args.empty?
    yield "/me #{command} <ID1> <ID2> ..."
    return
  end
  args.each do|tid|
    if entry = Info.find_status(db, tid)
      if entry.user.id == db.me.id
        api.delay(0) do|t|
          res = t.post("statuses/destroy/#{entry.status.id}")
          yield "Destroyed: #{entry.status.text}"

          db.statuses.transaction do|d|
            xs = d.find_by_screen_name db.me.screen_name,:limit=>1
            d.remove_by_id entry.id
            ys = d.find_by_screen_name db.me.screen_name,:limit=>1

            unless xs.map{|x| x.id} == ys.map{|y| y.id} then
              gateway.topic ys.first
            end
          end
        end
      else
        yield "The status you specified by the ID tid is not yours."
      end
    else
      yield "No such ID tid"
    end
  end
end

#command_nameObject



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

def command_name; %w(destroy remove rm) end