Sha256: 1339ea01834ae2f33606ca0f56066bacdb4745b24ebea0191892d90faa9b5c79

Contents?: true

Size: 1.03 KB

Versions: 7

Compression:

Stored size: 1.03 KB

Contents

module Muzang
  module Plugins
    module Helpers
      def on_channel(message)
        yield message.channel if message.channel
      end

      def match(message, regexp)
        message.message.match(regexp) do |match|
          yield match
        end
      end

      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
        end

        unless File.exist? @config + "/#{file}"
          db = YAML.dump container
          File.open(@config + "/#{file}", "w"){|f| f.write(db)}
        end

        send(:"#{variable}=", YAML.load(File.open(@config + "/#{file}", "r").read))

        unless self.respond_to?(:save)
          self.class.send(:define_method, :save) do
            File.open(@config + "/#{file}", "w"){|f| f.write YAML.dump(send(variable))}
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
muzang-plugins-1.1.6 lib/muzang-plugins/helpers.rb
muzang-plugins-1.1.5 lib/muzang-plugins/helpers.rb
muzang-plugins-1.1.4 lib/muzang-plugins/helpers.rb
muzang-plugins-1.1.3 lib/muzang-plugins/helpers.rb
muzang-plugins-1.1.2 lib/muzang-plugins/helpers.rb
muzang-plugins-1.1.1 lib/muzang-plugins/helpers.rb
muzang-plugins-1.1.0 lib/muzang-plugins/helpers.rb