annotate src/delete_server.js.luan @ 14:80105b716a62

start bot
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 31 Oct 2023 23:56:48 -0600
parents af2b95854072
children d0b8e1a8fc69
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
14
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
3 local stringify = Luan.stringify or error()
13
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local Io = require "luan:Io.luan"
14
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
5 local uri = Io.uri or error()
13
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local Http = require "luan:http/Http.luan"
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local Server = require "site:/lib/Server.luan"
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local Utils = require "site:/lib/Utils.luan"
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local get_user = Utils.get_user or error()
14
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
10 local Config = require "site:/lib/Config.luan"
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
11 local Logging = require "luan:logging/Logging.luan"
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
12 local logger = Logging.logger "delete_server.js"
13
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 return function()
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 local server_id = Http.request.parameters.server or error()
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 local server = Server.get_by_id(server_id)
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 server.owner_discord_id == get_user() or error()
14
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
19
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
20 local url = "https://discord.com/api/users/@me/guilds/"..server.discord_id
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
21 local config = Config.get()
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
22 local options = {
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
23 method = "DELETE"
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
24 headers = {
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
25 ["User-Agent"] = "fuck you" -- for retarded Cloudflare
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
26 Authorization = "Bot "..config.discord.bot_token
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
27 }
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
28 }
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
29 try
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
30 local result = uri(url,options).read_text()
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
31 catch e
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
32 -- logger.info(stringify(e))
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
33 e.response_code == 404 or e.throw()
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
34 end
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
35
13
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 server.delete()
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 Io.stdout = Http.response.text_writer()
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 %>
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 location.reload();
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 <%
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 end