Skip to content

Commit 4d2d72d

Browse files
Merge branch 'main' into milkshake/cts-ping-autowarn
2 parents 4d90201 + ce55ad4 commit 4d2d72d

Some content is hidden

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

66 files changed

+586
-514
lines changed

Cliptok.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
<ItemGroup>
1717
<PackageReference Include="Abyssal.HumanDateParser" Version="2.0.0-20191113.1" />
18-
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-02532" />
19-
<PackageReference Include="DSharpPlus.Commands" Version="5.0.0-nightly-02532" />
18+
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-02551" />
19+
<PackageReference Include="DSharpPlus.Commands" Version="5.0.0-nightly-02551" />
2020
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.2" />
2121
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.5">
2222
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

CommandChecks/HomeServerPerms.cs

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,41 +28,30 @@ public static async Task<ServerPermLevel> GetPermLevelAsync(DiscordMember target
2828
if (target is null || target.Guild is null || target.Guild.Id != Program.cfgjson.ServerID)
2929
return ServerPermLevel.Nothing;
3030

31-
// Torch approved of this.
3231
if (target.IsOwner)
3332
return ServerPermLevel.Owner;
34-
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.AdminRole)) || target.Id == Program.discord.CurrentUser.Id)
33+
34+
if (target.Id == Program.discord.CurrentUser.Id)
3535
return ServerPermLevel.Admin;
36-
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.ModRole)))
37-
return ServerPermLevel.Moderator;
38-
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.MutedRole)))
39-
return ServerPermLevel.Muted;
40-
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.TrialModRole)))
41-
return ServerPermLevel.TrialModerator;
42-
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.TqsRoleId)))
43-
return ServerPermLevel.TechnicalQueriesSlayer;
44-
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.TierRoles[9])))
45-
return ServerPermLevel.TierX;
46-
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.TierRoles[8])))
47-
return ServerPermLevel.TierS;
48-
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.TierRoles[7])))
49-
return ServerPermLevel.Tier8;
50-
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.TierRoles[6])))
51-
return ServerPermLevel.Tier7;
52-
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.TierRoles[5])))
53-
return ServerPermLevel.Tier6;
54-
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.TierRoles[4])))
55-
return ServerPermLevel.Tier5;
56-
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.TierRoles[3])))
57-
return ServerPermLevel.Tier4;
58-
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.TierRoles[2])))
59-
return ServerPermLevel.Tier3;
60-
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.TierRoles[1])))
61-
return ServerPermLevel.Tier2;
62-
else if (target.Roles.Contains(await target.Guild.GetRoleAsync(Program.cfgjson.TierRoles[0])))
63-
return ServerPermLevel.Tier1;
64-
else
65-
return ServerPermLevel.Nothing;
36+
37+
bool HasRole(ulong roleId) => target.Roles.Any(r => r.Id == roleId);
38+
39+
return HasRole(Program.cfgjson.AdminRole) ? ServerPermLevel.Admin
40+
: HasRole(Program.cfgjson.ModRole) ? ServerPermLevel.Moderator
41+
: HasRole(Program.cfgjson.MutedRole) ? ServerPermLevel.Muted
42+
: HasRole(Program.cfgjson.TrialModRole) ? ServerPermLevel.TrialModerator
43+
: HasRole(Program.cfgjson.TqsRoleId) ? ServerPermLevel.TechnicalQueriesSlayer
44+
: HasRole(Program.cfgjson.TierRoles[9]) ? ServerPermLevel.TierX
45+
: HasRole(Program.cfgjson.TierRoles[8]) ? ServerPermLevel.TierS
46+
: HasRole(Program.cfgjson.TierRoles[7]) ? ServerPermLevel.Tier8
47+
: HasRole(Program.cfgjson.TierRoles[6]) ? ServerPermLevel.Tier7
48+
: HasRole(Program.cfgjson.TierRoles[5]) ? ServerPermLevel.Tier6
49+
: HasRole(Program.cfgjson.TierRoles[4]) ? ServerPermLevel.Tier5
50+
: HasRole(Program.cfgjson.TierRoles[3]) ? ServerPermLevel.Tier4
51+
: HasRole(Program.cfgjson.TierRoles[2]) ? ServerPermLevel.Tier3
52+
: HasRole(Program.cfgjson.TierRoles[1]) ? ServerPermLevel.Tier2
53+
: HasRole(Program.cfgjson.TierRoles[0]) ? ServerPermLevel.Tier1
54+
: ServerPermLevel.Nothing;
6655
}
6756

