Move diary file into user-init-directory
[syinit] / 17-emchat-sy.el
1 ;; 17-emchat-sy.el --- EMchat Settings   -*- Emacs-Lisp -*-
2
3 ;; Copyright (C) 2007 - 2013 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: <Friday May 29, 2015 20:53:39 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 settings 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-port 5190
86  emchat-server "login.icq.com"
87  emchat-smiley t
88  emchat-track-enable t
89  emchat-track-indicator-type 'char
90  emchat-user-alias "JackaLX"
91  emchat-user-password (getenv "ICQPASSWD")
92  emchat-user-meta-nickname "JackaLX"
93  emchat-user-meta-firstname "Steve"
94  emchat-user-meta-lastname "Youngs"
95  emchat-user-meta-primary-email "steve@sxemacs.org"
96  emchat-user-meta-secondary-email "steve@steveyoungs.com"
97  emchat-user-meta-city "Brisbane"
98  emchat-user-meta-state "DOA"
99  emchat-user-meta-hide-ip t
100  emchat-user-meta-authorization t
101  emchat-user-meta-about 
102  "EMchat Maintainer.\n
103  If you'd like to help out with the EMchat project,
104  please send me a message.  Or go to:
105     <http://www.emchat.org/>\n
106  SXEmacs - It's not just an editor.
107           It's a way of life!
108     <http://www.sxemacs.org/>"
109  emchat-user-meta-homepage "http://www.sxemacs.org/"
110  emchat-user-meta-sex 'male
111  emchat-user-meta-language-1 12
112  emchat-user-meta-language-2 12
113  emchat-user-meta-language-3 12
114  emchat-user-meta-web-aware t
115  emchat-user-initial-status "online"
116  emchat-user-meta-age 38
117  emchat-user-meta-birth-day 19
118  emchat-user-meta-birth-month 6
119  emchat-user-meta-birth-year 66
120  emchat-user-meta-cell-phone "6666 6666"
121  emchat-user-meta-country 61
122  emchat-user-meta-fax "7777 7777"
123  emchat-user-meta-phone "8888 8888"
124  emchat-user-meta-street "1 Linux Lane"
125  emchat-user-meta-work-homepage "http://www.sxemacs.org/"
126  emchat-user-meta-work-address "What me, work?"
127  emchat-user-meta-work-city "Penguinville"
128  emchat-user-meta-work-company "SlackBiz"
129  emchat-user-meta-work-department "Slackers"
130  emchat-user-meta-work-fax "9999 9999"
131  emchat-user-meta-work-phone "5555 5555"
132  emchat-user-meta-work-position "Seated"
133  emchat-user-meta-work-state "DOA"
134  emchat-user-meta-zipcode "9999"
135  emchat-buddy-view 'emchat-all-aliases
136  emchat-use-sound-flag nil
137  emchat-save-log-on-exit-p nil
138  emchat-log-debug-flag t
139  emchat-user-meta-invisible nil
140  emchat-buddy-show-avatar t
141  emchat-buddy-xface-foreground "black"
142  emchat-buddy-xface-background "red")
143
144 ;; PulseAudio only seems to work if X is running
145 (when (getenv "DISPLAY")
146   (setq  emchat-use-sound-flag t))
147
148 ;; Lets not auto-away.
149 (customize-set-variable 'emchat-auto-away-timeout 0)
150
151 (emchat-world-update)
152
153 (when emchat-use-sound-flag
154   (setq emchat-audio-device
155         ;(make-audio-device 'alsa))
156         (make-audio-device 'pulse
157                            :client "SXEmacs::EMchat"
158                            :stream "EMchat::Stream"
159                            :role "phone"))
160   ;; SXEmacs doesn't like current ffmpeg, and SoX is dodgy ATM too
161   (setq emchat-media-driver 'sndfile)
162   (setq default-media-stream-volume 50)
163   (setq emchat-sound-alist
164         '((auth-sound . "Auth.wav")
165           (buddy-sound . "Online.wav")
166           (chat-sound . "Chat.wav")
167           (emailx-sound . "System.wav")
168           (message-sound . "Message.wav")
169           (pager-sound . "System.wav")
170           (system-sound . "System.wav")
171           (url-sound . "URL.wav"))))
172
173
174 ;:*=======================
175 ;:* Addons/extensions
176
177 (defun sy-emchat-now-playing ()
178   "Return title/artist of current song."
179   (interactive)
180   (format "NP: %s" (mpd-now-playing)))
181
182 (defun sy-emchat-send-now-playing ()
183   "Send title/artist of current song."
184   (interactive)
185   (let ((song (sy-emchat-now-playing))
186         (alias (emchat-alias-around)))
187     (emchat-send-message song alias)))
188
189 (defun sy-emchat-yow ()
190   "When you can't think of what to say..."
191   (interactive)
192   (let ((message (yow))
193         (alias (emchat-alias-around)))
194     (emchat-send-message message alias)))
195
196
197 (require 'emchat-menu)
198 (define-key emchat-log-mode-map (kbd "C-c p") #'sy-emchat-send-now-playing)
199 (define-key emchat-log-mode-map (kbd "C-c y") #'sy-emchat-yow)
200
201 ;:*=======================
202 ;:* Hooks
203 (eval-when-compile
204   (defvar alias)
205   (defvar message))
206
207 ;;(defun sy-emchat-temp (&optional fahrenheit)
208 ;;  "Returns a string to send to a ICQ user saying the current temp.
209
210 ;;With optional arg, FAHRENHEIT, don't send the temp in celsius."
211 ;;  (if fahrenheit
212 ;;      (let ((xwem-weather-temperature-format 'fahrenheit))
213 ;;      (format "The current temperature here is: %s°F"
214 ;;              (substring (xwem-weather-get-temp) 0 -2)))
215 ;;    (let ((xwem-weather-temperature-format 'celsius))
216 ;;      (format "The current temperature here is: %s°C"
217 ;;            (substring (xwem-weather-get-temp) 0 -2)))))
218
219 (defconst sy-beer-love
220   ["when you realise, 24 beers in a case, 24 hours in a day.  Coincidence?"
221    "when you wake up with `CRS'... Can't Remember Shit."
222    "when, to you, it's not a six-pack, it's a support group."
223    "when it is the reason you get up every afternoon."
224    "when you favour the 2 party system... party on Friday, party on Saturday."
225    "when getting f#@ked up is your hobby."]
226   "Proof you love beer.")
227
228 (defun sy-emchat-beer-love ()
229   (let ((prefix "You know you love beer... ")
230         (love (aref sy-beer-love
231                     (% (+ (% (random t) 1000) 1000)
232                        (length sy-beer-love)))))
233     (concat prefix love)))
234
235 (defun sy-emchat-incoming-msg-hook ()
236   (when (or (member alias emchat-visible-contacts)
237             (not (member alias emchat-invisible-contacts)))
238     (let ((repo "The main EMchat git repo is:
239 git clone http://git.emchat.org/emchat")
240           (download "EMchat source tarballs and (S)XEmacs pkg tarballs
241 can be downloaded from:  Offline ATM, sorry")
242           (latest (shell-command-to-string
243                    "cd ~/programming/EMchat/emchat && git describe"))
244           (lastlog (shell-command-to-string
245                     "cd ~/programming/EMchat/emchat && git log -1"))
246           (time (format-time-string "The local time here is: %c"))
247           (beer (sy-emchat-beer-love))
248           (song (sy-emchat-now-playing))
249           (help "Cmds are prefixed with `,,' (ie, ,,cmd).  Only the first
250 valid cmd in a msg is accepted.  The cmd can appear anywhere in
251 the msg.
252
253 Accepted cmds: version, latest, lastlog, emchat-repo, download, yow,
254 time, beer, song, help."))
255       (cond ((string-match ",,version" message)
256              (emchat-send-message-helper
257               (format "I am using %s" (emchat-version)) (list alias)
258               'automatic "Version sent"))
259             ((string-match ",,latest" message)
260              (emchat-send-message-helper latest (list alias) 'automatic "Latest sent"))
261             ((string-match ",,lastlog" message)
262              (emchat-send-message-helper lastlog (list alias) 'automatic "Lastlog sent"))
263             ((string-match ",,emchat-repo" message)
264              (emchat-send-message-helper repo (list alias) 'automatic "Repo sent"))
265             ((string-match ",,download" message)
266              (emchat-send-message-helper download (list alias) 'automatic "Download sent"))
267             ((string-match ",,yow" message)
268              (emchat-send-message-helper (format "%s" (yow)) (list alias)
269                                        'automatic "Yow sent"))
270             ((string-match ",,time" message)
271              (emchat-send-message-helper time (list alias) 'automatic "Time sent"))
272                                         ;((string-match ",,temp-f" message)
273                                         ; (emchat-send-message (sy-emchat-temp 'fahrenheit) alias))
274                                         ;((string-match ",,temp" message)
275                                         ; (emchat-send-message (sy-emchat-temp) alias))
276             ((string-match ",,beer" message)
277              (emchat-send-message-helper beer (list alias) 'automatic "Beer sent"))
278             ((string-match ",,song" message)
279              (emchat-send-message-helper song (list alias) 'automatic "Song sent"))
280             ((string-match ",,help" message)
281              (emchat-send-message-helper help (list alias) 'automatic "Help sent"))))))
282
283 (add-hook 'emchat-new-message-hook #'sy-emchat-incoming-msg-hook)
284
285 (defun sy-emchat-zero-wharf ()
286   "Helper func to zero wharf counters."
287   (interactive)
288   (emchat-wharf-change-messages "New" -9999)
289   (emchat-wharf-change-messages "Sys" -9999))
290
291 ;; Use the Wharf if not using XWEM
292 (unless (or (string= "notyet" (getenv "XWEM_RUNNING"))
293             (string= "yes" (getenv "XWEM_RUNNING"))
294             (not (device-on-window-system-p)))
295   (require 'emchat-wharf)
296   (setq emchat-wharf-frame-use-p t)
297   (setq emchat-wharf-notice-riece-flag t)
298   (push (cons 'left 1690) emchat-wharf-frame-props)
299   (push (cons 'top 5) emchat-wharf-frame-props)
300   (push (cons 'internal-border-width 4) emchat-wharf-frame-props)
301   ;; `override-redirect' means no WM decorations, and you also get
302   ;; sticky and always on top and skip pagers and task lists etc.
303   ;; The downside is that often new windows will appear underneath
304   ;; because the WM/DE has no knowledge of its existence.  I don't
305   ;; use this in KDE because you can easily get the same effect
306   ;; without the downside with KDE's "Window Rules".  I also don't
307   ;; use this in Sawfish for similar reasons.
308   (unless (or (string= (getenv "KDE_FULL_SESSION") "true")
309               (string= (getenv "SAWFISH_IS_RUNNING") "true"))
310     (push (cons 'override-redirect t) emchat-wharf-frame-props))
311   (push (cons 'border-width 1) emchat-wharf-frame-props)
312   (push (cons 'border-color "red") emchat-wharf-frame-props)
313   (add-hook 'emchat-new-message-hook #'emchat-wharf-inc-messages)
314   (add-hook 'emchat-system-message-hook #'emchat-wharf-inc-system)
315   (add-hook 'emchat-read-message-hook #'emchat-wharf-dec-messages)
316   (add-hook 'riece-biff-activity-hook #'emchat-wharf-riece-active)
317   (add-hook 'riece-biff-clear-hook #'emchat-wharf-riece-inactive)
318   (add-hook 'emchat-track-clear-hook #'sy-emchat-zero-wharf)
319   (define-key emchat-log-mode-map [?C] #'sy-emchat-zero-wharf))
320
321 ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*
322 (message "EMchat settings loaded")