lib/tgbot/dsl.rb in tgbot-0.1.0 vs lib/tgbot/dsl.rb in tgbot-0.1.1

- old
+ new

@@ -17,30 +17,33 @@ @procs[:before] = blk end def after(&blk) @procs[:after] = blk end - def on(regex, &blk) - @procs[:command][regex] = blk + def on(*regexes, &blk) + regexes.each { |regex| @procs[:command][regex] = blk } end alias get on + def alias(ori, *args) + args.each { |regex| @procs[:command][regex] = @procs[:command][ori] } + end def run yield self if block_given? @procs[:start]&.call begin @runner.mainloop do |update| @procs[:before]&.call update update.done = true @procs[:command].each do |key, blk| x = update.text&.match key - blk.call x, update if x + update.instance_exec(x, &blk) if x end @procs[:after]&.call update end rescue Interrupt @procs[:finish]&.call rescue => e - puts $! + puts e puts e.backtrace retry end end def method_missing(meth, *args, &blk)