da059c7f57875e6a6fc6387e2241f4c0df850003
[syinit] / 17-emchat-sy.el
1 ;; 17-emchat-sy.el --- EMchat Settings   -*- Emacs-Lisp -*-
2
3 ;; Copyright (C) 2007 - 2012 Steve Youngs
4
5 ;;     Author: Steve Youngs <steve@sxemacs.org>
6 ;; Maintainer: Steve Youngs <steve@sxemacs.org>
7 ;;    Created: <2007-12-02>
8 ;; Time-stamp: <Tuesday Jun 19, 2012 17:08:12 steve>
9 ;;   Download: <http://bastard.steveyoungs.com/~steve/SXEmacs/inits/>
10 ;;   HTMLised: <http://bastard.steveyoungs.com/~steve/SXEmacs/htmlinits/17-emchat-sy.html>
11 ;;   Git Repo: git clone http://git.sxemacs.org/syinit
12 ;;   Keywords: init, compile
13
14 ;; This file is part of SYinit
15
16 ;; Redistribution and use in source and binary forms, with or without
17 ;; modification, are permitted provided that the following conditions
18 ;; are met:
19 ;;
20 ;; 1. Redistributions of source code must retain the above copyright
21 ;;    notice, this list of conditions and the following disclaimer.
22 ;;
23 ;; 2. Redistributions in binary form must reproduce the above copyright
24 ;;    notice, this list of conditions and the following disclaimer in the
25 ;;    documentation and/or other materials provided with the distribution.
26 ;;
27 ;; 3. Neither the name of the author nor the names of any contributors
28 ;;    may be used to endorse or promote products derived from this
29 ;;    software without specific prior written permission.
30 ;;
31 ;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
32 ;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
33 ;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
34 ;; DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
35 ;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
36 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
38 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
39 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
40 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
41 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42
43 ;;; Commentary:
44 ;;
45 ;;   My EMchat settings.
46 ;;
47
48 ;;; Credits:
49 ;;
50 ;;   The HTML version of this file was created with Hrvoje Niksic's
51 ;;   htmlize.el which is part of the XEmacs "text-modes" package.
52 ;;
53
54 ;;; Todo:
55 ;;
56 ;;     
57
58 ;;; Code:
59 ;:*=======================
60 ;:* emchat settings
61 (load "emchat")
62
63 ;;; Experimental stuff
64
65
66 ;; EMchat works great in a tty, but some setttings I use are best
67 ;; suited for X, so this just turns them off.
68 (defun tty-im-setup ()
69   "Set some things so I can use EMchat/Riece in tty."
70   (interactive)
71   (setq emchat-status-use-gutter nil
72         emchat-start-in-new-frame nil
73         emchat-wharf-frame-use-p nil))
74 ;;; 
75
76 (when (device-on-window-system-p)
77   (setq emchat-status-use-gutter t
78         emchat-start-in-new-frame t))
79
80 (setq
81  emchat-doctor-enabled-flag t
82  emchat-emphasis-enabled-flag t
83  emchat-history-enabled-flag t
84  emchat-log-fill-column 72
85  emchat-smiley t
86  emchat-track-enable t
87  emchat-track-indicator-type 'char
88  emchat-user-alias "JackaLX"
89  emchat-user-password (getenv "ICQPASSWD")
90  emchat-user-meta-nickname "JackaLX"
91  emchat-user-meta-firstname "Steve"
92  emchat-user-meta-lastname "Youngs"
93  emchat-user-meta-primary-email "steve@sxemacs.org"
94  emchat-user-meta-secondary-email "steve@steveyoungs.com"
95  emchat-user-meta-city "Brisbane"
96  emchat-user-meta-state "DOA"
97  emchat-user-meta-hide-ip t
98  emchat-user-meta-authorization t
99  emchat-user-meta-about 
100  "EMchat Maintainer.\n
101  If you'd like to help out with the EMchat project,
102  please send me a message.  Or go to:
103     <http://www.emchat.org/>\n
104  SXEmacs - It's not just an editor.
105           It's a way of life!
106     <http://www.sxemacs.org/>"
107  emchat-user-meta-homepage "http://www.sxemacs.org/"
108  emchat-user-meta-sex 'male
109  emchat-user-meta-language-1 12
110  emchat-user-meta-language-2 12
111  emchat-user-meta-language-3 12
112  emchat-user-meta-web-aware t
113  emchat-user-initial-status "online"
114  emchat-user-meta-age 38
115  emchat-user-meta-birth-day 19
116  emchat-user-meta-birth-month 6
117  emchat-user-meta-birth-year 66
118  emchat-user-meta-cell-phone "6666 6666"
119  emchat-user-meta-country 61
120  emchat-user-meta-fax "7777 7777"
121  emchat-user-meta-phone "8888 8888"
122  emchat-user-meta-street "1 Linux Lane"
123  emchat-user-meta-work-homepage "http://www.sxemacs.org/"
124  emchat-user-meta-work-address "What me, work?"
125  emchat-user-meta-work-city "Penguinville"
126  emchat-user-meta-work-company "SlackBiz"
127  emchat-user-meta-work-department "Slackers"
128  emchat-user-meta-work-fax "9999 9999"
129  emchat-user-meta-work-phone "5555 5555"
130  emchat-user-meta-work-position "Seated"
131  emchat-user-meta-work-state "DOA"
132  emchat-user-meta-zipcode "9999"
133  emchat-buddy-view 'emchat-all-aliases
134  emchat-use-sound-flag nil
135  emchat-save-log-on-exit-p nil
136  emchat-log-debug-flag t
137  emchat-user-meta-invisible nil
138  emchat-buddy-show-xface t)
139
140 ;; PulseAudio only seems to work if X is running
141 (when (getenv "DISPLAY")
142   (setq  emchat-use-sound-flag t))
143
144 (customize-set-variable 'emchat-auto-away-timeout 1200)
145
146 (emchat-world-update)
147
148 (when emchat-use-sound-flag
149   (setq emchat-audio-device
150         ;(make-audio-device 'alsa :device "plughw:0,0"))
151         ;(make-audio-device 'ao :driver "alsa"))
152         ;; Pulseaudio is CRAP!!
153         (make-audio-device 'pulse
154                            :client "SXEmacs::EMchat"
155                            :stream "EMchat::Stream"))
156   ;; SXEmacs doesn't like current ffmpeg
157   (setq emchat-media-driver 'sox)
158   (setq emchat-sound-alist
159         '((auth-sound . "Auth.wav")
160           (buddy-sound . "Online.wav")
161           (chat-sound . "Chat.wav")
162           (emailx-sound . "System.wav")
163           (message-sound . "Message.wav")
164           (pager-sound . "System.wav")
165           (system-sound . "System.wav")
166           (url-sound . "URL.wav"))))
167
168
169 ;:*=======================
170 ;:* Addons/extensions
171
172 (defvar **mpd-var-Title* nil)
173 (defvar **mpd-var-Artist* nil)
174 (defun sy-emchat-now-playing ()
175   "Return title/artist of current song."
176   (interactive)
177   (let ((song (if **mpd-var-Title*
178                   (format "%s --- [%s]"
179                           **mpd-var-Title*
180                           **mpd-var-Artist*)
181                 "The Sounds of Silence --- [Marcel Marceau]")))
182     (format "NP: %s" song)))
183
184 (defun sy-emchat-send-now-playing ()
185   "Send title/artist of current song."
186   (interactive)
187   (let ((song (sy-emchat-now-playing))
188         (alias (emchat-alias-around)))
189     (emchat-send-message song alias)))
190
191 (defun sy-emchat-yow ()
192   "When you can't think of what to say..."
193   (interactive)
194   (let ((message (yow))
195         (alias (emchat-alias-around)))
196     (emchat-send-message message alias)))
197
198
199 (require 'emchat-menu)
200 (define-key emchat-log-mode-map (kbd "C-c p") #'sy-emchat-send-now-playing)
201 (define-key emchat-log-mode-map (kbd "C-c y") #'sy-emchat-yow)
202
203 ;:*=======================
204 ;:* Hooks
205 (eval-when-compile
206   (defvar alias)
207   (defvar message))
208
209 ;;(defun sy-emchat-temp (&optional fahrenheit)
210 ;;  "Returns a string to send to a ICQ user saying the current temp.
211
212 ;;With optional arg, FAHRENHEIT, don't send the temp in celsius."
213 ;;  (if fahrenheit
214 ;;      (let ((xwem-weather-temperature-format 'fahrenheit))
215 ;;      (format "The current temperature here is: %s°F"
216 ;;              (substring (xwem-weather-get-temp) 0 -2)))
217 ;;    (let ((xwem-weather-temperature-format 'celsius))
218 ;;      (format "The current temperature here is: %s°C"
219 ;;            (substring (xwem-weather-get-temp) 0 -2)))))
220
221 (defconst sy-beer-love
222   ["when you realise, 24 beers in a case, 24 hours in a day.  Coincidence?"
223    "when you wake up with `CRS'... Can't Remember Shit."
224    "when, to you, it's not a six-pack, it's a support group."
225    "when it is the reason you get up every afternoon."
226    "when you favour the 2 party system... party on Friday, party on Saturday."
227    "when getting f#@ked up is your hobby."]
228   "Proof you love beer.")
229
230 (defun sy-emchat-beer-love ()
231   (let ((prefix "You know you love beer... ")
232         (love (aref sy-beer-love
233                     (% (+ (% (random t) 1000) 1000)
234                        (length sy-beer-love)))))
235     (concat prefix love)))
236
237 (defun sy-emchat-incoming-msg-hook ()
238   (when (or (member alias emchat-visible-contacts)
239             (not (member alias emchat-invisible-contacts)))
240     (let ((repo "The main EMchat git repo is:
241 git clone http://git.emchat.org/emchat")
242           (download "EMchat source tarballs and (S)XEmacs pkg tarballs
243 can be downloaded from:  Offline ATM, sorry")
244           (latest (shell-command-to-string
245                    "cd ~/programming/EMchat/emchat && git describe"))
246           (lastlog (shell-command-to-string
247                     "cd ~/programming/EMchat/emchat && git log -1"))
248           (time (format-time-string "The local time here is: %c"))
249           (beer (sy-emchat-beer-love))
250           (song (sy-emchat-now-playing))
251           (help "Cmds are prefixed with `,,' (ie, ,,cmd).  Only the first
252 valid cmd in a msg is accepted.  The cmd can appear anywhere in
253 the msg.
254
255 Accepted cmds: version, latest, lastlog, emchat-repo, download, yow,
256 time, beer, song, help."))
257       (cond ((string-match ",,version" message)
258              (emchat-send-message-helper
259               (format "I am using %s" (emchat-version)) (list alias)
260               'automatic "Version sent"))
261             ((string-match ",,latest" message)
262              (emchat-send-message-helper latest (list alias) 'automatic "Latest sent"))
263             ((string-match ",,lastlog" message)
264              (emchat-send-message-helper lastlog (list alias) 'automatic "Lastlog sent"))
265             ((string-match ",,emchat-repo" message)
266              (emchat-send-message-helper repo (list alias) 'automatic "Repo sent"))
267             ((string-match ",,download" message)
268              (emchat-send-message-helper download (list alias) 'automatic "Download sent"))
269             ((string-match ",,yow" message)
270              (emchat-send-message-helper (format "%s" (yow)) (list alias)
271                                        'automatic "Yow sent"))
272             ((string-match ",,time" message)
273              (emchat-send-message-helper time (list alias) 'automatic "Time sent"))
274                                         ;((string-match ",,temp-f" message)
275                                         ; (emchat-send-message (sy-emchat-temp 'fahrenheit) alias))
276                                         ;((string-match ",,temp" message)
277                                         ; (emchat-send-message (sy-emchat-temp) alias))
278             ((string-match ",,beer" message)
279              (emchat-send-message-helper beer (list alias) 'automatic "Beer sent"))
280             ((string-match ",,song" message)
281              (emchat-send-message-helper song (list alias) 'automatic "Song sent"))
282             ((string-match ",,help" message)
283              (emchat-send-message-helper help (list alias) 'automatic "Help sent"))))))
284
285 (add-hook 'emchat-new-message-hook #'sy-emchat-incoming-msg-hook)
286
287 (defun sy-emchat-zero-wharf ()
288   "Helper func to zero wharf counters."
289   (interactive)
290   (emchat-wharf-change-messages "New" -9999)
291   (emchat-wharf-change-messages "Sys" -9999))
292
293 ;; Use the Wharf if not using XWEM
294 (unless (or (string= "notyet" (getenv "XWEM_RUNNING"))
295             (string= "yes" (getenv "XWEM_RUNNING"))
296             (not (device-on-window-system-p)))
297   (require 'emchat-wharf)
298   (setq emchat-wharf-frame-use-p t)
299   (setq emchat-wharf-notice-riece-flag t)
300   (push (cons 'left 1578) emchat-wharf-frame-props)
301   (push (cons 'top 289) emchat-wharf-frame-props)
302   (push (cons 'internal-border-width 4) emchat-wharf-frame-props)
303   ;; `override-redirect' means no WM decorations, and you also get
304   ;; sticky and always on top
305   ;(push (cons 'override-redirect t) emchat-wharf-frame-props)
306   (push (cons 'border-width 1) emchat-wharf-frame-props)
307   (push (cons 'border-color "red") emchat-wharf-frame-props)
308   (add-hook 'emchat-new-message-hook #'emchat-wharf-inc-messages)
309   (add-hook 'emchat-system-message-hook #'emchat-wharf-inc-system)
310   (add-hook 'emchat-read-message-hook #'emchat-wharf-dec-messages)
311   (add-hook 'riece-biff-activity-hook #'emchat-wharf-riece-active)
312   (add-hook 'riece-biff-clear-hook #'emchat-wharf-riece-inactive)
313   (add-hook 'emchat-track-clear-hook #'sy-emchat-zero-wharf)
314   (define-key emchat-log-mode-map [?C] #'sy-emchat-zero-wharf))
315
316 ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*
317 (message "EMchat settings loaded")