Class: Slk::Formatters::MentionReplacer
- Inherits:
-
Object
- Object
- Slk::Formatters::MentionReplacer
- Defined in:
- lib/slk/formatters/mention_replacer.rb
Overview
Replaces Slack mention syntax with readable @names and #channels rubocop:disable Metrics/ClassLength
Constant Summary collapse
- USER_MENTION_REGEX =
/<@([UW][A-Z0-9]+)(?:\|([^>]+))?>/- CHANNEL_MENTION_REGEX =
/<#([A-Z0-9]+)(?:\|([^>]*))?>/- SUBTEAM_MENTION_REGEX =
/<!subteam\^([A-Z0-9]+)(?:\|@?([^>]+))?>/- LINK_REGEX =
%r{<(https?://[^|>]+)(?:\|([^>]+))?>}- SPECIAL_MENTIONS =
{ '<!here>' => '@here', '<!channel>' => '@channel', '<!everyone>' => '@everyone' }.freeze
Instance Method Summary collapse
-
#initialize(cache_store:, api_client: nil, on_debug: nil) ⇒ MentionReplacer
constructor
A new instance of MentionReplacer.
-
#lookup_user_name(workspace, user_id) ⇒ Object
Public API for looking up user names (used by MessageFormatter).
- #replace(text, workspace) ⇒ Object
Constructor Details
#initialize(cache_store:, api_client: nil, on_debug: nil) ⇒ MentionReplacer
Returns a new instance of MentionReplacer.
18 19 20 21 22 |
# File 'lib/slk/formatters/mention_replacer.rb', line 18 def initialize(cache_store:, api_client: nil, on_debug: nil) @cache = cache_store @api = api_client @on_debug = on_debug end |
Instance Method Details
#lookup_user_name(workspace, user_id) ⇒ Object
Public API for looking up user names (used by MessageFormatter)
34 35 36 |
# File 'lib/slk/formatters/mention_replacer.rb', line 34 def lookup_user_name(workspace, user_id) user_lookup_for(workspace).resolve_name(user_id) end |
#replace(text, workspace) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/slk/formatters/mention_replacer.rb', line 24 def replace(text, workspace) result = text.dup result = replace_user_mentions(result, workspace) result = replace_channel_mentions(result, workspace) result = replace_subteam_mentions(result, workspace) result = replace_links(result) replace_special_mentions(result) end |