12
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
|
3 local String = require "luan:String.luan"
|
|
4 local regex = String.regex or error()
|
16
|
5 local Time = require "luan:Time.luan"
|
|
6 local time_now = Time.now or error()
|
12
|
7 local Io = require "luan:Io.luan"
|
|
8 local Http = require "luan:http/Http.luan"
|
|
9 local Shared = require "site:/lib/Shared.luan"
|
|
10 local js_error = Shared.js_error or error()
|
13
|
11 local Server = require "site:/lib/Server.luan"
|
|
12 local Utils = require "site:/lib/Utils.luan"
|
|
13 local get_user = Utils.get_user or error()
|
|
14 local Db = require "site:/lib/Db.luan"
|
|
15 local run_in_transaction = Db.run_in_transaction or error()
|
12
|
16 local Logging = require "luan:logging/Logging.luan"
|
|
17 local logger = Logging.logger "add_server.js"
|
|
18
|
|
19
|
|
20 local invite_regex = regex[[^https://discord.gg/(\w+)$]]
|
|
21
|
|
22 return function()
|
|
23 Io.stdout = Http.response.text_writer()
|
|
24 local parameters = Http.request.parameters
|
|
25 local id = parameters.id or error()
|
|
26 local name = parameters.name or error()
|
|
27 local icon = parameters.icon or error()
|
|
28 local invite = parameters.invite or error()
|
|
29 invite = invite_regex.match(invite)
|
|
30 logger.info("invite = "..invite)
|
|
31 if invite==nil then
|
|
32 js_error( "invite", [[Invalid Discord invite URL]] )
|
|
33 return
|
|
34 end
|
13
|
35 run_in_transaction( function()
|
|
36 local server = Server.new{
|
|
37 owner_discord_id = get_user() or error()
|
|
38 discord_id = id
|
16
|
39 bumped = time_now()
|
13
|
40 name = name
|
|
41 icon = icon
|
|
42 invite = invite
|
|
43 }
|
|
44 server.save()
|
|
45 end )
|
12
|
46 %>
|
|
47 location = '/servers.html';
|
|
48 <%
|
|
49 end
|