Class: T::Delete

Inherits:
Thor
  • Object
show all
Includes:
Requestable, Utils
Defined in:
lib/t/delete.rb

Instance Method Summary collapse

Constructor Details

#initializeDelete

Returns a new instance of Delete.



14
15
16
17
# File 'lib/t/delete.rb', line 14

def initialize(*)
  @rcfile = T::RCFile.instance
  super
end

Instance Method Details

#account(account, key = nil) ⇒ Object



106
107
108
109
110
111
112
# File 'lib/t/delete.rb', line 106

def (, key = nil)
  if key && @rcfile.profiles[].keys.size > 1
    @rcfile.delete_key(, key)
  else
    @rcfile.delete_profile()
  end
end

#block(user, *users) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/t/delete.rb', line 22

def block(user, *users)
  unblocked_users, number = fetch_users(users.unshift(user), options) do |users_to_unblock|
    client.unblock(users_to_unblock)
  end
  say "@#{@rcfile.active_profile[0]} unblocked #{pluralize(number, 'user')}."
  say
  say "Run `#{File.basename($PROGRAM_NAME)} block #{unblocked_users.collect { |unblocked_user| "@#{unblocked_user.screen_name}" }.join(' ')}` to block."
end

#dm(direct_message_id, *direct_message_ids) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/t/delete.rb', line 33

def dm(direct_message_id, *direct_message_ids)
  direct_message_ids.unshift(direct_message_id)
  require "t/core_ext/string"
  direct_message_ids.collect!(&:to_i)
  if options["force"]
    client.destroy_direct_message(*direct_message_ids)
    say "@#{@rcfile.active_profile[0]} deleted #{direct_message_ids.size} direct message#{direct_message_ids.size == 1 ? '' : 's'}."
  else
    direct_message_ids.each do |direct_message_id_to_delete|
      direct_message = client.direct_message(direct_message_id_to_delete)
      next unless direct_message

      recipient = client.user(direct_message.recipient_id)
      next unless yes? "Are you sure you want to permanently delete the direct message to @#{recipient.screen_name}: \"#{direct_message.text}\"? [y/N]"

      client.destroy_direct_message(direct_message_id_to_delete)
      say "@#{@rcfile.active_profile[0]} deleted the direct message sent to @#{recipient.screen_name}: \"#{direct_message.text}\""
    end
  end
end

#favorite(status_id, *status_ids) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/t/delete.rb', line 57

def favorite(status_id, *status_ids)
  status_ids.unshift(status_id)
  require "t/core_ext/string"
  status_ids.collect!(&:to_i)
  if options["force"]
    tweets = client.unfavorite(status_ids)
    tweets.each do |status|
      say "@#{@rcfile.active_profile[0]} unfavorited @#{status.user.screen_name}'s status: \"#{status.full_text}\""
    end
  else
    status_ids.each do |status_id_to_unfavorite|
      status = client.status(status_id_to_unfavorite, include_my_retweet: false)
      next unless yes? "Are you sure you want to remove @#{status.user.screen_name}'s status: \"#{status.full_text}\" from your favorites? [y/N]"

      client.unfavorite(status_id_to_unfavorite)
      say "@#{@rcfile.active_profile[0]} unfavorited @#{status.user.screen_name}'s status: \"#{status.full_text}\""
    end
  end
end

#list(list) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/t/delete.rb', line 81

def list(list)
  if options["id"]
    require "t/core_ext/string"
    list = list.to_i
  end
  list = client.list(list)
  return if !options["force"] && !(yes? "Are you sure you want to permanently delete the list \"#{list.name}\"? [y/N]")

  client.destroy_list(list)
  say "@#{@rcfile.active_profile[0]} deleted the list \"#{list.name}\"."
end

#mute(user, *users) ⇒ Object



96
97
98
99
100
101
102
103
# File 'lib/t/delete.rb', line 96

def mute(user, *users)
  unmuted_users, number = fetch_users(users.unshift(user), options) do |users_to_unmute|
    client.unmute(users_to_unmute)
  end
  say "@#{@rcfile.active_profile[0]} unmuted #{pluralize(number, 'user')}."
  say
  say "Run `#{File.basename($PROGRAM_NAME)} mute #{unmuted_users.collect { |unmuted_user| "@#{unmuted_user.screen_name}" }.join(' ')}` to mute."
end

#status(status_id, *status_ids) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/t/delete.rb', line 116

def status(status_id, *status_ids)
  status_ids.unshift(status_id)
  require "t/core_ext/string"
  status_ids.collect!(&:to_i)
  if options["force"]
    tweets = client.destroy_status(status_ids, trim_user: true)
    tweets.each do |status|
      say "@#{@rcfile.active_profile[0]} deleted the Tweet: \"#{status.full_text}\""
    end
  else
    status_ids.each do |status_id_to_delete|
      status = client.status(status_id_to_delete, include_my_retweet: false)
      next unless yes? "Are you sure you want to permanently delete @#{status.user.screen_name}'s status: \"#{status.full_text}\"? [y/N]"

      client.destroy_status(status_id_to_delete, trim_user: true)
      say "@#{@rcfile.active_profile[0]} deleted the Tweet: \"#{status.full_text}\""
    end
  end
end