Skip to content

Commit

Permalink
Added ability to have more than one hex or rgb on a message
Browse files Browse the repository at this point in the history
  • Loading branch information
gabceb committed Feb 8, 2013
1 parent fe683a8 commit 555f7e9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
class Kandan.Plugins.HexColorEmbed
@options:
regex: /#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/
regex: /#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/g

template: _.template '''
<span class="color-preview" style="background-color:<%= hex %>;"/>
'''
template: _.template '''<span class="color-preview" style="background-color:<%= hex %>;"/>'''

@init: ()->
Kandan.Modifiers.register @options.regex, (message, state) =>
hex = message.content.match(@options.regex)[0]
replacement = @options.template({hex: hex}) + hex

message.content = message.content.replace(hex, replacement)
for hex in message.content.match(@options.regex)
replacement = @options.template({hex: hex}) + hex
message.content = message.content.replace(hex, replacement)

return Kandan.Helpers.Activities.buildFromMessageTemplate(message)
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
class Kandan.Plugins.RgbColorEmbed
@options:
regex: /rgb\((\d{1,3}),\s?(\d{1,3}),\s?(\d{1,3})\)/
regex: /rgb\((\d{1,3}),\s?(\d{1,3}),\s?(\d{1,3})\)/g

template: _.template '''
<span class="color-preview" style="background-color:<%= rgb %>;"/>
'''
template: _.template '''<span class="color-preview" style="background-color:<%= rgb %>;"/>'''

@init: ()->
Kandan.Modifiers.register @options.regex, (message, state) =>
rgb = message.content.match(@options.regex)[0]
replacement = @options.template({rgb: rgb}) + rgb

message.content = message.content.replace(rgb, replacement)
for rgb in message.content.match(@options.regex)
replacement = @options.template({rgb: rgb}) + rgb
message.content = message.content.replace(rgb, replacement)

return Kandan.Helpers.Activities.buildFromMessageTemplate(message)

0 comments on commit 555f7e9

Please sign in to comment.