chore: format with csharpier

This commit is contained in:
sam 2024-10-09 17:35:11 +02:00
parent 2f516dcb73
commit 4f54077c68
59 changed files with 2000 additions and 942 deletions

View file

@ -23,7 +23,8 @@ public class GuildMemberAddResponder(
UserCache userCache,
WebhookExecutorService webhookExecutor,
IDiscordRestGuildAPI guildApi,
PluralkitApiService pluralkitApi) : IResponder<IGuildMemberAdd>
PluralkitApiService pluralkitApi
) : IResponder<IGuildMemberAdd>
{
private readonly ILogger _logger = logger.ForContext<GuildMemberAddResponder>();
private static readonly TimeSpan NewAccountThreshold = 7.Days();
@ -45,7 +46,8 @@ public class GuildMemberAddResponder(
var guildConfig = await db.GetGuildAsync(member.GuildID, ct);
var guildRes = await guildApi.GetGuildAsync(member.GuildID, withCounts: true, ct);
if (guildRes.IsSuccess)
builder.Description += $"\n{guildRes.Entity.ApproximateMemberCount.Value.Ordinalize()} to join";
builder.Description +=
$"\n{guildRes.Entity.ApproximateMemberCount.Value.Ordinalize()} to join";
builder.Description +=
$"\ncreated {user.ID.Timestamp.Prettify()} ago\n<t:{user.ID.Timestamp.ToUnixTimeSeconds()}:F>";
@ -53,15 +55,19 @@ public class GuildMemberAddResponder(
var pkSystem = await pluralkitApi.GetPluralKitSystemAsync(user.ID.Value, ct);
if (pkSystem != null)
{
var createdAt = pkSystem.Created != null
? $"{pkSystem.Created.Value.Prettify()} ago (<t:{pkSystem.Created.Value.ToUnixTimeSeconds()}:F>)"
: "*(unknown)*";
builder.AddField("PluralKit system", $"""
**ID:** {pkSystem.Id} (`{pkSystem.Uuid}`)
**Name:** {pkSystem.Name ?? "*(none)*"}
**Tag:** {pkSystem.Tag ?? "*(none)*"}
**Created:** {createdAt}
""");
var createdAt =
pkSystem.Created != null
? $"{pkSystem.Created.Value.Prettify()} ago (<t:{pkSystem.Created.Value.ToUnixTimeSeconds()}:F>)"
: "*(unknown)*";
builder.AddField(
"PluralKit system",
$"""
**ID:** {pkSystem.Id} (`{pkSystem.Uuid}`)
**Name:** {pkSystem.Name ?? "*(none)*"}
**Tag:** {pkSystem.Tag ?? "*(none)*"}
**Created:** {createdAt}
"""
);
}
// TODO: find used invite
@ -70,51 +76,73 @@ public class GuildMemberAddResponder(
if (user.ID.Timestamp > DateTimeOffset.Now - NewAccountThreshold)
{
embeds.Add(new EmbedBuilder()
.WithTitle("New account")
.WithColour(DiscordUtils.Orange)
.WithDescription($"\u26a0\ufe0f Created {user.ID.Timestamp.Prettify()} ago")
.Build()
.GetOrThrow());
embeds.Add(
new EmbedBuilder()
.WithTitle("New account")
.WithColour(DiscordUtils.Orange)
.WithDescription($"\u26a0\ufe0f Created {user.ID.Timestamp.Prettify()} ago")
.Build()
.GetOrThrow()
);
}
var watchlist = await db.GetWatchlistEntryAsync(member.GuildID, user.ID, ct);
if (watchlist != null)
{
var moderator = await userCache.GetUserAsync(DiscordSnowflake.New(watchlist.ModeratorId));
var mod = moderator != null ? $"{moderator.Tag()} (<@{moderator.ID}>)" : $"<@{watchlist.ModeratorId}>";
var moderator = await userCache.GetUserAsync(
DiscordSnowflake.New(watchlist.ModeratorId)
);
var mod =
moderator != null
? $"{moderator.Tag()} (<@{moderator.ID}>)"
: $"<@{watchlist.ModeratorId}>";
embeds.Add(new EmbedBuilder()
.WithTitle("⚠️ User on watchlist")
.WithColour(DiscordUtils.Red)
.WithDescription($"**{user.Tag()}** is on this server's watch list.\n\n{watchlist.Reason}")
.WithFooter($"ID: {user.ID} | Added")
.WithTimestamp(watchlist.AddedAt.ToDateTimeOffset())
.AddField("Moderator", mod).GetOrThrow()
.Build()
.GetOrThrow());
embeds.Add(
new EmbedBuilder()
.WithTitle("⚠️ User on watchlist")
.WithColour(DiscordUtils.Red)
.WithDescription(
$"**{user.Tag()}** is on this server's watch list.\n\n{watchlist.Reason}"
)
.WithFooter($"ID: {user.ID} | Added")
.WithTimestamp(watchlist.AddedAt.ToDateTimeOffset())
.AddField("Moderator", mod)
.GetOrThrow()
.Build()
.GetOrThrow()
);
}
if (pkSystem != null)
{
if (guildConfig.BannedSystems.Contains(pkSystem.Id) ||
guildConfig.BannedSystems.Contains(pkSystem.Uuid.ToString()))
if (
guildConfig.BannedSystems.Contains(pkSystem.Id)
|| guildConfig.BannedSystems.Contains(pkSystem.Uuid.ToString())
)
{
embeds.Add(new EmbedBuilder().WithTitle("Banned system")
.WithDescription(
"\u26a0\ufe0f The system associated with this account has been banned from the server.")
.WithColour(DiscordUtils.Red)
.WithFooter($"ID: {pkSystem.Id}")
.Build()
.GetOrThrow());
embeds.Add(
new EmbedBuilder()
.WithTitle("Banned system")
.WithDescription(
"\u26a0\ufe0f The system associated with this account has been banned from the server."
)
.WithColour(DiscordUtils.Red)
.WithFooter($"ID: {pkSystem.Id}")
.Build()
.GetOrThrow()
);
}
}
if (embeds.Count > 1)
await webhookExecutor.SendLogAsync(guildConfig.Channels.GuildMemberAdd,
embeds.Cast<IEmbed>().ToList(), []);
else webhookExecutor.QueueLog(guildConfig.Channels.GuildMemberAdd, embeds[0]);
await webhookExecutor.SendLogAsync(
guildConfig.Channels.GuildMemberAdd,
embeds.Cast<IEmbed>().ToList(),
[]
);
else
webhookExecutor.QueueLog(guildConfig.Channels.GuildMemberAdd, embeds[0]);
return Result.Success;
}
}
}