-
Notifications
You must be signed in to change notification settings - Fork 0
/
irchat-hooks.el
205 lines (180 loc) · 5.96 KB
/
irchat-hooks.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
;;; -*- emacs-lisp -*-
;;;
;;; Example hooks to customize irchat. These are copy-pasted from 2.2beta
;;; and modified a bit. The might or might not work. The general idea is
;;; that if hook returns nil, the appropriate handler is called after the
;;; hook. Any other value returned causes further processing of message
;;; cancelled.
(defun string-memberp (thing list)
"Dummy case insensitive function to check if string THING is a member of
LIST"
(cond ((null list) nil)
((string-equal (downcase thing) (downcase (car list))) t)
(t (string-memberp thing (cdr list)))))
;;;
;;;
;;;
(defvar irchat-watched-nicks '("God" "Pope" "Paavi" "JuhaF|hr"))
(defun irchat-join-hook (nick channel)
(cond
((string= "#report" channel)
t)
;; greet persons at current channel
((and (string-memberp nick irchat-watched-nicks)
(string= irchat-current-channel channel))
(progn
(beep)
(irchat-Command-send-message (format "%s: et ole kuitenkaan aito" nick))
(message "%s has joined channel %s" nick channel)
nil))
(t nil)))
(defun irchat-part-hook (prefix rest)
(if (string= "#report" rest)
t nil))
(setq irchat-join-hook (function irchat-join-hook))
(setq irchat-part-hook (function irchat-part-hook))
;;;
;;;
;;;
(defvar irchat-broadcast-partner nil)
(defun irchat-privmsg-hook (prefix rest)
(if (and irchat-broadcast-partner (not irchat-chat-partner))
(progn
(if (eq prefix nil)
(setq prefix "")
(setq prefix (concat "<" prefix "> ")))
(if (and (string= prefix "")
(string-match (format "^%s.*"
(format (irchat-format-string 1
nil)))
rest))
nil
(progn
(string-match "[^ ]* :\\(.*\\)" rest)
(irchat-send-privmsg "PRIVMSG %s :%s%s"
irchat-broadcast-partner
prefix
(matching-substring rest 1))))
nil)
nil))
(defun irchat-msg-hook (prefix rest)
(if (and irchat-broadcast-partner (not irchat-chat-partner))
(progn
(if (eq prefix nil)
(setq prefix "")
(setq prefix (concat "<" prefix "> ")))
(if (and (string= prefix "")
(string-match (format "^%s.*"
(format (irchat-format-string 1
nil)))
rest))
nil
(progn
(string-match "[^ ]* :\\(.*\\)" rest)
(irchat-send-privmsg "PRIVMSG %s :%s%s"
irchat-broadcast-partner
prefix
(matching-substring rest 1))))
nil)
nil))
(setq irchat-privmsg-hook (function irchat-privmsg-hook))
(setq irchat-msg-hook (function irchat-msg-hook))
;;;
;;; following stuff stolen from nAm (modified a bit), untested,
;;; use on your own risk
;;;
(define-key irchat-Command-mode-map "\C-c\C-a"
'(lambda (&optional private)
"Send action ctcp - if on empty line, ask for the message"
(interactive
(if current-prefix-arg
(list current-prefix-arg)
nil))
(let ((completion-ignore-case t) message start stop)
(if private
(setq irchat-privmsg-partner
(irchat-completing-default-read
"To whom: "
(append irchat-nick-alist irchat-channel-alist)
'(lambda (s) t)
nil irchat-privmsg-partner)))
(beginning-of-line)
(setq start (point))
(end-of-line)
(setq stop (point))
(if (eq start stop)
(setq message (read-string "Action: "))
(setq message (buffer-substring start stop))
(irchat-next-line 1))
(irchat-send-privmsg "PRIVMSG %s :ACTION %s"
(if private
irchat-privmsg-partner
irchat-current-channel)
message)
(if private
(irchat-own-message (format "*** Action to %s: %s %s"
irchat-privmsg-partner irchat-real-nickname
message))
(irchat-own-message (format "*** Action: %s %s" irchat-real-nickname
message))))))
(setq irchat-Startup-hook '(lambda ()
(sit-for 3) ; wait for possible nick collision
(irchat-Command-message "eu-oper" "invite")
(irchat-Command-message "Arska" "kutsu")
(setq scroll-step 1)))
(setq irchat-invite-hook '(lambda (prefix rest)
(if (string-match " \\([^ ]+\\)" rest)
(let ((chnl (matching-substring rest 1)))
(cond
((string= prefix "Arska")
(irchat-Command-join chnl))
((string= prefix "Eu-Oper")
(let ((curchnl irchat-current-channel))
(irchat-Command-join chnl)
(if curchnl
(irchat-Command-join curchnl)))))))
nil))
;;;
;;; to make a bot....
;;;
(defvar irchat-arska-mode nil)
(defun irchat-ownjoin-hook (prefix rest)
(if (and (string-match "#eu-opers" rest)
(string-match irchat-real-nickname prefix))
(irchat-Command-message "eu-oper" "op"))
(if (string-match "kuolepois" prefix)
(setq irchat-arska-mode nil)
(if (string-match "namarska" prefix)
(setq irchat-arska-mode t)))
(if (and irchat-arska-mode
(string-match "\\(.fi\\)" irchat-userathost)
(= (match-end 0) (match-end 1)))
(irchat-send "mode %s +o %s" rest prefix))
(if (and (string-match "#report" rest)
(not (string-match prefix irchat-real-nickname)))
(message "%s (%s) has joined this channel%s"
prefix irchat-userathost
(if (string= (or irchat-current-channel "") rest) ""
(format " (%s)" rest)))
nil))
(defun irchat-ownpart-hook (prefix rest)
(if (and (string-match "#report" rest)
(not (string-match prefix irchat-real-nickname)))
(message "%s has left this channel%s"
prefix
(if (string= (or irchat-current-channel "") rest) ""
(format " (%s)" rest)))
nil))
(defun irchat-ownquit-hook (prefix rest)
(if (and (string-match "#report" rest)
(not (string-match prefix irchat-real-nickname)))
(message "%s has left IRC%s"
prefix
(if (= 0 (length rest)) "" (format " (%s)" rest)))
nil))
(setq irchat-join-hook (function irchat-ownjoin-hook))
(setq irchat-part-hook (function irchat-ownpart-hook))
(setq irchat-quit-hook (function irchat-ownquit-hook))
(eval-and-compile (provide 'irchat-hooks))
;;;
;;; eof