Sha256: 8557f61c0d09113658eb799887579c53307ba3a199a0355737315dd4e5dd235c

Contents?: true

Size: 1.27 KB

Versions: 17

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.exist?("#{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

17 entries across 17 versions & 1 rubygems

Version Path
slack-smart-bot-1.14.2 lib/slack/smart-bot/commands/general/delete_share.rb
slack-smart-bot-1.14.1 lib/slack/smart-bot/commands/general/delete_share.rb
slack-smart-bot-1.14.0 lib/slack/smart-bot/commands/general/delete_share.rb
slack-smart-bot-1.13.2 lib/slack/smart-bot/commands/general/delete_share.rb
slack-smart-bot-1.13.1 lib/slack/smart-bot/commands/general/delete_share.rb
slack-smart-bot-1.13.0 lib/slack/smart-bot/commands/general/delete_share.rb
slack-smart-bot-1.12.9 lib/slack/smart-bot/commands/general/delete_share.rb
slack-smart-bot-1.12.8 lib/slack/smart-bot/commands/general/delete_share.rb
slack-smart-bot-1.12.7 lib/slack/smart-bot/commands/general/delete_share.rb
slack-smart-bot-1.12.6 lib/slack/smart-bot/commands/general/delete_share.rb
slack-smart-bot-1.12.5 lib/slack/smart-bot/commands/general/delete_share.rb
slack-smart-bot-1.12.4 lib/slack/smart-bot/commands/general/delete_share.rb
slack-smart-bot-1.12.3 lib/slack/smart-bot/commands/general/delete_share.rb
slack-smart-bot-1.12.2 lib/slack/smart-bot/commands/general/delete_share.rb
slack-smart-bot-1.12.1 lib/slack/smart-bot/commands/general/delete_share.rb
slack-smart-bot-1.12.0 lib/slack/smart-bot/commands/general/delete_share.rb
slack-smart-bot-1.11.0 lib/slack/smart-bot/commands/general/delete_share.rb