tpmkms_4wp 9.3.0-beta.4 → 9.3.0-beta.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/common/animals.instance.json +0 -65
  2. package/common/asking.js +16 -2
  3. package/common/colors.instance.json +28 -70
  4. package/common/comparable.instance.json +0 -15
  5. package/common/concept.test.json +279 -193
  6. package/common/crew.instance.json +0 -202
  7. package/common/dateTimeSelectors.instance.json +67 -0
  8. package/common/dateTimeSelectors.js +85 -0
  9. package/common/dateTimeSelectors.test.json +4529 -0
  10. package/common/dates.instance.json +136 -27
  11. package/common/dates.js +13 -0
  12. package/common/dates.test.json +1787 -0
  13. package/common/dialogues.js +5 -43
  14. package/common/dimension.instance.json +0 -5
  15. package/common/edible.instance.json +56 -160
  16. package/common/emotions.instance.json +0 -5
  17. package/common/evaluate.js +1 -1
  18. package/common/events.js +1 -1
  19. package/common/fastfood.instance.json +180 -879
  20. package/common/fastfood.test.json +16291 -6597
  21. package/common/formulas.instance.json +0 -5
  22. package/common/helpers/dateTimeSelectors.js +92 -0
  23. package/common/helpers/dialogues.js +3 -7
  24. package/common/helpers.js +24 -7
  25. package/common/kirk.instance.json +0 -5
  26. package/common/length.instance.json +0 -75
  27. package/common/math.instance.json +0 -5
  28. package/common/menus.instance.json +0 -35
  29. package/common/numbers.js +1 -1
  30. package/common/numbers.test.json +89 -23
  31. package/common/ordering.instance.json +0 -10
  32. package/common/people.instance.json +0 -40
  33. package/common/percentages.js +1 -1
  34. package/common/pipboy.instance.json +56 -85
  35. package/common/pipboy.test.json +4377 -3386
  36. package/common/pokemon.instance.json +0 -65
  37. package/common/pressure.instance.json +0 -20
  38. package/common/properties.instance.json +0 -5
  39. package/common/reminders.instance.json +196 -10
  40. package/common/reminders.js +270 -78
  41. package/common/reminders.test.json +55544 -23
  42. package/common/reports.instance.json +2 -12
  43. package/common/scorekeeper.test.json +3565 -7550
  44. package/common/spock.instance.json +0 -5
  45. package/common/temperature.instance.json +0 -20
  46. package/common/time.js +63 -30
  47. package/common/time.test.json +4124 -124
  48. package/common/ui.instance.json +0 -5
  49. package/common/ui.js +3 -1
  50. package/common/weight.instance.json +0 -60
  51. package/common/wp.instance.json +56 -70
  52. package/common/wp.test.json +8057 -3867
  53. package/main.js +2 -0
  54. package/package.json +8 -4
@@ -3,38 +3,180 @@ const { defaultContextCheck } = require('./helpers')
3
3
  const reminders_tests = require('./reminders.test.json')
4
4
  const reminders_instance = require('./reminders.instance.json')
5
5
  const selfKM = require('./self')
6
- const dates = require('./dates')
6
+ const dateTimeSelectors = require('./dateTimeSelectors')
7
7
  const helpers = require('./helpers')
8
8
 
