Skip to content

Instantly share code, notes, and snippets.

@Sixeight
Created September 9, 2009 19:19
Show Gist options
  • Select an option

  • Save Sixeight/184005 to your computer and use it in GitHub Desktop.

Select an option

Save Sixeight/184005 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
require 'rubygems'
require 'sinatra'
require 'json'
get '/' do
text = JSON.parse(params[:json])['events'][0]['message']['text']
NiseHarizon.say if NiseHarizon.yharian?(text)
end
class NiseHarizon
@@_mode = :normal
def self.yharian?(text)
pm, *messages = text.split.reverse
false unless pm.end_with?('.') || pm.end_with?('!') || pm.end_with?('?')
messages << pm.chop
if messages.all? {|s| /\A(?:_|____)\z/ =~ s }
@@_mode = :silent
return true
end
@@_mode = :normal
messages.all? {|s| /\A(?:y|hara)\z/ =~ s }
end
def self.say
words = %w[ y hara ]
ret = rand(10).times.map { words[rand(2)] }
if @@_mode == :silent
ret = ret.map {|w| '_' * w.length }
end
ret.join(' ') + %w[ . ! ? ][rand(3)]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment