Sha256: 4c24ba89667a12398b9df80a07093feafaead1644f2c663e8356eff71f805882

Contents?: true

Size: 1.39 KB

Versions: 17

Compression:

Stored size: 1.39 KB

Contents

class SlackSmartBot

  def add_announcement(user, type, message)
    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}/announcements/#{channel}.csv") and !@announcements.key?(channel)
        t = CSV.table("#{config.path}/announcements/#{channel}.csv", headers: ['message_id', 'user_deleted', 'user_created', 'date', 'time', 'type', 'message'])
        @announcements[channel] = t
        num = t[:message_id].max + 1
      elsif !@announcements.key?(channel)
        File.open("#{config.path}/announcements/#{channel}.csv","w")
        t = CSV.table("#{config.path}/announcements/#{channel}.csv", headers: ['message_id', 'user_deleted', 'user_created', 'date', 'time', 'type', 'message'])
        num = 1
        @announcements[channel] = t
      else
        num = @announcements[channel][:message_id].max + 1
      end
      values = [num, '', user.name, Time.now.strftime("%Y/%m/%d"), Time.now.strftime("%H:%M"), type, message]
      @announcements[channel] << values
      CSV.open("#{config.path}/announcements/#{channel}.csv", "a+") do |csv|
        csv << values
      end
      respond "The announcement has been added. (id: #{num}).\nRelated commands `see announcements`, `delete announcement ID`"

    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/add_announcement.rb
slack-smart-bot-1.14.1 lib/slack/smart-bot/commands/general/add_announcement.rb
slack-smart-bot-1.14.0 lib/slack/smart-bot/commands/general/add_announcement.rb
slack-smart-bot-1.13.2 lib/slack/smart-bot/commands/general/add_announcement.rb
slack-smart-bot-1.13.1 lib/slack/smart-bot/commands/general/add_announcement.rb
slack-smart-bot-1.13.0 lib/slack/smart-bot/commands/general/add_announcement.rb
slack-smart-bot-1.12.9 lib/slack/smart-bot/commands/general/add_announcement.rb
slack-smart-bot-1.12.8 lib/slack/smart-bot/commands/general/add_announcement.rb
slack-smart-bot-1.12.7 lib/slack/smart-bot/commands/general/add_announcement.rb
slack-smart-bot-1.12.6 lib/slack/smart-bot/commands/general/add_announcement.rb
slack-smart-bot-1.12.5 lib/slack/smart-bot/commands/general/add_announcement.rb
slack-smart-bot-1.12.4 lib/slack/smart-bot/commands/general/add_announcement.rb
slack-smart-bot-1.12.3 lib/slack/smart-bot/commands/general/add_announcement.rb
slack-smart-bot-1.12.2 lib/slack/smart-bot/commands/general/add_announcement.rb
slack-smart-bot-1.12.1 lib/slack/smart-bot/commands/general/add_announcement.rb
slack-smart-bot-1.12.0 lib/slack/smart-bot/commands/general/add_announcement.rb
slack-smart-bot-1.11.0 lib/slack/smart-bot/commands/general/add_announcement.rb