Module: IIRC::IRCv3::LabeledRequests

Included in:
IIRC::IRCv3Bot
Defined in:
lib/iirc/modules/ircv3/labeled_requests.rb

Instance Method Summary collapse

Instance Method Details

#configure_labeled_requestsObject (private)



16
17
18
# File 'lib/iirc/modules/ircv3/labeled_requests.rb', line 16

def configure_labeled_requests
  hook :dispatch_replies
end

#dispatch_replies(evt) ⇒ Object (private)



20
21
22
23
24
# File 'lib/iirc/modules/ircv3/labeled_requests.rb', line 20

def dispatch_replies(evt)
  if evt.tags['label']
    labeled_requests.delete(evt.tags['label'])&.call(evt)
  end
end

#labeled_request(line) ⇒ Object



4
5
6
7
8
9
# File 'lib/iirc/modules/ircv3/labeled_requests.rb', line 4

def labeled_request(line)
  SecureRandom.alphanumeric(8).tap { |id|
    labeled_requests[id] = -> evt { yield evt }
    self << "@label=#{id} #{line}"
  }
end

#labeled_requestsObject



11
12
13
# File 'lib/iirc/modules/ircv3/labeled_requests.rb', line 11

def labeled_requests
  @requests ||= {}
end