Skip to content

Commit

Permalink
Update D#+ and add /isolate command
Browse files Browse the repository at this point in the history
  • Loading branch information
Naamloos committed Dec 6, 2022
1 parent 842f21b commit bcfe73b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 17 deletions.
69 changes: 57 additions & 12 deletions ModCore/Commands/Moderation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ public class Moderation : ApplicationCommandModule

[SlashCommand("tempban", "Temporarily bans a member.")]
[SlashCommandPermissions(Permissions.BanMembers)]
public async Task TempbanAsync(InteractionContext ctx,
[Option("user", "User to temporarily ban.")]DiscordUser user,
[Option("unban_in", "When to unban this user.")]string unban_in,
[Option("reason", "Reason why this member was banned.")]string reason = "")
public async Task TempbanAsync(InteractionContext ctx,
[Option("user", "User to temporarily ban.")] DiscordUser user,
[Option("unban_in", "When to unban this user.")] string unban_in,
[Option("reason", "Reason why this member was banned.")] string reason = "")
{
if (ctx.User.Id == user.Id)
{
Expand Down Expand Up @@ -145,11 +145,11 @@ await ctx.Client.GetInteractionExtension()

[SlashCommand("hackban", "Bans a user by ID. This user does not have to be part of this server.")]
[SlashCommandPermissions(Permissions.BanMembers)]
public async Task HackbanAsync(InteractionContext ctx,
[Option("userid", "ID of the user to ban.")]string userId,
[Option("reason", "Reason to ban this user.")]string reason = null)
public async Task HackbanAsync(InteractionContext ctx,
[Option("userid", "ID of the user to ban.")] string userId,
[Option("reason", "Reason to ban this user.")] string reason = null)
{
if(!ulong.TryParse(userId, out var id))
if (!ulong.TryParse(userId, out var id))
{
await ctx.CreateResponseAsync("⚠️ Invalid ID!", true);
return;
Expand All @@ -160,17 +160,17 @@ await ctx.Client.GetInteractionExtension()
await ctx.Guild.BanMemberAsync(id, 7, reason);
await ctx.CreateResponseAsync($"🚓 User with ID {userId} was banned.", true);
}
catch(Exception)
catch (Exception)
{
await ctx.CreateResponseAsync($"⚠️ Failed to ban user with ID {userId}.", true);
}
}

[SlashCommand("softban", "Bans and immediately unbans a member from this server. Deletes their messages up until a week ago.")]
[SlashCommandPermissions(Permissions.BanMembers)]
public async Task SoftbanAsync(InteractionContext ctx,
[Option("user", "User to softban.")]DiscordUser user,
[Option("reason", "Reason this user was soft banned.")]string reason = null)
public async Task SoftbanAsync(InteractionContext ctx,
[Option("user", "User to softban.")] DiscordUser user,
[Option("reason", "Reason this user was soft banned.")] string reason = null)
{
var member = await ctx.Guild.GetMemberAsync(user.Id);
if (ctx.User.Id == member.Id)
Expand All @@ -194,5 +194,50 @@ await ctx.Client.GetInteractionExtension()
await member.UnbanAsync(ctx.Guild, $"{userstring}{reasonstring}");
await ctx.CreateResponseAsync($"🚓 Softbanned user {member.DisplayName} (ID:{member.Id}).\n{(sent_dm ? "Said user has been notified of this action." : "")}", true);
}

[SlashCommand("isolate", "Creates a new private thread with a user for moderation.")]
[SlashCommandPermissions(Permissions.ManageThreads | Permissions.CreatePrivateThreads | Permissions.KickMembers)]
public async Task IsolateAsync(InteractionContext ctx,
[Option("user", "User to isolate.")] DiscordUser user,
[Option("reason", "Reason to isolate said member.")] string reason = null,
[Option("user_2", "Add another user to isolate")] DiscordUser user2 = null,
[Option("user_3", "Add another user to isolate")] DiscordUser user3 = null,
[Option("user_4", "Add another user to isolate")] DiscordUser user4 = null,
[Option("user_5", "Add another user to isolate")] DiscordUser user5 = null)
{
List<DiscordUser> users = new List<DiscordUser>();
users.Add(user);
users.Add(user2);
users.Add(user3);
users.Add(user4);
users.Add(user5);
users.RemoveAll(x => x == null);

foreach(var cuser in users)
{
if (!(cuser as DiscordMember).PermissionsIn(ctx.Channel).HasPermission(Permissions.AccessChannels))
{
await ctx.CreateResponseAsync(new DiscordInteractionResponseBuilder()
.WithContent($"⛔ One of the selected members can not access this channel. Try executing the command somewhere else!")
.AsEphemeral());
return;
}
}

var mentions = string.Join(", ", users.Select(x => x.Mention));
var names = string.Join(", ", users.Select(x => x.Username));

var thread = await ctx.Channel.CreateThreadAsync($"{names}", AutoArchiveDuration.Day, ChannelType.PrivateThread, reason);
await thread.SendMessageAsync($"{mentions}, a moderator has created an isolated chat with you" +
$"{(reason != null ? $" for the following reasoning:\n```\n{reason}\n```" : ".")}" +
$"_Said moderator can bring in more members through_ ***@pinging*** _when needed._");

// Add the responsible moderator through a ping
await (await thread.SendMessageAsync(ctx.Member.Mention)).DeleteAsync();

await ctx.CreateResponseAsync(new DiscordInteractionResponseBuilder()
.WithContent($"✅ Created a new private thread: {thread.Mention}")
.AsEphemeral());
}
}
}
10 changes: 5 additions & 5 deletions ModCore/ModCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Chronic-netstandard" Version="0.3.2.4" />
<PackageReference Include="DSharpPlus" Version="4.3.0-nightly-01184" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="4.3.0-nightly-01184" />
<PackageReference Include="DSharpPlus.Interactivity" Version="4.3.0-nightly-01184" />
<PackageReference Include="DSharpPlus.Rest" Version="4.3.0-nightly-01184" />
<PackageReference Include="DSharpPlus.SlashCommands" Version="4.3.0-nightly-01184" />
<PackageReference Include="DSharpPlus" Version="4.3.0-nightly-01192" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="4.3.0-nightly-01192" />
<PackageReference Include="DSharpPlus.Interactivity" Version="4.3.0-nightly-01192" />
<PackageReference Include="DSharpPlus.Rest" Version="4.3.0-nightly-01192" />
<PackageReference Include="DSharpPlus.SlashCommands" Version="4.3.0-nightly-01192" />
<PackageReference Include="F23.StringSimilarity" Version="5.0.0" />
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.4" />
Expand Down

0 comments on commit bcfe73b

Please sign in to comment.