Class: IIRC::Bot
- Inherits:
-
Object
- Object
- IIRC::Bot
- Includes:
- Configure, Hooks, Parsing, Pong, Reading, ReplyTarget, TrackOwnNick
- Defined in:
- lib/iirc.rb,
lib/iirc/bot.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#socket ⇒ Object
Returns the value of attribute socket.
-
#user ⇒ Object
(also: #me)
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(text) ⇒ Object
- #ensure_registration_info! ⇒ Object private
-
#initialize(socket = nil, user = {}) ⇒ Bot
constructor
A new instance of Bot.
- #inspect ⇒ Object
- #register! ⇒ Object
- #to_s ⇒ Object
Methods included from ReplyTarget
Methods included from TrackOwnNick
#configure_own_nick_tracking, #track_own_nick_change, #track_own_nick_from_welcome
Methods included from Pong
Methods included from Configure
#configure!, #configure_actions, included
Methods included from Hooks
#>>, #call, #fire!, #hook, #hook_seq, #hooks, #off, #on, #run
Methods included from Parsing
Methods included from Reading
Constructor Details
#initialize(socket = nil, user = {}) ⇒ Bot
Returns a new instance of Bot.
20 21 22 23 24 25 26 27 28 |
# File 'lib/iirc/bot.rb', line 20 def initialize(socket=nil, user={}) super() if defined? super self.socket = socket self.user = user.is_a?(User) ? user : User.new(**user) if !user.key?(:nick) self.user.nick ||= self.class.name&.split('::')&.last end end |
Instance Attribute Details
#socket ⇒ Object
Returns the value of attribute socket.
3 4 5 |
# File 'lib/iirc/bot.rb', line 3 def socket @socket end |
#user ⇒ Object Also known as: me
Returns the value of attribute user.
4 5 6 |
# File 'lib/iirc/bot.rb', line 4 def user @user end |
Class Method Details
.run(host, port = 6697, local_host: nil, local_port: nil, ssl_context: SSL.default_context, **user_params, &blk) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/iirc.rb', line 47 def self.run(host, port=6697, local_host: nil, local_port: nil, ssl_context: SSL.default_context, **user_params, &blk) socket = IIRC.dial(host, port, local_host: local_host, local_port: local_port, ssl_context: ssl_context) new(socket, **user_params).tap { |bot| bot.register! bot.tap(&blk) if blk bot.run } end |
Instance Method Details
#<<(text) ⇒ Object
7 8 9 10 |
# File 'lib/iirc/bot.rb', line 7 def <<(text) socket << text.tr("\r", "").tr("\n", "") + "\r\n" self end |
#ensure_registration_info! ⇒ Object (private)
36 37 38 39 40 |
# File 'lib/iirc/bot.rb', line 36 private def ensure_registration_info! me.username ||= me.nick&.downcase me.realname ||= me.nick raise ArgumentError.new('no nick given') unless me.nick && !me.nick.empty? end |
#inspect ⇒ Object
16 17 18 |
# File 'lib/iirc/bot.rb', line 16 def inspect "<#{me}>" end |
#register! ⇒ Object
30 31 32 33 34 |
# File 'lib/iirc/bot.rb', line 30 def register! ensure_registration_info! self << "USER #{me.username} 0 0 :#{me.realname}" self << "NICK #{me.nick}" end |
#to_s ⇒ Object
12 13 14 |
# File 'lib/iirc/bot.rb', line 12 def to_s "[#{self.class.name}:#{user.nick}]" end |