Birthday cake emoji for the chat room

face-detect
Noah Petherbridge 2023-10-10 19:30:39 -07:00
parent 09ba634556
commit 59338d510f
3 changed files with 43 additions and 2 deletions

View File

@ -66,8 +66,9 @@ func Landing() http.HandlerFunc {
// Are they logging into the chat room?
var (
intent = r.FormValue("intent")
isShy = currentUser.IsShy()
intent = r.FormValue("intent")
isShy = currentUser.IsShy()
birthday = r.FormValue("birthday") == "true" && currentUser.IsBirthday()
)
if intent == "join" {
// Maintenance mode?
@ -114,6 +115,11 @@ func Landing() http.HandlerFunc {
}
}
// Birthday cake emoji?
if birthday {
emoji = "🍰 It's my birthday!"
}
// Create the JWT claims.
claims := Claims{
IsAdmin: currentUser.HasAdminScope(config.ScopeChatModerator),

View File

@ -606,6 +606,23 @@ func (u *User) GetDisplayAge() string {
return "n/a"
}
// IsBirthday returns whether it is currently the user's birthday (+- a day for time zones).
func (u *User) IsBirthday() bool {
if u.Birthdate.IsZero() {
return false
}
// Window of time to be valid.
var (
now, _ = time.Parse(time.DateOnly, time.Now().Format(time.DateOnly))
bday, _ = time.Parse(time.DateOnly, fmt.Sprintf("%d-%d-%d", now.Year(), u.Birthdate.Month(), u.Birthdate.Day()))
startDate = now.Add(-24 * time.Hour)
endDate = now.Add(24 * time.Hour)
)
return bday.Before(endDate) && bday.After(startDate)
}
// ProfileFieldIn checks if a substring is IN a profile field. Currently
// does a naive strings.Contains(), intended for the "here_for" field.
func (u *User) ProfileFieldIn(field, substr string) bool {

View File

@ -26,6 +26,24 @@
</div>
<div class="block p-4">
{{if .CurrentUser.IsBirthday}}
<div class="notification is-success is-light content">
<h2>🎂 Happy birthday!</h2>
<p>
If you would like, you may enter the chat room with a special 🍰 birthday cake emoji next to
your username instead of the usual country flag. This is totally optional and you may do this
by clicking the button <em>below</em> to enter the chat room:
</p>
<p>
<a href="/chat?intent=join&birthday=true" class="button">
🍰 Join the Chat Room
</a>
</p>
</div>
{{end}}
{{if .IsShyUser}}
<div class="notification is-danger is-light">
<i class="fa fa-exclamation-triangle"></i> You have a <strong>Shy Account</strong> and you may not enter