Skip to content

Commit 9fd4896

Browse files
committed
Use utils where applicable
1 parent 9ac8475 commit 9fd4896

5 files changed

Lines changed: 11 additions & 7 deletions

File tree

src/commands/poll.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Optionen:
119119
let finishTime: Date | undefined;
120120
if (options.delayed) {
121121
const delayTime = Number(options.delayed);
122-
finishTime = new Date(Date.now() + delayTime * 60 * 1000);
122+
finishTime = new Date(Date.now() + timeUtils.minutes(delayTime));
123123

124124
if (Number.isNaN(delayTime) || delayTime <= 0) {
125125
return "Bruder keine ungültigen Zeiten angeben 🙄";

src/commands/selfban.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { MessageCommand } from "#commands/command.ts";
44
import type { BotContext } from "#context.ts";
55
import type { ProcessableMessage } from "#service/command.ts";
66

7+
import * as timeUtils from "#utils/time.ts";
78
import * as banService from "#service/ban.ts";
89
import { parseLegacyMessageParts } from "#service/command.ts";
910

@@ -75,7 +76,7 @@ export default class MinCommand implements MessageCommand {
7576
return err;
7677
}
7778

78-
const targetTime = new Date(Date.now() + durationInMinutes * 60 * 1000);
79+
const targetTime = new Date(Date.now() + timeUtils.minutes(durationInMinutes));
7980

8081
if (tilt) {
8182
const alarmEmote = message.guild?.emojis.cache.find(e => e.name === "alarm");

src/commands/vote2.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
time,
1717
} from "discord.js";
1818

19+
import * as timeUtils from "#utils/time.ts";
1920
import type { ApplicationCommand } from "#commands/command.ts";
2021

2122
export default class Vote2Command implements ApplicationCommand {
@@ -109,7 +110,7 @@ export default class Vote2Command implements ApplicationCommand {
109110
.setLabel("👎")
110111
.setStyle(ButtonStyle.Secondary);
111112

112-
const end = new Date(Date.now() + duration * 1000);
113+
const end = new Date(Date.now() + timeUtils.seconds(duration));
113114
const endStr = time(end, "R");
114115

115116
const embed: APIEmbed = {
@@ -141,7 +142,7 @@ export default class Vote2Command implements ApplicationCommand {
141142
const collector: InteractionCollector<ButtonInteraction> =
142143
response.createMessageComponentCollector({
143144
componentType: ComponentType.Button,
144-
time: duration * 1000,
145+
time: timeUtils.seconds(duration),
145146
filter: i => !collector.users.has(i.user.id),
146147
});
147148

src/service/lootDrop.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import type { BotContext } from "#context.ts";
2424
import type { Loot, LootId } from "#storage/db/model.ts";
2525
import type { LootTemplate } from "#storage/loot.ts";
2626
import { randomBoolean, randomEntry, randomEntryWeighted } from "#service/random.ts";
27+
import * as timeUtils from "#utils/time.ts";
2728

2829
import * as lootService from "#service/loot.ts";
2930
import {
@@ -35,7 +36,7 @@ import {
3536

3637
import log from "#log";
3738

38-
const lootTimeoutMs = 60 * 1000;
39+
const lootTimeoutMs = timeUtils.minutes(1);
3940

4041
export async function runDropAttempt(context: BotContext) {
4142
const lootConfig = context.commandConfig.loot;

src/storage/reminders.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Snowflake, User } from "discord.js";
2+
import { Temporal } from "@js-temporal/polyfill";
23

34
import type { Reminder } from "./db/model.ts";
45

@@ -9,10 +10,10 @@ export async function removeReminder(reminderId: Reminder["id"], ctx = db()) {
910
await ctx.deleteFrom("reminders").where("id", "=", reminderId).execute();
1011
}
1112

12-
export function getCurrentReminders(now = new Date(), ctx = db()): Promise<Reminder[]> {
13+
export function getCurrentReminders(now = Temporal.Now.instant(), ctx = db()): Promise<Reminder[]> {
1314
return ctx
1415
.selectFrom("reminders")
15-
.where("remindAt", "<=", now.toISOString())
16+
.where("remindAt", "<=", now.toString())
1617
.selectAll()
1718
.execute();
1819
}

0 commit comments

Comments
 (0)