Skip to content

Commit

Permalink
fix(hubInvite): fix error with /hub invite create expiry
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-737 committed Jan 4, 2024
1 parent 0277123 commit 87509fe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/commands/slash/Main/hub/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export default class Hub extends BaseCommand {
autocomplete: true,
},
{
type: ApplicationCommandOptionType.Number,
type: ApplicationCommandOptionType.String,
name: 'expiry',
description: 'The expiry of the invite link. Eg. 10h (10 hours from now)',
required: false,
Expand Down
11 changes: 5 additions & 6 deletions src/commands/slash/Main/hub/invite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import db from '../../../../utils/Db.js';
import Logger from '../../../../utils/Logger.js';
import { simpleEmbed } from '../../../../utils/Utils.js';
import { t } from '../../../../utils/Locale.js';
import parse from 'parse-duration';

export default class Invite extends Hub {
readonly cooldown = 3000; // 3 seconds
Expand All @@ -15,12 +16,10 @@ export default class Invite extends Hub {

switch (subcommand) {
case 'create': {
const expires = new Date();
const hubName = interaction.options.getString('hub', true);
const hours = interaction.options.getNumber('expiry');
hours
? expires.setHours(expires.getHours() + hours)
: expires.setHours(expires.getHours() + 24);
const expiryStr = interaction.options.getString('expiry');
const duration = expiryStr ? parse(expiryStr) : undefined;
const expires = new Date(Date.now() + (duration || 60 * 60 * 4000));

const hubInDb = await db.hubs.findFirst({
where: {
Expand All @@ -44,8 +43,8 @@ export default class Invite extends Hub {
}
const createdInvite = await db.hubInvites.create({
data: {
expires,
hub: { connect: { name: hubName } },
expires,
},
});

Expand Down

0 comments on commit 87509fe

Please sign in to comment.