Skip to content

Commit

Permalink
Fixes for /birthday and /timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
Hipperooni committed Nov 28, 2023
1 parent 63eda0c commit d903b3f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 18 deletions.
6 changes: 5 additions & 1 deletion src/discord/commands/guild/d.birthday.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,12 @@ export const dBirthday: SlashCommand = {
.setName('day'))),
async execute(interaction) {
log.info(F, await commandContext(interaction));
await interaction.deferReply({ ephemeral: (interaction.options.getBoolean('ephemeral') === true) });
let command = interaction.options.getSubcommand() as 'get' | 'set' | undefined;
if (command === 'set') {
await interaction.deferReply({ ephemeral: true });
} else {
await interaction.deferReply({ ephemeral: (interaction.options.getBoolean('ephemeral') === true) });
}
let member = interaction.options.getMember('user');
const monthInput = interaction.options.getString('month');
const day = interaction.options.getInteger('day');
Expand Down
16 changes: 8 additions & 8 deletions src/discord/commands/guild/d.rpg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ const timesUp = 'Time\'s up!';

const items = {
general: {
// giftcard: {
// label: 'Gift Card',
// value: 'giftcard',
// description: 'A gift card to gift to someone else',
// userflair: {
// label: 'User Flair',
// value: 'userflair',
// description: 'A flair that appears next to your name.',
// quantity: 1,
// weight: 0,
// cost: 0,
// cost: 1000,
// equipped: false,
// consumable: false,
// effect: 'tokens',
// effect_value: '100',
// emoji: 'buttonBetHuge',
// effect: 'userflair',
// effect_value: 'userflair',
// emoji: 'itemDiscount',
// },
// testkit: {
// label: 'TestKit',
Expand Down
20 changes: 15 additions & 5 deletions src/discord/commands/guild/d.timezone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from 'discord.js';
import { SlashCommand } from '../../@types/commandDef';
import { timezone } from '../../../global/commands/g.timezone';
import { embedTemplate } from '../../utils/embedTemplate';
import commandContext from '../../utils/context';
// import log from '../../../global/utils/log';
const F = f(__filename);
Expand Down Expand Up @@ -32,8 +33,12 @@ export const dTimezone: SlashCommand = {
.setAutocomplete(true))),
async execute(interaction) {
log.info(F, await commandContext(interaction));
await interaction.deferReply({ ephemeral: (interaction.options.getBoolean('ephemeral') === true) });
let command = interaction.options.getSubcommand() as 'get' | 'set' | undefined;
if (command === 'set') {
await interaction.deferReply({ ephemeral: true });
} else {
await interaction.deferReply({ ephemeral: (interaction.options.getBoolean('ephemeral') === true) });
}
const tzValue = interaction.options.getString('timezone');
let member = interaction.options.getMember('user') as GuildMember | null;

Expand All @@ -45,15 +50,20 @@ export const dTimezone: SlashCommand = {
member = interaction.member as GuildMember;
}

const response = await timezone(command, member.id, tzValue);
const response = await timezone(command, member.id, tzValue, interaction);

// log.debug(F, `response: ${response}`);

if (command === 'get') {
if (response === null) {
await interaction.editReply({ content: `${member.displayName} is a timeless treasure <3 (and has not set a time zone)` });
const embed = embedTemplate();
if (response === '') {
embed.setTitle(`${member.displayName} is a timeless treasure <3\n(Has not set a time zone)`);
await interaction.editReply({ embeds: [embed] });
// await interaction.editReply({ content: `${member.displayName} is a timeless treasure <3 (and has not set a time zone)` });
} else {
await interaction.editReply({ content: `${response} wherever ${member.displayName} is located.` });
embed.setTitle(`${response} wherever ${member.displayName} is located`);
await interaction.editReply({ embeds: [embed] });
// await interaction.editReply({ content: `${response} wherever ${member.displayName} is located.` });
}
} else {
await interaction.editReply({ content: response as string });
Expand Down
2 changes: 1 addition & 1 deletion src/global/commands/g.birthday.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function birthday(
let response = {} as DateTime | null;
if (command === 'set') {
// log.debug(F, `${command} ${memberId} ${month} ${day}`);
const birthDate = DateTime.utc(2000, month as number, day as number);
const birthDate = DateTime.local(2000, month as number, day as number);

// log.debug(F, `Setting birthDate for ${memberId} to ${birthDate}`);

Expand Down
16 changes: 13 additions & 3 deletions src/global/commands/g.timezone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import timezones from '../assets/data/timezones.json';
import { getUser, usersUpdate } from '../utils/knex';
import { embedTemplate } from '../../discord/utils/embedTemplate';

const F = f(__filename);

Expand All @@ -18,11 +19,13 @@ export async function timezone(
command: 'get' | 'set',
memberId: string,
tzvalue?:string | null,
interaction?:any,
):Promise<string | null> {
// log.debug(F, `tzvalue: ${command} ${memberId} ${tzvalue}`);

let response = '' as string | null;
if (command === 'set') {
const embed = embedTemplate();
// define offset as the value from the timezones array
let tzCode = '';
for (const zone of timezones) { // eslint-disable-line no-restricted-syntax
Expand All @@ -31,6 +34,11 @@ export async function timezone(
// log.debug(F, `tzCode: ${tzCode}`);
}
}
if (tzCode === '') {
embed.setTitle('Invalid timezone!\nPlease only use the options from the autocomplete list.');
await interaction.editReply({ embeds: [embed] });
return null;
}
// log.debug(F, `actor.id: ${actor.id}`);

const userData = await getUser(memberId, null, null);
Expand All @@ -39,7 +47,9 @@ export async function timezone(

await usersUpdate(userData);

return `I updated your timezone to ${tzvalue}`;
embed.setTitle(`I updated your timezone to ${tzvalue}`);
await interaction.editReply({ embeds: [embed] });
return null;
}
let gmtValue = '';

Expand All @@ -56,8 +66,8 @@ export async function timezone(
}
}
// get the user's timezone from the database
const timestring = new Date().toLocaleTimeString('en-US', { timeZone: tzCode });
response = `It is likely ${timestring} (GMT${gmtValue})`;
const timestring = new Date().toLocaleTimeString('en-US', { timeZone: tzCode, hour: '2-digit', minute: '2-digit' });
response = `It's ${timestring} (GMT${gmtValue})`;
log.info(F, `response: ${JSON.stringify(response, null, 2)}`);
}
log.info(F, `response: ${JSON.stringify(response, null, 2)}`);
Expand Down

0 comments on commit d903b3f

Please sign in to comment.