Skip to content

Commit b942cdb

Browse files
committed
Add a user timezone as well as build up the slash commands for timezone settings
1 parent 30a1d16 commit b942cdb

File tree

17 files changed

+285
-31
lines changed

17 files changed

+285
-31
lines changed

src/api/raw.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ export async function editUser(
433433
channel_id: options.channelId,
434434
locale: options.locale,
435435
opt_out_content: options.optOutContent,
436+
timezone: options.timezone,
436437
};
437438
const params = {userId};
438439
return request(context, {
@@ -1775,6 +1776,7 @@ export async function putUser(
17751776
channel_id: options.channelId,
17761777
discriminator: options.discriminator,
17771778
locale: options.locale,
1779+
timezone: options.timezone,
17781780
username: options.username,
17791781
};
17801782
const params = {userId};

src/api/structures/user.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const keysUserFull = new Collections.BaseSet<string>([
5959
NotSoApiKeys.LOCALE,
6060
NotSoApiKeys.OPTED_OUT,
6161
NotSoApiKeys.PREMIUM_TYPE,
62+
NotSoApiKeys.TIMEZONE,
6263
NotSoApiKeys.USERNAME,
6364
]);
6465

@@ -77,6 +78,7 @@ export class UserFull extends User {
7778
content: string | null,
7879
};
7980
premiumType: UserPremiumTypes = UserPremiumTypes.NONE;
81+
timezone: string | null = null;
8082
username: string = '';
8183

8284
constructor(data: Structures.BaseStructureData) {

src/api/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export namespace RestOptions {
105105
channelId?: null | string,
106106
locale?: null | string,
107107
optOutContent?: boolean,
108+
timezone?: null | string,
108109
}
109110

110111

@@ -313,6 +314,7 @@ export namespace RestOptions {
313314
channelId?: null | string,
314315
discriminator: string,
315316
locale?: null | string,
317+
timezone?: null | string,
316318
username: string,
317319
}
318320

src/commands/interactions/slash/settings-user/set/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { BaseInteractionCommandOptionGroup } from '../../../basecommand';
22

33
import { SettingsUserSetLocaleCommand } from './set.locale';
4+
import { SettingsUserSetTimezoneCommand } from './set.timezone';
45

56

67
export class SettingsUserSetGroupCommand extends BaseInteractionCommandOptionGroup {
@@ -11,6 +12,7 @@ export class SettingsUserSetGroupCommand extends BaseInteractionCommandOptionGro
1112
super({
1213
options: [
1314
new SettingsUserSetLocaleCommand(),
15+
new SettingsUserSetTimezoneCommand(),
1416
],
1517
});
1618
}

src/commands/interactions/slash/settings-user/set/set.locale.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export interface CommandArgs {
1313

1414
export class SettingsUserSetLocaleCommand extends BaseInteractionCommandOption {
1515
description = 'Set your default language for the bot.';
16+
metadata = {
17+
id: Formatter.Commands.SettingsMeLocale.COMMAND_ID,
18+
};
1619
name = 'locale';
1720

1821
constructor() {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Interaction } from 'detritus-client';
2+
import { MessageFlags } from 'detritus-client/lib/constants';
3+
4+
import { Formatter, Parameters, editOrReply } from '../../../../../utils';
5+
6+
import { BaseInteractionCommandOption } from '../../../basecommand';
7+
8+
9+
export interface CommandArgs {
10+
timezone: string,
11+
}
12+
13+
export class SettingsUserSetTimezoneCommand extends BaseInteractionCommandOption {
14+
description = 'Set your default timezone for the bot';
15+
metadata = {
16+
id: Formatter.Commands.SettingsMeTimezone.COMMAND_ID,
17+
};
18+
name = 'timezone';
19+
20+
constructor() {
21+
super({
22+
options: [
23+
{
24+
name: 'timezone',
25+
description: 'Timezone to choose from',
26+
onAutoComplete: Parameters.AutoComplete.timezone,
27+
},
28+
],
29+
});
30+
}
31+
32+
async run(context: Interaction.InteractionContext, args: CommandArgs) {
33+
return Formatter.Commands.SettingsMeTimezone.createMessage(context, args);
34+
}
35+
}

src/commands/interactions/slash/settings/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { SettingsSetGroupCommand } from './set';
66

77
export default class SettingsGroupCommand extends BaseSlashCommand {
88
description = '.';
9+
disableDm = true;
910
name = 'settings';
1011

1112
constructor() {

src/commands/interactions/slash/settings/prefixes/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { SettingsPrefixesReplaceCommand } from './prefixes.replace';
99

1010
export class SettingsPrefixesGroupCommand extends BaseInteractionCommandOptionGroup {
1111
description = '.';
12-
disableDm = true;
1312
name = 'prefixes';
1413

1514
constructor() {
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { Interaction } from 'detritus-client';
2-
import { InteractionCallbackTypes } from 'detritus-client/lib/constants';
3-
import { Embed, Markup } from 'detritus-client/lib/utils';
2+
import { Permissions } from 'detritus-client/lib/constants';
43

5-
import { EmbedBrands, EmbedColors } from '../../../../../constants';
4+
import { Formatter, Parameters } from '../../../../../utils';
65

76
import { BaseInteractionCommandOption } from '../../../basecommand';
87

@@ -12,26 +11,26 @@ export interface CommandArgs {
1211
}
1312

1413
export class SettingsSetTimezoneCommand extends BaseInteractionCommandOption {
15-
description = 'Set the Server\'s Timezone';
14+
description = 'Set the server\'s default timezone for the bot';
15+
metadata = {
16+
id: Formatter.Commands.SettingsMeTimezone.COMMAND_ID,
17+
};
1618
name = 'timezone';
19+
permissions = [Permissions.MANAGE_GUILD];
1720

1821
constructor() {
1922
super({
2023
options: [
2124
{
2225
name: 'timezone',
2326
description: 'Timezone to choose from',
24-
required: true,
25-
choices: [{name: 'Test', value: 'a'}],
27+
onAutoComplete: Parameters.AutoComplete.timezone,
2628
},
2729
],
2830
});
2931
}
3032

3133
async run(context: Interaction.InteractionContext, args: CommandArgs) {
32-
return context.respond(InteractionCallbackTypes.CHANNEL_MESSAGE_WITH_SOURCE, {
33-
content: 'wip',
34-
flags: 64,
35-
});
34+
return Formatter.Commands.SettingsTimezone.createMessage(context, args);
3635
}
3736
}

src/constants.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ export const ReminderMessages = [
911911

912912
export enum Timezones {
913913
MIT = 'Pacific/Midway',
914-
HST = 'Us/Hawaii',
914+
HST = 'US/Hawaii',
915915
AST = 'US/Alaska',
916916
PST = 'US/Pacific',
917917
PNT = 'America/Phoenix',
@@ -925,7 +925,7 @@ export enum Timezones {
925925
BET = 'Brazil/East',
926926
CAT = 'Etc/GMT-1',
927927
GMT = 'GMT',
928-
ECT = 'Etc/GMT+1',
928+
ECT = 'Etc/GMT-5',
929929
EET = 'EET',
930930
ART = 'Egypt',
931931
EAT = 'Etc/GMT+3',
@@ -944,6 +944,41 @@ export enum Timezones {
944944
};
945945

946946

947+
export const TimezonesToText: Record<Timezones, string> = Object.freeze({
948+
[Timezones.HST]: '(GMT-10:00) Hawaii Standard Time (HST)',
949+
[Timezones.MIT]: '(GMT-09:30) Marquesas Islands Time (MIT)',
950+
[Timezones.PST]: '(GMT-08:00) Pacific Standard Time (PST)',
951+
[Timezones.PNT]: '(GMT-07:00) Phoenix Standard Time (PNT)',
952+
[Timezones.AST]: '(GMT-04:00) Atlantic Standard Time (AST)',
953+
[Timezones.MST]: '(GMT-07:00) Mountain Standard Time (MST)',
954+
[Timezones.CST]: '(GMT-06:00) Central Standard Time (CST)',
955+
[Timezones.EST]: '(GMT-05:00) Eastern Standard Time (EST)',
956+
[Timezones.IET]: '(GMT-05:00) Indiana Eastern Standard Time (IET)',
957+
[Timezones.PRT]: '(GMT+01:00) Western European Summer Time (CNT)',
958+
[Timezones.CNT]: '(GMT-03:30) Canada Newfoundland Time (CNT)',
959+
[Timezones.AGT]: '(GMT-03:00) Argentina Standard Time(AGT)',
960+
[Timezones.BET]: '(GMT-11:00) Bering Standard Time (BET)',
961+
[Timezones.CAT]: '(GMT+02:00) Central Africa Time (CAT)',
962+
[Timezones.GMT]: '(GMT+00:00) Greenwich Mean Time (GMT)',
963+
[Timezones.ECT]: '(GMT-05:00) Ecuador Central Time (ECT)',
964+
[Timezones.EET]: '(GMT+03:00) Eastern European Time (EET)',
965+
[Timezones.ART]: '(GMT-03:00) Argentina Time (ART)',
966+
[Timezones.EAT]: '(GMT+03:00) Eastern Africa Time (EAT)',
967+
[Timezones.MET]: '(GMT+01:00) Middle European Time (MET)', // duplicate of CET
968+
[Timezones.NET]: '',
969+
[Timezones.PLT]: '',
970+
[Timezones.IST]: '',
971+
[Timezones.BST]: '',
972+
[Timezones.VST]: '',
973+
[Timezones.CTT]: '',
974+
[Timezones.JST]: '(GMT+09:00) Japan Standard Time (JST)',
975+
[Timezones.ACT]: '(GMT+09:30) Australian Central Time (ACT)',
976+
[Timezones.AET]: '',
977+
[Timezones.SST]: '',
978+
[Timezones.NST]: '',
979+
});
980+
981+
947982

948983
export enum UserFlags {
949984
NONE = 0,

0 commit comments

Comments
 (0)