summaryrefslogtreecommitdiff
path: root/elisp/erbot/erbc5.el
blob: 6c663aa968927b40295a620c0f9a2f1b3b00af4e (plain)
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
;;; erbc5.el --- continuation of erbc.el
;; Time-stamp: <2007-11-23 11:30:12 deego>
;; Copyright (C) 2003 D. Goel
;; Emacs Lisp Archive entry
;; Filename: erbc5.el
;; Package: erbc5
;; Author: D. Goel <deego@gnufans.org>
;; Keywords:  
;; Version:  
;; URL:  http://www.emacswiki.org/cgi-bin/wiki.pl?ErBot
;; For latest version: 

(defconst erbc5-home-page
  "http://gnufans.net/~deego")


 
;; This file is NOT (yet) part of GNU Emacs.
 
;; This is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
 
;; This is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
 

;; See also:


(defconst erbc5-version "0.0dev")
;;==========================================
;;; Requires:
(eval-when-compile (require 'cl))

;;; Code:

(defgroup erbc5 nil 
  "The group erbc5."
  :group 'applications)
(defcustom erbc5-before-load-hook nil 
  "Hook to run before loading erbc5."
  :group 'erbc5)
(defcustom erbc5-after-load-hook nil 
  "Hook to run after loading erbc5."
  :group 'erbc5)
(run-hooks 'erbc5-before-load-hook)

(defcustom erbc5-verbosity 0
  "How verbose to be.  
Once you are experienced with this lib, 0 is the recommended
value.  Values between -90 to +90 are \"sane\".  The
rest are for debugging."
  :type 'integer
  :group 'erbc5)
(defcustom erbc5-interactivity 0
  "How interactive to be.  
Once you are experienced with this lib, 0 is the recommended
value.  Values between -90 and +90 are \"sane\".  The rest are for
debugging."
  :type 'integer
  :group 'erbc5)
(defcustom erbc5-y-or-n-p-function 'erbc5-y-or-n-p
  "Function to use for interactivity-dependent  `y-or-n-p'.
Format same as that of `erbc5-y-or-n-p'."
  :type 'function
  :group 'erbc5)
(defcustom erbc5-n-or-y-p-function 'erbc5-y-or-n-p
  "Function to use for interactivity-dependent `n-or-y-p'.
Format same as that of `erbc5-n-or-y-p'."
  :type 'function
  :group 'erbc5)
(defun erbc5-message (points &rest args)
  "Signal message, depending on POINTS anderbc5-verbosity.
ARGS are passed to `message'."
  (unless (minusp (+ points erbc5-verbosity))
    (apply #'message args)))
(defun erbc5-y-or-n-p (add prompt)
  "Query or assume t, based on `erbc5-interactivity'.
ADD is added to `erbc5-interactivity' to decide whether
to query using PROMPT, or just return t."
  (if (minusp (+ add erbc5-interactivity))
        t
      (funcall 'y-or-n-p prompt)))
(defun erbc5-n-or-y-p (add prompt)
  "Query or assume t, based on `erbc5-interactivity'.
ADD is added to `erbc5-interactivity' to decide whether
to query using PROMPT, or just return t."
  (if (minusp (+ add erbc5-interactivity))
        nil
      (funcall 'y-or-n-p prompt)))

;;; Real Code:

(defalias 'fsi-listp-proper 'erbutils-listp-proper)
(erbutils-defalias-i '(upcase downcase capitalize upcase-initials))



(ignore-errors (require 'calc))

(defvar erbn-calc-time 3)
(defcustom erbn-calc-p nil
  "Enable this variable at your own risk.
Enabling this means that fsbot will do calc operations, but those have
no timeout build in... leading to DOS attacks. ")


(defun fsi-calc-eval (&optional str)
  "
Note that  even though this function has a with-timeout built into it,
that doesn't save us from a DOS attack..since emacs polls only when
waiting for user input.. 

which is why turned off by default.

"
  (unless (and erbn-calc-p  (not erbot-paranoid-p))
    (error "Sorry, but i am a bot! not a calc!"))
  (unless str (error "Eval what?"))
  (unless (stringp str)
    (setq str (format "%s" str)))
  (with-timeout 
      (erbn-calc-time "That's WAY too much math for me!")
    (calc-eval str)))
    
(defalias 'fs-calc 'fs-calc-eval)

(erbutils-defalias '(process-list))
(defalias 'fs-list-processes 'fs-process-list)

(defcustom erbn-sregex-p nil
  "Nil by default for safety. Enable to permit fs-sregex.
I think it is safe, but not 100% sure, so disabled by default. --DG"
  )


(defun fsi-sreg (&rest args)
  (format "%S" 
	  (apply 'fs-sregex args)))


(defun fsi-sregex (&rest args)
  (cond
   ((and erbn-sregex-p (not erbot-paranoid-p))
    (apply 'sregex args))
   (t
    (error "sregexp is disabled in this bot. "))))



(defmacro fsi-ignore-errors-else-string (&rest body)
  "Like ignore-errors, but tells and returns the erros.
\(Improved for me by Kalle on 7/3/01:)"
  (let ((err (gensym)))
    `(condition-case ,err (progn ,@body)
       (error
	(let 
	    ((str 	
	      (message "IGNORED ERROR: %s" (error-message-string ,err))))
	  (ding t)
	  (ding t)
	  (ding t)
  	  (sit-for 1)
	  str)))))


;; more math functions
(erbutils-defalias-i '(mod))
;; these from cl-extra
(erbutils-defalias-i '(isqrt floor* ceiling* round* mod* rem* signum
			     random*))


(erbutils-defalias-i '(symbol-name))



(provide 'erbc5)
(run-hooks 'erbc5-after-load-hook)



;;; erbc5.el ends here