Sha256: de75e3068805e9a257e88f596d59732a012c6c359c890e419190c8e6273138e6

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

class SlackSmartBot

  def delete_share(user, share_id)
    save_stats(__method__)
    if has_access?(__method__, user)
      if Thread.current[:typem] == :on_call
        channel = Thread.current[:dchannel]
      else
        channel = Thread.current[:dest]
      end
      if File.exists?("#{config.path}/shares/#{@channels_name[channel]}.csv") and !@shares.key?(@channels_name[channel])
        t = CSV.table("#{config.path}/shares/#{@channels_name[channel]}.csv", headers: ['share_id', 'user_deleted', 'user_created', 'date', 'time', 'type', 'to_channel', 'condition'])
        @shares[@channels_name[channel]] = t
      end
      found = false
      message = ''
      if @shares[@channels_name[channel]][:share_id].include?(share_id.to_i)
        CSV.open("#{config.path}/shares/#{@channels_name[channel]}.csv", "w") do |csv|
          @shares[@channels_name[channel]].each do |row|
            if row[:share_id].to_i == share_id.to_i
              message = row[:condition]
              row[:user_deleted] = user.name
            end    
            csv << row
          end
        end
        respond "The share has been deleted: #{message}"
      else
        respond "Sorry but I didn't find the share id #{share_id}. Call `see shares` to see all the ids."
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
slack-smart-bot-1.10.0 lib/slack/smart-bot/commands/general/delete_share.rb