diff --git a/src/events/buttonUsed.ts b/src/events/buttonUsed.ts index 9fcefe00..87d37f7e 100644 --- a/src/events/buttonUsed.ts +++ b/src/events/buttonUsed.ts @@ -1,4 +1,3 @@ -import { Component } from "@interfaces/components"; import { Event } from "@interfaces/events"; import { Client, ButtonInteraction } from "@client"; import { info } from "@helpers/logger"; @@ -8,11 +7,11 @@ export default { async execute(client: Client, interaction: ButtonInteraction) { client.storeAction("button", interaction); - if (client.verbose) console.log(`${info}Button used`); - let button: Component; + if (client.verbose) console.log(`${info}Button used!`); - if (interaction.customId.startsWith("pollVote__")) button = client.buttons.get("pollVote"); - else button = client.buttons.get(interaction.customId); + const button = interaction.customId.startsWith("pollVote__") + ? client.buttons.get("pollVote") + : client.buttons.get(interaction.customId); if (button) return button.execute(client, interaction); }, diff --git a/src/helpers/exec.ts b/src/helpers/exec.ts index 81560dcd..94e834b4 100644 --- a/src/helpers/exec.ts +++ b/src/helpers/exec.ts @@ -1,29 +1,33 @@ -// spawn a child process and execute shell command -// borrowed from https://github.com/mout/mout/ build script -// borrowed from Miller Medeiros on https://gist.github.com/millermedeiros/4724047 -// released under MIT License -// version: 0.1.0 (2021/08/13) - import { dev } from "@json/tokens.json"; +import { spawn, SpawnOptions } from "child_process"; + +/** + * spawn a child process and execute shell command + * borrowed from https://github.com/mout/mout/ build script + * borrowed from Miller Medeiros on https://gist.github.com/millermedeiros/4724047 + * released under MIT License + * version: 0.1.0 (2021/08/13) + */ /** * execute a single shell command where "cmd" is a string - * @author Juknum + * @author Miller Medeiros * @param cmd what command to run - * @param cb what to run afterwards (grabs error too) + * @param cb callback to run afterwards (grabs error too) * @param options extra command line options for child_process */ -export const execSync = (cmd: string, cb: Function, options = undefined) => { +export const execSync = (cmd: string, cb: Function, options: SpawnOptions = {}) => { // this would be way easier on a shell/bash script :P - const child_process = require("child_process"); const parts = cmd.split(/\s+/g); // don't spam console logs in production with command outputs - let opt = { stdio: dev ? "inherit" : "ignore" }; - - if (options !== undefined) opt = Object.assign({}, opt, options); + const opt: SpawnOptions = { + // ordered as [stdin, stdout, stderr] + stdio: dev ? "inherit" : ["ignore", "ignore", "inherit"], + ...options, + }; - const p = child_process.spawn(parts[0], parts.slice(1), opt); + const p = spawn(parts[0], parts.slice(1), opt); p.on("exit", (code: number) => { let err = null; if (code) { @@ -38,7 +42,7 @@ export const execSync = (cmd: string, cb: Function, options = undefined) => { // execute multiple commands in series // this could be replaced by any flow control lib -export const seriesSync = (cmds: string[], cb: Function, options = undefined) => { +export const seriesSync = (cmds: string[], cb: Function, options: SpawnOptions = {}) => { const execNext = () => { execSync( cmds.shift(), @@ -56,7 +60,7 @@ export const seriesSync = (cmds: string[], cb: Function, options = undefined) => execNext(); }; -export const exec = async (cmd: string, options: any = undefined) => { +export const exec = async (cmd: string, options: SpawnOptions = {}) => { return new Promise((res, rej) => { execSync( cmd, @@ -69,7 +73,7 @@ export const exec = async (cmd: string, options: any = undefined) => { }); }; -export const series = async (cmds: string[], options = undefined) => { +export const series = async (cmds: string[], options: SpawnOptions = {}) => { return new Promise((res, rej) => { seriesSync( cmds, diff --git a/src/helpers/images/tile.ts b/src/helpers/images/tile.ts index 3e46aca0..706abdb8 100644 --- a/src/helpers/images/tile.ts +++ b/src/helpers/images/tile.ts @@ -56,13 +56,6 @@ export async function tile(origin: ImageSource, options: TileOptions = {}): Prom ctx.restore(); }; - /** - * Follows this pattern: - * x x x x x x . x . . x . . . . - * x x x -> x . x -> x x x -> . x . OR x x x - * x x x x x x . x . . x . . . . - */ - if (options.random == "rotation") { // grid to get all possible rotation states matched with each other // specific configuration originally by Pomi108