emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r103526: * lisp/net/rcirc.el: Add fun


From: Deniz Dogan
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r103526: * lisp/net/rcirc.el: Add functionality to authenticate before autojoining channels.
Date: Sat, 05 Mar 2011 14:34:55 +0100
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 103526
committer: Deniz Dogan <address@hidden>
branch nick: emacs-trunk
timestamp: Sat 2011-03-05 14:34:55 +0100
message:
  * lisp/net/rcirc.el: Add functionality to authenticate before autojoining 
channels.
  (rcirc-authenticate-before-join): New option.
  (rcirc-authenticated-hook): New variable.
  (rcirc-connect): Make local variable rcirc-user-authenticated.
  (rcirc-handler-001): Respect rcirc-authenticate-before-join.
  (rcirc-check-auth-status, rcirc-join-channels-post-auth): New
  functions.
  (rcirc-handler-PRIVMSG, rcirc-handler-NOTICE): Call
  rcirc-check-auth-status.
modified:
  lisp/ChangeLog
  lisp/net/rcirc.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2011-03-05 10:32:10 +0000
+++ b/lisp/ChangeLog    2011-03-05 13:34:55 +0000
@@ -1,3 +1,16 @@
+2011-03-05  Deniz Dogan  <address@hidden>
+
+       * net/rcirc.el: Add functionality to authenticate before
+       autojoining channels.
+       (rcirc-authenticate-before-join): New option.
+       (rcirc-authenticated-hook): New variable.
+       (rcirc-connect): Make local variable rcirc-user-authenticated.
+       (rcirc-handler-001): Respect rcirc-authenticate-before-join.
+       (rcirc-check-auth-status, rcirc-join-channels-post-auth): New
+       functions.
+       (rcirc-handler-PRIVMSG, rcirc-handler-NOTICE): Call
+       rcirc-check-auth-status.
+
 2011-03-05  Alex Harsanyi  <address@hidden>
 
        * net/soap-client.el (soap-namespace-put-link): Check if the target

=== modified file 'lisp/net/rcirc.el'
--- a/lisp/net/rcirc.el 2011-03-03 15:56:38 +0000
+++ b/lisp/net/rcirc.el 2011-03-05 13:34:55 +0000
@@ -232,6 +232,13 @@
   :type 'boolean
   :group 'rcirc)
 
+(defcustom rcirc-authenticate-before-join t
+  "*Non-nil means authenticate to services before joining channels.
+Currently only works with NickServ on some networks."
+  :version "24.1"
+  :type 'boolean
+  :group 'rcirc)
+
 (defcustom rcirc-prompt "> "
   "Prompt string to use in IRC buffers.
 
@@ -282,6 +289,9 @@
   :type 'hook
   :group 'rcirc)
 
+(defvar rcirc-authenticated-hook nil
+  "Hook run after successfully authenticated.")
+
 (defcustom rcirc-always-use-server-buffer-flag nil
   "Non-nil means messages without a channel target will go to the server 
buffer."
   :type 'boolean
@@ -524,6 +534,8 @@
       (setq rcirc-timeout-timer nil)
       (make-local-variable 'rcirc-user-disconnect)
       (setq rcirc-user-disconnect nil)
+      (make-local-variable 'rcirc-user-authenticated)
+      (setq rcirc-user-authenticated nil)
       (make-local-variable 'rcirc-connecting)
       (setq rcirc-connecting t)
 
@@ -2428,10 +2440,23 @@
     (setq rcirc-server-name sender)
     (setq rcirc-nick (car args))
     (rcirc-update-prompt)
-    (when rcirc-auto-authenticate-flag (rcirc-authenticate))
+    (if rcirc-auto-authenticate-flag
+        (if rcirc-authenticate-before-join
+            (progn
+              (with-rcirc-process-buffer process
+                (add-hook 'rcirc-authenticated-hook 
'rcirc-join-channels-post-auth t t))
+              (rcirc-authenticate))
+          (rcirc-authenticate)
+          (rcirc-join-channels process rcirc-startup-channels))
+      (rcirc-join-channels process rcirc-startup-channels))))
+
+(defun rcirc-join-channels-post-auth (process)
+  "Join `rcirc-startup-channels' after authenticating."
+  (with-rcirc-process-buffer process
     (rcirc-join-channels process rcirc-startup-channels)))
 
 (defun rcirc-handler-PRIVMSG (process sender args text)
+  (rcirc-check-auth-status process sender args text)
   (let ((target (if (rcirc-channel-p (car args))
                     (car args)
                   sender))
@@ -2444,6 +2469,7 @@
       (rcirc-put-nick-channel process sender target rcirc-current-line))))
 
 (defun rcirc-handler-NOTICE (process sender args text)
+  (rcirc-check-auth-status process sender args text)
   (let ((target (car args))
         (message (cadr args)))
     (if (string-match "^\C-a\\(.*\\)\C-a$" message)
@@ -2461,6 +2487,31 @@
                            sender)))
                  message t))))
 
+(defun rcirc-check-auth-status (process sender args text)
+  "Check if the user just authenticated.
+If authenticated, runs `rcirc-authenticated-hook' with PROCESS as
+the only argument."
+  (with-rcirc-process-buffer process
+    (when (and (not rcirc-user-authenticated)
+               rcirc-authenticate-before-join
+               rcirc-auto-authenticate-flag)
+      (let ((target (car args))
+            (message (cadr args)))
+        (when (or
+               (and ;; nickserv
+                (string= sender "NickServ")
+                (string= target rcirc-nick)
+                (member message
+                        (list
+                         (format "You are now identified for \C-b%s\C-b." 
rcirc-nick)
+                         "Password accepted - you are now recognized."
+                         )))
+               ;; place for other methods
+               )
+          (setq rcirc-user-authenticated t)
+          (run-hook-with-args 'rcirc-authenticated-hook process)
+          (remove-hook 'rcirc-authenticated-hook 
'rcirc-join-channels-post-auth t))))))
+
 (defun rcirc-handler-WALLOPS (process sender args text)
   (rcirc-print process sender "WALLOPS" sender (car args) t))
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]