-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdialog_system.py
More file actions
358 lines (336 loc) · 11.4 KB
/
Copy pathdialog_system.py
File metadata and controls
358 lines (336 loc) · 11.4 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
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
"""dialog_system.py - dialog data and random selection logic."""
from __future__ import annotations
import getpass
import random
from typing import Dict, List, Optional
from pet_state import PetState
_USERNAME: str = getpass.getuser()
def format_text(text: str) -> str:
return text.replace("{user}", _USERNAME)
DIALOGS: List[Dict] = [
# wellbeing
{
"text": "Hey {user}, when did you last drink water?",
"choices": [
{"text": "Just now", "result": "satisfied"},
{"text": "Hours ago", "result": "angry"},
],
},
{
"text": "Are you sitting up straight, {user}?",
"choices": [
{"text": "I am now", "result": "satisfied"},
{"text": "Still slouching", "result": "angry"},
],
},
{
"text": "Have you taken a break recently, {user}?",
"choices": [
{"text": "Yes, I stepped away", "result": "satisfied"},
{"text": "Not today", "result": "angry"},
],
},
{
"text": "Are you getting enough sleep, {user}?",
"choices": [
{"text": "Yes, well-rested", "result": "happy"},
{"text": "Definitely not", "result": "angry"},
],
},
{
"text": "Did you eat something proper today, {user}?",
"choices": [
{"text": "Yes, actual food", "result": "happy"},
{"text": "Just coffee", "result": "angry"},
],
},
{
"text": "How's your stress level today, {user}?",
"choices": [
{"text": "Fine, under control", "result": "satisfied"},
{"text": "Through the roof", "result": "angry"},
],
},
# opinions
{
"text": "Tabs or spaces, {user}?",
"choices": [
{"text": "Tabs, obviously", "result": "happy"},
{"text": "Spaces, clearly", "result": "angry"},
],
},
{
"text": "Dark mode or light mode?",
"choices": [
{"text": "Dark, always", "result": "happy"},
{"text": "Light mode", "result": "angry"},
],
},
{
"text": "Vim or something else?",
"choices": [
{"text": "Vim, obviously", "result": "happy"},
{"text": "Anything else", "result": "angry"},
],
},
{
"text": "Linux was the right choice, wasn't it, {user}?",
"choices": [
{"text": "Obviously yes", "result": "happy"},
{"text": "I had no choice", "result": "angry"},
],
},
{
"text": "Rolling release or stable, {user}?",
"choices": [
{"text": "Rolling, live dangerously", "result": "happy"},
{"text": "Stable, I value sleep", "result": "satisfied"},
],
},
{
"text": "Is a hotdog a sandwich, {user}?",
"choices": [
{"text": "Yes, obviously", "result": "happy"},
{"text": "Absolutely not", "result": "angry"},
],
},
{
"text": "Git pull or git fetch then merge, {user}?",
"choices": [
{"text": "Fetch then merge", "result": "happy"},
{"text": "Just pull, yolo", "result": "angry"},
],
},
# challenges
{
"text": "Can you name the shortcut for undo without thinking?",
"choices": [
{"text": "Ctrl+Z, trivial", "result": "happy"},
{"text": "Had to think", "result": "satisfied"},
],
},
{
"text": "How many browser tabs do you have open right now, {user}?",
"choices": [
{"text": "Under 10, healthy", "result": "happy"},
{"text": "Don't judge me", "result": "angry"},
],
},
{
"text": "Have you saved your work recently, {user}?",
"choices": [
{"text": "Auto-save is on", "result": "satisfied"},
{"text": "Oh no...", "result": "angry"},
],
},
{
"text": "Is your code currently compiling, {user}?",
"choices": [
{"text": "Yes, it builds", "result": "happy"},
{"text": "There are... issues", "result": "angry"},
],
},
# pc tips
{
"text": "Did you know Ctrl+R in bash searches your command history, {user}?",
"choices": [
{"text": "Yes, I use it", "result": "satisfied"},
{"text": "Oh, I didn't know", "result": "happy"},
],
},
{
"text": "Do you back up your files regularly, {user}?",
"choices": [
{"text": "3-2-1 rule, always", "result": "happy"},
{"text": "I should do that", "result": "angry"},
],
},
{
"text": "Do you use a password manager, {user}?",
"choices": [
{"text": "Yes, KeePassXC", "result": "happy"},
{"text": "My brain is my vault", "result": "angry"},
],
},
{
"text": "Do you check 'man' pages when stuck, or just Google, {user}?",
"choices": [
{"text": "man first, always", "result": "happy"},
{"text": "Stack Overflow wins", "result": "angry"},
],
},
{
"text": "Have you set up SSH keys instead of typing passwords, {user}?",
"choices": [
{"text": "Yes, long ago", "result": "satisfied"},
{"text": "Not yet, I should", "result": "angry"},
],
},
{
"text": "Do you use tmux or screen for persistent sessions, {user}?",
"choices": [
{"text": "tmux, obviously", "result": "happy"},
{"text": "What's the point", "result": "angry"},
],
},
{
"text": "Do you use aliases in your shell config, {user}?",
"choices": [
{"text": "Dozens of them", "result": "happy"},
{"text": "I type everything out", "result": "angry"},
],
},
# personal
{
"text": "Coffee or tea, {user}?",
"choices": [
{"text": "Coffee, life depends", "result": "happy"},
{"text": "Tea, civilised choice", "result": "satisfied"},
],
},
{
"text": "What's your favourite programming language, {user}?",
"choices": [
{"text": "Python, obviously", "result": "happy"},
{"text": "Something compiled", "result": "satisfied"},
],
},
{
"text": "Am I your favourite thing on screen, {user}?",
"choices": [
{"text": "Of course, Konqi!", "result": "happy"},
{"text": "There are others...", "result": "angry"},
],
},
{
"text": "Should I wake you if you fall asleep at your desk, {user}?",
"choices": [
{"text": "Please, yes", "result": "happy"},
{"text": "Let me sleep", "result": "satisfied"},
],
},
{
"text": "I've been watching you all day, {user}. Any regrets?",
"choices": [
{"text": "Not really", "result": "satisfied"},
{"text": "Several, actually", "result": "angry"},
],
},
{
"text": "Do you think you're being productive today, {user}?",
"choices": [
{"text": "Actually, yes", "result": "happy"},
{"text": "That's a strong word", "result": "angry"},
],
},
{
"text": "What's more dangerous: merge conflicts or segfaults, {user}?",
"choices": [
{"text": "Merge conflicts, clearly", "result": "angry"},
{"text": "Segfaults, no contest", "result": "angry"},
],
},
{
"text": "If you could delete one folder forever, what would it be?",
"choices": [
{"text": "node_modules, obviously", "result": "happy"},
{"text": "__pycache__, same energy", "result": "satisfied"},
],
},
# games
{
"text": "Want to play a game, {user}?",
"choices": [
{"text": "Absolutely, let's go", "result": "happy"},
{"text": "Maybe later", "result": "satisfied"},
],
},
{
"text": "How about a round of tic-tac-toe, {user}?",
"choices": [
{"text": "Challenge accepted", "result": "happy"},
{"text": "I'll pass", "result": "satisfied"},
],
},
{
"text": "Do you think you could beat me at tic-tac-toe, {user}?",
"choices": [
{"text": "Easily, watch me", "result": "happy"},
{"text": "I have no confidence", "result": "angry"},
],
},
# konqi
{
"text": "Can I try climbing the wall?",
"choices": [
{"text": "Go for it", "result": "happy"},
{"text": "Stay down", "result": "angry"},
],
},
{
"text": "Should I keep watching you work, {user}?",
"choices": [
{"text": "Yes, stay here", "result": "satisfied"},
{"text": "Leave me alone", "result": "angry"},
],
},
{
"text": "I think you should take a break, {user}.",
"choices": [
{"text": "Good idea", "result": "satisfied"},
{"text": "I'm almost done", "result": "angry"},
],
},
{
"text": "Do you need me to be quiet for a while, {user}?",
"choices": [
{"text": "Yes please", "result": "satisfied"},
{"text": "Keep talking", "result": "happy"},
],
},
{
"text": "I've been here all day, {user}. Do I get overtime?",
"choices": [
{"text": "You're salaried", "result": "angry"},
{"text": "Fine, extra treats", "result": "happy"},
],
},
]
_REACTIONS: Dict[str, List[str]] = {
"happy": ["Yes!", "Thank you!", "You are the best.", "I love this.", "Noted positively."],
"satisfied": ["Fine.", "Acceptable.", "Okay.", "Noted.", "Reasonable choice."],
"angry": ["Rude.", "Wrong answer.", "You will regret that.", "Fine. Be that way.", "Noted. Negatively."],
"idle": ["Hm.", "Okay.", "Fine."],
}
class DialogSystem:
"""
Selects dialogs without repeating the same one back-to-back.
No persistence, no randomness beyond the selection itself.
"""
def __init__(self) -> None:
self._recent: List[int] = []
def pick(self) -> Dict:
"""Return a random dialog (not shown in the last few picks) with {user} substituted."""
n = len(DIALOGS)
choices = [i for i in range(n) if i not in self._recent]
if not choices:
choices = list(range(n))
idx = random.choice(choices)
self._recent.append(idx)
if len(self._recent) > min(6, n - 1):
self._recent.pop(0)
entry = DIALOGS[idx]
return {"text": format_text(entry["text"]), "choices": entry["choices"]}
@staticmethod
def result_to_state(result: str) -> PetState:
"""Map a choice result string to a PetState enum value."""
return {
"idle": PetState.IDLE,
"happy": PetState.HAPPY,
"angry": PetState.ANGRY,
"satisfied": PetState.SATISFIED,
}.get(result, PetState.IDLE)
@staticmethod
def reaction(result: str) -> str:
"""Return a short reaction line for the pet to say after the choice."""
return random.choice(_REACTIONS.get(result, _REACTIONS["idle"]))