;;; sound setting
(eval-when (:compile-toplevel :load-toplevel :execute)
(require "foreign") (require "wip/winapi"))
(c:define-dll-entry winapi::BOOL PlaySound (winapi::LPCSTR winapi::HMODULE winapi::DWORD) "winmm" "PlaySoundA")
;;; for privmsg sound
(setf sf-privmsg (si:make-string-chunk "C:\WINDOWS\MEDIA\chimes.wav"))
;;; for join/part sound
(setf sf-join-part (si:make-string-chunk "C:\WINDOWS\MEDIA\chord.wav"))
;;; for change-of-nick, change-of-topic sound
(setf sf-chtopic (si:make-string-chunk "C:\WINDOWS\MEDIA\notify.wav"))
(defun ps-privmsg (msg channel nick text)
(when (and channel
(string-equal (irc-message-command msg) "PRIVMSG")
(not (string-equal nick *irc-nick*)))
(PlaySound sf-privmsg 0 #x00020000)))
(add-hook '*irc-command-privmsg-hook* 'ps-privmsg)
(defun ps-join-part-quit (msg channel nick &optional (text "not used"))
(when (and channel
(or
(string-equal (irc-message-command msg) "JOIN")
(string-equal (irc-message-command msg) "PART")
(string-equal (irc-message-command msg) "QUIT")))
(PlaySound sf-join-part 0 #x00020000)))
(add-hook '*irc-command-join-hook* 'ps-join-part-quit)
(add-hook '*irc-command-quit-hook* 'ps-join-part-quit)
(add-hook '*irc-command-part-hook* 'ps-join-part-quit)
(defun ps-topic (msg channel channel-or-nick text)
(when (and channel
(string-equal (irc-message-command msg) "TOPIC"))
(PlaySound sf-chtopic 0 #x00020000)))
(add-hook '*irc-command-topic-hook* 'ps-topic)
(defvar *irc-use-sound* t)
(when (and channel
*irc-use-sound*
...
...
(defun irc-toggle-use-sound ()
(interactive)
(if *irc-use-sound*
(progn
(setq *irc-use-sound* nil)
(message "Disable sound on irc-mode."))
(progn
(setq *irc-use-sound* t)
(message "Enable sound on irc-mode."))))
(defun ircn-save-user-list (&optional (file *ircn-user-list-file*))
"なるとを配ってもいいユーザーリストをファイルに書き出す"
(interactive)
(when (file-exist-p file)
(let ((ircn-user-list-buffer nil))
(save-window-excursion
(ed::find-file-internal file)
(setq ircn-user-list-buffer (file-namestring file))
(set-buffer ircn-user-list-buffer)
(delete-region (point-min) (point-max))
(dolist (item *ircn-user-list*)
(insert item)
(insert #\LFD))
(save-buffer)
(delete-buffer (selected-buffer))))))
(defun ircn-save-channel-list (&optional (file *ircn-channel-list-file*))
"なると配布用のチャンネルリストをファイルに書き出す"
(interactive)
(with-open-stream (fp (open file :direction :output :if-doed-not-exist :create))
(with-hash-table-iterator (foo *ircn-channel-hash-table*)
(loop
(multiple-value-bind (f x y)
(foo)
(unless f (return))
(princ x fp)
(princ #\TAB fp)
(princ y fp)
(princ #\LFD fp)))))
t)
(defun auto-naruto (msg channel nick)
(when (and channel
(string-equal (irc-message-command msg) "JOIN")
*ircn-auto-naruto*)
(irc-escape-window-buffer
(set-buffer (irc-dialog-buffer channel))
(when (gethash (irc-channel-name channel) *ircn-channel-hash-table*)
(cond
((string-equal (gethash (irc-channel-name channel) *ircn-channel-hash-table*) "none"))
((string-equal (gethash (irc-channel-name channel) *ircn-channel-hash-table*) "normal")
(when (ircn-auth-user-p (irc-message-user msg))
(cond
((not (irc-dialog-chop-list)))
((irc-dialog-chop-p nick))
((irc-dialog-chop-p)
(start-timer (1+ (random *ircn-delay-time*))
#'(lambda () (irc-dialog-send-mode-+o nick)) t)))))
((string-equal (gethash (irc-channel-name channel) *ircn-channel-hash-table*) "ext")
(start-timer (1+ (random *ircn-delay-time*))
#'(lambda () (irc-dialog-send-mode-+o nick)) t)))))))
;;; ######################
;;; ## なると自動配布機能
;;; ######################
(defvar *ircn-auto-naruto* t)
(defun ircn-load-user-list-file (&optional (userlist *ircn-user-list-file*))
"なるとを配ってもいいユーザーのリストファイルをロード"
(interactive)
(when (file-exist-p userlist)
(with-open-file (fp userlist)
(let ((line nil)
(user-list (make-list 0)))
(while (setq line (read-line fp nil nil nil))
(push line user-list))
user-list))))
;;; read
(defun ircn-load-channel-list-file (&optional (file *ircn-channel-list-file*))
"なると配布用のチャンネルリストをファイルから読み込む"
(interactive)
(if (not (file-exist-p file)) (return-from ircn-load-file nil))
(let ((hash-table (make-hash-table :test 'equal))
(tmplist nil))
(with-open-stream (fp (open file))
(while (setq line (read-line fp nil))
(setq tmplist (split-string line #\TAB))
(setf (gethash (car tmplist) hash-table) (cadr tmplist))))
hash-table))
(defvar *ircn-user-list-file* "hogehoge.txt")
(defvar *ircn-user-list* nil)
(unless *ircn-user-list*
(setf *ircn-user-list* (ircn-load-user-list-file *ircn-user-list-file*)))
(defvar *ircn-channel-list-file* (merge-pathnames "hugahuga.txt" (user-homedir-pathname)))
(defvar *ircn-channel-hash-table* nil)
(unless *ircn-channel-hash-table*
(setf *ircn-channel-hash-table* (ircn-load-channel-list-file *ircn-channel-list-file*)))
(defun ircn-save-user-list (&optional (file *ircn-user-list-file*))
"なるとを配ってもいいユーザーリストをファイルに書き出す"
(interactive)
(with-open-stream (fp (open file :direction :output :if-does-not-exist :create))
(dolist (user *ircn-user-list*)
(princ user fp)
(princ #\LFD fp)))
t)
(defun ircn-auth-user-p (user)
"user がなるとを配ってもいいユーザーかどうか"
(interactive)
(dolist (item *ircn-user-list*)
(if (string-equal item user)
(return-from ircn-auth-user-p t)))
nil)
(defun ircn-delete-auth-user (user)
"user をなるとを配ってもいいユーザーリストから削除"
(interactive "sUSER: ")
(when (and (stringp user)
(member user *ircn-user-list* :test 'string-equal))
(delete user *ircn-user-list* :test 'string-equal)
(return-from ircn-delete-auth-user t))
nil)
(defun ircn-add-auth-user (user)
"user をなるとを配ってもいいユーザーリストに追加"
(interactive "sUSER: ")
(when (and (stringp user)
(not (member user *ircn-user-list* :test 'string-equal)))
(push user *ircn-user-list*)
(return-from ircn-add-auth-user t))
nil)
;;; write
(defun ircn-save-channel-list (&optional (file *ircn-channel-list-file*))
"なると配布用のチャンネルリストをファイルに書き出す"
(interactive)
(with-open-stream (fp (open file :direction :output :if-does-not-exist :create))
(with-hash-table-iterator (foo *ircn-channel-hash-table*)
(loop
(multiple-value-bind (f x y)
(foo)
(unless f (return))
(princ x fp)
(princ #\TAB fp)
(princ y fp)
(princ #\LFD fp)))))
t)
(defun ircn-add-channel-hash-table (channel mode)
"なると配布用チャンネルハッシュテーブルにチャンネルとモードを追加"
(interactive "sChannel: \nsmode: ")
(unless (gethash channel *ircn-channel-hash-table*)
(setf (gethash channel *ircn-channel-hash-table*) mode)
t))
(defun ircn-remove-channel-hash-table (channel)
"なると配布用のチャンネルリストからチャンネルを削除"
(interactive "sChannel: ")
(remhash channel *ircn-channel-hash-table*))
(defun ircn-change-channel-hash-table (channel mode)
"なると配布用チャンネルのモードを変更"
(interactive "sChannel: \nsmode: ")
(when (gethash channel *ircn-channel-hash-table*)
(setf (gethash channel *ircn-channel-hash-table*) mode)
t))
(defun ircn-popup-channel-hash-table ()
"popup *ircn-channel-hash-table*"
(interactive)
(with-hash-table-iterator (foo *ircn-channel-hash-table*)
(let ((chlist nil))
(loop
(multiple-value-bind (f x y)
(foo)
(unless f (return))
(push (format nil "channel: ~20@A\tmode: ~5A" x y) chlist)))
(popup-string (format nil "===ircn Channel mode list===\n~{~A\n~}" chlist) (point)))))
(defun auto-naruto (msg channel nick)
(when (and channel
(string-equal (irc-message-command msg) "JOIN")
*ircn-auto-naruto*)
(irc-escape-window-buffer
(set-buffer (irc-dialog-buffer channel))
(when (gethash (irc-channel-name channel) *ircn-channel-hash-table*)
(cond
((string-equal (gethash (irc-channel-name channel) *ircn-channel-hash-table*) "none"))
((string-equal (gethash (irc-channel-name channel) *ircn-channel-hash-table*) "normal")
(when (ircn-auth-user-p (irc-message-user msg))
(cond
((not (irc-dialog-chop-list)))
((irc-dialog-chop-p nick))
((irc-dialog-chop-p)
(irc-dialog-send-mode-+o nick)))))
((string-equal (gethash (irc-channel-name channel) *ircn-channel-hash-table*) "ext")
(cond
((not (irc-dialog-chop-list)))
((irc-dialog-chop-p nick))
((irc-dialog-chop-p)
(irc-dialog-send-mode-+o nick)))))))))
(add-hook '*irc-command-join-hook* 'auto-naruto)
(add-hook '*irc-close-hook* 'ircn-save-user-list)
(add-hook '*irc-close-hook* 'ircn-save-channel-list)