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>
145 lines • 9.33 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.logoRoll = exports.mainRequester = exports.botPlaceholder = exports.webhookSecretKey = exports.botTokenKey = exports.CONSTANTS = exports.SpeedyCard = exports.SpeedyBot = void 0;
__exportStar(require("./types"), exports);
var speedybot_1 = require("./speedybot");
Object.defineProperty(exports, "SpeedyBot", { enumerable: true, get: function () { return speedybot_1.SpeedyBot; } });
var cards_1 = require("./cards");
Object.defineProperty(exports, "SpeedyCard", { enumerable: true, get: function () { return cards_1.SpeedyCard; } });
exports.CONSTANTS = {
submitToken: "_private_speedybot_",
CHIP_LABEL: "speedybot_CHIP_CLICK",
invalidMessage: "Invalid message passed to sendTo",
unwrapLabel: "🎁 Unwrap",
destroyLabel: "🔥 Destroy",
action_delete: "delete",
};
exports.botTokenKey = "BOT_TOKEN";
exports.webhookSecretKey = "WEBHOOK_SECRET";
exports.botPlaceholder = "__REPLACE__ME__";
class RequestError extends Error {
constructor(message, statusCode, url) {
super(message);
this.statusCode = statusCode;
this.url = url;
if (Error.captureStackTrace) {
Error.captureStackTrace(this, RequestError);
}
}
}
const mainRequester = (url, body, opts = {}) => __awaiter(void 0, void 0, void 0, function* () {
if ("rawInit" in opts) {
try {
const response = yield 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: Object.assign({ "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 = yield fetch(url, init);
if (!response.ok) {
console.log("Full", { init, response });
const beer = yield 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;
}
});
exports.mainRequester = mainRequester;
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;
};
exports.logoRoll = logoRoll;
//# sourceMappingURL=index.js.map