Mercurial Hosting > disearch
comparison src/lib/Server.luan @ 14:80105b716a62
start bot
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 31 Oct 2023 23:56:48 -0600 |
parents | af2b95854072 |
children | 552d6f944acb |
comparison
equal
deleted
inserted
replaced
13:af2b95854072 | 14:80105b716a62 |
---|---|
10 | 10 |
11 local function from_doc(doc) | 11 local function from_doc(doc) |
12 doc.type == "server" or error "wrong type" | 12 doc.type == "server" or error "wrong type" |
13 return Server.new { | 13 return Server.new { |
14 id = doc.id | 14 id = doc.id |
15 discord_id = doc.server_discord_id | |
15 owner_discord_id = doc.server_owner_discord_id | 16 owner_discord_id = doc.server_owner_discord_id |
16 discord_id = doc.discord_id | |
17 name = doc.name | 17 name = doc.name |
18 icon = doc.icon | 18 icon = doc.icon |
19 invite = doc.invite | 19 invite = doc.invite |
20 } | 20 } |
21 end | 21 end |
22 | 22 |
23 local function to_doc(server) | 23 local function to_doc(server) |
24 return { | 24 return { |
25 type = "server" | 25 type = "server" |
26 id = server.id | 26 id = server.id |
27 server_discord_id = server.discord_id or error() | |
27 server_owner_discord_id = server.owner_discord_id or error() | 28 server_owner_discord_id = server.owner_discord_id or error() |
28 discord_id = server.discord_id or error() | |
29 name = server.name or error() | 29 name = server.name or error() |
30 icon = server.icon or error() | 30 icon = server.icon or error() |
31 invite = server.invite or error() | 31 invite = server.invite or error() |
32 } | 32 } |
33 end | 33 end |
64 function Server.get_by_id(id) | 64 function Server.get_by_id(id) |
65 local doc = Db.get_document("id:"..id) | 65 local doc = Db.get_document("id:"..id) |
66 return doc and from_doc(doc) | 66 return doc and from_doc(doc) |
67 end | 67 end |
68 | 68 |
69 function Server.get_by_discord_id(discord_id) | |
70 local doc = Db.get_document("server_discord_id:"..discord_id) | |
71 return doc and from_doc(doc) | |
72 end | |
73 | |
69 local function search(query,sort,rows) | 74 local function search(query,sort,rows) |
70 rows = rows or 1000000 | 75 rows = rows or 1000000 |
71 local docs = Db.search(query,1,rows,{sort=sort}) | 76 local docs = Db.search(query,1,rows,{sort=sort}) |
72 local servers = {} | 77 local servers = {} |
73 for _, doc in ipairs(docs) do | 78 for _, doc in ipairs(docs) do |