Class: Sponge::Bot
- Inherits:
-
IRC::Client
- Object
- IRC::Client
- Sponge::Bot
- Defined in:
- lib/sponge/bot.rb
Instance Attribute Summary collapse
-
#auth ⇒ Object
readonly
Returns the value of attribute auth.
-
#plugins ⇒ Object
readonly
Returns the value of attribute plugins.
Attributes inherited from IRC::Client
Instance Method Summary collapse
-
#add_plugin(plugin) ⇒ Object
Should only be used by #setup_plugins (for now..) Sugar for Sponge::Plugins#add.
-
#init_listeners ⇒ Object
This probably isn’t a good idea, I generally don’t like seeing any eval lines, as it’s a nightmare to debug.
-
#initialize(server = nil, options = {}, &blk) ⇒ Bot
constructor
A new instance of Bot.
-
#register(command, message) ⇒ Object
Registers an IRC command ready to dispatch to any plugin who are listening.
-
#setup_plugins ⇒ Object
Looks through the ‘plugins’ directory, require all plugins found, and add them into Sponge::Plugins.
Methods inherited from IRC::Client
#connect, #on, #process, #quit, #run, #set_nick
Constructor Details
#initialize(server = nil, options = {}, &blk) ⇒ Bot
Returns a new instance of Bot.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/sponge/bot.rb', line 8 def initialize(server=nil, ={}, &blk) @plugins = Plugins.new(self) @auth = Auth.new(self, [:users] || {}) @command_prefix = [:prefix] || '!' @channels = [:channels] || [] setup_plugins super(server, , &blk) init_listeners end |
Instance Attribute Details
#auth ⇒ Object (readonly)
Returns the value of attribute auth.
6 7 8 |
# File 'lib/sponge/bot.rb', line 6 def auth @auth end |
#plugins ⇒ Object (readonly)
Returns the value of attribute plugins.
4 5 6 |
# File 'lib/sponge/bot.rb', line 4 def plugins @plugins end |
Instance Method Details
#add_plugin(plugin) ⇒ Object
Should only be used by #setup_plugins (for now..) Sugar for Sponge::Plugins#add
48 49 50 |
# File 'lib/sponge/bot.rb', line 48 def add_plugin(plugin) plugins.add(plugin) end |
#init_listeners ⇒ Object
This probably isn’t a good idea, I generally don’t like seeing any eval lines, as it’s a nightmare to debug. It’ll do for now, though.
23 24 25 26 27 28 |
# File 'lib/sponge/bot.rb', line 23 def init_listeners path = File.('../listeners', __FILE__) Dir[path + '/*.rb'].each do |listener| instance_eval(File.read(listener)) end end |
#register(command, message) ⇒ Object
Registers an IRC command ready to dispatch to any plugin who are listening
54 55 56 57 58 59 60 |
# File 'lib/sponge/bot.rb', line 54 def register(command, ) if Plugin.has_listener?(command) Plugin::LISTENERS[command.to_s.downcase].each do |cmd| plugins.dispatch_listen(cmd, ) end end end |
#setup_plugins ⇒ Object
Looks through the ‘plugins’ directory, require all plugins found, and add them into Sponge::Plugins
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sponge/bot.rb', line 32 def setup_plugins unless File.directory?(@plugins.path) raise(LoadError, "No plugins directory found. Did you run `sponge init'?") end Dir[@plugins.path + '/*.rb'].each do |plugin| require plugin end Plugin::LIST.each do |plugin| add_plugin(plugin) end end |