annotate src/private/tools/config_save.txt.luan @ 23:e5c77f8d506d default tip

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 15 Sep 2024 10:45:43 -0600
parents 552d6f944acb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
43814e9f5802 add config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
43814e9f5802 add config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
43814e9f5802 add config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local stringify = Luan.stringify or error()
16
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
4 local Parsers = require "luan:Parsers.luan"
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
5 local json_string = Parsers.json_string or error()
3
43814e9f5802 add config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local Io = require "luan:Io.luan"
16
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
7 local uri = Io.uri or error()
3
43814e9f5802 add config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local Http = require "luan:http/Http.luan"
43814e9f5802 add config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local Config = require "site:/lib/Config.luan"
16
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
10 local Logging = require "luan:logging/Logging.luan"
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
11 local logger = Logging.logger "config_save.txt"
3
43814e9f5802 add config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12
43814e9f5802 add config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13
16
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
14 local function set_cmd()
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
15 local config = Config.get()
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
16 local url = "https://discord.com/api/applications/"..config.discord.client_id.."/commands"
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
17 local options = {
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
18 method = "POST"
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
19 headers = {
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
20 ["User-Agent"] = "Disearch" -- for retarded Cloudflare
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
21 Authorization = "Bot "..config.discord.bot_token
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
22 ["Content-Type"] = "application/json"
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
23 }
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
24 content = json_string{
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
25 type = 1
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
26 name = "dbump"
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
27 description = "Bump this server in Disearch."
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
28 }
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
29 }
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
30 local result = uri(url,options).read_text()
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
31 logger.info(result)
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
32 end
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
33
3
43814e9f5802 add config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 return function()
43814e9f5802 add config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 local config = Http.request.parameters.config or error()
43814e9f5802 add config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 Config.set(config)
16
552d6f944acb add bump
Franklin Schmidt <fschmidt@gmail.com>
parents: 3
diff changeset
37 -- set_cmd() don't do this
3
43814e9f5802 add config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 Io.stdout = Http.response.text_writer()
43814e9f5802 add config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 %>saved<%
43814e9f5802 add config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 end