Fixed a typo.
[riece] / lisp / riece-hangman.el
index 54f6349..5aa821f 100644 (file)
@@ -1,4 +1,4 @@
-;;; riece-hangman.el --- hangman
+;;; riece-hangman.el --- allow channel members to play the hangman game
 ;; Copyright (C) 1998-2004 Daiki Ueno
 
 ;; Author: Daiki Ueno <ueno@unixuser.org>
@@ -23,8 +23,7 @@
 
 ;;; Commentary:
 
-;; To use, add the following line to your ~/.riece/init.el:
-;; (add-to-list 'riece-addons 'riece-hangman)
+;; NOTE: This is an add-on module for Riece.
 
 ;;; Code:
 
 (require 'riece-server)
 
 (defgroup riece-hangman nil
-  "Interface to hangman.el"
+  "Allow channel members to play the hangman game."
   :prefix "riece-"
   :group 'riece)
 
-(defcustom riece-hangman-hello-regexp "^, hangman"
+(defcustom riece-hangman-hello-regexp "^,hangman$"
   "Pattern of string to start the game."
   :type 'string
   :group 'riece-hangman)
 
-(defcustom riece-hangman-bye-regexp "^, bye hangman"
+(defcustom riece-hangman-bye-regexp "^,hangman bye$"
   "Pattern of string to end the game."
   :type 'string
   :group 'riece-hangman)
 (defvar riece-hangman-player-context-alist nil)
 (defvar riece-hangman-words-buffer nil)
 
-(defvar riece-hangman-enabled nil)
-
 (defconst riece-hangman-description
-  "Allow users in channel to play classic textual game \"hangman\"")
+  "Allow channel members to play the hangman game.")
 
 (put 'riece-hangman 'riece-addon-default-disabled t)
 
@@ -96,7 +93,8 @@ This function is for internal use only."
 (defun riece-hangman-word ()
   "Return random word.
 The wordlist is read from `riece-hangman-words-file'."
-  (unless riece-hangman-words-buffer
+  (unless (and riece-hangman-words-buffer
+              (buffer-name riece-hangman-words-buffer))
     (setq riece-hangman-words-buffer (generate-new-buffer " *riece-hangman*"))
     (save-excursion
       (set-buffer riece-hangman-words-buffer)
@@ -106,7 +104,7 @@ The wordlist is read from `riece-hangman-words-file'."
        (delete-non-matching-lines "^[a-z][a-z][a-z][a-z][a-z][a-z]+"))))
   (save-excursion
     (set-buffer riece-hangman-words-buffer)
-    (goto-char (% (1+ (random)) (buffer-size)))
+    (goto-char (1+ (random (buffer-size))))
     (if (eobp)
        (beginning-of-line -1)
       (beginning-of-line))
@@ -140,7 +138,7 @@ The wordlist is read from `riece-hangman-words-file'."
               "")))))
 
 (defun riece-hangman-after-privmsg-hook (prefix string)
-  (if riece-hangman-enabled
+  (if (get 'riece-hangman 'riece-addon-enabled)
       (let* ((user (riece-prefix-nickname prefix))
             (parameters (riece-split-parameters string))
             (targets (split-string (car parameters) ","))
@@ -217,7 +215,8 @@ The wordlist is read from `riece-hangman-words-file'."
                          (riece-hangman-reply-with-context user (car targets)
                                                            (cdr pointer))
                        (riece-hangman-reply (car targets)
-                                            (format "%s: You got it!" user))
+                                            (format "%s: You got it! (%s)"
+                                                    user word))
                        (setq riece-hangman-player-context-alist
                              (delq
                               pointer
@@ -226,11 +225,11 @@ The wordlist is read from `riece-hangman-words-file'."
 (defun riece-hangman-insinuate ()
   (add-hook 'riece-after-privmsg-hook 'riece-hangman-after-privmsg-hook))
 
-(defun riece-hangman-enable ()
-  (setq riece-hangman-enabled t))
+(defun riece-hangman-uninstall ()
+  (remove-hook 'riece-after-privmsg-hook 'riece-hangman-after-privmsg-hook))
 
-(defun riece-hangman-disable ()
-  (setq riece-hangman-enabled nil))
+(defun riece-hangman-enable ()
+  (random t))
 
 (provide 'riece-hangman)