-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherwin-elnode.el
More file actions
162 lines (149 loc) · 4.46 KB
/
erwin-elnode.el
File metadata and controls
162 lines (149 loc) · 4.46 KB
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
;;; erwin functions in elnode -*- lexical-binding: t -*-
(elnode-app erwin-elnode-dir
db)
(defvar erwin-insult-adjectives-list
(list "ill-conceived"
"delusional"
"disproven"
"poorly-researched"
"needhamish"
"so-called"
"jumped-up"
"touch-typing"
"randian"
"tree-hugging"
"bleeding-heart"
"elnode "
"bassoonist "
"oboe-playing"
"big fat"
"freedom-hating"
"functional gab"
"excel-loving"
"post-technical"
"dirigible-shaped"
"enterprisey"
"ruby threaded"
"hipster"
"tinsel cheeked"
"stinky"
"tiny-minded"
"pea-brained"
"heavily lidded"
"muck minded"
"flat footed")
"List of adjectives used in the insulter.")
(defvar erwin-insult-nouns-list
(list
"decepticon"
"kief"
"suit"
"luser"
"sharepoint-developer"
"liberal"
"socialist "
"Tutankhamun"
"gimboid"
"person who thinks digital watches are a really neat idea"
"smeghead"
"jobbie-face"
"derpgineer"
"urban dictionary contributor"
"manager"
"power point jockey"
"windows user"
"brogrammer"
"long winded fun bus hater"
"hipster"
"windy nonsense talker"
"idiot who can"
"category theory dumbass"
"smeggy pants"
"java programmer"
"bog warbler"
"tin pincher"
"yeti"
"whoo-har")
"List of nouns used in the insulter.")
(defun erwin-elnode/insult-handler (httpcon)
"Insult someone specified.
Every now and then just randomly yell stuff unrelated to the
requested insult.
A bit of silly fun."
(elnode-method httpcon
(POST
(let* ((whom (elnode-http-param httpcon "who"))
(sender (elnode-http-param httpcon "sender"))
(target (elnode-http-param httpcon "target"))
(gielgud-p (equal 10 (random 11)))
(bunny-p (equal 10 (random 11)))
(adjective
(elt
erwin-insult-adjectives-list
(random (length erwin-insult-adjectives-list))))
(noun
(elt
erwin-insult-nouns-list
(random (length erwin-insult-nouns-list)))))
(elnode-send-json
httpcon
(list
:insult
(cond
(gielgud-p
(format "%s: wash your own arse you little shit." sender))
(bunny-p
(format "NOBODY FUCKING MOVE! THIS IS A ROBBERY!"))
;; Else respond with the proper insult
(t
(format "%s is a %s %s." whom adjective noun)))))))))
(defconst erwin-elnode/cred-db
(db-make
`(db-hash
:filename
,(expand-file-name
(concat
(file-name-as-directory erwin-elnode-dir)
"cred-db"))))
"Database of cred.
Key is the username of the person with cred.
The fields in the record are: last-giver, count, last-time.")
(defun erwin-elnode/cred-handler (httpcon)
"A real cred bot.
Stores cred for everyone in a database."
(elnode-method httpcon
(POST
(let* ((whom (elnode-http-param httpcon "who"))
(sender (elnode-http-param httpcon "sender"))
(target (elnode-http-param httpcon "target"))
(current-cred (db-get whom erwin-elnode/cred-db)))
(if (or
;; someone trying to game it on behalf of someone else
(and
current-cred
(equal (aget current-cred "last-giver") sender))
;; someone trying to give themselves cred
(equal whom sender))
(elnode-send-json httpcon '(:cred "can't game it that way"))
;; Else it's good - update the record
(let ((count (if current-cred
(+ (aget current-cred "count") 1)
1)))
(db-put
whom
(list (cons "last-giver" sender)
(cons "last-time" (current-time))
(cons "count" count)) erwin-elnode/cred-db)
;; Now send the json response
(elnode-send-json
httpcon
(list :cred (format "one point for %s" whom)
:owner whom
:count count))))))))
(defun erwin-elnode-router (httpcon)
"Top level handler dispatching requests for Erwin stuff."
(elnode-hostpath-dispatcher
httpcon
'(("^[^/]+//insult/" . erwin-elnode/insult-handler)
("^[^/]+//cred/" . erwin-elnode/cred-handler))))
;;; erwin-elnode.el ends here