Skip to content

Commit c60e016

Browse files
Merge branch 'main' into milkshake/pardon-warnings
2 parents 586a7ba + 4f355c8 commit c60e016

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+2203
-755
lines changed

.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ Dockerfile.*
1313
Lists/Private/*
1414
data/*
1515
Properties/launchSettings.json
16-
ssh_key
16+
ssh_key
17+
pgdata/*

.env-example

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ CLIPTOK_TOKEN=yourtokenhere
22
CLIPTOK_GITHUB_TOKEN=githubtokenhere
33
CLIPTOK_ANTIPHISHING_ENDPOINT=useyourimagination
44
CLOUDFLARED_TOKEN=ignoreifnotrelevant
5-
USERNAME_CHECK_ENDPOINT=https://api.example.com/username
65
CLIPTALK_WEBHOOK=https://discord.com
76
REACTION_LOG_WEBHOOK=https://discord.com
87
UPTIME_KUMA_PUSH_URL=
9-
TS_AUTHKEY=tskey-auth-asdfg-asdfghj
8+
TS_AUTHKEY=tskey-auth-asdfg-asdfghj
9+
POSTGRES_PASSWORD=mypassword
10+
CLIPTOK_POSTGRES=postgres://cliptok:mypassword@postgres:5432/cliptok

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Lists/Private/*
66
Lists/Private
77
data/*
88
ssh_key
9+
db/*
10+
pgdata/*
911

1012
# Created by https://www.toptal.com/developers/gitignore/api/dotnetcore,windows,linux,redis,visualstudio,visualstudiocode
1113
# Edit at https://www.toptal.com/developers/gitignore?templates=dotnetcore,windows,linux,redis,visualstudio,visualstudiocode

APIs/UsernameAPI.cs

Lines changed: 0 additions & 40 deletions
This file was deleted.

Cliptok.csproj

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@
1818
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-02520" />
1919
<PackageReference Include="DSharpPlus.Commands" Version="5.0.0-nightly-02520" />
2020
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.2" />
21-
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="9.0.4" />
22-
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.4" />
23-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.4" />
24-
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.4" />
21+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.5">
22+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
23+
<PrivateAssets>all</PrivateAssets>
24+
</PackageReference>
25+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.3" />
26+
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="9.0.5" />
27+
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.5" />
28+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.5" />
29+
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.5" />
2530
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
31+
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
2632
<PackageReference Include="Serilog" Version="4.2.0" />
2733
<PackageReference Include="Serilog.Expressions" Version="5.0.0" />
2834
<PackageReference Include="Serilog.Extensions.Logging" Version="9.0.0" />
@@ -47,5 +53,8 @@
4753
<Content Include="Lists/**">
4854
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
4955
</Content>
56+
<Content Include="db/**">
57+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
58+
</Content>
5059
</ItemGroup>
5160
</Project>

Commands/AnnouncementCmds.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ public async Task AnnounceBuildSlashCommand(SlashCommandContext ctx,
6565
}
6666

6767
// Avoid duplicate announcements
68-
if (await Program.db.SetContainsAsync("announcedInsiderBuilds", buildNumber) && !forceReannounce)
68+
if (await Program.redis.SetContainsAsync("announcedInsiderBuilds", buildNumber) && !forceReannounce)
6969
{
7070
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} Build {buildNumber} has already been announced! If you are sure you want to announce it again, set `force_reannounce` to True.", ephemeral: true);
7171
return;
7272
}
7373

74-
await Program.db.SetAddAsync("announcedInsiderBuilds", buildNumber);
74+
await Program.redis.SetAddAsync("announcedInsiderBuilds", buildNumber);
7575

7676
if (flavourText == "" && windowsVersion == 10)
7777
{

Commands/BanCmds.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public async Task UnbanCmd(CommandContext ctx, [Description("The user to unban,
147147
if (reason != "No reason specified.")
148148
unbanMsg += $": **{reason}**";
149149

150-
if (await Program.db.HashExistsAsync("bans", targetUser.Id))
150+
if (await Program.redis.HashExistsAsync("bans", targetUser.Id))
151151
{
152152
await UnbanUserAsync(ctx.Guild, targetUser, $"[Unban by {DiscordHelpers.UniqueUsername(ctx.User)}]: {reason}");
153153
await ctx.RespondAsync(unbanMsg);
@@ -452,15 +452,15 @@ public async Task EditBanCmd(TextCommandContext ctx,
452452
[RemainingText, Description("The time and reason for the ban. e.g. '14d trolling' NOTE: Add 'appeal' to the start of the reason to include an appeal link")] string timeAndReason = "No reason specified."
453453
)
454454
{
455-
if (!await Program.db.HashExistsAsync("bans", targetUser.Id))
455+
if (!await Program.redis.HashExistsAsync("bans", targetUser.Id))
456456
{
457457
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} There's no record of a ban for that user! Please make sure they're banned or you got the right user.");
458458
return;
459459
}
460460

461461
(TimeSpan banDuration, string reason, bool appealable) = PunishmentHelpers.UnpackTimeAndReason(timeAndReason, ctx.Message.Timestamp.DateTime);
462462

463-
var ban = JsonConvert.DeserializeObject<MemberPunishment>(await Program.db.HashGetAsync("bans", targetUser.Id));
463+
var ban = JsonConvert.DeserializeObject<MemberPunishment>(await Program.redis.HashGetAsync("bans", targetUser.Id));
464464

465465
ban.ModId = ctx.User.Id;
466466
if (banDuration == default)
@@ -473,17 +473,17 @@ public async Task EditBanCmd(TextCommandContext ctx,
473473
// and pardon any automatic warnings issued within the last 12 hours
474474
if (ban.Reason.ToLower().Contains("compromised"))
475475
{
476-
Program.db.HashSet("compromisedAccountBans", targetUser.Id, JsonConvert.SerializeObject(ban));
476+
Program.redis.HashSet("compromisedAccountBans", targetUser.Id, JsonConvert.SerializeObject(ban));
477477

478-
var warnings = (await Program.db.HashGetAllAsync(targetUser.Id.ToString())).Select(x => JsonConvert.DeserializeObject<UserWarning>(x.Value)).ToList();
478+
var warnings = (await Program.redis.HashGetAllAsync(targetUser.Id.ToString())).Select(x => JsonConvert.DeserializeObject<UserWarning>(x.Value)).ToList();
479479
foreach (var warning in warnings)
480480
{
481481
if (warning.Type == WarningType.Warning
482482
&& (warning.ModUserId == Program.discord.CurrentUser.Id || (await Program.discord.GetUserAsync(warning.ModUserId)).IsBot)
483483
&& (DateTime.Now - warning.WarnTimestamp).TotalHours < Program.cfgjson.CompromisedAccountBanAutoPardonHours)
484484
{
485485
warning.IsPardoned = true;
486-
await Program.db.HashSetAsync(warning.TargetUserId.ToString(), warning.WarningId, JsonConvert.SerializeObject(warning));
486+
await Program.redis.HashSetAsync(warning.TargetUserId.ToString(), warning.WarningId, JsonConvert.SerializeObject(warning));
487487
}
488488
}
489489
}
@@ -525,7 +525,7 @@ public async Task EditBanCmd(TextCommandContext ctx,
525525
}
526526
}
527527

528-
await Program.db.HashSetAsync("bans", targetUser.Id.ToString(), JsonConvert.SerializeObject(ban));
528+
await Program.redis.HashSetAsync("bans", targetUser.Id.ToString(), JsonConvert.SerializeObject(ban));
529529

530530
// Construct log message
531531
string logOut = $"{Program.cfgjson.Emoji.MessageEdit} The ban for {targetUser.Mention} was edited by {ctx.User.Mention}!\nReason: **{reason}**";

Commands/ClearCmds.cs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,19 @@ public async Task ClearSlashCommand(SlashCommandContext ctx,
105105
}
106106

107107
// List of messages to delete, up to (not including) the one we just got.
108-
var firstMsg = (await channel.GetMessagesAfterAsync(message.Id, 1).ToListAsync())[0];
108+
var firstMsg = (await channel.GetMessagesAfterAsync(message.Id, 1).ToListAsync()).FirstOrDefault();
109+
if (firstMsg is null)
110+
{
111+
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} I couldn't find any messages to clear! Please try again. (Hint: `up_to` is NOT inclusive.)");
112+
return;
113+
}
109114
var firstMsgId = firstMsg.Id;
110115
messagesToClear.Add(firstMsg);
111116
while (true)
112117
{
113118
var newMessages = (await channel.GetMessagesAfterAsync(firstMsgId, 100).ToListAsync()).OrderByDescending(x => x.Id).ToList();
119+
if (newMessages.Count == 0)
120+
break;
114121
messagesToClear.AddRange(newMessages);
115122
firstMsgId = newMessages.First().Id;
116123
if (newMessages.Count() < 100)
@@ -256,9 +263,9 @@ public async Task ClearSlashCommand(SlashCommandContext ctx,
256263

257264
if (dryRun)
258265
{
259-
var msg = await LogChannelHelper.CreateDumpMessageAsync($"{Program.cfgjson.Emoji.Information} **{messagesToClear.Count}** messages would have been deleted, but are instead logged below.",
266+
var msg = (await LogChannelHelper.CreateDumpMessageAsync($"{Program.cfgjson.Emoji.Information} **{messagesToClear.Count}** messages would have been deleted, but are instead logged below.",
260267
messagesToClear,
261-
channel);
268+
channel)).messageBuilder;
262269
await ctx.FollowupAsync(new DiscordFollowupMessageBuilder().WithContent(msg.Content).AddFiles(msg.Files).AddEmbeds(msg.Embeds).AsEphemeral(false));
263270
return;
264271
}
@@ -296,13 +303,17 @@ await LogChannelHelper.LogMessageAsync("mod",
296303
await ctx.FollowupAsync(new DiscordFollowupMessageBuilder().WithContent($"{Program.cfgjson.Emoji.Error} There were no messages that matched all of the arguments you provided! Nothing to do."));
297304
}
298305

299-
await LogChannelHelper.LogDeletedMessagesAsync(
300-
"messages",
301-
$"{Program.cfgjson.Emoji.Deleted} **{messagesToClear.Count}** messages were cleared from {channel.Mention} by {ctx.User.Mention}.",
302-
messagesToClear,
303-
channel
304-
);
306+
// logging is now handled in the bulk delete event
305307

308+
if (!Program.cfgjson.EnablePersistentDb)
309+
{
310+
await LogChannelHelper.LogDeletedMessagesAsync(
311+
"messages",
312+
$"{Program.cfgjson.Emoji.Deleted} **{messagesToClear.Count}** messages were cleared from {channel.Mention} by {ctx.User.Mention}.",
313+
messagesToClear,
314+
channel
315+
);
316+
}
306317
}
307318
}
308319
}

0 commit comments

Comments
 (0)