9
+ /*
10
+ friday instead
11
+ change it to friday
12
+ delete it
13
+ make it friday instead
14
+ 2 sundays from now
15
+ the sunday after july 1st
16
+ remind every truck driver to whatever tomorrow at 8 am
17
+ */
18
+
19
+ const query = (missing, reminder_id) => {
20
+ return {
21
+ where: where(),
22
+ // oneShot: false,
23
+ onNevermind: ({verbatim, ...args}) => {
24
+ const api = args.kms.reminders.api
25
+ api.delete_reminder(reminder_id)
26
+ },
27
+
28
+ matchq: ({ api, context }) => api.missing(missing, reminder_id) && context.marker == 'controlEnd',
29
+ applyq: async ({ api, context, gs, enable }) => {
30
+ context.cascade = false
31
+ const item = api.missing(missing, reminder_id)
32
+ let who
33
+ if (Array.isArray(item.who)) {
34
+ who = await gs(item.who.map((who) => who.text), ', ', ' and ')
35
+ } else {
36
+ if (item.who.text == 'me') {
37
+ who = 'you'
38
+ } else {
39
+ who = item.who.text
40
+ }
41
+ }
42
+ if (item.missingDate) {
43
+ return `When should I remind ${who} to ${item.text}`
44
+ }
45
+ if (item.missingReminder) {
46
+ enable(['remindResponse', 0])
47
+ return `What should I remind ${who} to do?`
48
+ }
49
+ },
50
+
51
+ matchr: ({ isA, api, context }) => {
52
+ if (context.evaluate || context.isControl || context.isResponse) {
53
+ return false
54
+ }
55
+ const gotADate = ((isA(context.marker, 'onDateValue_dates') || isA(context.marker, 'dateTimeSelector')) && api.missing(missing, reminder_id))
56
+ if (missing == 'missingDate') {
57
+ return gotADate
58
+ } else {
59
+ // return !gotADate && !context.isControl
60
+ }
61
+ return false
62
+ },
63
+ applyr: async ({ context, api, gp }) => {
64
+ const item = api.missing(missing, reminder_id)
65
+ await api.update({ id: item.id, dateTimeSelector: context, dateTimeSelectorText: await gp(context) })
66
+ }
67
+ }
68
+ }
69
+
9
70
  class API {
10
71
  initialize({ objects }) {
11
72
  this._objects = objects
12
73
  this._objects.reminders = []
13
74
  this._objects.id = 0
75
+ this._objects.current = null
76
+ this._objects.defaultTime = { hour: 9, minute: 0, second: 0, millisecond: 0 }
14
77
  }
15
78
 
16
- add(reminder) {
79
+ async add(reminder) {
80
+ await this.instantiate(reminder)
17
81
  const id = ++this._objects.id
18
- this._objects.reminders.push({ ...reminder, id })
82
+ reminder.id = id
83
+ this._objects.reminders.push(reminder)
84
+ this.args.mentioned({ context: reminder })
85
+ this._objects.current = id
86
+ }
87
+
88
+ getCurrentId() {
89
+ return this._objects.current
90
+ }
91
+
92
+ // addUser to current
93
+ addUser(user) {
94
+ const reminder = this.reminders().find((r) => r.id == this._objects.current)
95
+ if (reminder) {
96
+ if (Array.isArray(reminder.who)) {
97
+ reminder.who = [...reminder.who, user]
98
+ } else {
99
+ reminder.who = [reminder.who, user]
100
+ }
101
+ }
102
+ }
103
+
104
+ removeUser(user) {
105
+ const reminder = this.reminders().find((r) => r.id == this._objects.current)
106
+ if (reminder) {
107
+ reminder.who = reminder.who.filter((who) => who.remindee_id != user.remindee_id)
108
+ }
109
+ }
110
+
111
+ addRemindable(id, text) {
112
+ if (!text) {
113
+ text = id
114
+ }
115
+ this.args.makeObject({ ...this.args, context: { word: text, value: id, number: 'one', remindee_id: id }, initial: `remindee_id: "${id}"`, types: ['remindable'] })
116
+ }
117
+
118
+ async instantiate(reminder) {
119
+ if (reminder.dateTimeSelector) {
120
+ reminder.dateTimeSelector.defaultTime = this._objects.defaultTime
121
+ }
122
+ const value = await this.args.e(reminder.dateTimeSelector)
123
+ reminder.nextISODate = value?.evalue
124
+ }
125
+
126
+ contextToWho(who) {
127
+ if (who.isList) {
128
+ const whos = []
129
+ for (const element of this.args.values(who)) {
130
+ whos.push(this.contextToWho(element))
131
+ }
132
+ return whos
133
+ } else {
134
+ return { id: who.value || who.text, text: who.text, remindee_id: who.remindee_id }
135
+ }
136
+ }
137
+
138
+ missing(what, reminder_id) {
139
+ const reminder = this.reminder(reminder_id)
140
+ if (what == 'missingReminder' && !reminder.text) {
141
+ return { when: true, who: reminder.who, text: reminder.text, id: reminder.id, missingReminder: true }
142
+ }
143
+ if (what == 'missingDate' && !reminder.dateTimeSelector) {
144
+ return { when: true, who: reminder.who, text: reminder.text, id: reminder.id, missingDate: true }
145
+ }
146
+ }
147
+
148
+ reminder(id) {
149
+ return this._objects.reminders.find((reminder) => reminder.id == id)
150
+ }
151
+
152
+ reminders() {
153
+ return this._objects.reminders
154
+ }
155
+
156
+ setReminders(reminders) {
157
+ this._objects.reminders = reminders
19
158
  }
20
159
 
21
- askAbout() {
160
+ askAbout(what) {
22
161
  const items = []
23
- for (const item of this._objects.reminders) {
24
- if (!item.when) {
25
- items.push({ when: true, text: item.text, id: item.id })
162
+ for (const item of this.reminders()) {
163
+ if (this.missing('missingReminder', item.id)) {
164
+ items.push(this.missing('missingReminder', item.id))
165
+ }
166
+ if (this.missing('missingDate', item.id)) {
167
+ items.push(this.missing('missingDate', item.id))
26
168
  }
27
169
  }
28
170
  return items
29
171
  }
30
172
 
31
173
  show() {
32
- if (this._objects.reminders.length == 0) {
174
+ if (this.reminders().length == 0) {
33
175
  return "There are no reminders"
34
176
  }
35
177
  let s = 'The reminders are\n'
36
178
  let counter = 1
37
- for (const item of this._objects.reminders) {
179
+ for (const item of this.reminders()) {
38
180
  s += ` ${counter}. ${item.text}\n`
39
181
  counter += 1
40
182
  }
@@ -42,21 +184,27 @@ class API {
42
184
  // -> return a table object. then have ability to talk about the table. maybe later let's focus on this for now
43
185
  }
44
186
 
45
- delete_reminder(ordinal) {
46
- if (ordinal < 1 || ordinal > this._objects.reminders.length) {
47
- return `Not possible`
187
+ delete_reminder(id) {
188
+ const reminder = this.reminders().find((reminder) => reminder.id)
189
+ if (reminder) {
190
+ if (reminder.cleanUp) {
191
+ reminder.cleanUp()
192
+ }
193
+ this.setReminders(this._objects.reminders.filter((reminder) => reminder.id != id))
48
194
  }
49
- this._objects.reminders = this._objects.reminders.splice(ordinal, 1)
50
195
  }
51
196
 
52
- update(update) {
197
+ async update(update) {
198
+ if (!update.id) {
199
+ update.id = this.getCurrentId()
200
+ }
53
201
  for (const item of this._objects.reminders) {
54
202
  if (item.id == update.id) {
55
203
  Object.assign(item, update)
204
+ await this.instantiate(item)
56
205
  return
57
206
  }
58
207
  }
59
-
60
208
  }
61
209
  }
62
210
 
@@ -67,26 +215,106 @@ const template = {
67
215
  configs: [
68
216
  {
69
217
  operators: [
70
- "([remind] (self/*) (*)*)",
71
- "([reminderTime|])",
218
+ "([remindable])",
219
+ { pattern: "([addRemindable] (word)*)", development: true },
220
+ "([remind:justWhoBridge] (remindable/*))",
221
+ "([remind] (remindable/*) (!@<= 'dateTimeSelector' && !@<= 'inAddition')*)",
222
+ "([remind:withDateBridge] (remindable/*) (!@<= 'dateTimeSelector' && !@<= 'inAddition')* (dateTimeSelector))",
223
+ "([remind:withDateAndTimeBridge] (remindable/*) (!@<= 'dateTimeSelector' && !@<= 'inAddition')* (dateTimeSelector) (atTime))",
224
+ "([remindResponse] (!@<= 'remindResponse' && !@<= 'dateTimeSelector' && !@<= 'inAddition')+ (dateTimeSelector))",
72
225
  "([show] ([reminders]))",
73
226
  "([delete_reminders|delete,cancel] (number/*))",
227
+ "([add] (remindable/*))",
228
+ "([remove|] (remindable/*))",
229
+ "((verb/*) [inAddition|also,too])",
74
230
  ],
75
231
  bridges: [
76
232
  {
77
- id: 'remind',
233
+ id: 'inAddition',
234
+ after: ['verb'],
235
+ bridge: "{ ...before[0], inAddition: true, verb: before[0], operator: operator, interpolate: '${verb} ${operator}' }",
236
+ },
237
+ {
238
+ id: 'add',
78
239
  isA: ['verb'],
79
- bridge: "{ ...next(operator), operator: operator, who: after[0], reminder: after[1], interpolate: '${operator} ${who} ${reminder}' }",
80
- semantic: async ({api, gsp, context}) => {
240
+ bridge: "{ ...next(operator), arg: after[0], operator: operator, interpolate: '${operator} ${arg}' }",
241
+ semantic: ({api, context}) => {
242
+ api.addUser(api.contextToWho(context.arg))
243
+ }
244
+ },
245
+ {
246
+ id: 'remove',
247
+ words: ['delete', 'remove'],
248
+ isA: ['verb'],
249
+ bridge: "{ ...next(operator), arg: after[0], operator: operator, interpolate: '${operator} ${arg}' }",
250
+ semantic: ({api, context}) => {
251
+ api.removeUser(api.contextToWho(context.arg))
252
+ }
253
+ },
254
+ {
255
+ id: 'addRemindable',
256
+ isA: ['verb'],
257
+ development: true,
258
+ bridge: "{ ...next(operator), flatten: true, arg: after[0], operator: operator, interpolate: '${operator} ${arg}' }",
259
+ semantic: ({api, context}) => {
260
+ const name = context.arg.map( (word) => word.text ).join(' ')
261
+ api.addRemindable(name)
262
+ }
263
+ },
264
+ {
265
+ id: 'remindable',
266
+ isA: ['listable'],
267
+ },
268
+ {
269
+ id: 'remindResponse',
270
+ isA: ['verb'],
271
+ convolution: true,
272
+ disabled: true,
273
+ bridge: "{ ...next(operator), operator: operator, reminder: after[0], date: after[1], interpolate: '${reminder} ${date}' }",
274
+ semantic: async ({context, api, gp, gsp}) => {
81
275
  const text = await gsp(context.reminder.slice(1));
82
- api.add({ text });
83
- },
276
+ const update = { text }
277
+ if (context.date) {
278
+ update.dateTimeSelector = context.date
279
+ update.dateTimeSelectorText = await gp(context.date)
280
+ }
281
+ await api.update(update)
282
+ }
84
283
  },
85
284
  {
86
- id: 'reminderTime',
87
- children: [
88
- 'month_dates',
285
+ id: 'remind',
286
+ isA: ['verb'],
287
+ localHierarchy: [['self', 'remindable']],
288
+ bridge: "{ ...next(operator), operator: operator, who: after[0], reminder: after[1], interpolate: '${operator} ${who} ${reminder}' }",
289
+ justWhoBridge: "{ ...next(operator), bridge: 'justWhoBridge', operator: operator, who: after[0], interpolate: '${operator} ${who}' }",
290
+ withDateBridge: "{ ...next(operator), operator: operator, who: after[0], reminder: after[1], date: after[2], interpolate: '${operator} ${who} ${reminder} ${date}' }",
291
+ withDateAndTimeBridge: "{ ...next(operator), operator: operator, who: after[0], reminder: after[1], date: after[2], time: after[3], interpolate: '${operator} ${who} ${reminder} ${date} ${time}' }",
292
+ semantics: [
293
+ {
294
+ match: ({context}) => context.marker == 'remind' && context.inAddition,
295
+ apply: ({context, api}) => {
296
+ api.addUser(api.contextToWho(context.who))
297
+ }
298
+ },
89
299
  ],
300
+ semantic: async ({ask, api, gsp, gp, context}) => {
301
+ const who = api.contextToWho(context.who)
302
+ let text;
303
+ if (context.reminder) {
304
+ text = await gsp(context.reminder.slice(1));
305
+ }
306
+ const reminder = { text, dateTimeSelector: context.date, who }
307
+ if (context.date) {
308
+ reminder.dateTimeSelector = context.date
309
+ reminder.dateTimeSelectorText = await gp(context.date)
310
+ }
311
+ // await api.instantiate(reminder)
312
+ await api.add(reminder)
313
+ reminder.cleanUp = ask([
314
+ query('missingReminder', reminder.id),
315
+ query('missingDate', reminder.id),
316
+ ])
317
+ },
90
318
  },
91
319
  {
92
320
  id: 'reminders',
@@ -113,66 +341,20 @@ const template = {
113
341
  },
114
342
  ]
115
343
  },
344
+ /*
116
345
  ({ask, api}) => {
117
346
  ask([
118
- {
119
- where: where(),
120
- oneShot: false,
121
- onNevermind: ({verbatim, ...args}) => {
122
- // this is cross km boundaries from the dialogues km to this one so the api if for dialogs.
123
- // i need to get the one for fastfood here.
124
- const api = args.kms.fastfood.api
125
- const needsDrink = askAbout({ args, api })
126
- for (const item of needsDrink) {
127
- api.remove(item)
128
- }
129
- },
130
-
131
- matchq: ({ api, context }) => api.askAbout().length > 0 && context.marker == 'controlEnd',
132
- applyq: ({ api, context }) => {
133
- context.cascade = false
134
- const items = api.askAbout()
135
- const item = items[0]
136
- return 'When should I remind you to ' + item.text;
137
- },
138
-
139
- matchr: ({ isA, api, context }) => {
140
- if (isA(context.marker, 'reminderTime') && api.askAbout().length > 0) {
141
- return true
142
- }
143
- return false
144
- },
145
- applyr: ({ context, api }) => {
146
- const items = api.askAbout()
147
- api.update({ id: items[0].id, when: context })
148
- // TODO check for is available for all modifications
149
- /*
150
- const needsDrink = askAbout(args)
151
- const { api, context } = args
152
- if (isMany(context)) {
153
- let count = getCount(context) || Number.MAX_SAFE_INTEGER
154
- for (const item of needsDrink) {
155
- if (count < 1) {
156
- break
157
- }
158
- count -= 1
159
- api.addDrink(item.item_id, { id: context.value })
160
- }
161
- } else {
162
- const item_id = needsDrink[0].item_id
163
- api.addDrink(item_id, { id: context.value })
164
- }
165
- */
166
- }
167
- },
347
+ query('missingReminder'),
348
+ query('missingDate'),
168
349
  ])
169
350
  }
351
+ */
170
352
  ],
171
353
  }
172
354
 
173
355
  knowledgeModule( {
174
356
  config: { name: 'reminders' },
175
- includes: [dates, selfKM],
357
+ includes: [dateTimeSelectors, selfKM],
176
358
  api: () => new API(),
177
359
 
178
360
  module,
@@ -181,11 +363,21 @@ knowledgeModule( {
181
363
  name: './reminders.test.json',
182
364
  contents: reminders_tests,
183
365
  checks: {
184
- context: defaultContextCheck(['who', 'reminder']),
366
+ context: defaultContextCheck(['who', 'reminder', 'verbatim']),
185
367
  objects: [
186
368
  {
187
369
  property: 'reminders',
188
- filter: [ 'text', 'when' ],
370
+ filter: [
371
+ 'text',
372
+ 'dateTimeSelectorText',
373
+ 'nextISODate',
374
+ 'who',
375
+ 'stm',
376
+ {
377
+ property: 'dateTimeSelector',
378
+ filter: ['marker', 'text', 'value'],
379
+ },
380
+ ],
189
381
  }
190
382
  ],
191
383
  },