lib/muzang-plugins/helpers.rb in muzang-plugins-1.0.2 vs lib/muzang-plugins/helpers.rb in muzang-plugins-1.1.0

- old
+ new

@@ -1,21 +1,22 @@ module Muzang module Plugins module Helpers - DEFAULT_MATCH_OPTIONS = { position: 1 } - - def on_channel?(message) - message.channel + def on_channel(message) + yield message.channel if message.channel end - def match?(message, options = {}) - options = DEFAULT_MATCH_OPTIONS.merge(options) - message.message.match(options[:regexp]) ? message.message.match(options[:regexp])[options[:position]] : false + def match(message, regexp) + message.message.match(regexp) do |match| + yield match + end end - def on_join?(connection, message) - message.command == :join && message.nick == connection.nick + def on_join(connection, message) + if message.command == :join && message.nick == connection.nick + yield + end end def create_database(file, container, variable) unless File.exist?(@config = ENV["HOME"] + "/.muzang") FileUtils.mkdir @config @@ -34,6 +35,6 @@ end end end end end -end \ No newline at end of file +end