about summary refs log tree commit diff stats
path: root/data/maps/daedalus/rooms/Zoo E.txtpb
blob: 59479dca07965de54c82570bc9c6e6074a2a1d2a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
name: "Zoo E"
display_name: "Zoo"
panels {
  name: "WING"
  path: "Panels/V Maze/four_1"
  clue: "wing"
  answer: "bat"
  symbols: BOXES
}
panels {
  name: "WHISKER"
  path: "Panels/V Maze/four_2"
  clue: "whisker"
  answer: "cat"
  symbols: BOXES
}
panels {
  name: "CLAW"
  path: "Panels/V Maze/four_3"
  clue: "claw"
  answer: "cat"
  symbols: BOXES
}
panels {
  name: "FUR"
  path: "Panels/V Maze/four_4"
  clue: "fur"
  answer: "bat"
  symbols: BOXES
}
id='n239' href='#n239'>239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
class QuotesController < ApplicationController
  protect_from_forgery with: :null_session, if: -> { request.format.json? or request.format.xml? }

  def index
    @quote = Quote.find(310)
    @qnumber = Quote.published.count
    @mnumber = Quote.pending.count
  end

  def latest
    @quotes = Quote.published.order(id: :desc).paginate(page: params[:page], per_page: 10)

    respond_to do |format|
      format.html { render :list }
      format.json { render :json => @quotes }
      format.xml { render :xml => @quotes }
      format.atom { render :atom => @quotes }
    end
  end

  def top
    @quotes = Quote.published
    @quotes = @quotes.where("created_at > ?", Time.new(2015,1,1)) if params[:modern]
    @quotes = @quotes.order(Arel.sql("(upvotes - downvotes) DESC, id ASC")).paginate(page: params[:page], per_page: 10)

    respond_to do |format|
      format.html { render :list }
      format.json { render :json => @quotes }
      format.xml { render :xml => @quotes }
    end
  end

  def search_form
    @q = Quote.published.ransack
  end

  def search
    @quotes = Quote.published.ransack(params[:q]).result(distinct: true).paginate(page: params[:page], per_page: 10)

    respond_to do |format|
      format.html { render :list }
      format.json { render :json => @quotes }
      format.xml { render :xml => @quotes }
    end
  end

  def random
    picked = Quote.where(state: :published).ids.sample
    redirect_to quote_url(picked)
  end

  def tags
    @tags = Quote.published.tag_counts_on(:tags)
  end

  def tag
    @quotes = Quote.published.tagged_with(params[:id]).order(id: :desc).paginate(page: params[:page], per_page: 10)

    respond_to do |format|
      format.html { render :list }
      format.json { render :json => @quotes }
      format.xml { render :xml => @quotes }
    end
  end

  def stats
    @months = []
    0.upto(11) do |i|
      month = i.months.ago.month
      year = i.months.ago.year
      beginning = i.months.ago.beginning_of_month.beginning_of_day
      endtime = i.months.ago.end_of_month.end_of_day
      quotes = Quote.published.where("created_at >= :start_date AND created_at <= :end_date", { :start_date => beginning, :end_date => endtime }).all
      @months[11-i] = { :name => Date::MONTHNAMES[month], :number => quotes.count }
    end

    #@months2 = []
    #i = 0
    #while true
    #  month = i.months.ago.month
    #  year = i.months.ago.year
    #  beginning = i.months.ago.beginning_of_month.beginning_of_day
    #  endtime = i.months.ago.end_of_month.end_of_day
    #  quotes = Quote.where("created_at <= :end_date", { :end_date => endtime }).all
    #  @months2[i] = { :name => i.months.ago.strftime("%Y-%m"), :number => quotes.count }
    #
    #  break if month == 4 and year == 2008
    #
    #  i=i+1
    #end
    #
    #@months2.reverse!
    #
    #@upvotes = Vote.where(upvote: 1, votable_type: :quote).count
    #@downvotes = Vote.where(upvote: 0, votable_type: :quote).count

    hardcoded_aliases = {
      "hatkirby": "Hatkirby",
      "Gryphic": "Drifty",
      "DriftyBeyond": "Drifty",
      "Starla": "Hatkirby",
      "BleuM937": "Bluemonkey",
      "BlueM937": "Bluemonkey",
      "Drifty1": "Drifty",
      "Starla Insigna": "Hatkirby",
      "Starla Alice Insigna": "Hatkirby",
      "tamasys": "Tamasys",
      "Student 2": "Student",
      "Старла Эппрет": "Hatkirby",
      "Girl Without Slipper": "Hatkirby",
      "Actias": "Drifty",
      "Salaboy123": "Tamasys",
      "TaMACsys": "Tamasys",
      "RealityCheck": "Drifty",
      "Student 3": "Student",
      "toothpastecanyon": "ToothPasteCanyon",
      "eka-caesium": "eka_caesium",
    }

    person_count = {}
    Quote.published.each do |quote|
      person_in_quote = {}

      quote.content.split("\n").each do |line|
        check = line.chomp
        hi = /([\(\[][^\]\)]*[\]\)] )?([^:]*): /.match(check)
        if hi and hi[2] then
          person = hi[2]
          if hardcoded_aliases.has_key? person.intern
            person = hardcoded_aliases[person.intern]
          end
          unless person_in_quote.has_key? person
            person_count[person] ||= 0
            person_count[person] += 1
            person_in_quote[person] = 1
          end
        end
      end
    end

    @by_speaker = person_count.to_a.sort_by {|hi| hi[1]}.reverse.take(20)
  end

  def show
    @quote = Quote.published.find(params[:id])

    set_meta_tags(og: {
      title: "Quote \##{@quote.id}",
      type: "article",
      description: (@quote.content.length <= 300 ? @quote.content : @quote.content[0..299]),
      url: quote_url(@quote, host: "www.fourisland.com"),
      article: {
        published_time: @quote.created_at.iso8601,
        modified_time: @quote.updated_at.iso8601
      }
    })

    respond_to do |format|
      format.html
      format.json { render :json => @quote }
      format.xml { render :xml => @quote }
    end
  end

  def new
    @quote = Quote.new
  end

  def create
    @quote = Quote.new(quote_params)
    @quote.submitter = nil if @quote.submitter.empty?

    unless @quote.valid?
      flash.alert = "Error submitting quote."

      respond_to do |format|
        format.html { render :new }
        format.json { render json: { error: "Error submitting quote." }, status: :bad_request }
        format.xml { render xml: { error: "Error submitting quote." }, status: :bad_request }
      end

      return
    end

    if user_signed_in?
      @quote.state = :published
      @quote.save!

      flash[:notice] = "Thank you for submitting your quote!"
      respond_to do |format|
        format.html { redirect_to @quote }
        format.json { render json: @quote }
        format.xml { render xml: @quote }
      end
    else
      @quote.state = :pending
      @quote.save!

      # hacky little thing to reduce the number of emails I get
      unless @quote.submitter == "hatkirby"
        QuoteMailer.with(quote: @quote).pending_quote_email.deliver_later
      end

      flash[:notice] = "Your quote has been submitted and is pending moderation."
      respond_to do |format|
        format.html { redirect_to new_quote_url }
        format.json { render json: @quote }
        format.xml { render xml: @quote }
      end
    end
  end

  def upvote
    @quote = Quote.published.find(params[:id])

    respond_to do |format|
      if @quote.upvote! request.remote_ip
        format.html do
          flash[:notice] = "You have upvoted Quote \"#{@quote.id}\"."
          redirect_to @quote
        end
        format.js { render "voted" }
        format.xml { head :ok }
      else
        format.html do
          flash[:notice] = "You have already voted on Quote \"#{@quote.id}\"."
          redirect_to @quote
        end
        format.xml { render :xml => { :error => "Someone from your IP address has already voted on this quote."} }
      end
    end
  end

  def downvote
    @quote = Quote.published.find(params[:id])

    respond_to do |format|
      if @quote.downvote! request.remote_ip
        format.html do
          flash[:notice] = "You have downvoted Quote \"#{@quote.id}\"."
          redirect_to @quote
        end
        format.js { render "voted" }
        format.xml { head :ok }
      else
        format.html do
          flash[:notice] = "You have already voted on Quote \"#{@quote.id}\"."
          redirect_to @quote
        end
        format.xml { render :xml => { :error => "Someone from your IP address has already voted on this quote."} }
      end
    end
  end

  private

    def quote_params
      params.require(:quote).permit(:content, :notes, :submitter, :tag_list)
    end
end