2021-05-27 03:04:06 -06:00
|
|
|
package lila.mailer
|
2017-12-20 07:18:00 -07:00
|
|
|
|
2020-12-03 02:04:04 -07:00
|
|
|
import play.api.i18n.Lang
|
|
|
|
import scala.util.chaining._
|
2017-12-20 07:18:00 -07:00
|
|
|
|
2019-11-30 08:36:09 -07:00
|
|
|
import lila.common.config.BaseUrl
|
2020-12-03 02:04:04 -07:00
|
|
|
import lila.common.EmailAddress
|
|
|
|
import lila.hub.actorApi.msg.SystemMsg
|
2019-04-28 08:14:16 -06:00
|
|
|
import lila.i18n.I18nKeys.{ emails => trans }
|
2017-12-20 07:18:00 -07:00
|
|
|
import lila.user.{ User, UserRepo }
|
2021-02-10 14:58:22 -07:00
|
|
|
import lila.base.LilaException
|
2017-12-20 07:18:00 -07:00
|
|
|
|
|
|
|
final class AutomaticEmail(
|
2019-11-30 00:34:21 -07:00
|
|
|
userRepo: UserRepo,
|
2021-03-31 10:43:52 -06:00
|
|
|
mailer: Mailer,
|
2019-11-30 08:36:09 -07:00
|
|
|
baseUrl: BaseUrl
|
2019-12-13 18:17:43 -07:00
|
|
|
)(implicit ec: scala.concurrent.ExecutionContext) {
|
2017-12-20 07:18:00 -07:00
|
|
|
|
2021-03-31 10:43:52 -06:00
|
|
|
import Mailer.html._
|
2019-04-28 08:14:16 -06:00
|
|
|
|
2020-02-10 16:45:23 -07:00
|
|
|
val regards = """Regards,
|
|
|
|
|
|
|
|
The Lichess team"""
|
|
|
|
|
2021-05-28 08:15:44 -06:00
|
|
|
def welcomeEmail(user: User, email: EmailAddress)(implicit lang: Lang): Funit = {
|
2020-12-03 02:48:55 -07:00
|
|
|
lila.mon.email.send.welcome.increment()
|
2019-04-28 08:14:16 -06:00
|
|
|
val profileUrl = s"$baseUrl/@/${user.username}"
|
2019-12-13 07:30:20 -07:00
|
|
|
val editUrl = s"$baseUrl/account/profile"
|
2021-03-31 10:43:52 -06:00
|
|
|
mailer send Mailer.Message(
|
2019-04-28 08:14:16 -06:00
|
|
|
to = email,
|
2020-02-11 17:11:50 -07:00
|
|
|
subject = trans.welcome_subject.txt(user.username),
|
2021-05-27 02:03:55 -06:00
|
|
|
text = Mailer.txt.addServiceNote(trans.welcome_text.txt(profileUrl, editUrl)),
|
2019-04-28 08:14:16 -06:00
|
|
|
htmlBody = standardEmail(
|
2020-02-11 17:11:50 -07:00
|
|
|
trans.welcome_text.txt(profileUrl, editUrl)
|
2019-04-28 08:14:16 -06:00
|
|
|
).some
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-05-28 08:15:44 -06:00
|
|
|
def welcomePM(user: User): Funit = fuccess {
|
|
|
|
alsoSendAsPrivateMessage(user) { implicit lang =>
|
2021-05-28 08:28:21 -06:00
|
|
|
import lila.i18n.I18nKeys._
|
|
|
|
s"""${welcome.txt()}\n${lichessPatronInfo.txt()}"""
|
2021-05-28 08:15:44 -06:00
|
|
|
}.unit
|
|
|
|
}
|
|
|
|
|
2021-02-10 14:58:22 -07:00
|
|
|
def onTitleSet(username: String): Funit = {
|
2019-12-13 07:30:20 -07:00
|
|
|
for {
|
|
|
|
user <- userRepo named username orFail s"No such user $username"
|
|
|
|
emailOption <- userRepo email user.id
|
2020-12-03 02:04:04 -07:00
|
|
|
title <- fuccess(user.title) orFail "User doesn't have a title!"
|
|
|
|
body = alsoSendAsPrivateMessage(user) { implicit lang =>
|
|
|
|
s"""Hello,
|
2017-12-20 07:18:00 -07:00
|
|
|
|
2020-01-14 08:05:10 -07:00
|
|
|
Thank you for confirming your $title title on Lichess.
|
2020-08-16 06:48:46 -06:00
|
|
|
It is now visible on your profile page: $baseUrl/@/${user.username}.
|
2017-12-20 07:18:00 -07:00
|
|
|
|
2020-02-10 16:45:23 -07:00
|
|
|
$regards
|
2017-12-20 07:18:00 -07:00
|
|
|
"""
|
2020-12-03 02:04:04 -07:00
|
|
|
}
|
|
|
|
_ <- emailOption ?? { email =>
|
|
|
|
implicit val lang = userLang(user)
|
2021-03-31 10:43:52 -06:00
|
|
|
mailer send Mailer.Message(
|
2020-09-29 01:51:32 -06:00
|
|
|
to = email,
|
|
|
|
subject = s"$title title confirmed on lichess.org",
|
2021-05-27 02:03:55 -06:00
|
|
|
text = Mailer.txt.addServiceNote(body),
|
2020-09-29 01:51:32 -06:00
|
|
|
htmlBody = standardEmail(body).some
|
|
|
|
)
|
|
|
|
}
|
|
|
|
} yield ()
|
2021-02-10 14:58:22 -07:00
|
|
|
} recover { case e: LilaException =>
|
|
|
|
logger.info(e.message)
|
|
|
|
}
|
2017-12-20 07:18:00 -07:00
|
|
|
|
2021-05-27 02:13:48 -06:00
|
|
|
def onBecomeCoach(user: User): Funit =
|
|
|
|
sendAsPrivateMessageAndEmail(user)(
|
|
|
|
subject = _ => "Coach profile unlocked on lichess.org",
|
|
|
|
body = _ => s"""Hello,
|
2017-12-20 07:18:00 -07:00
|
|
|
|
2020-01-14 08:05:10 -07:00
|
|
|
It is our pleasure to welcome you as a Lichess coach.
|
2020-08-16 06:48:46 -06:00
|
|
|
Your coach profile awaits you on $baseUrl/coach/edit.
|
2017-12-20 07:18:00 -07:00
|
|
|
|
2020-02-10 16:45:23 -07:00
|
|
|
$regards
|
2017-12-20 07:18:00 -07:00
|
|
|
"""
|
2021-05-27 02:13:48 -06:00
|
|
|
)
|
2017-12-20 07:27:24 -07:00
|
|
|
|
2020-02-10 16:15:26 -07:00
|
|
|
def onFishnetKey(userId: User.ID, key: String): Funit =
|
2021-05-27 02:13:48 -06:00
|
|
|
sendAsPrivateMessageAndEmail(userId)(
|
|
|
|
subject = _ => "Your private fishnet key",
|
|
|
|
body = _ => s"""Hello,
|
2017-12-27 09:46:50 -07:00
|
|
|
|
2020-12-08 15:46:57 -07:00
|
|
|
This message contains your private fishnet key. Please treat it like a password. You can use the same key on multiple machines (even at the same time), but you should not share it with anyone.
|
2017-12-27 09:46:50 -07:00
|
|
|
|
2020-12-08 15:46:57 -07:00
|
|
|
Thank you very much for your help! Thanks to you, chess lovers all around the world will enjoy swift and powerful analysis for their games.
|
2017-12-20 07:27:24 -07:00
|
|
|
|
2020-12-08 15:46:57 -07:00
|
|
|
Your key is:
|
2017-12-20 07:27:24 -07:00
|
|
|
|
2020-12-08 15:46:57 -07:00
|
|
|
$key
|
2017-12-20 07:27:24 -07:00
|
|
|
|
2020-02-10 16:45:23 -07:00
|
|
|
$regards
|
2017-12-20 07:27:24 -07:00
|
|
|
"""
|
2021-05-27 02:13:48 -06:00
|
|
|
)
|
2020-02-10 16:15:26 -07:00
|
|
|
|
2021-05-27 02:13:48 -06:00
|
|
|
def onAppealReply(user: User): Funit =
|
|
|
|
sendAsPrivateMessageAndEmail(user)(
|
|
|
|
subject = _ => "Appeal response on lichess.org",
|
|
|
|
body = _ => s"""Hello,
|
2020-07-30 02:44:05 -06:00
|
|
|
|
2021-05-27 02:13:48 -06:00
|
|
|
Your appeal has received a response from the moderation team, to see it click here: $baseUrl/appeal
|
2020-07-30 02:44:05 -06:00
|
|
|
|
|
|
|
$regards
|
|
|
|
"""
|
2021-05-27 02:13:48 -06:00
|
|
|
)
|
2020-07-30 02:44:05 -06:00
|
|
|
|
2021-05-18 01:24:07 -06:00
|
|
|
def gdprErase(user: User): Funit = {
|
|
|
|
val body =
|
|
|
|
s"""Hello,
|
|
|
|
|
2021-07-13 08:26:27 -06:00
|
|
|
Following your request, the Lichess account "${user.username}" will be fully erased in 24h from now.
|
2021-05-18 01:24:07 -06:00
|
|
|
|
|
|
|
$regards
|
|
|
|
"""
|
|
|
|
userRepo emailOrPrevious user.id flatMap {
|
|
|
|
_ ?? { email =>
|
|
|
|
implicit val lang = userLang(user)
|
|
|
|
mailer send Mailer.Message(
|
|
|
|
to = email,
|
|
|
|
subject = "lichess.org account erasure",
|
2021-05-27 02:03:55 -06:00
|
|
|
text = Mailer.txt.addServiceNote(body),
|
2021-05-18 01:24:07 -06:00
|
|
|
htmlBody = standardEmail(body).some
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-27 12:04:07 -06:00
|
|
|
def onPatronNew(userId: User.ID): Funit =
|
|
|
|
sendAsPrivateMessageAndEmail(userId)(
|
2021-05-27 02:34:23 -06:00
|
|
|
subject = _ => "Thank you for supporting Lichess!",
|
|
|
|
body = _ =>
|
2021-05-27 12:04:07 -06:00
|
|
|
s"""Thank you for your donation to Lichess - your patronage directly goes to keeping the site running and new features coming.
|
|
|
|
Lichess is entirely funded by user's donations like yours, and we truly appreciate the help we're getting.
|
|
|
|
As a small token of our thanks, your account now has the awesome Patron wings!"""
|
2021-05-27 02:34:23 -06:00
|
|
|
)
|
|
|
|
|
2021-05-27 12:04:07 -06:00
|
|
|
def onPatronStop(userId: User.ID): Funit =
|
|
|
|
sendAsPrivateMessageAndEmail(userId)(
|
2021-05-27 02:34:23 -06:00
|
|
|
subject = _ => "End of Lichess Patron subscription",
|
|
|
|
body = _ => s"""
|
|
|
|
Thank you for your support over the last month.
|
2021-05-27 12:04:07 -06:00
|
|
|
We appreciate all donations, being a small team relying entirely on generous donors like you!
|
2021-05-27 02:34:23 -06:00
|
|
|
If you're still interested in supporting us in other ways, you can see non-financial ways of supporting us here $baseUrl/help/contribute.
|
|
|
|
To make a new donation, head to $baseUrl/patron"""
|
|
|
|
)
|
|
|
|
|
2021-06-05 10:49:22 -06:00
|
|
|
def onPatronGift(from: User.ID, to: User.ID, lifetime: Boolean): Funit =
|
2021-06-05 08:05:05 -06:00
|
|
|
userRepo.pair(from, to) map {
|
|
|
|
_ ?? { case (from, to) =>
|
2021-06-05 10:49:22 -06:00
|
|
|
val wings =
|
|
|
|
if (lifetime) "lifetime Patron wings"
|
|
|
|
else "Patron wings for one month"
|
2021-06-05 08:05:05 -06:00
|
|
|
alsoSendAsPrivateMessage(from) { _ =>
|
2021-06-05 10:49:22 -06:00
|
|
|
s"""You gift @${to.username} the $wings. Thank you so much!"""
|
2021-06-05 08:05:05 -06:00
|
|
|
}.unit
|
|
|
|
alsoSendAsPrivateMessage(to) { _ =>
|
2021-06-05 10:49:22 -06:00
|
|
|
s"""@${from.username} gifts you the $wings!"""
|
2021-06-05 08:05:05 -06:00
|
|
|
}.unit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-03 02:04:04 -07:00
|
|
|
private def alsoSendAsPrivateMessage(user: User)(body: Lang => String): String = {
|
|
|
|
implicit val lang = userLang(user)
|
|
|
|
body(userLang(user)) tap { txt =>
|
|
|
|
lila.common.Bus.publish(SystemMsg(user.id, txt), "msgSystemSend")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-27 02:13:48 -06:00
|
|
|
private def sendAsPrivateMessageAndEmail(user: User)(subject: Lang => String, body: Lang => String): Funit =
|
|
|
|
alsoSendAsPrivateMessage(user)(body) pipe { body =>
|
|
|
|
userRepo email user.id flatMap {
|
|
|
|
_ ?? { email =>
|
|
|
|
implicit val lang = userLang(user)
|
|
|
|
mailer send Mailer.Message(
|
|
|
|
to = email,
|
|
|
|
subject = subject(lang),
|
|
|
|
text = Mailer.txt.addServiceNote(body),
|
|
|
|
htmlBody = standardEmail(body).some
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private def sendAsPrivateMessageAndEmail(
|
|
|
|
username: String
|
|
|
|
)(subject: Lang => String, body: Lang => String): Funit =
|
|
|
|
userRepo named username flatMap {
|
|
|
|
_ ?? { user =>
|
|
|
|
sendAsPrivateMessageAndEmail(user)(subject, body)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-03 02:04:04 -07:00
|
|
|
private def userLang(user: User): Lang = user.realLang | lila.i18n.defaultLang
|
2017-12-20 07:18:00 -07:00
|
|
|
}
|