-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathruboty-in.rb
More file actions
37 lines (34 loc) · 820 Bytes
/
ruboty-in.rb
File metadata and controls
37 lines (34 loc) · 820 Bytes
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
31
32
33
34
35
36
37
module Ruboty
module Handlers
class In < Base
IN_RE = /(?<a>(?<a_colon>:?).+\g<a_colon>) in (?<b>(?<b_colon>:?).+\g<b_colon>)/
on(
IN_RE,
name: 'in',
description: "emoji in emoji",
)
def nest(a, b)
if IN_RE =~ a
inner = nest($~[:a], $~[:b])
else
inner = [a.strip.gsub(/\A:|:\z/, '')]
end
b = b.strip.gsub(/\A:|:\z/, '')
[
[b] * (inner.size + 2),
*inner.map{|row| [b, *row, b] },
[b] * (inner.size + 2),
]
end
def in(message)
m = message.match_data
resp = nest(m[:a], m[:b]).map do |row|
row.map do |s|
":#{s}:"
end.join('')
end.join("\n")
message.reply resp
end
end
end
end