Skip to content

Instantly share code, notes, and snippets.

@june29
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save june29/bd78b591ad1a22bee835 to your computer and use it in GitHub Desktop.
Save june29/bd78b591ad1a22bee835 to your computer and use it in GitHub Desktop.
Gem::Specification.new do |spec|
spec.name = "ruboty-totsuzenno"
spec.version = "0.0.2"
spec.authors = ["Jun OHWADA"]
spec.email = ["june29.jp@gmail.com"]
spec.summary = "Totsuzen no Shi"
spec.files = ["ruboty-totsuzenno.rb"]
spec.require_path = "."
end
module Ruboty
module Handlers
class Totsuzenno < Base
on(
//,
all: true,
description: "突然の",
name: "totsuzenno",
)
def totsuzenno(message)
return if message.from == robot.name
body = message.body.sub(/\s*#{robot.name}:?\s*/, "")
return unless body.match(/\A突然の/)
message.reply(totsuzenize(body))
end
private
def totsuzenize(string)
length = (string.chars.inject(0){ |sum, c| sum + (c.bytesize > 1 ? 2 : 1) } / 2).floor
<<-EOS
_#{"人" * (length + 2)}_
> #{string} <
 ̄Y#{"^Y" * (length + 1)} ̄
EOS
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment