Skip to content

Commit

Permalink
fix move supporter
Browse files Browse the repository at this point in the history
  • Loading branch information
th0mk committed Feb 13, 2025
1 parent 4f0731b commit 2b7184e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
33 changes: 30 additions & 3 deletions src/FMBot.Bot/Services/SupporterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1279,13 +1279,28 @@ public async Task MigrateDiscordForSupporter(ulong oldDiscordUserId, ulong newDi

await using var db = await this._contextFactory.CreateDbContextAsync();

var oldUser = await db.Users.FirstAsync(f => f.DiscordUserId == oldDiscordUserId);
var newUser = await db.Users.FirstAsync(f => f.DiscordUserId == newDiscordUserId);

var supporter = await db.Supporters.FirstAsync(f => f.DiscordUserId == oldDiscordUserId);
supporter.Notes = $"Migrated from {oldDiscordUserId} to {newDiscordUserId}";
supporter.DiscordUserId = newDiscordUserId;
db.Update(supporter);

var oldUser = await db.Users.FirstAsync(f => f.DiscordUserId == oldDiscordUserId);
if (oldUser.UserType == UserType.Supporter)
{
oldUser.UserType = UserType.User;
}
oldUser.DataSource = DataSource.LastFm;
db.Update(oldUser);
await ModifyGuildRole(oldDiscordUserId, false);

var newUser = await db.Users.FirstAsync(f => f.DiscordUserId == newDiscordUserId);
if (newUser.UserType == UserType.User)
{
newUser.UserType = UserType.Supporter;
}
db.Update(newUser);
await ModifyGuildRole(newDiscordUserId);

if (supporter.SubscriptionType == SubscriptionType.Stripe)
{
var entitlements = await this._discordSkuService.GetRawEntitlementsFromDiscord(discordUserId: oldDiscordUserId);
Expand Down Expand Up @@ -1335,6 +1350,18 @@ await this._supporterLinkService.MigrateDiscordForStripeSupporterAsync(
}

await db.SaveChangesAsync();

await Task.Delay(200);

await RunFullUpdate(oldDiscordUserId);
await RunFullUpdate(newDiscordUserId);

var supporterAuditLogChannel = new DiscordWebhookClient(this._botSettings.Bot.SupporterAuditLogWebhookUrl);
var embed = new EmbedBuilder().WithDescription(
$"Moved supporter:\n" +
$"- Old: {oldDiscordUserId} - <@{oldDiscordUserId}>\n" +
$"- New: {newDiscordUserId} - <@{newDiscordUserId}>");
await supporterAuditLogChannel.SendMessageAsync(embeds: [embed.Build()]);
}

public async Task AddRoleToNewSupporters()
Expand Down
3 changes: 0 additions & 3 deletions src/FMBot.Bot/SlashCommands/AdminSlashCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -649,9 +649,6 @@ public async Task MoveSupporter(string oldUserId, string newUserId)
{
await this._supporterService.MigrateDiscordForSupporter(ulong.Parse(oldUserId), ulong.Parse(newUserId));

await this._supporterService.UpdateSingleDiscordSupporter(ulong.Parse(oldUserId));
await this._supporterService.UpdateSingleDiscordSupporter(ulong.Parse(newUserId));

await FollowupAsync("Moving supporter completed.", ephemeral: true);

var message = (this.Context.Interaction as SocketMessageComponent)?.Message;
Expand Down
6 changes: 3 additions & 3 deletions src/FMBot.Subscriptions/Services/DiscordSkuService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public async Task<bool> RemoveEntitlement(ulong entitlementId)

if (!httpResponse.IsSuccessStatusCode)
{
Log.Error("DiscordEntitlements: HTTP status code {statusCode} - {reason}", httpResponse.StatusCode,
Log.Error("DiscordEntitlements - Remove entitlement - HTTP status code {statusCode} - {reason}", httpResponse.StatusCode,
httpResponse.ReasonPhrase);
return false;
}
Expand All @@ -173,7 +173,7 @@ public async Task<bool> AddStripeEntitlement(ulong discordUserId)
{
var request = new HttpRequestMessage
{
RequestUri = new Uri($"{_baseUrl}applications/{this._appId}/entitlements/"),
RequestUri = new Uri($"{_baseUrl}applications/{this._appId}/entitlements"),
Method = HttpMethod.Post,
Content = new StringContent(
JsonSerializer.Serialize(new
Expand All @@ -191,7 +191,7 @@ public async Task<bool> AddStripeEntitlement(ulong discordUserId)

if (!httpResponse.IsSuccessStatusCode)
{
Log.Error("DiscordEntitlements: HTTP status code {statusCode} - {reason}", httpResponse.StatusCode,
Log.Error("DiscordEntitlements - Add entitlement - HTTP status code {statusCode} - {reason}", httpResponse.StatusCode,
httpResponse.ReasonPhrase);
return false;
}
Expand Down

0 comments on commit 2b7184e

Please sign in to comment.