@@ -2,8 +2,9 @@ import { ChatInputCommandInteraction, inlineCode } from "discord.js";
2
2
import { birthdayDb } from "../../db" ;
3
3
import { DateTime } from "luxon" ;
4
4
import { getTimezoneFromRole } from "../misc/role" ;
5
- import { longDateFormatWithTimezone } from "../misc/time" ;
5
+ import { longDateFormatWithTimezone , shortDateFormatWithTimezone } from "../misc/time" ;
6
6
import { config } from "../../config" ;
7
+ import { getAge } from "./loop" ;
7
8
8
9
export async function setBirthday ( interaction : ChatInputCommandInteraction ) {
9
10
const oldDate = birthdayDb . get ( interaction . user . id ) ;
@@ -55,9 +56,9 @@ export async function setBirthday(interaction: ChatInputCommandInteraction) {
55
56
56
57
if ( oldDate ) {
57
58
await interaction . reply ( {
58
- content : `Changed your birthday from * ${ oldDate . toFormat (
59
+ content : `Changed your birthday from ${ oldDate . toFormat (
59
60
longDateFormatWithTimezone
60
- ) } * to **${ date . toFormat ( longDateFormatWithTimezone ) } **!`,
61
+ ) } to **${ date . toFormat ( longDateFormatWithTimezone ) } **!`,
61
62
} ) ;
62
63
} else {
63
64
await interaction . reply ( {
@@ -66,18 +67,36 @@ export async function setBirthday(interaction: ChatInputCommandInteraction) {
66
67
}
67
68
}
68
69
69
- export async function myBirthday ( interaction : ChatInputCommandInteraction ) {
70
- if ( ! birthdayDb . has ( interaction . user . id ) ) {
70
+ export async function getBirthday ( interaction : ChatInputCommandInteraction ) {
71
+ const user = interaction . options . getUser ( "user" ) ?? interaction . user ;
72
+ const member = interaction . guild ! . members . cache . get ( user . id ) ;
73
+
74
+ if ( ! member ) {
75
+ await interaction . reply ( {
76
+ content : "This user is not on this server!" ,
77
+ ephemeral : true ,
78
+ } ) ;
79
+ return ;
80
+ }
81
+
82
+ const isUserItself = interaction . user . id == user . id ;
83
+
84
+ if ( ! birthdayDb . has ( user . id ) ) {
71
85
await interaction . reply ( {
72
- content : "You haven't set your birthday yet!\nYou can do this by using `/birthday set`" ,
86
+ content : isUserItself
87
+ ? "You don't have a birthday set yet!\nYou can set it with `/birthday set`!"
88
+ : `${ member . displayName } hasn't set their birthday yet!` ,
73
89
ephemeral : true ,
74
90
} ) ;
75
91
return ;
76
92
}
77
93
78
- const date = birthdayDb . get ( interaction . user . id ) ! ;
94
+ const date = birthdayDb . get ( user . id ) ! ;
95
+ const age = getAge ( date ) ;
79
96
80
97
await interaction . reply ( {
81
- content : `Your birthday is set for the **${ date . toFormat ( longDateFormatWithTimezone ) } **!` ,
98
+ content : `${ isUserItself ? "Your" : member . displayName + "s" } birthday is set for the ${ date . toFormat (
99
+ age != null ? longDateFormatWithTimezone : shortDateFormatWithTimezone
100
+ ) } !${ age != null ? ` That means ${ isUserItself ? "you" : "they" } are ${ age } years old!` : "" } `,
82
101
} ) ;
83
102
}
0 commit comments