Finally do something about my midnight bug
[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: <Monday Jun 25, 2012 13:53:34 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                            :role "phone"))
157   ;; SXEmacs doesn't like current ffmpeg
158   (setq emchat-media-driver 'sox)
159   (setq emchat-sound-alist
160         '((auth-sound . "Auth.wav")
161           (buddy-sound . "Online.wav")
162           (chat-sound . "Chat.wav")
163           (emailx-sound . "System.wav")
164           (message-sound . "Message.wav")
165           (pager-sound . "System.wav")
166           (system-sound . "System.wav")
167           (url-sound . "URL.wav"))))
168
169
170 ;:*=======================
171 ;:* Addons/extensions
172
173 (defvar **mpd-var-Title* nil)
174 (defvar **mpd-var-Artist* nil)
175 (defun sy-emchat-now-playing ()
176   "Return title/artist of current song."
177   (interactive)
178   (let ((song (if **mpd-var-Title*
179                   (format "%s --- [%s]"
180                           **mpd-var-Title*
181                           **mpd-var-Artist*)
182                 "The Sounds of Silence --- [Marcel Marceau]")))
183     (format "NP: %s" song)))
184
185 (defun sy-emchat-send-now-playing ()
186   "Send title/artist of current song."
187   (interactive)
188   (let ((song (sy-emchat-now-playing))
189         (alias (emchat-alias-around)))
190     (emchat-send-message song alias)))
191
192 (defun sy-emchat-yow ()
193   "When you can't think of what to say..."
194   (interactive)
195   (let ((message (yow))
196         (alias (emchat-alias-around)))
197     (emchat-send-message message alias)))
198
199
200 (require 'emchat-menu)
201 (define-key emchat-log-mode-map (kbd "C-c p") #'sy-emchat-send-now-playing)
202 (define-key emchat-log-mode-map (kbd "C-c y") #'sy-emchat-yow)
203
204 ;:*=======================
205 ;:* Hooks
206 (eval-when-compile
207   (defvar alias)
208   (defvar message))
209
210 ;;(defun sy-emchat-temp (&optional fahrenheit)
211 ;;  "Returns a string to send to a ICQ user saying the current temp.
212
213 ;;With optional arg, FAHRENHEIT, don't send the temp in celsius."
214 ;;  (if fahrenheit
215 ;;      (let ((xwem-weather-temperature-format 'fahrenheit))
216 ;;      (format "The current temperature here is: %s°F"
217 ;;              (substring (xwem-weather-get-temp) 0 -2)))
218 ;;    (let ((xwem-weather-temperature-format 'celsius))
219 ;;      (format "The current temperature here is: %s°C"
220 ;;            (substring (xwem-weather-get-temp) 0 -2)))))
221
222 (defconst sy-beer-love
223   ["when you realise, 24 beers in a case, 24 hours in a day.  Coincidence?"
224    "when you wake up with `CRS'... Can't Remember Shit."
225    "when, to you, it's not a six-pack, it's a support group."
226    "when it is the reason you get up every afternoon."
227    "when you favour the 2 party system... party on Friday, party on Saturday."
228    "when getting f#@ked up is your hobby."]
229   "Proof you love beer.")
230
231 (defun sy-emchat-beer-love ()
232   (let ((prefix "You know you love beer... ")
233         (love (aref sy-beer-love
234                     (% (+ (% (random t) 1000) 1000)
235                        (length sy-beer-love)))))
236     (concat prefix love)))
237
238 (defun sy-emchat-incoming-msg-hook ()
239   (when (or (member alias emchat-visible-contacts)
240             (not (member alias emchat-invisible-contacts)))
241     (let ((repo "The main EMchat git repo is:
242 git clone http://git.emchat.org/emchat")
243           (download "EMchat source tarballs and (S)XEmacs pkg tarballs
244 can be downloaded from:  Offline ATM, sorry")
245           (latest (shell-command-to-string
246                    "cd ~/programming/EMchat/emchat && git describe"))
247           (lastlog (shell-command-to-string
248                     "cd ~/programming/EMchat/emchat && git log -1"))
249           (time (format-time-string "The local time here is: %c"))
250           (beer (sy-emchat-beer-love))
251           (song (sy-emchat-now-playing))
252           (help "Cmds are prefixed with `,,' (ie, ,,cmd).  Only the first
253 valid cmd in a msg is accepted.  The cmd can appear anywhere in
254 the msg.
255
256 Accepted cmds: version, latest, lastlog, emchat-repo, download, yow,
257 time, beer, song, help."))
258       (cond ((string-match ",,version" message)
259              (emchat-send-message-helper
260               (format "I am using %s" (emchat-version)) (list alias)
261               'automatic "Version sent"))
262             ((string-match ",,latest" message)
263              (emchat-send-message-helper latest (list alias) 'automatic "Latest sent"))
264             ((string-match ",,lastlog" message)
265              (emchat-send-message-helper lastlog (list alias) 'automatic "Lastlog sent"))
266             ((string-match ",,emchat-repo" message)
267              (emchat-send-message-helper repo (list alias) 'automatic "Repo sent"))
268             ((string-match ",,download" message)
269              (emchat-send-message-helper download (list alias) 'automatic "Download sent"))
270             ((string-match ",,yow" message)
271              (emchat-send-message-helper (format "%s" (yow)) (list alias)
272                                        'automatic "Yow sent"))
273             ((string-match ",,time" message)
274              (emchat-send-message-helper time (list alias) 'automatic "Time sent"))
275                                         ;((string-match ",,temp-f" message)
276                                         ; (emchat-send-message (sy-emchat-temp 'fahrenheit) alias))
277                                         ;((string-match ",,temp" message)
278                                         ; (emchat-send-message (sy-emchat-temp) alias))
279             ((string-match ",,beer" message)
280              (emchat-send-message-helper beer (list alias) 'automatic "Beer sent"))
281             ((string-match ",,song" message)
282              (emchat-send-message-helper song (list alias) 'automatic "Song sent"))
283             ((string-match ",,help" message)
284              (emchat-send-message-helper help (list alias) 'automatic "Help sent"))))))
285
286 (add-hook 'emchat-new-message-hook #'sy-emchat-incoming-msg-hook)
287
288 (defun sy-emchat-zero-wharf ()
289   "Helper func to zero wharf counters."
290   (interactive)
291   (emchat-wharf-change-messages "New" -9999)
292   (emchat-wharf-change-messages "Sys" -9999))
293
294 ;; Use the Wharf if not using XWEM
295 (unless (or (string= "notyet" (getenv "XWEM_RUNNING"))
296             (string= "yes" (getenv "XWEM_RUNNING"))
297             (not (device-on-window-system-p)))
298   (require 'emchat-wharf)
299   (setq emchat-wharf-frame-use-p t)
300   (setq emchat-wharf-notice-riece-flag t)
301   (push (cons 'left 1578) emchat-wharf-frame-props)
302   (push (cons 'top 289) emchat-wharf-frame-props)
303   (push (cons 'internal-border-width 4) emchat-wharf-frame-props)
304   ;; `override-redirect' means no WM decorations, and you also get
305   ;; sticky and always on top
306   ;(push (cons 'override-redirect t) emchat-wharf-frame-props)
307   (push (cons 'border-width 1) emchat-wharf-frame-props)
308   (push (cons 'border-color "red") emchat-wharf-frame-props)
309   (add-hook 'emchat-new-message-hook #'emchat-wharf-inc-messages)
310   (add-hook 'emchat-system-message-hook #'emchat-wharf-inc-system)
311   (add-hook 'emchat-read-message-hook #'emchat-wharf-dec-messages)
312   (add-hook 'riece-biff-activity-hook #'emchat-wharf-riece-active)
313   (add-hook 'riece-biff-clear-hook #'emchat-wharf-riece-inactive)
314   (add-hook 'emchat-track-clear-hook #'sy-emchat-zero-wharf)
315   (define-key emchat-log-mode-map [?C] #'sy-emchat-zero-wharf))
316
317 ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*
318 (message "EMchat settings loaded")