Class: Ircbot::Client
- Defined in:
- lib/ircbot/client.rb,
lib/ircbot/client/config.rb,
lib/ircbot/client/plugins.rb,
lib/ircbot/client/commands.rb,
lib/ircbot/client/encoding.rb,
lib/ircbot/client/config/plugins.rb,
lib/ircbot/client/config/channels.rb,
lib/ircbot/client/config/generator.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Config, Standalone
Class Method Summary collapse
Instance Method Summary collapse
-
#broadcast(text) ⇒ Object
Command.
- #config ⇒ Object
-
#decode(text) ⇒ Object
Character conversions.
- #encode(text) ⇒ Object
-
#initialize(hash) ⇒ Client
constructor
A new instance of Client.
-
#method_missing(name, *args) ⇒ Object
escape from nil black hole.
- #notice(channel, text) ⇒ Object
-
#on_privmsg(m) ⇒ Object
Events.
-
#on_rpl_welcome(m) ⇒ Object
Event.
-
#plugins ⇒ Object
Accessors.
-
#post(command, *params) ⇒ Object
Convinient access to commands.
- #privmsg(channel, text) ⇒ Object
Constructor Details
#initialize(hash) ⇒ Client
Returns a new instance of Client.
47 48 49 |
# File 'lib/ircbot/client/config.rb', line 47 def initialize(hash) super(hash[:host], hash[:port], hash) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
escape from nil black hole
10 11 12 13 14 15 16 17 |
# File 'lib/ircbot/client.rb', line 10 def method_missing(name, *args) case name.to_s when /^on_/ # nop for calling super from subclass else raise NameError, "undefined local variable or method `#{name}' for #{self}" end end |
Class Method Details
.from_file(path) ⇒ Object
43 44 45 |
# File 'lib/ircbot/client/config.rb', line 43 def self.from_file(path) new(Config.read(path)) end |
Instance Method Details
#broadcast(text) ⇒ Object
Command
34 35 36 37 38 |
# File 'lib/ircbot/client/config/channels.rb', line 34 def broadcast(text) config.channels.each do |channel| privmsg channel, text end end |
#config ⇒ Object
51 52 53 |
# File 'lib/ircbot/client/config.rb', line 51 def config @config ||= Config.new(opts) end |
#decode(text) ⇒ Object
Character conversions
8 9 10 |
# File 'lib/ircbot/client/encoding.rb', line 8 def decode(text) NKF.nkf('-w', text.to_s) end |
#encode(text) ⇒ Object
12 13 14 |
# File 'lib/ircbot/client/encoding.rb', line 12 def encode(text) NKF.nkf('-j', text.to_s) end |
#notice(channel, text) ⇒ Object
23 24 25 26 |
# File 'lib/ircbot/client/commands.rb', line 23 def notice(channel, text) text = encode(text) post NOTICE, channel, text end |
#on_privmsg(m) ⇒ Object
Events
18 19 20 21 22 23 24 25 |
# File 'lib/ircbot/client/plugins.rb', line 18 def on_privmsg(m) super text = decode(m.params[1].to_s) args = [text, m.prefix.nick, m] plugins_call_replies(args, m) end |
#on_rpl_welcome(m) ⇒ Object
Event
23 24 25 26 27 28 29 |
# File 'lib/ircbot/client/config/channels.rb', line 23 def on_rpl_welcome(m) super config.channels.each do |channel| post JOIN, channel end end |
#plugins ⇒ Object
Accessors
8 9 10 |
# File 'lib/ircbot/client/plugins.rb', line 8 def plugins @plugins ||= Plugins.new(self, config.plugins) end |
#post(command, *params) ⇒ Object
Convinient access to commands
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ircbot/client/commands.rb', line 8 def post(command, *params) if params[1] params[1] = encode(params[1]).strip if config.multiline params[1].split(/\n/).compact.each do |text| params[1] = text super(command, *params) end return end end super(command, *params) end |
#privmsg(channel, text) ⇒ Object
28 29 30 31 |
# File 'lib/ircbot/client/commands.rb', line 28 def privmsg(channel, text) text = encode(text) post PRIVMSG, channel, text end |