lib/lita/handlers/butt.rb in lita-butt-0.1.1 vs lib/lita/handlers/butt.rb in lita-butt-0.1.2

- old
+ new

@@ -6,17 +6,30 @@ route(/^b(u*)tt(s?)/, :butt, help: { 'butt' => '(_)_)' }) def butt(response) groups = response.matches.first width = groups.first.size + butt = make_butt width + if groups.last == 's' + response.reply(escape([butt, butt].join(' '))) + else + response.reply(escape(butt)) + end + end + + def make_butt(width = 1) bottom = '_' * width - butt = "(#{bottom})#{bottom})" + "(#{bottom})#{bottom})" + end - if groups.last == 's' - response.reply [butt, butt].join ' ' + # Properly escape the butt for a given chat service + def escape(butt, adapter = robot.config.robot.adapter) + case adapter + when :slack + "`#{butt}`" else - response.reply butt + butt end end Lita.register_handler(self) end