UNPKG

speedybot

Version:

<p align="center"> <a href="https://github.com/valgaze/speedybot"> <img src="https://img.shields.io/npm/v/speedybot.svg" /> </a> <a href="https://github.com/valgaze/speedybot"> <img src="https://img.shields.io/npm/dm/speedybot.svg" /> </a>

121 lines 7.43 kB
export * from "./types"; export { SpeedyBot } from "./speedybot"; export { SpeedyCard } from "./cards"; export const CONSTANTS = { submitToken: "_private_speedybot_", CHIP_LABEL: "speedybot_CHIP_CLICK", invalidMessage: "Invalid message passed to sendTo", unwrapLabel: "🎁 Unwrap", destroyLabel: "🔥 Destroy", action_delete: "delete", }; export const botTokenKey = "BOT_TOKEN"; export const webhookSecretKey = "WEBHOOK_SECRET"; export const botPlaceholder = "__REPLACE__ME__"; class RequestError extends Error { statusCode; url; constructor(message, statusCode, url) { super(message); this.statusCode = statusCode; this.url = url; if (Error.captureStackTrace) { Error.captureStackTrace(this, RequestError); } } } export const mainRequester = async (url, body, opts = {}) => { if ("rawInit" in opts) { try { const response = await fetch(url, opts.rawInit); if (!response.ok) { throw new RequestError(`The request to ${url} failed with status ${response.status}${response.status === 401 ? " (You may need to double-check your access token)" : ""}`, response.status, url); } return response; } catch (error) { throw error; } } const defaultConfig = { method: "POST", "content-type": "application/json;charset=UTF-8", raw: false, }; const contentType = opts["content-type"] || defaultConfig["content-type"]; const init = { method: opts.method ? opts.method : defaultConfig.method, headers: { "content-type": contentType, Authorization: `Bearer ${opts.token}`, ...(opts.headers || {}), }, }; if (opts.method === "POST" || opts.method === "PUT" || opts.method === "PATCH") { init.body = opts.raw ? body : JSON.stringify(body); } try { const response = await fetch(url, init); if (!response.ok) { console.log("Full", { init, response }); const beer = await response.text(); console.log("#", beer); throw new RequestError(`The request to ${url} failed with status ${response.status}${response.status === 401 ? " (You may need to double-check your access token)" : ""}`, response.status, url); } return response; } catch (error) { throw error; } }; export const logoRoll = (idx) => { const variants = [ ` ███████╗██████╗ ███████╗███████╗██████╗ ██╗ ██╗██████╗ ██████╗ ████████╗ ██╔════╝██╔══██╗██╔════╝██╔════╝██╔══██╗╚██╗ ██╔╝██╔══██╗██╔═══██╗╚══██╔══╝ ███████╗██████╔╝█████╗ █████╗ ██║ ██║ ╚████╔╝ ██████╔╝██║ ██║ ██║ ╚════██║██╔═══╝ ██╔══╝ ██╔══╝ ██║ ██║ ╚██╔╝ ██╔══██╗██║ ██║ ██║ ███████║██║ ███████╗███████╗██████╔╝ ██║ ██████╔╝╚██████╔╝ ██║ ╚══════╝╚═╝ ╚══════╝╚══════╝╚═════╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝`, ` ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ░░███░███░░████░████░███░░█░█░███░░░██░░███░ ░█ ░█ █░█ ░█ ░█ █░███░█ █░█ █░ █ ░ ░ ██░░███ ░███░░███░░█░░█░ █ ░███ ░█░░█░░█░░ ░░ █░█ ░░█ ░░█ ░░█░░█░░█░░█ █░█░░█░░█░░ ░███ ░█░░░░████░████░███ ░░█░░███ ░ ██ ░░█░░ ░ ░░ ░░░░ ░ ░ ░░░ ░░ ░░░ ░░░ ░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░`, ` ╱╭━━━╮╱╭━━━╮╱╭━━━╮╱╭━━━╮╱╭━━━╮╱╭╮╱╱╭╮╱╭━━╮╱╱╭━━━╮╱╭━━━━╮╱ ╱┃╭━╮┃╱┃╭━╮┃╱┃╭━━╯╱┃╭━━╯╱╰╮╭╮┃╱┃╰╮╭╯┃╱┃╭╮┃╱╱┃╭━╮┃╱┃╭╮╭╮┃╱ ╱┃╰━━╮╱┃╰━╯┃╱┃╰━━╮╱┃╰━━╮╱╱┃┃┃┃╱╰╮╰╯╭╯╱┃╰╯╰╮╱┃┃╱┃┃╱╰╯┃┃╰╯╱ ╱╰━━╮┃╱┃╭━━╯╱┃╭━━╯╱┃╭━━╯╱╱┃┃┃┃╱╱╰╮╭╯╱╱┃╭━╮┃╱┃┃╱┃┃╱╱╱┃┃╱╱╱ ╱┃╰━╯┃╱┃┃╱╱╱╱┃╰━━╮╱┃╰━━╮╱╭╯╰╯┃╱╱╱┃┃╱╱╱┃╰━╯┃╱┃╰━╯┃╱╱╱┃┃╱╱╱ ╱╰━━━╯╱╰╯╱╱╱╱╰━━━╯╱╰━━━╯╱╰━━━╯╱╱╱╰╯╱╱╱╰━━━╯╱╰━━━╯╱╱╱ ╱`, ` ─╔═══╗─╔═══╗─╔═══╗─╔═══╗─╔═══╗─╔╗──╔╗─╔══╗──╔═══╗─╔════╗─ ─║╔═╗║─║╔═╗║─║╔══╝─║╔══╝─╚╗╔╗║─║╚╗╔╝║─║╔╗║──║╔═╗║─║╔╗╔╗║─ ─║╚══╗─║╚═╝║─║╚══╗─║╚══╗──║║║║─╚╗╚╝╔╝─║╚╝╚╗─║║─║║─╚╝║║╚╝─ ─╚══╗║─║╔══╝─║╔══╝─║╔══╝──║║║║──╚╗╔╝──║╔═╗║─║║─║║───║║─── ─║╚═╝║─║║────║╚══╗─║╚══╗─╔╝╚╝║───║║───║╚═╝║─║╚═╝║───║║─── ─╚═══╝─╚╝────╚═══╝─╚═══╝─╚═══╝───╚╝───╚═══╝─╚═══╝───╚╝───`, ` ╔═╗ ╔═╗ ╔═╗ ╔═╗ ╔╦╗ ╦ ╦ ╔╗ ╔═╗ ╔╦╗ ╚═╗ ╠═╝ ║╣ ║╣ ║║ ╚╦╝ ╠╩╗ ║ ║ ║ ╚═╝ ╩ ╚═╝ ╚═╝ ═╩╝ ╩ ╚═╝ ╚═╝ ╩ `, ]; if (idx) { const logo = variants[idx] || variants[Math.floor(Math.random() * variants.length)]; return logo; } const logo = variants[Math.floor(Math.random() * variants.length)]; return logo; }; //# sourceMappingURL=index.js.map