6857
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = false)]

Commands/AnnouncementCmds.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public class AnnouncementCmds
55
// used to pass context to modal handling for /editannounce
66
// keyed by user ID
77
public static Dictionary<ulong, (ulong msgId, string role1, string role2)> EditAnnounceCache = new();
8-
8+
99
[Command("announcebuild")]
1010
[Description("Announce a Windows Insider build in the current channel.")]
1111
[AllowedProcessors(typeof(SlashCommandProcessor))]
@@ -51,13 +51,13 @@ public async Task AnnounceBuildSlashCommand(SlashCommandContext ctx,
5151
await ctx.RespondAsync(text: $"{Program.cfgjson.Emoji.Error} Windows 10 only has a Release Preview Channel.", ephemeral: true);
5252
return;
5353
}
54-
54+
5555
if (threadChannel != default && threadChannel == threadChannel2)
5656
{
5757
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} Both threads cannot be the same! Simply set one instead.", ephemeral: true);
5858
return;
5959
}
60-
60+
6161
if (threadChannel == default && threadChannel2 != default)
6262
{
6363
threadChannel = threadChannel2;
@@ -188,7 +188,7 @@ public async Task AnnounceBuildSlashCommand(SlashCommandContext ctx,
188188
threadChannel = await ctx.Client.GetChannelAsync(Program.cfgjson.InsiderThreads["rp"]);
189189
break;
190190
}
191-
191+
192192
switch (insiderChannel2)
193193
{
194194
case "Canary":
@@ -207,7 +207,7 @@ public async Task AnnounceBuildSlashCommand(SlashCommandContext ctx,
207207
threadChannel2 = await ctx.Client.GetChannelAsync(Program.cfgjson.InsiderThreads["rp"]);
208208
break;
209209
}
210-
210+
211211
pingMsgString += $"\n\nDiscuss it here: {threadChannel.Mention}";
212212
if (threadChannel2 != default)
213213
pingMsgString += $" & {threadChannel2.Mention}";
@@ -258,7 +258,7 @@ public async Task AnnounceBuildSlashCommand(SlashCommandContext ctx,
258258
threadChannel = await ctx.Client.GetChannelAsync(Program.cfgjson.InsiderThreads["rp"]);
259259
break;
260260
}
261-
261+
262262
switch (insiderChannel2)
263263
{
264264
case "Canary":
@@ -277,7 +277,7 @@ public async Task AnnounceBuildSlashCommand(SlashCommandContext ctx,
277277
threadChannel2 = await ctx.Client.GetChannelAsync(Program.cfgjson.InsiderThreads["rp"]);
278278
break;
279279
}
280-
280+
281281
noPingMsgString += $"\n\nDiscuss it here: {threadChannel.Mention}";
282282
if (threadChannel2 != default)
283283
noPingMsgString += $" & {threadChannel2.Mention}";
@@ -349,7 +349,7 @@ public async Task AnnounceBuildSlashCommand(SlashCommandContext ctx,
349349
TimeSpan lockDuration;
350350
try
351351
{
352-
lockDuration = HumanDateParser.HumanDateParser.Parse(lockdownTime).Subtract(DateTime.Now);
352+
lockDuration = HumanDateParser.HumanDateParser.Parse(lockdownTime).ToUniversalTime().Subtract(DateTime.UtcNow);
353353
}
354354
catch
355355
{
@@ -384,13 +384,13 @@ public async Task EditAnnounce(
384384
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} That message ID wasn't recognised!", ephemeral: true);
385385
return;
386386
}
387-
387+
388388
if (msg.Author.Id != ctx.Client.CurrentUser.Id)
389389
{
390390
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} That message wasn't sent by me, so I can't edit it!", ephemeral: true);
391391
return;
392392
}
393-
393+
394394
// Validate roles
395395
if (!Program.cfgjson.AnnouncementRoles.ContainsKey(role1Name) || (role2Name is not null && !Program.cfgjson.AnnouncementRoles.ContainsKey(role2Name)))
396396
{
@@ -402,12 +402,12 @@ public async Task EditAnnounce(
402402
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Warning} You provided the same role name twice! Did you mean to use two different roles?", ephemeral: true);
403403
return;
404404
}
405-
405+
406406
EditAnnounceCache[ctx.User.Id] = (Convert.ToUInt64(messageId), role1Name, role2Name);
407407

408-
await ctx.RespondWithModalAsync(new DiscordInteractionResponseBuilder().WithTitle("Edit Announcement").WithCustomId("editannounce-modal-callback").AddTextInputComponent(new DiscordTextInputComponent("New announcement text. Do not include roles!", "editannounce-modal-new-text", value: msg.Content, style: DiscordTextInputStyle.Paragraph)));
408+
await ctx.RespondWithModalAsync(new DiscordModalBuilder().WithTitle("Edit Announcement").WithCustomId("editannounce-modal-callback").AddTextInput(new DiscordTextInputComponent("editannounce-modal-new-text", style: DiscordTextInputStyle.Paragraph, value: msg.Content), "New announcement text. Do not include roles!"));
409409
}
410-
410+
411411
[Command("announce")]
412412
[Description("Announces something in the current channel, pinging an Insider role in the process.")]
413413
[HomeServer, RequireHomeserverPerm(ServerPermLevel.Moderator)]
@@ -431,7 +431,7 @@ public async Task AnounceSlashCmd(SlashCommandContext ctx,
431431
await ctx.RespondAsync(text: $"{Program.cfgjson.Emoji.Error} Windows 10 only has a Release Preview Channel.", ephemeral: true);
432432
return;
433433
}
434-
434+
435435
string roleKey1;
436436
if (windowsVersion == 10 && insiderChannel1 == "RP")
437437
{
@@ -465,7 +465,7 @@ public async Task AnounceSlashCmd(SlashCommandContext ctx,
465465

466466
insiderRole2 = await ctx.Guild.GetRoleAsync(Program.cfgjson.AnnouncementRoles[roleKey2]);
467467
}
468-
468+
469469
await insiderRole1.ModifyAsync(mentionable: true);
470470
if (insiderRole2 != default)
471471
await insiderRole2.ModifyAsync(mentionable: true);
@@ -486,7 +486,7 @@ public async Task AnounceSlashCmd(SlashCommandContext ctx,
486486
await insiderRole1.ModifyAsync(mentionable: false);
487487
if (insiderRole2 != default)
488488
await insiderRole2.ModifyAsync(mentionable: false);
489-
489+
490490
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} Announcement sent successfully!");
491491
}
492492

@@ -632,7 +632,7 @@ public async ValueTask<IEnumerable<DiscordApplicationCommandOptionChoice>> Provi
632632
};
633633
}
634634
}
635-
635+
636636
internal class AnnouncementRoleChoiceProvider : IChoiceProvider
637637
{
638638
public async ValueTask<IEnumerable<DiscordApplicationCommandOptionChoice>> ProvideAsync(CommandParameter _)

Commands/BanCmds.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public async Task BanSlashCommand(SlashCommandContext ctx,
8585
{
8686
try
8787
{
88-
banDuration = HumanDateParser.HumanDateParser.Parse(time).Subtract(ctx.Interaction.CreationTimestamp.DateTime);
88+
banDuration = HumanDateParser.HumanDateParser.Parse(time).ToUniversalTime().Subtract(ctx.Interaction.CreationTimestamp.DateTime);
8989
}
9090
catch
9191
{
@@ -274,7 +274,7 @@ public async Task BanCmd(TextCommandContext ctx,
274274
string possibleTime = timeAndReason.Split(' ').First();
275275
try
276276
{
277-
banDuration = HumanDateParser.HumanDateParser.Parse(possibleTime).Subtract(ctx.Message.Timestamp.DateTime);
277+
banDuration = HumanDateParser.HumanDateParser.Parse(possibleTime).ToUniversalTime().Subtract(ctx.Message.Timestamp.DateTime);
278278
timeParsed = true;
279279
}
280280
catch
@@ -379,7 +379,7 @@ public async Task BankeepCmd(TextCommandContext ctx,
379379
string possibleTime = timeAndReason.Split(' ').First();
380380
try
381381
{
382-
banDuration = HumanDateParser.HumanDateParser.Parse(possibleTime).Subtract(ctx.Message.Timestamp.DateTime);
382+
banDuration = HumanDateParser.HumanDateParser.Parse(possibleTime).ToUniversalTime().Subtract(ctx.Message.Timestamp.DateTime);
383383
timeParsed = true;
384384
}
385385
catch
@@ -441,7 +441,7 @@ public async Task BankeepCmd(TextCommandContext ctx,
441441
}
442442
}
443443
}
444-
444+
445445
[Command("editbantextcmd")]
446446
[TextAlias("editban")]
447447
[Description("Edit the details of a ban. Updates the DM to the user, among other things.")]
@@ -457,39 +457,39 @@ public async Task EditBanCmd(TextCommandContext ctx,
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
}
460-
460+
461461
(TimeSpan banDuration, string reason, bool appealable) = PunishmentHelpers.UnpackTimeAndReason(timeAndReason, ctx.Message.Timestamp.DateTime);
462462

463463
var ban = JsonConvert.DeserializeObject<MemberPunishment>(await Program.redis.HashGetAsync("bans", targetUser.Id));
464-
464+
465465
ban.ModId = ctx.User.Id;
466466
if (banDuration == default)
467467
ban.ExpireTime = null;
468468
else
469469
ban.ExpireTime = ban.ActionTime + banDuration;
470470
ban.Reason = reason;
471-
471+
472472
var guild = await Program.discord.GetGuildAsync(ban.ServerId);
473-
473+
474474
var contextMessage = await DiscordHelpers.GetMessageFromReferenceAsync(ban.ContextMessageReference);
475475
var dmMessage = await DiscordHelpers.GetMessageFromReferenceAsync(ban.DmMessageReference);
476-
476+
477477
reason = reason.Replace("`", "\\`").Replace("*", "\\*");
478-
478+
479479
if (contextMessage is not null)
480480
{
481481
string newCtxMsg;
482482
if (banDuration == default)
483483
newCtxMsg = $"{Program.cfgjson.Emoji.Banned} {targetUser.Mention} has been banned: **{reason}**";
484484
else
485485
newCtxMsg = $"{Program.cfgjson.Emoji.Banned} {targetUser.Mention} has been banned for **{TimeHelpers.TimeToPrettyFormat(banDuration, false)}**: **{reason}**";
486-
486+
487487
if (contextMessage.Content.Contains("-# This user's messages have been kept."))
488488
newCtxMsg += "\n-# This user's messages have been kept.";
489-
489+
490490
await contextMessage.ModifyAsync(newCtxMsg);
491491
}
492-
492+
493493
if (dmMessage is not null)
494494
{
495495
if (ban.ExpireTime == null)
@@ -511,12 +511,12 @@ public async Task EditBanCmd(TextCommandContext ctx,
511511
await dmMessage.ModifyAsync($"{Program.cfgjson.Emoji.Banned} You have been banned from **{guild.Name}** for {TimeHelpers.TimeToPrettyFormat(banDuration, false)}!\nReason: **{reason}**\nBan expires: <t:{TimeHelpers.ToUnixTimestamp(ban.ExpireTime)}:R>");
512512
}
513513
}
514-
514+
515515
await Program.redis.HashSetAsync("bans", targetUser.Id.ToString(), JsonConvert.SerializeObject(ban));
516-
516+
517517
// Construct log message
518518
string logOut = $"{Program.cfgjson.Emoji.MessageEdit} The ban for {targetUser.Mention} was edited by {ctx.User.Mention}!\nReason: **{reason}**";
519-
519+
520520
if (ban.ExpireTime == null)
521521
{
522522
logOut += "\nBan expires: **Never**"
@@ -526,10 +526,10 @@ public async Task EditBanCmd(TextCommandContext ctx,
526526
{
527527
logOut += $"\nBan expires: <t:{TimeHelpers.ToUnixTimestamp(ban.ExpireTime)}:R>";
528528
}
529-
529+
530530
// Log to mod log
531531
await LogChannelHelper.LogMessageAsync("mod", logOut);
532-
532+
533533
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Success} Successfully edited the ban for {targetUser.Mention}!");
534534
}
535535
}

Commands/ClearCmds.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public async Task ClearSlashCommand(SlashCommandContext ctx,
2424
)
2525
{
2626
await ctx.DeferResponseAsync(ephemeral: !dryRun);
27-
27+
2828
if (channel is null)
2929
channel = ctx.Channel;
3030

Commands/DebugCmds.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using Cliptok.Helpers;
21
using Microsoft.EntityFrameworkCore;
32

43
namespace Cliptok.Commands
@@ -159,7 +158,8 @@ public async Task Restart(TextCommandContext ctx)
159158
{
160159
await ctx.RespondAsync("Invalid argument. Make sure you know what you are doing.");
161160

162-
};
161+
}
162+
;
163163
}
164164

165165
[Command("refresh")]

Commands/DehoistCmds.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public async Task DehoistCmd(CommandContext ctx, [Parameter("member"), Descripti
2525
return;
2626
}
2727

28-
if (member.MemberFlags.Value.HasFlag(DiscordMemberFlags.AutomodQuarantinedUsername))
28+
if (member.MemberFlags.Value.HasFlag(DiscordMemberFlags.AutomodQuarantinedUsername) || member.MemberFlags.Value.HasFlag(DiscordMemberFlags.AutomodQuarantinedGuildTag))
2929
{
30-
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} {member.Mention} is quarantined because their name is in violation of AutoMod rules! Discord will not let me dehoist them. Please change their nickname manually.", ephemeral: true);
30+
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} {member.Mention} is quarantined because their profile is in violation of AutoMod rules! Discord will not let me dehoist them. Please change their nickname manually.", ephemeral: true);
3131
return;
3232
}
3333

@@ -192,7 +192,7 @@ public async Task MassUndhoist(TextCommandContext ctx)
192192
continue;
193193
}
194194

195-
if (member.DisplayName[0] == DehoistHelpers.dehoistCharacter && !member.MemberFlags.Value.HasFlag(DiscordMemberFlags.AutomodQuarantinedUsername))
195+
if (member.DisplayName[0] == DehoistHelpers.dehoistCharacter && !member.MemberFlags.Value.HasFlag(DiscordMemberFlags.AutomodQuarantinedUsername) && !member.MemberFlags.Value.HasFlag(DiscordMemberFlags.AutomodQuarantinedGuildTag))
196196
{
197197
var newNickname = member.Nickname[1..];
198198
await member.ModifyAsync(a =>

Commands/FunCmds.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using Cliptok.Constants;
2-
31
namespace Cliptok.Commands
42
{
53
public class FunCmds

0 commit comments

Comments
 (0)