Skip to content
This repository has been archived by the owner on Jul 24, 2018. It is now read-only.

Commit

Permalink
Handle colorizing IRC messages.
Browse files Browse the repository at this point in the history
Fixes #16.
  • Loading branch information
ralphbean committed Jun 10, 2014
1 parent 7d039fb commit 7c5df91
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
14 changes: 14 additions & 0 deletions fedmsg.d/fmn.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@
},
},

# Colors:
"irc_color_lookup": {
"fas": "light blue",
"bodhi": "green",
"git": "red",
"tagger": "brown",
"wiki": "purple",
"logger": "orange",
"pkgdb": "teal",
"buildsys": "yellow",
"planet": "light green",
"fmn": "purple",
},

## Backend stuff ##

# This is the list of enabled backends (so we can turn one off globally)
Expand Down
27 changes: 27 additions & 0 deletions fmn/consumer/backends/irc.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@
You can contact {support_email} if you have any concerns/issues/abuse.
"""

mirc_colors = {
"white": 0,
"black": 1,
"blue": 2,
"green": 3,
"red": 4,
"brown": 5,
"purple": 6,
"orange": 7,
"yellow": 8,
"light green": 9,
"teal": 10,
"light cyan": 11,
"light blue": 12,
"pink": 13,
"grey": 14,
"light grey": 15,
}


def _shorten(link):
if not link:
Expand Down Expand Up @@ -62,6 +81,14 @@ def _format_message(msg, recipient, config):
flt_link = _shorten(flt_link)
flt = " (triggered by %s)" % flt_link

if recipient['markup_messages']:
markup = lambda s, color: "\x03%i%s\x03" % (mirc_colors[color], s)
color_lookup = config.get('irc_color_lookup', {})
title_color = color_lookup.get(title.split('.')[0], "light grey")
title = markup(title, title_color)
if link:
link = markup(link, "teal")

return template.format(title=title, subtitle=subtitle, delta=delta,
link=link, flt=flt)

Expand Down
1 change: 1 addition & 0 deletions fmn/consumer/producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def manage_batch(session, backend, pref):
recipients = [{
name: value.value,
'user': pref.user.openid,
'markup_messages': pref.markup_messages,
'triggered_by_links': pref.triggered_by_links,
'shorten_links': pref.shorten_links,
} for value in pref.detail_values]
Expand Down

0 comments on commit 7c5df91

Please sign in to comment.