Mercurial Hosting > disearch
view src/delete_server.js.luan @ 21:1956302daa38
domain change
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 24 Aug 2024 22:24:53 -0600 |
parents | d0b8e1a8fc69 |
children |
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"] = "Disearch" -- 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