Module: Muzang::Plugins::Helpers

Included in:
Eval, Google, Grep, LiveReload, Meme, Motd, NerdPursuit, PlusOne, Reddit, RubyGems, SoupIRC
Defined in:
lib/muzang-plugins/helpers.rb

Instance Method Summary collapse

Instance Method Details

#create_database(file, container, variable) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/muzang-plugins/helpers.rb', line 20

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

#match(message, regexp) ⇒ Object



8
9
10
11
12
# File 'lib/muzang-plugins/helpers.rb', line 8

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

#on_channel(message) {|message.channel| ... } ⇒ Object

Yields:

  • (message.channel)


4
5
6
# File 'lib/muzang-plugins/helpers.rb', line 4

def on_channel(message)
  yield message.channel if message.channel
end

#on_join(connection, message) ⇒ Object



14
15
16
17
18
# File 'lib/muzang-plugins/helpers.rb', line 14

def on_join(connection, message)
  if message.command == :join && message.nick == connection.nick
    yield
  end
end