Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nick highlight function #72

Open
vibhavp opened this issue Jan 4, 2014 · 4 comments
Open

Nick highlight function #72

vibhavp opened this issue Jan 4, 2014 · 4 comments
Milestone

Comments

@vibhavp
Copy link

vibhavp commented Jan 4, 2014

A user defined function called when the users nick gets highlighted in a channel would be a nice feature.

@jorgenschaefer jorgenschaefer modified the milestones: Release v1.4, Release 1.5 Aug 26, 2014
@jorgenschaefer jorgenschaefer modified the milestones: Release v1.5, v1.6 Dec 12, 2014
@jorgenschaefer
Copy link
Collaborator

Oh, just over a year since this issue was created! :-)

This should work:

(circe-add-message-handler "PRIVMSG" 'my/handle-highlight)
(defun my/handle-highlight (nick user host command args)
  (when (string-match (with-circe-server-buffer (regexp-quote circe-server-nick))
                      (cadr args))
    ...))

While I think an accessor function for the current nick would be nice, I don't think this is particularly cumbersome to warrant a special hook.

Any opinions?

@wasamasa
Copy link
Collaborator

wasamasa commented Feb 4, 2015

It would be nice to have a dedicated function (or rather, variable with a function name doing the work as value) in combination with a list of regular expressions it is fired for.

I'm using this and that for my own handling of highlights. It would be nice to be able to simplify it.

@jorgenschaefer
Copy link
Collaborator

Actually, (circe-server-nick) already does what I meant above … doh self.

@wasamasa, does not sound complicated at all. Something like this?

(defvar circe-message-regex-handlers nil
  "List of (regex . handler) pairs.                                             

If a PRIVMSG matches REGEX, HANDLER is called with the usual                    
nick/user/host/command/args arguments.")

(circe-add-message-handler "PRIVMSG" 'circe-message-regex-handler)
(defun circe-message-regex-handler (nick user host command args)
  (dolist (entry circe-message-regex-handlers)
    (when (string-match (car entry)
                        (cadr args))
      (funcall (cdr entry) nick user host command args))))

@wasamasa
Copy link
Collaborator

wasamasa commented Feb 6, 2015

Hmm, that looks a bit too flexible (and rather like something I'd use for an IRC bot, not myself), I rather thought of separating the handler and the regular expression since I only have one function I'm firing, but many more regular expressions.

It shouldn't really matter though since I could just use regexp-opt to combine my list into a single regular expression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants