Last active
August 29, 2015 14:22
-
-
Save june29/bd78b591ad1a22bee835 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Gem::Specification.new do |spec| | |
spec.name = "ruboty-totsuzenno" | |
spec.version = "0.0.2" | |
spec.authors = ["Jun OHWADA"] | |
spec.email = ["[email protected]"] | |
spec.summary = "Totsuzen no Shi" | |
spec.files = ["ruboty-totsuzenno.rb"] | |
spec.require_path = "." | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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