Mercurial Hosting > lang
comparison src/lib/Chat.luan @ 31:1e7d855afde3
voices
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 03 Aug 2025 17:05:38 -0600 |
parents | 505185272dd7 |
children | d34d709a7a8e |
comparison
equal
deleted
inserted
replaced
30:d48f48e1b790 | 31:1e7d855afde3 |
---|---|
13 local languages = require "site:/lib/languages.luan" | 13 local languages = require "site:/lib/languages.luan" |
14 local Utils = require "site:/lib/Utils.luan" | 14 local Utils = require "site:/lib/Utils.luan" |
15 local get_first = Utils.get_first or error() | 15 local get_first = Utils.get_first or error() |
16 local Course = require "site:/lib/Course.luan" | 16 local Course = require "site:/lib/Course.luan" |
17 local get_course_by_id = Course.get_by_id or error() | 17 local get_course_by_id = Course.get_by_id or error() |
18 local Shared = require "site:/lib/Shared.luan" | |
19 local voices = Shared.voices or error() | |
18 | 20 |
19 | 21 |
20 local Chat = {} | 22 local Chat = {} |
21 | 23 |
22 local function from_doc(doc) | 24 local function from_doc(doc) |
28 course_id = doc.course_id | 30 course_id = doc.course_id |
29 name = doc.name | 31 name = doc.name |
30 ai_thread = doc.ai_thread | 32 ai_thread = doc.ai_thread |
31 language = doc.language | 33 language = doc.language |
32 language_region = doc.language_region | 34 language_region = doc.language_region |
35 voice = doc.voice | |
33 } | 36 } |
34 end | 37 end |
35 | 38 |
36 local function to_doc(chat) | 39 local function to_doc(chat) |
37 return { | 40 return { |
42 course_id = long(chat.course_id) | 45 course_id = long(chat.course_id) |
43 name = chat.name or error() | 46 name = chat.name or error() |
44 ai_thread = chat.ai_thread | 47 ai_thread = chat.ai_thread |
45 language = chat.language or error() | 48 language = chat.language or error() |
46 language_region = chat.language_region or error() | 49 language_region = chat.language_region or error() |
50 voice = chat.voice or error() | |
47 } | 51 } |
48 end | 52 end |
49 | 53 |
50 local function first_region(language) | 54 local function first_region(language) |
51 return get_first(languages[language].regions) | 55 return get_first(languages[language].regions) |
52 end | 56 end |
53 | 57 |
54 function Chat.new(chat) | 58 function Chat.new(chat) |
55 chat.updated = chat.updated or time_now() | 59 chat.updated = chat.updated or time_now() |
56 chat.language_region = chat.language_region or first_region(chat.language) | 60 chat.language_region = chat.language_region or first_region(chat.language) |
61 chat.voice = chat.voice or voices[1].code | |
57 | 62 |
58 function chat.save() | 63 function chat.save() |
59 local doc = to_doc(chat) | 64 local doc = to_doc(chat) |
60 Db.save(doc) | 65 Db.save(doc) |
61 chat.id = doc.id | 66 chat.id = doc.id |
71 | 76 |
72 function chat.info() | 77 function chat.info() |
73 return { | 78 return { |
74 id = chat.id | 79 id = chat.id |
75 language_region = chat.language_region | 80 language_region = chat.language_region |
81 voice = chat.voice | |
76 name = chat.name | 82 name = chat.name |
77 } | 83 } |
78 end | 84 end |
79 | 85 |
80 function chat.name_html() | 86 function chat.name_html() |