From eb05654085fe55beac96cb33e96b29b86613a655 Mon Sep 17 00:00:00 2001 From: smartfrigde <37928912+smartfrigde@users.noreply.github.com> Date: Wed, 5 Jan 2022 21:27:24 +0100 Subject: [PATCH] Pull request review fixes --- src/commands/fun/insult.ts | 2 +- src/commands/fun/modules/eco-bet.ts | 29 +---------------------------- src/commands/fun/poll.ts | 6 +++--- src/lib.ts | 26 ++++++++++++++++++++++++++ 4 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/commands/fun/insult.ts b/src/commands/fun/insult.ts index 8fe1c6c..fa17437 100644 --- a/src/commands/fun/insult.ts +++ b/src/commands/fun/insult.ts @@ -6,7 +6,7 @@ import {CommandInteraction} from "discord.js"; export const header = new SlashCommandBuilder().setDescription("Insult TravBot >:D"); export async function handler(interaction: CommandInteraction) { interaction.reply( - `@${interaction.user.tag} What the fuck did you just fucking say about me, you little bitch? I'll have you know I graduated top of my class in the Navy Seals, and I've been involved in numerous secret raids on Al-Quaeda, and I have over 300 confirmed kills. I am trained in gorilla warfare and I'm the top sniper in the entire US armed forces. You are nothing to me but just another target. I will wipe you the fuck out with precision the likes of which has never been seen before on this Earth, mark my fucking words. You think you can get away with saying that shit to me over the Internet? Think again, fucker. As we speak I am contacting my secret network of spies across the USA and your IP is being traced right now so you better prepare for the storm, maggot. The storm that wipes out the pathetic little thing you call your life. You're fucking dead, kid. I can be anywhere, anytime, and I can kill you in over seven hundred ways, and that's just with my bare hands. Not only am I extensively trained in unarmed combat, but I have access to the entire arsenal of the United States Marine Corps and I will use it to its full extent to wipe your miserable ass off the face of the continent, you little shit. If only you could have known what unholy retribution your little "clever" comment was about to bring down upon you, maybe you would have held your fucking tongue. But you couldn't, you didn't, and now you're paying the price, you goddamn idiot. I will shit fury all over you and you will drown in it. You're fucking dead, kiddo.` + `<@${interaction.user.id}> What the fuck did you just fucking say about me, you little bitch? I'll have you know I graduated top of my class in the Navy Seals, and I've been involved in numerous secret raids on Al-Quaeda, and I have over 300 confirmed kills. I am trained in gorilla warfare and I'm the top sniper in the entire US armed forces. You are nothing to me but just another target. I will wipe you the fuck out with precision the likes of which has never been seen before on this Earth, mark my fucking words. You think you can get away with saying that shit to me over the Internet? Think again, fucker. As we speak I am contacting my secret network of spies across the USA and your IP is being traced right now so you better prepare for the storm, maggot. The storm that wipes out the pathetic little thing you call your life. You're fucking dead, kid. I can be anywhere, anytime, and I can kill you in over seven hundred ways, and that's just with my bare hands. Not only am I extensively trained in unarmed combat, but I have access to the entire arsenal of the United States Marine Corps and I will use it to its full extent to wipe your miserable ass off the face of the continent, you little shit. If only you could have known what unholy retribution your little "clever" comment was about to bring down upon you, maybe you would have held your fucking tongue. But you couldn't, you didn't, and now you're paying the price, you goddamn idiot. I will shit fury all over you and you will drown in it. You're fucking dead, kiddo.` ); } export default new NamedCommand({ diff --git a/src/commands/fun/modules/eco-bet.ts b/src/commands/fun/modules/eco-bet.ts index 669a931..36d3ffe 100644 --- a/src/commands/fun/modules/eco-bet.ts +++ b/src/commands/fun/modules/eco-bet.ts @@ -1,5 +1,5 @@ import {Command, NamedCommand, confirm, poll} from "onion-lasers"; -import {pluralise} from "../../../lib"; +import {pluralise, parseDuration} from "../../../lib"; import {Storage} from "../../../structures"; import {isAuthorized, getMoneyEmbed} from "./eco-utils"; import {User} from "discord.js"; @@ -167,30 +167,3 @@ export const BetCommand = new NamedCommand({ }) }) }); - -/** - * Parses a duration string into milliseconds - * Examples: - * - 3d -> 3 days -> 259200000ms - * - 2h -> 2 hours -> 7200000ms - * - 7m -> 7 minutes -> 420000ms - * - 3s -> 3 seconds -> 3000ms - */ -function parseDuration(duration: string): number { - // extract last char as unit - const unit = duration[duration.length - 1].toLowerCase(); - // get the rest as value - let value: number = +duration.substring(0, duration.length - 1); - - if (!["d", "h", "m", "s"].includes(unit) || isNaN(value)) return 0; - - if (unit === "d") value *= 86400000; - // 1000ms * 60s * 60m * 24h - else if (unit === "h") value *= 3600000; - // 1000ms * 60s * 60m - else if (unit === "m") value *= 60000; - // 1000ms * 60s - else if (unit === "s") value *= 1000; // 1000ms - - return value; -} diff --git a/src/commands/fun/poll.ts b/src/commands/fun/poll.ts index d595b4c..ccaf09e 100644 --- a/src/commands/fun/poll.ts +++ b/src/commands/fun/poll.ts @@ -2,7 +2,7 @@ import {MessageEmbed, Message, User, MessageActionRow, MessageButton} from "disc import {NamedCommand, RestCommand, poll, CHANNEL_TYPE, SendFunction, Command} from "onion-lasers"; import {SlashCommandBuilder} from "@discordjs/builders"; import {CommandInteraction} from "discord.js"; -import {pluralise} from "../../lib"; +import {pluralise, parseDuration} from "../../lib"; export const header = new SlashCommandBuilder() .setDescription("Create a poll.") @@ -14,8 +14,8 @@ export const header = new SlashCommandBuilder() export async function handler(interaction: CommandInteraction) { const {options} = interaction; const question = options.getString("question", true); - const duration = options.getInteger("duration", false); - + var duration = options.getInteger("duration", false); + duration = parseDuration(duration + "s"); //override the duration variable with miliseconds one execSlashPoll(interaction, question, duration || 60000); } diff --git a/src/lib.ts b/src/lib.ts index b999791..6afe664 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -269,3 +269,29 @@ export function split(array: T[], lengthOfEachSection: number): T[][] { export function requireAllCasesHandledFor(variable: never): never { throw new Error(`This function should never be called but got the value: ${variable}`); } +/** + * Parses a duration string into milliseconds + * Examples: + * - 3d -> 3 days -> 259200000ms + * - 2h -> 2 hours -> 7200000ms + * - 7m -> 7 minutes -> 420000ms + * - 3s -> 3 seconds -> 3000ms + */ +export function parseDuration(duration: string): number { + // extract last char as unit + const unit = duration[duration.length - 1].toLowerCase(); + // get the rest as value + let value: number = +duration.substring(0, duration.length - 1); + + if (!["d", "h", "m", "s"].includes(unit) || isNaN(value)) return 0; + + if (unit === "d") value *= 86400000; + // 1000ms * 60s * 60m * 24h + else if (unit === "h") value *= 3600000; + // 1000ms * 60s * 60m + else if (unit === "m") value *= 60000; + // 1000ms * 60s + else if (unit === "s") value *= 1000; // 1000ms + + return value; +}