Class: Ircbot::Client
- Includes:
- Extlib::Hook
- Defined in:
- lib/ircbot/client/core.rb,
lib/ircbot/client/config.rb,
lib/ircbot/client/logger.rb,
lib/ircbot/client/plugins.rb,
lib/ircbot/client/timeout.rb,
lib/ircbot/client/commands.rb,
lib/ircbot/client/encoding.rb,
lib/ircbot/client/eventable.rb,
lib/ircbot/client/standalone.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, Timeouted
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
-
#broadcast(text) ⇒ Object
Command.
- #debug(text) ⇒ Object
-
#decode(text) ⇒ Object
Character conversions.
- #encode(text) ⇒ Object
-
#initialize(hash) ⇒ Client
constructor
A new instance of Client.
- #notice(channel, text) ⇒ Object
-
#plugins ⇒ Object
Accessors.
-
#post(command, *params) ⇒ Object
Convinient access to commands.
- #privmsg(channel, text) ⇒ Object
- #start ⇒ Object
- #trim(text, size = 120) ⇒ Object
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object (private)
17 18 19 |
# File 'lib/ircbot/client/eventable.rb', line 17 def method_missing(name, *args) raise NameError, "undefined local variable or method `#{name}' for #{self}" end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
65 66 67 |
# File 'lib/ircbot/client/config.rb', line 65 def config @config end |
Class Method Details
.event(name, &block) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/ircbot/client/eventable.rb', line 6 def event(name, &block) name = "on_#{name}".intern unless instance_methods.include?(name.to_s) define_method(name){|m|} end before name, &block end |
Instance Method Details
#broadcast(text) ⇒ Object
Command
32 33 34 35 36 |
# File 'lib/ircbot/client/config/channels.rb', line 32 def broadcast(text) config.channels.each do |channel| privmsg channel, text end end |
#debug(text) ⇒ Object
5 6 7 |
# File 'lib/ircbot/client/logger.rb', line 5 def debug(text) p [:debug, text] 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 |
#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 |
#start ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/ircbot/client/timeout.rb', line 17 def start super rescue Exception => e sec = [config.wait_before_restart.to_i, 10].max sleep sec $stderr.puts "Restarting after timeouted" retry end |
#trim(text, size = 120) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/ircbot/client/config.rb', line 56 def trim(text, size = 120) a = text.to_s.split(//) if a.size > size return a[0..size].join + "..." else return text.to_s end end |