Skip to content

Commit

Permalink
update supporterservice
Browse files Browse the repository at this point in the history
  • Loading branch information
th0mk committed Oct 6, 2024
1 parent d7c43e1 commit eea6507
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/FMBot.Bot/Services/SupporterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -860,9 +860,12 @@ public async Task UpdateDiscordSupporters(List<DiscordEntitlement> discordSuppor

var supporterAuditLogChannel =
new DiscordWebhookClient(this._botSettings.Bot.SupporterAuditLogWebhookUrl);

var endDate = discordSupporter.EndsAt.HasValue ? $"<t:{((DateTimeOffset?)discordSupporter.EndsAt)?.ToUnixTimeSeconds()}:f>" : "no end date";

var embed = new EmbedBuilder().WithDescription(
$"Updated Discord supporter {discordSupporter.DiscordUserId} - <@{discordSupporter.DiscordUserId}>\n" +
$"*End date from <t:{((DateTimeOffset?)oldDate)?.ToUnixTimeSeconds()}:f> to <t:{((DateTimeOffset?)discordSupporter.EndsAt)?.ToUnixTimeSeconds()}:f>*");
$"*End date from <t:{((DateTimeOffset?)oldDate)?.ToUnixTimeSeconds()}:f> to {endDate}*");
await supporterAuditLogChannel.SendMessageAsync(embeds: new[] { embed.Build() });
}

Expand Down Expand Up @@ -932,15 +935,18 @@ public async Task UpdateDiscordSupporters(List<DiscordEntitlement> discordSuppor
public async Task CheckExpiredDiscordSupporters()
{
var expiredDate = DateTime.UtcNow.AddDays(-3);
var modifiedDate = DateTime.UtcNow.AddDays(-35);

await using var db = await this._contextFactory.CreateDbContextAsync();
var possiblyExpiredSupporters = await db.Supporters
.Where(w =>
w.DiscordUserId != null &&
w.SubscriptionType == SubscriptionType.Discord &&
w.Expired != true &&
w.LastPayment.HasValue &&
w.LastPayment.Value < expiredDate)
(w.LastPayment.HasValue &&
w.LastPayment.Value < expiredDate ||
w.Modified.HasValue &&
w.Modified < modifiedDate))
.ToListAsync();

foreach (var existingSupporter in possiblyExpiredSupporters)
Expand Down Expand Up @@ -970,9 +976,12 @@ public async Task CheckExpiredDiscordSupporters()

var supporterAuditLogChannel =
new DiscordWebhookClient(this._botSettings.Bot.SupporterAuditLogWebhookUrl);
var endDate = discordSupporter.EndsAt.HasValue ? $"<t:{((DateTimeOffset?)discordSupporter.EndsAt)?.ToUnixTimeSeconds()}:f>" : "no end date";

var embed = new EmbedBuilder().WithDescription(
$"Updated Discord supporter {discordSupporter.DiscordUserId} - <@{discordSupporter.DiscordUserId}>\n" +
$"*End date from <t:{((DateTimeOffset?)oldDate)?.ToUnixTimeSeconds()}:f> to <t:{((DateTimeOffset?)discordSupporter.EndsAt)?.ToUnixTimeSeconds()}:f>*");
$"*End date from <t:{((DateTimeOffset?)oldDate)?.ToUnixTimeSeconds()}:f> to {endDate}*");

await supporterAuditLogChannel.SendMessageAsync(embeds: new[] { embed.Build() });

continue;
Expand Down

0 comments on commit eea6507

Please sign in to comment.