view 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
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local stringify = Luan.stringify or error()
local Io = require "luan:Io.luan"
local uri = Io.uri or error()
local Http = require "luan:http/Http.luan"
local Server = require "site:/lib/Server.luan"
local Utils = require "site:/lib/Utils.luan"
local get_user = Utils.get_user or error()
local Config = require "site:/lib/Config.luan"
local Logging = require "luan:logging/Logging.luan"
local logger = Logging.logger "delete_server.js"


return function()
	local server_id = Http.request.parameters.server or error()
	local server = Server.get_by_id(server_id)
	server.owner_discord_id == get_user() or error()

	local url = "https://discord.com/api/users/@me/guilds/"..server.discord_id
	local config = Config.get()
	local options = {
		method = "DELETE"
		headers = {
			["User-Agent"] = "fuck you"  -- for retarded Cloudflare
			Authorization = "Bot "..config.discord.bot_token
		}
	}
	try
		local result = uri(url,options).read_text()
	catch e
		-- logger.info(stringify(e))
		e.response_code == 404 or e.throw()
	end

	server.delete()
	Io.stdout = Http.response.text_writer()
%>
	location.reload();
<%
end