Skip to content
This repository has been archived by the owner on Apr 13, 2019. It is now read-only.

Commit

Permalink
Initial support for IRC v3.2 tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Defman21 committed May 30, 2017
1 parent 09b10af commit b002f22
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cinch.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'cinch'
s.version = '2.3.1'
s.version = '2.3.2'
s.summary = 'An IRC Bot Building Framework'
s.description = 'A simple, friendly DSL for creating IRC bots'
s.authors = ['Dominik Honnef']
Expand Down
2 changes: 1 addition & 1 deletion lib/cinch/irc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def send_cap_ls
# @return [void]
# @since 2.0.0
def send_cap_req
caps = [:"away-notify", :"multi-prefix", :sasl] & @network.capabilities
caps = [:"away-notify", :"multi-prefix", :sasl, :"twitch.tv/tags"] & @network.capabilities

# InspIRCd doesn't respond to empty REQs, so send an END in that
# case.
Expand Down
27 changes: 25 additions & 2 deletions lib/cinch/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class Message

# @return [Array<String>]
attr_reader :params

# @return [Hash]
attr_reader :tags

# @return [Array<Symbol>]
attr_reader :events
Expand Down Expand Up @@ -94,8 +97,8 @@ def initialize(msg, bot)
# @api private
# @return [void]
def parse
match = @raw.match(/(^:(\S+) )?(\S+)(.*)/)
_, @prefix, @command, raw_params = match.captures
match = @raw.match(/(?:^@([^:]+))?(?::?(\S+) )?(\S+)(.*)/)
tags, @prefix, @command, raw_params = match.captures

if @bot.irc.network.ngametv?
if @prefix != "ngame"
Expand All @@ -104,6 +107,7 @@ def parse
end

@params = parse_params(raw_params)
@tags = parse_tags(tags)

@user = parse_user
@channel, @statusmsg_mode = parse_channel
Expand Down Expand Up @@ -266,6 +270,25 @@ def parse_params(raw_params)

return params
end

def parse_tags(raw_tags)
return {} if raw_tags.nil?

tags = {}
raw_tags.split(";").each do |tag|
key, value = tag.split("=")
if value =~ /,/
_value = value
value = {}
_value.split(",").each do |item|
_key, _value = item.split "/"
value[_key] = _value
end
end
tags[key] = value
end
return tags
end

def parse_user
return unless @prefix
Expand Down

0 comments on commit b002f22

Please sign in to comment.