-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathirchat-commands.el
1719 lines (1555 loc) · 54.1 KB
/
irchat-commands.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; -*- emacs-lisp -*-
;;;
;;; see file irchat-copyright.el for change log and copyright info
(eval-when-compile (require 'irchat-inlines))
(eval-and-compile
; (require 'irchat-crypt)
(require 'irchat-vars)
(require 'irchat-dcc)
(require 'irchat-utf8)
(require 'irchat-caesar))
(defun irchat-Command-describe-briefly ()
(message (substitute-command-keys "Type \\[describe-mode] for help")))
(defun irchat-Command-redisplay (&optional center)
"Un-freezes and re-selects the Dialogue buffer in another window.
With argument, recenter with that argument."
(interactive "P")
(if (irchat-frozen (car irchat-D-buffer))
(irchat-freeze-toggle (car irchat-D-buffer)))
(if (irchat-ownfrozen (car irchat-D-buffer))
(irchat-ownfreeze-toggle (car irchat-D-buffer)))
(setq irchat-freeze-indicator "-")
(setq irchat-ownfreeze nil)
(setq irchat-ownfreeze-indicator "-")
(if (irchat-get-buffer-window irchat-Dialogue-buffer)
nil
(if (one-window-p)
(irchat-configure-windows)
(display-buffer irchat-Dialogue-buffer)))
(set-buffer irchat-Dialogue-buffer)
(set-window-point (irchat-get-buffer-window irchat-Dialogue-buffer)
(point-max)))
(defun irchat-Command-pollnames ()
(setq irchat-polling (+ irchat-polling (length irchat-channel-alist)))
(mapcar (function (lambda (channel)
(irchat-send "NAMES %s" (car channel))))
irchat-channel-alist))
(defun irchat-Command-find-timestamp ()
(interactive)
(save-excursion
(let ((obuffer (current-buffer))
(range ""))
(switch-to-buffer irchat-Dialogue-buffer)
(if (re-search-backward "^\\*\\*\\* Time: " (point-min) t)
(let ((start (+ (point) 10)))
(end-of-line)
(setq range (format "%s --- "
(buffer-substring start (point))))))
(if (re-search-forward "^\\*\\*\\* Time: " (point-max) t)
(let ((start (point)))
(end-of-line)
(setq range (concat range (buffer-substring start (point))))))
(message range)
(switch-to-buffer obuffer))))
(defun irchat-Command-keepalive ()
(if (not (irchat-server-opened))
(irchat 'always))
(irchat-ping-if-idle))
(defun irchat-compose-servertimestring (s)
(let* ((w '(("Mon" "Monday") ("Tue" "Tuesday") ("Wed" "Wednesday")
("Thu" "Thursday") ("Fri" "Friday") ("Sat" "Saturday")
("Sun" "Sunday")))
(m '(("Jan" "January") ("Feb" "February") ("Mar" "March")
("Apr" "April") ("May" "May") ("Jun" "June") ("Jul" "July")
("Aug" "August") ("Sep" "September") ("Oct" "October")
("Nov" "November") ("Dec" "December")))
(wdat) (mnam)
(wabb (substring s 0 3))
(mabb (substring s 4 7)))
(setq wdat (car (cdr (assoc wabb w)))
mnam (car (cdr (assoc mabb m))))
(format "%s %s %s %s %s"
wdat mnam (substring s 8 10) (substring s 20 24)
(substring s 11 16))))
(defvar irchat-last-timestamp-time nil "Last time timestamp was inserted")
(defvar irchat-last-timestamp-no-cons-p nil "Last timestamp was no-cons")
(defun irchat-Command-timestamp-if-interval-expired (&optional no-cons)
(interactive)
(if (and (not (and no-cons
irchat-last-timestamp-no-cons-p))
(numberp irchat-timestamp-interval)
(> irchat-timestamp-interval 0)
(or (null irchat-last-timestamp-time)
(> (irchat-time-difference irchat-last-timestamp-time
(current-time))
irchat-timestamp-interval)))
(progn
(if irchat-save-vars-is-dirty
(irchat-Command-save-vars))
(irchat-Command-timestamp)
(setq irchat-last-timestamp-no-cons-p no-cons))))
(defun irchat-Command-timestamp ()
(interactive)
(let ((stamp (format "%s" (format irchat-timestamp-format
(if irchat-format-time-function
(apply irchat-format-time-function
(list (current-time-string)))
(current-time-string))))))
(let ((irchat-timestamp-interval 0))
(irchat-Dialogue-insert stamp)))
(setq irchat-last-timestamp-time (current-time)))
(defun irchat-Command-send-message (message &optional crypt-type
user-defined-key
own-message
do-not-split)
"Send MESSAGE to current chat partner of current channel."
(if (not irchat-crypt-mode-active) (setq crypt-type 'cleartext))
(if (and (not do-not-split)
(not (eq irchat-command-buffer-mode 'chat))
(stringp irchat-message-split-separator)
(> (length message) irchat-message-length-limit)
(> irchat-message-length-limit
(* 2 (length irchat-message-split-separator))))
(let ((lst (irchat-split-string-with-separator
message
irchat-message-split-separator
irchat-message-length-limit))
(r nil))
(while lst
(let ((msg (car lst)))
(setq lst (cdr lst))
(setq r (irchat-Command-send-message msg
crypt-type
user-defined-key
(if lst "" message)
t))))
r)
(if (> (length message) 0)
(let* ((addr (if (eq irchat-command-buffer-mode 'chat)
irchat-current-chat-partner
irchat-current-channel))
(msg-encrypted-p nil)
(msg
(cond ((eq irchat-command-buffer-mode 'chat)
(progn
;; Chat mode is encrypted later if needed.
(setq msg-encrypted-p nil)
message))
((equal crypt-type 'cleartext)
(progn
(setq msg-encrypted-p nil)
message))
((and (equal crypt-type 'encrypted)
addr)
(progn
(setq msg-encrypted-p t)
(irchat-encrypt-message message addr t)))
((equal crypt-type 'user-defined-key)
(progn
(setq msg-encrypted-p t)
(irchat-encrypt-message message user-defined-key t)))
(addr
(let ((cipher (irchat-encrypt-message message
addr
nil)))
(if (not (string= cipher message))
(progn
(setq msg-encrypted-p t)
cipher)
(progn
(setq msg-encrypted-p nil)
message))))
(t (progn
(setq msg-encrypted-p nil)
message)))))
(if (eq irchat-command-buffer-mode 'chat)
(if irchat-current-chat-partner
(irchat-Command-message irchat-current-chat-partner
msg
crypt-type
own-message
do-not-split)
(message (substitute-command-keys
"Type \\[irchat-Command-join] to start private conversation"))
nil)
(if (not irchat-current-channel)
(progn
(beep t)
(message
(substitute-command-keys
"Type \\[irchat-Command-join] to join a channel"))
nil)
(progn
(irchat-send-privmsg "PRIVMSG %s :%s"
irchat-current-channel
msg)
(cond ((null own-message)
(irchat-own-message
(format (format (format "%s %%%%s"
(irchat-format-string
t
msg-encrypted-p))
irchat-real-nickname) message)))
((> (length own-message) 0)
(irchat-own-message
(format (format (format "%s %%%%s"
(irchat-format-string
t
msg-encrypted-p))
irchat-real-nickname) own-message)))
(t '())))))
t)
(progn
(message "IRCHAT: NO text to send")
nil))))
(defun irchat-enter-message (crypt-type &optional key opposite-utf8-mode)
"Enter the current line as an entry in the IRC dialogue on the
current channel."
(interactive)
(let (message start)
(beginning-of-line)
(setq start (point))
(end-of-line)
(setq message (buffer-substring start (point)))
(if (and (null irchat-utf8-kludge-disable)
(or (and irchat-utf8-kludge-send-utf8-as-default
(null opposite-utf8-mode))
(and (null irchat-utf8-kludge-send-utf8-as-default)
opposite-utf8-mode)))
(setq message (irchat-utf8-kludge-encode-extended message)))
(if (and irchat-confirm-bell-on-channel-message
(stringp irchat-current-channel)
(string-match "^#" irchat-current-channel)
(string-match "" message))
(if (yes-or-no-p
(format "Do you really want to send bell to the channel %s? "
irchat-current-channel))
(if (irchat-Command-send-message message crypt-type key)
(irchat-next-line 1))
(message "Message not sent!"))
(if (irchat-Command-send-message message crypt-type key)
(irchat-next-line 1)))))
(defun irchat-Command-enter-message ()
(interactive)
(irchat-enter-message nil nil nil))
(defun irchat-Command-enter-message-opposite-utf8-mode ()
(interactive)
(irchat-enter-message nil nil t))
(defun irchat-Command-enter-message-encrypted ()
(interactive)
(let ((irchat-crypt-mode-active t))
(irchat-enter-message 'encrypted nil nil)))
(defun irchat-Command-enter-message-cleartext ()
(interactive)
(irchat-enter-message 'cleartext nil nil))
(defun irchat-Command-enter-message-opposite-crypt-mode ()
(interactive)
(let ((irchat-crypt-mode-active (not irchat-crypt-mode-active)))
(irchat-enter-message nil nil nil)))
(defun irchat-Command-enter-message-opposite-utf8-and-crypt-modes ()
(interactive)
(let ((irchat-crypt-mode-active (not irchat-crypt-mode-active)))
(irchat-enter-message nil nil t)))
(defun irchat-Dialogue-enter-message ()
"Ask for a line as an entry in the IRC dialogue on the current channel."
(interactive)
(let ((message "x"))
(while (not (string= message ""))
(setq message (read-string "> "))
(if (not (string= message ""))
(irchat-Command-send-message message)))))
(defun irchat-Command-debug ()
"Start debugging irchat."
(interactive)
(let ((buf (current-buffer))
win)
(if irchat-debug-buffer
(progn
(if (eq buf irchat-debug-buffer)
(setq buf nil))
(delete-windows-on irchat-debug-buffer)
(setq irchat-debug-buffer nil)
(and buf (select-window (irchat-get-buffer-window buf)))
)
(if irchat-use-full-window
(progn
(delete-other-windows)
(irchat-configure-windows)))
(and (setq win (irchat-get-buffer-window irchat-Dialogue-buffer))
(select-window win))
(and (< (window-height) (* window-min-height 2))
(enlarge-window (- (* window-min-height 2) (window-height))))
(split-window)
(setq irchat-debug-buffer (irchat-get-buffer-create "*IRC Debugging*"))
(switch-to-buffer irchat-debug-buffer)
(goto-char (point-max))
(recenter)
(and (setq win (irchat-get-buffer-window buf))
(select-window win)))))
(defun irchat-Command-inline ()
"Send current line as a message to the IRC server."
(interactive)
(let (message start stop)
(beginning-of-line)
(setq start (point))
(end-of-line)
(setq stop (point))
(setq message (buffer-substring start stop))
(newline)
(irchat-send message)))
(defun irchat-Command-join (join-channel-var)
"Join a channel or private conversation.
If user nicname is given, join the same set of channels as
the specified user.
If Command-buffer is in chat-mode, start private conversation
with specified user."
(interactive (let (join-channel-var (completion-ignore-case t))
(setq join-channel-var
(if (eq irchat-command-buffer-mode 'chat)
(irchat-completing-default-read
"Start private conversation with: "
irchat-nick-alist
'(lambda (s) t) nil irchat-privmsg-partner)
(irchat-completing-default-read
"Join channel: "
(append irchat-channel-alist
irchat-nick-alist)
'(lambda (s) t) nil irchat-invited-channel)))
(list join-channel-var)))
(if (eq irchat-command-buffer-mode 'chat)
(progn
(setq irchat-current-chat-partners (append
(list join-channel-var)
(string-list-ci-delete
join-channel-var
irchat-current-chat-partners))
irchat-current-chat-partner join-channel-var
irchat-chat-partner-alist (list-to-assoclist
irchat-current-chat-partners)
irchat-channel-indicator (if irchat-current-chat-partner
(format "Chatting with %s"
irchat-current-chat-partner)
"No partner"))
(irchat-set-crypt-indicator))
(progn
(let ((nicks irchat-nick-alist)
(found nil))
(while (and (not found) nicks)
(if (and (car (car nicks))
(string-ci-equal join-channel-var (car (car nicks))))
(setq join-channel-var
(or (car (get (intern (car (car nicks)) irchat-obarray)
'chnl))
join-channel-var)
found t))
(setq nicks (cdr nicks))))
(let ((found nil))
(mapcar
'(lambda (elem)
(if (string-ci-equal join-channel-var elem)
(setq irchat-current-channel elem
found t)))
irchat-current-channels)
(setq irchat-channel-indicator
(if irchat-current-channel
(format "Channel %s" irchat-current-channel)
"No channel"))
(irchat-set-crypt-indicator)
(setq irchat-invited-channel nil)
(or found (irchat-send "JOIN %s" join-channel-var))))))
(defun irchat-Command-part (part-channel-var)
"Part a channel or private conversation."
(interactive (let (part-channel-var (completion-ignore-case t))
(setq part-channel-var
(if (eq irchat-command-buffer-mode 'chat)
(irchat-completing-default-read
"End private conversation with: "
irchat-chat-partner-alist
'(lambda (s) t) nil
irchat-current-chat-partner)
(irchat-completing-default-read
"Part channel: "
(list-to-assoclist irchat-current-channels)
'(lambda (s) t) nil
irchat-current-channel)))
(list part-channel-var)))
(if (eq irchat-command-buffer-mode 'chat)
(progn
(setq irchat-current-chat-partners (string-list-ci-delete
part-channel-var
irchat-current-chat-partners)
irchat-current-chat-partner (car irchat-current-chat-partners)
irchat-chat-partner-alist (list-to-assoclist
irchat-current-chat-partners)
irchat-channel-indicator (if irchat-current-chat-partner
(format "Chatting with %s"
irchat-current-chat-partner)
"No partner"))
(irchat-set-crypt-indicator))
(progn
(if (string-list-ci-memberp part-channel-var irchat-current-channels)
(setq irchat-current-channel part-channel-var)) ; just refocusing
(irchat-send "PART %s" part-channel-var))))
(defun irchat-Command-ignore (kill-nickname-var &optional timeout silent)
"Ignore messages from this user. Username can be given as case insensitive
regular expression of form \".*@.*\.sub.domain\".
If already ignoring him/her, toggle.
If variable irchat-variables-file is defined and the file is writable, its
contents are updated future sessions."
(interactive (let ((kill-nickname-var nil)
(timeout nil)
(completion-ignore-case t))
(setq kill-nickname-var
(completing-read "Ignore nickname or regexp: "
(append irchat-nick-alist
irchat-ignore-nickname)
'(lambda (s) t) nil nil))
(if (and (not (string= "" kill-nickname-var))
(not (assoc-ci-string kill-nickname-var irchat-ignore-nickname)))
(setq timeout
(string-to-int
(read-from-minibuffer "Timeout [RET for none]: "))))
(list kill-nickname-var timeout)))
;; empty, just list them
(if (string= "" kill-nickname-var)
(let ((buf (current-buffer))
(buffer-read-only))
(set-buffer irchat-Dialogue-buffer)
(goto-char (point-max))
(irchat-w-insert irchat-D-buffer
(format "%sCurrently ignoring:" irchat-info-prefix))
(let ((mylist irchat-ignore-nickname)
(time (current-time)))
(while mylist
(let* ((expiretime (if (cdr (car mylist))
(/ (irchat-time-difference time (cdr (car mylist))) 60)
nil))
(expire (cond ((not expiretime) "")
((>= expiretime 0)
(format " (%d min)" expiretime))
((< expiretime 0)
(format " expired")))))
(irchat-w-insert irchat-D-buffer
(format " %s%s" (car (car mylist)) expire)))
(setq mylist (cdr mylist))))
(irchat-w-insert irchat-D-buffer "\n")
(set-buffer buf))
;; else not empty, check if exists
(let ((elem (assoc-ci-string kill-nickname-var irchat-ignore-nickname)))
(if elem
(progn
(setq irchat-ignore-nickname (remassoc (car elem)
irchat-ignore-nickname))
(irchat-w-insert irchat-D-buffer
(format "%sNo longer ignoring: %s.\n"
irchat-info-prefix (car elem))))
;; did not find, add to ignored ones
(let ((expire-time (if (> timeout 0)
(irchat-time-add (current-time)
(* timeout 60)))))
(if (and silent (> timeout 0))
(setcar (cdr (cdr expire-time)) -1))
(setq irchat-ignore-nickname
(cons (cons kill-nickname-var expire-time)
irchat-ignore-nickname))
(if (not silent)
(progn
(irchat-w-insert irchat-D-buffer
(format "%sIgnoring %s"
irchat-info-prefix kill-nickname-var))
(irchat-w-insert irchat-D-buffer
(if (> timeout 0)
(format " for %d minutes.\n" timeout)
(format ".\n"))))))))
(setq irchat-save-vars-is-dirty t)))
(defun irchat-Command-ignore-by-regexp (kill-regexp-var
&optional timeout
silent)
"Ignore messages matcing regexp. If already ignoring regexp, toggle."
(interactive (let ((kill-regexp-var nil)
(timeout nil)
(completion-ignore-case t))
(setq kill-regexp-var
(completing-read "Ignore messages matching: "
irchat-ignore-message-regexp
'(lambda (s) t) nil nil))
(if (and (not (string= "" kill-regexp-var))
(not (assoc-ci-string kill-regexp-var
irchat-ignore-message-regexp)))
(setq timeout
(string-to-int
(read-from-minibuffer
"Timeout [RET for none]: "))))
(list kill-regexp-var timeout)))
;; empty, just list them
(if (string= "" kill-regexp-var)
(let ((buf (current-buffer))
(buffer-read-only))
(set-buffer irchat-Dialogue-buffer)
(goto-char (point-max))
(irchat-w-insert irchat-D-buffer
(format "%sCurrently ignoring messages matching:"
irchat-info-prefix))
(let ((mylist irchat-ignore-message-regexp)
(time (current-time)))
(while mylist
(let* ((expiretime (if (cdr (car mylist))
(/ (irchat-time-difference time
(cdr
(car mylist)))
60)
nil))
(expire (cond ((not expiretime) "")
((>= expiretime 0)
(format " (%d min)" expiretime))
((< expiretime 0)
(format " expired")))))
(irchat-w-insert irchat-D-buffer
(format " \"%s\"%s" (car (car mylist)) expire)))
(setq mylist (cdr mylist))))
(irchat-w-insert irchat-D-buffer "\n")
(set-buffer buf))
;; else not empty, check if exists
(let ((elem (assoc-ci-string kill-regexp-var irchat-ignore-message-regexp)))
(if elem
(progn
(setq irchat-ignore-message-regexp
(remassoc (car elem)
irchat-ignore-message-regexp))
(irchat-w-insert irchat-D-buffer
(format "%sNo longer ignoring: \"%s\".\n"
irchat-info-prefix (car elem))))
;; did not find, add to ignored ones
(let ((expire-time (if (> timeout 0)
(irchat-time-add (current-time)
(* timeout 60)))))
(if (and silent (> timeout 0))
(setcar (cdr (cdr expire-time)) -1))
(setq irchat-ignore-message-regexp
(cons (cons kill-regexp-var expire-time)
irchat-ignore-message-regexp))
(if (not silent)
(progn
(irchat-w-insert irchat-D-buffer
(format "%sIgnoring messages matching \"%s\""
irchat-info-prefix kill-regexp-var))
(irchat-w-insert irchat-D-buffer
(if (> timeout 0)
(format " for %d minutes.\n" timeout)
(format ".\n"))))))))
(setq irchat-save-vars-is-dirty t)))
(defun irchat-Command-send-action (&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-private-message (format "%sAction to %s: %s %s"
irchat-info-prefix
irchat-privmsg-partner
irchat-real-nickname
message))
(irchat-own-message (format "%sAction: %s %s"
irchat-info-prefix irchat-real-nickname
message)))))
(defun irchat-Command-kick (kick-nickname-var &optional why-var)
"Kick this user out."
(interactive (let (kick-nickname-var
why-var
(completion-ignore-case t))
(setq kick-nickname-var
(completing-read
"Kick out nickname: "
irchat-nick-alist
'(lambda (s) t) nil nil))
(setq why-var (if irchat-ask-kick-message
(read-from-minibuffer
"Kick message: "
(if (stringp irchat-default-kick-message)
irchat-default-kick-message
nil))
(if (stringp irchat-default-kick-message)
irchat-default-kick-message
nil)))
(list kick-nickname-var (if (and why-var
(not (string= ""
why-var)))
why-var
nil))))
(irchat-send "KICK %s %s%s"
irchat-current-channel
kick-nickname-var
(if why-var (concat " :" why-var) "")))
(defun irchat-Command-list (&optional channel)
"List the given channel and its topics.
If you enter only Control-U as argument, list the current channel.
With - as argument, list all channels."
(interactive
(if current-prefix-arg
(if (eq current-prefix-arg '-)
(list current-prefix-arg)
nil)
(list
(let ((completion-ignore-case t))
(completing-read
"LIST channel: "
irchat-channel-alist
'(lambda (s) t) nil nil)))))
(if (not channel)
(irchat-send "LIST %s" irchat-current-channel)
(if (eq channel '-)
(irchat-send "LIST")
(irchat-send "LIST %s" channel))))
(defun irchat-Command-lusers ()
"List the number of users and servers"
(interactive)
(irchat-send "LUSERS"))
(defun irchat-Command-modec (change)
"Send a MODE command"
(interactive "sMode for this channel: ")
(irchat-send "MODE %s %s" irchat-current-channel change))
(defun irchat-Command-message-delayed (&rest args)
"Send an always delayed private message to another user."
(interactive (let (message-nick-var
crypt-type-var
(completion-ignore-case t))
(setq message-nick-var
(irchat-completing-default-read
"Private message to: "
(append irchat-nick-alist irchat-channel-alist)
'(lambda (s) t) nil irchat-privmsg-partner))
(setq crypt-type-var nil)
(list message-nick-var
(read-string
(format "Private message to %s: " message-nick-var))
crypt-type-var
nil)))
(let ((irchat-use-delayed-privmsg t))
(eval (cons (function irchat-Command-message) args))))
(defun irchat-Command-message (message-nick-var
message
&optional crypt-type-var
own-message-var
do-not-split
opposite-utf8-mode)
"Send a private message to another user. If you send a message that
is already encrypted use 'cleartext flag and put message as a cleartext
into own-message-var"
(interactive (let (message-nick-var
crypt-type-var
(completion-ignore-case t))
(setq message-nick-var
(irchat-completing-default-read
"Private message to: "
(append irchat-nick-alist irchat-channel-alist)
'(lambda (s) t) nil irchat-privmsg-partner))
(setq crypt-type-var nil)
(list message-nick-var
(read-string
(format "Private message to %s: " message-nick-var))
crypt-type-var
nil
nil)))
(if (and (not do-not-split)
(stringp irchat-message-split-separator)
(> (length message) irchat-message-length-limit)
(> irchat-message-length-limit
(* 2 (length irchat-message-split-separator))))
(let ((lst (irchat-split-string-with-separator
message
irchat-message-split-separator
irchat-message-length-limit))
(r nil))
(while lst
(let ((msg (car lst)))
(setq lst (cdr lst))
(setq r (irchat-Command-message message-nick-var
msg
crypt-type-var
(if lst
""
(if own-message-var
own-message-var
message))
t
opposite-utf8-mode))))
r)
(let* ((message
(if (and (null irchat-utf8-kludge-disable)
(or (and irchat-utf8-kludge-send-utf8-as-default
(null opposite-utf8-mode))
(and (null irchat-utf8-kludge-send-utf8-as-default)
opposite-utf8-mode)))
(irchat-utf8-kludge-encode-extended message)
message))
(msg-encrypted-p nil)
(msg (cond ((equal crypt-type-var 'cleartext)
message)
((and (equal crypt-type-var 'encrypted)
message-nick-var)
(progn
(setq msg-encrypted-p t)
(irchat-encrypt-message message message-nick-var t)))
(message-nick-var
(let ((cipher (irchat-encrypt-message message
message-nick-var
nil)))
(if (not (string= cipher message))
(progn
(setq msg-encrypted-p t)
cipher)
(progn
(setq msg-encrypted-p nil)
message))))
(t
(progn
(setq msg-encrypted-p nil)
message)))))
(setq irchat-privmsg-partner message-nick-var)
(irchat-send-privmsg "PRIVMSG %s :%s" message-nick-var msg)
(if (or (null own-message-var)
(> (length own-message-var) 0))
(irchat-own-private-message
(format (format "%s %%s"
(irchat-format-string
nil
(or msg-encrypted-p
(and (not (null own-message-var))
(string-match "^|\\*E\\*|" msg)))))
message-nick-var (if own-message-var
own-message-var
message)))))))
;; Added at mta@tut.fi's request...
;; Does not support encryption (yet!?)
(defun irchat-Command-mta-private ()
"Send a private message (current line) to another user."
(interactive)
(let ((completion-ignore-case t) message start stop)
(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))
(setq message (buffer-substring start stop))
(irchat-next-line 1)
(if (> (length message) 0)
(irchat-Command-message irchat-privmsg-partner message)
(message "IRCHAT: No text to send"))))
(defun irchat-Command-names (&optional channel)
"List the nicknames of the current IRC users on given channel.
With an Control-U as argument, only the current channel is listed.
With - as argument, list all channels."
(interactive
(if current-prefix-arg
(if (eq current-prefix-arg '-)
(list current-prefix-arg)
nil)
(list
(let ((completion-ignore-case t))
(completing-read
"Names on channel: "
irchat-channel-alist
'(lambda (s) t) nil nil)))))
(if (not channel)
(irchat-send "NAMES %s" irchat-current-channel)
(if (eq channel '-)
(irchat-send "NAMES")
(irchat-send "NAMES %s" channel))))
(defun irchat-Command-nickname (nick)
"Set your nickname."
(interactive "sEnter your nickname: ")
(let ((nickname (irchat-read-nickname nick)))
(if (not (= (length nickname) 0))
(progn
(setq irchat-old-nickname irchat-real-nickname)
(setq irchat-real-nickname nickname)
(irchat-send "NICK %s" nick))
(message "IRCHAT: illegal nickname \"%s\"; not changed" nickname))))
(defun irchat-Command-who (&optional expr)
"Lists tue users that match the given expression.
If you enter only Control-U as argument, list the current channel.
With - as argument, list all users."
(interactive
(if current-prefix-arg
(if (eq current-prefix-arg '-)
(list current-prefix-arg)
nil)
(list
(let ((completion-ignore-case t))
(completing-read
"WHO expression: "
irchat-channel-alist
'(lambda (s) t) nil nil)))))
(if (not expr)
(irchat-send "WHO %s" irchat-current-channel)
(if (eq expr '-)
(irchat-send "WHO")
(irchat-send "WHO %s" expr))))
(defun irchat-Command-wait (nick &optional greeting)
"Wait for NICK to enter IRC. When this person appears, you will
be informed. If the optional argument GREETING is non-nil, it should
be a string to send NICK upon entering."
(interactive
(progn (setq nick (read-string "Wait for: ")
greeting (read-string
(format "Message to send %s upon entering: " nick)))
(if (string= greeting "")
(setq greeting nil))
(list nick greeting)))
(put (intern nick irchat-obarray) 'irchat-waited-for t)
(if greeting
(put (intern nick irchat-obarray) 'irchat-greeting greeting)))
(defun irchat-Command-finger (finger-nick-var)
"Get information about a specific user."
(interactive (let (finger-nick-var (completion-ignore-case t))
(setq finger-nick-var
(completing-read
"Finger whom: " irchat-nick-alist
'(lambda (s) t) nil nil))
(list finger-nick-var)))
(irchat-send "WHOIS %s" finger-nick-var))
(defun irchat-Command-topic (topic)
"Change topic of channel."
(interactive "sTopic: ")
(irchat-send "TOPIC %s :%s" irchat-current-channel topic))
(defun irchat-Command-invite (&optional invite-channel-var invite-nick-var)
"Invite user to channel."
(interactive
(list
(if current-prefix-arg
(let ((completion-ignore-case t))
(completing-read
"Invite channel: "
(mapcar '(lambda (x)
(list x))
irchat-current-channels)
'(lambda (s) t) nil nil)
nil))
(let ((completion-ignore-case t))
(completing-read "Invite whom: "
irchat-nick-alist
'(lambda (s) t) nil nil))))
(if (not invite-channel-var)
(setq invite-channel-var irchat-current-channel))
(irchat-send "INVITE %s %s" invite-nick-var invite-channel-var))
(defun irchat-Command-away (awaymsg)
"Mark/unmark yourself as being away."
(interactive "sAway message: ")
(progn
(irchat-send "AWAY :%s" awaymsg)
(setq irchat-awaymsg awaymsg)))
(defun irchat-Command-scroll-down ()
"Scroll Dialogue-buffer down from Command-buffer."
(interactive)
(let ((obuffer (current-buffer)) (owindow (selected-window)))
(select-window (irchat-get-buffer-window irchat-Dialogue-buffer))
(pop-to-buffer irchat-Dialogue-buffer)
(if (pos-visible-in-window-p (point-min))
(message "Beginning of buffer")
(scroll-down))
(select-window (irchat-get-buffer-window obuffer))
(pop-to-buffer obuffer)))
(defun irchat-Command-scroll-up ()
"Scroll Dialogue-buffer up from Command-buffer."
(interactive)
(let ((obuffer (current-buffer)))
(select-window (irchat-get-buffer-window irchat-Dialogue-buffer))
(pop-to-buffer irchat-Dialogue-buffer)
(if (pos-visible-in-window-p (point-max))
(progn
(goto-char (point-max))
(recenter 1))
(scroll-up))
(select-window (irchat-get-buffer-window obuffer))
(pop-to-buffer obuffer)))
(defun irchat-Command-toggle-crypt ()
(interactive)
(if (irchat-crypt-support-p)
(progn
(if irchat-crypt-mode-active
(setq irchat-crypt-mode-active nil)
(setq irchat-crypt-mode-active t))
(irchat-set-crypt-indicator)
(switch-to-buffer (current-buffer)))
(error "Crypto not supported in this version of Irchat.")))
(defun irchat-Command-toggle-utf8 ()
(interactive)
(if (null irchat-utf8-kludge-disable)
(setq irchat-utf8-kludge-send-utf8-as-default
(if irchat-utf8-kludge-send-utf8-as-default
nil
t))
(error "UTF8 support has been explicitly disabled."))
(irchat-set-utf8-indicator))
(defun irchat-Command-freeze ()
"Toggle the automatic scrolling of the Dialogue window."
(interactive)
(if (irchat-frozen (car irchat-D-buffer))
(setq irchat-freeze-indicator "-")
(setq irchat-freeze-indicator "F"))
(switch-to-buffer (current-buffer))
(irchat-freeze-toggle (car irchat-D-buffer))
)