如何编写一个函数,当有人在 Emacs 的 irc 上提及我时通知我

发布于 2025-01-04 15:22:32 字数 875 浏览 3 评论 0原文

我有这个功能

(defun mention-notify (match-type nickuserhost msg)
  (interactive)
  (if (and (eq match-type 'current-nick)
           (eq (string-match "^-NickServ-" msg) nil) ;this is probably not needed
           (eq (string-match "^\\*\\*\\*" msg) nil))
      (progn
        (shell-command "mpg123 -q /home/kuba/Pobrane/beep-8.mp3")
        (notify "ERC" msg))))

(add-hook 'erc-text-matched-hook 'mention-notify)

,但它执行命令,即使它的消息从 *** 开始。我在这里做错了什么?这个函数应该是什么样子的?

我阅读了该页面,但它只显示了如何发送所有提及的通知,甚至从服务器发送通知。例如:

*** #上的用户:jcubic...

*** jcubic 已将 jcubic 的模式更改为 +i

看来当我检查时对于 'current-nick - msg 不是整个消息,而是包含我的昵称的子字符串,我尝试检查关键字而不是当前昵称,并检查我总是使用的昵称是否出现在文本中,但是使用关键字根本不起作用。

I have this function

(defun mention-notify (match-type nickuserhost msg)
  (interactive)
  (if (and (eq match-type 'current-nick)
           (eq (string-match "^-NickServ-" msg) nil) ;this is probably not needed
           (eq (string-match "^\\*\\*\\*" msg) nil))
      (progn
        (shell-command "mpg123 -q /home/kuba/Pobrane/beep-8.mp3")
        (notify "ERC" msg))))

(add-hook 'erc-text-matched-hook 'mention-notify)

But it execute command even it message start from ***. What I'm doing wrong here? How this function should look like?

I read that page but it only show how to send notification for all mentions, even from server. like:

*** Users on #<chanel>: jcubic...

or

*** jcubic has changed mode for jcubic to +i

It seams that when I check for 'current-nick - msg is not the whole message but substring containing my nick, I try to check for keyword instead of current-nick and check if my nick that I always use appear in the text but using keyword doesn't work at all.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

恍梦境° 2025-01-11 15:22:32

您可能还想看看 Sauron:

http://www.emacswiki.org/emacs/Sauron

You might also want to look at Sauron:

http://www.emacswiki.org/emacs/Sauron

不乱于心 2025-01-11 15:22:32

我将 erc-match-message 函数从 erc.el 文件复制到我的 .emacs 文件中,并添加了一个标志来挂钩

(run-hook-with-args
 'erc-text-matched-hook
 (intern match-type)
 (or nickuserhost
     (concat "Server:" (erc-get-parsed-vector-type vector)))
 message
 (string-match "^\\*\\*\\*"
               (buffer-substring (point-min) (point-max)))))))

如果消息是 erc 系统消息 - 以 ** 开头则设置最后一个标志* 所以现在我可以在我的钩子中检查这个标志

(defun mention-notify (match-type nickuserhost msg notification)
  (interactive)
  (if (and (eq match-type 'current-nick)
           (not notification))
      (progn
        (shell-command "mpg123 -q /home/kuba/Pobrane/beep-8.mp3")
        (notify "ERC" msg))))

UPDATE 我也不想接收来自 -NickServ- 的消息,所以我添加了这个

(run-hook-with-args
 'erc-text-matched-hook
 (intern match-type)
 (or nickuserhost
     (concat "Server:" (erc-get-parsed-vector-type vector)))
 message
 (let ((whole-msg (buffer-substring (point-min) (point-max))))
    (or (string-match "^-NickServ-" whole-msg)
        (string-match "^\\*\\*\\*" whole-msg)))))))

I copied erc-match-message function from erc.el file into my .emacs file and I added one flag to hook

(run-hook-with-args
 'erc-text-matched-hook
 (intern match-type)
 (or nickuserhost
     (concat "Server:" (erc-get-parsed-vector-type vector)))
 message
 (string-match "^\\*\\*\\*"
               (buffer-substring (point-min) (point-max)))))))

last flag is set if message is erc system message - starts with *** so now I can check this flag in my hook

(defun mention-notify (match-type nickuserhost msg notification)
  (interactive)
  (if (and (eq match-type 'current-nick)
           (not notification))
      (progn
        (shell-command "mpg123 -q /home/kuba/Pobrane/beep-8.mp3")
        (notify "ERC" msg))))

UPDATE I also didn't want to recive message from -NickServ- so I add this

(run-hook-with-args
 'erc-text-matched-hook
 (intern match-type)
 (or nickuserhost
     (concat "Server:" (erc-get-parsed-vector-type vector)))
 message
 (let ((whole-msg (buffer-substring (point-min) (point-max))))
    (or (string-match "^-NickServ-" whole-msg)
        (string-match "^\\*\\*\\*" whole-msg)))))))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文