Add a discord webhook for when users join for the first time. (#698)

* Add a discord webhook for when users join for the first time.

* Fix compilation error related to embed colors

* Make config migration backup use the version of the stored file

* Make DiscordConfiguration not halt startup

* Allow the registration message to be configured

* Clean up registration announcement and add userId variable

* Fix userid resolution and convert newline string to actual character
Also make WebhookHelper not fail if all destinations aren't configured
This commit is contained in:
Josh 2023-03-22 19:57:28 -05:00 committed by GitHub
parent b87c16ab7c
commit fa5ff0b490
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 90 additions and 26 deletions

View file

@ -138,7 +138,20 @@ public class LoginController : ControllerBase
user.LinkedRpcnId = npTicket.Platform == Platform.RPCS3 ? npTicket.UserId : 0;
user.LinkedPsnId = npTicket.Platform != Platform.RPCS3 ? npTicket.UserId : 0;
await this.database.SaveChangesAsync();
if (DiscordConfiguration.Instance.DiscordIntegrationEnabled)
{
string registrationAnnouncementMsg = DiscordConfiguration.Instance.RegistrationAnnouncement
.Replace("%user", username)
.Replace("%id", user.UserId.ToString())
.Replace("%instance", ServerConfiguration.Instance.Customization.ServerName)
.Replace("%platform", npTicket.Platform.ToString())
.Replace(@"\n", "\n");
await WebhookHelper.SendWebhook(title: "A new user has registered!",
description: registrationAnnouncementMsg,
dest: WebhookHelper.WebhookDestination.Registration);
}
Logger.Success($"Created new user for {username}, platform={npTicket.Platform}", LogArea.Login);
}
// automatically change username if it doesn't match

View file

@ -139,7 +139,7 @@ public class PhotosController : ControllerBase
Title = "New photo uploaded!",
Description = $"{user.Username} uploaded a new photo.",
ImageUrl = $"{ServerConfiguration.Instance.ExternalUrl}/gameAssets/{photo.LargeHash}",
Color = WebhookHelper.UnionColor,
Color = WebhookHelper.GetEmbedColor(),
}
);