Module: Needabot

Defined in:
lib/needabot.rb,
lib/needabot/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

CHANNEL =
"##{c}"
VERSION =
"0.1.2"
@@C =
Zircon.new(
  :server   => HOST,
  :port     => "#{PORT}",
  :channel  => CHANNEL,
  :username => NICK
)
@@FACE =
{}
@@ON =
{}
@@CHAN =
{}
@@PRIV =
{}

Class Method Summary collapse

Class Method Details

.chanObject



64
65
66
# File 'lib/needabot.rb', line 64

def self.chan
	@@CHAN
end

.chan?(i, h = {}) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
70
71
# File 'lib/needabot.rb', line 67

def self.chan? i, h={}
	r = []
	@@CHAN.each_pair { |kk,vv| if m = Regexp.new(kk).match(i); r << vv.call(m, h); end }
	return r.flatten.compact
end

.faceObject



49
50
51
# File 'lib/needabot.rb', line 49

def self.face
	@@FACE
end

.msg(h = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/needabot.rb', line 28

def self.msg h={}
  h.each_pair { |k,v| 
  	if "#{v}".length > 0; 
  		fork {
  			if v.class == String
			vv = v.split("\n")
  			elsif v.class == Array
			vv = v
  			end
  			
  			vv.each { |e|
  				puts %[========> #{k} #{e}];
  				@@C.privmsg(k,%[:#{e}]);
  				sleep 1
  			}
  		}
  	end
  }
end

.on(k, h = {}, &b) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/needabot.rb', line 54

def self.on k, h={}, &b
	if block_given?
@@ON[k] = b
	else
puts %[ON: #{k} => #{h}]
@@ON[k].call(h)
	end
end

.privObject



73
74
75
# File 'lib/needabot.rb', line 73

def self.priv
	@@PRIV
end

.priv?(i, h = {}) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
79
80
# File 'lib/needabot.rb', line 76

def self.priv? i, h={}
	r = []
	@@PRIV.each_pair { |kk,vv| if m = Regexp.new(kk).match(i); r << vv.call(m, h); end }
	return r.flatten.compact
end

.runObject



95
96
97
98
99
100
101
# File 'lib/needabot.rb', line 95

def self.run
  begin
    @@C.run!
  rescue => err
    puts %[Err: #{err}]
  end
end

.run!Object



102
103
104
# File 'lib/needabot.rb', line 102

def self.run!
  fork { Needabot.run }
end