Skip to content

Commit

Permalink
Merge branch 'main' into floatingmilkshake/automod-filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
FloatingMilkshake committed Aug 15, 2024
2 parents d5c6de3 + dff0e2a commit e8fe72e
Show file tree
Hide file tree
Showing 43 changed files with 1,228 additions and 584 deletions.
1 change: 0 additions & 1 deletion .env-example
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
CLIPTOK_TOKEN=yourtokenhere
CLIPTOK_GITHUB_TOKEN=githubtokenhere
CLIPTOK_ANTIPHISHING_ENDPOINT=useyourimagination
RAVY_API_TOKEN=goodluckfindingone
CLOUDFLARED_TOKEN=ignoreifnotrelevant
USERNAME_CHECK_ENDPOINT=https://api.example.com/username
CLIPTALK_WEBHOOK=https://discord.com
Expand Down
38 changes: 0 additions & 38 deletions APIs/AvatarAPI.cs

This file was deleted.

14 changes: 9 additions & 5 deletions Cliptok.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@
<TargetFramework>net8.0</TargetFramework>
<LangVersion>12.0</LangVersion>
<UserSecretsId>d9345310-5908-4697-8613-28a24d06d183</UserSecretsId>

<!-- <RestoreAdditionalProjectSources>
https://www.myget.org/F/erisa/api/v3/index.json
</RestoreAdditionalProjectSources> -->
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Abyssal.HumanDateParser" Version="2.0.0-20191113.1" />
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-02302" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="5.0.0-nightly-02302" />
<PackageReference Include="DSharpPlus.SlashCommands" Version="5.0.0-nightly-02302" />
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-02351" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="5.0.0-nightly-02351" />
<PackageReference Include="DSharpPlus.SlashCommands" Version="5.0.0-nightly-02351" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Serilog" Version="4.0.0" />
<PackageReference Include="Serilog" Version="4.0.1" />
<PackageReference Include="Serilog.Expressions" Version="5.0.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.TextWriter" Version="2.1.0" />
<PackageReference Include="Serilog.Sinks.TextWriter" Version="3.0.0" />
<PackageReference Include="StackExchange.Redis" Version="2.8.0" />
<PackageReference Include="System.Linq" Version="4.3.0" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
Expand Down
479 changes: 361 additions & 118 deletions Commands/Debug.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Commands/Dehoist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ await discordMember.ModifyAsync(a =>
}

[Command("massdehoist")]
[Description("Dehoist everyone on the server who has a bad name. WARNING: This is a computationally expensive operation.")]
[Description("Dehoist everyone on the server who has a bad name. This may take a while and can exhaust rate limits.")]
[HomeServer, RequireHomeserverPerm(ServerPermLevel.Moderator)]
public async Task MassDehoist(CommandContext ctx)
{
Expand Down
2 changes: 1 addition & 1 deletion Commands/InteractionCommands/AnnouncementInteractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async Task AnnounceBuildSlashCommand(InteractionContext ctx,
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} Both insider channels cannot be the same! Simply set one instead.", ephemeral: true);
}

List<string> validWindows10Channels = ["RP", "Beta"];
List<string> validWindows10Channels = ["RP", "Beta", ""];

if (windowsVersion == 10 && (!validWindows10Channels.Contains(insiderChannel1) || !validWindows10Channels.Contains(insiderChannel2)))
{
Expand Down
2 changes: 1 addition & 1 deletion Commands/InteractionCommands/ClearInteractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task ClearSlashCommand(InteractionContext ctx,
[Option("dry_run", "Don't actually delete the messages, just output what would be deleted.")] bool dryRun = false
)
{
await ctx.CreateResponseAsync(DiscordInteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder().AsEphemeral(!dryRun));
await ctx.DeferAsync(ephemeral: !dryRun);

// If all args are unset
if (count == 0 && upTo == "" && user == default && ignoreMods == false && match == "" && botsOnly == false && humansOnly == false && attachmentsOnly == false && stickersOnly == false && linksOnly == false)
Expand Down
22 changes: 4 additions & 18 deletions Commands/InteractionCommands/DebugInteractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,15 @@ public async Task ScamCheck(InteractionContext ctx, [Option("input", "Domain or
string responseToSend;
if (match)
{
responseToSend = $"Match found:\n```json\n{responseText}\n```";

responseToSend = $"Match found:\n`";
}
else
{
responseToSend = $"No valid match found.\nHTTP Status `{(int)httpStatus}`, result:\n```json\n{responseText}\n```";
responseToSend = $"No valid match found.\nHTTP Status `{(int)httpStatus}`, result:\n";
}

if (responseToSend.Length > 1940)
{
try
{
HasteBinResult hasteURL = await Program.hasteUploader.Post(responseText);
if (hasteURL.IsSuccess)
responseToSend = hasteURL.FullUrl + ".json";
else
responseToSend = "Response was too big and Hastebin failed, sorry.";
}
catch
{
responseToSend = "Response was too big and Hastebin failed, sorry.";
}
}
responseToSend += await StringHelpers.CodeOrHasteBinAsync(responseText, "json");

await ctx.RespondAsync(responseToSend);
}
else
Expand Down
6 changes: 3 additions & 3 deletions Commands/InteractionCommands/LockdownInteractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public async Task LockdownChannelCommand(
[Option("time", "The length of time to lock the channel for.")] string time = null,
[Option("lockthreads", "Whether to lock this channel's threads. Disables sending messages, but does not archive them.")] bool lockThreads = false)
{
await ctx.CreateResponseAsync(DiscordInteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder().AsEphemeral(true));
await ctx.DeferAsync(ephemeral: true);

if (ctx.Channel.Type is DiscordChannelType.PublicThread or DiscordChannelType.PrivateThread or DiscordChannelType.NewsThread)
{
Expand Down Expand Up @@ -71,7 +71,7 @@ public async Task LockdownAllCommand(
[Option("time", "The length of time to lock the channels for.")] string time = null,
[Option("lockthreads", "Whether to lock threads. Disables sending messages, but does not archive them.")] bool lockThreads = false)
{
await ctx.CreateResponseAsync(DiscordInteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder().WithContent("test deferred response"));
await ctx.DeferAsync();

ongoingLockdown = true;
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent($"{Program.cfgjson.Emoji.Loading} Working on it, please hold..."));
Expand Down Expand Up @@ -109,7 +109,7 @@ public class UnlockCmds
[SlashCommand("channel", "Unlock the current channel. See also: lockdown")]
public async Task UnlockChannelCommand(InteractionContext ctx, [Option("reason", "The reason for the unlock.")] string reason = "")
{
await ctx.CreateResponseAsync(DiscordInteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder().AsEphemeral(true));
await ctx.DeferAsync(ephemeral: true);

var currentChannel = ctx.Channel;
if (!Program.cfgjson.LockdownEnabledChannels.Contains(currentChannel.Id))
Expand Down
20 changes: 11 additions & 9 deletions Commands/InteractionCommands/MuteInteractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public async Task UnmuteSlashCommand(
[Option("reason", "The reason for the unmute.")] string reason = "No reason specified."
)
{
await ctx.DeferAsync(ephemeral: false);

reason = $"[Manual unmute by {DiscordHelpers.UniqueUsername(ctx.User)}]: {reason}";

// todo: store per-guild
Expand All @@ -75,18 +77,18 @@ public async Task UnmuteSlashCommand(
if ((await Program.db.HashExistsAsync("mutes", targetUser.Id)) || (member != default && member.Roles.Contains(mutedRole)))
{
await MuteHelpers.UnmuteUserAsync(targetUser, reason, true, ctx.User);
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Information} Successfully unmuted **{DiscordHelpers.UniqueUsername(targetUser)}**.");
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent($"{Program.cfgjson.Emoji.Information} Successfully unmuted **{DiscordHelpers.UniqueUsername(targetUser)}**."));
}
else
try
{
await MuteHelpers.UnmuteUserAsync(targetUser, reason, true, ctx.User);
await ctx.CreateResponseAsync($"{Program.cfgjson.Emoji.Warning} According to Discord that user is not muted, but I tried to unmute them anyway. Hope it works.");
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent($"{Program.cfgjson.Emoji.Warning} According to Discord that user is not muted, but I tried to unmute them anyway. Hope it works."));
}
catch (Exception e)
{
Program.discord.Logger.LogError(e, "An error occurred unmuting {user}", targetUser.Id);
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} That user doesn't appear to be muted, *and* an error occurred while attempting to unmute them anyway. Please contact the bot owner, the error has been logged.");
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent($"{Program.cfgjson.Emoji.Error} That user doesn't appear to be muted, *and* an error occurred while attempting to unmute them anyway. Please contact the bot owner, the error has been logged."));
}
}

Expand Down Expand Up @@ -114,12 +116,6 @@ public async Task TqsMuteSlashCommand(
DiscordRole mutedRole = ctx.Guild.GetRole(Program.cfgjson.MutedRole);
DiscordRole tqsMutedRole = ctx.Guild.GetRole(Program.cfgjson.TqsMutedRole);

if (await Program.db.HashExistsAsync("mutes", targetUser.Id) || ctx.Member.Roles.Contains(mutedRole) || ctx.Member.Roles.Contains(tqsMutedRole))
{
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"{Program.cfgjson.Emoji.Error} {ctx.User.Mention}, that user is already muted."));
return;
}

// Get member
DiscordMember targetMember = default;
try
Expand All @@ -131,6 +127,12 @@ public async Task TqsMuteSlashCommand(
// blah
}

if (await Program.db.HashExistsAsync("mutes", targetUser.Id) || (targetMember is not null && (targetMember.Roles.Contains(mutedRole) || targetMember.Roles.Contains(tqsMutedRole))))
{
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"{Program.cfgjson.Emoji.Error} {ctx.User.Mention}, that user is already muted."));
return;
}

// Check if user to be muted is staff or TQS, and disallow if so
if (targetMember != default && GetPermLevel(ctx.Member) == ServerPermLevel.TechnicalQueriesSlayer && (GetPermLevel(targetMember) >= ServerPermLevel.TechnicalQueriesSlayer || targetMember.IsBot))
{
Expand Down
14 changes: 9 additions & 5 deletions Commands/InteractionCommands/TrackingInteractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ public class PermadehoistSlashCommands
[SlashCommand("add", "Track a users messages.")]
public async Task TrackingAddSlashCmd(InteractionContext ctx, [Option("member", "The member to track.")] DiscordUser discordUser)
{
await ctx.DeferAsync(ephemeral: false);

if (Program.db.SetContains("trackedUsers", discordUser.Id))
{
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} This user is already tracked!");
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent($"{Program.cfgjson.Emoji.Error} This user is already tracked!"));
return;
}

Expand All @@ -24,7 +26,7 @@ public async Task TrackingAddSlashCmd(InteractionContext ctx, [Option("member",

await thread.SendMessageAsync($"{Program.cfgjson.Emoji.On} Now tracking {discordUser.Mention} in this thread! :eyes:");
thread.AddThreadMemberAsync(ctx.Member);
await ctx.RespondAsync($"{Program.cfgjson.Emoji.On} Now tracking {discordUser.Mention} in {thread.Mention}!");
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent($"{Program.cfgjson.Emoji.On} Now tracking {discordUser.Mention} in {thread.Mention}!"));

}
else
Expand All @@ -33,16 +35,18 @@ public async Task TrackingAddSlashCmd(InteractionContext ctx, [Option("member",
await Program.db.HashSetAsync("trackingThreads", discordUser.Id, thread.Id);
await thread.SendMessageAsync($"{Program.cfgjson.Emoji.On} Now tracking {discordUser.Mention} in this thread! :eyes:");
await thread.AddThreadMemberAsync(ctx.Member);
await ctx.RespondAsync($"{Program.cfgjson.Emoji.On} Now tracking {discordUser.Mention} in {thread.Mention}!");
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent($"{Program.cfgjson.Emoji.On} Now tracking {discordUser.Mention} in {thread.Mention}!"));
}
}

[SlashCommand("remove", "Stop tracking a users messages.")]
public async Task TrackingRemoveSlashCmd(InteractionContext ctx, [Option("member", "The member to track.")] DiscordUser discordUser)
{
await ctx.DeferAsync(ephemeral: false);

if (!Program.db.SetContains("trackedUsers", discordUser.Id))
{
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} This user is not being tracked.");
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent($"{Program.cfgjson.Emoji.Error} This user is not being tracked."));
return;
}

Expand All @@ -57,7 +61,7 @@ await thread.ModifyAsync(thread =>
thread.IsArchived = true;
});

await ctx.RespondAsync($"{Program.cfgjson.Emoji.Off} No longer tracking {discordUser.Mention}! Thread has been archived for now.");
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent($"{Program.cfgjson.Emoji.Off} No longer tracking {discordUser.Mention}! Thread has been archived for now."));
}
}

Expand Down
2 changes: 1 addition & 1 deletion Commands/InteractionCommands/UserNoteInteractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public async Task AddUserNoteAsync(InteractionContext ctx,
[Option("show_all_mods", "Whether to show this note to all mods, versus just yourself. Default: true")] bool showAllMods = true,
[Option("show_once", "Whether to show this note once and then discard it. Default: false")] bool showOnce = false)
{
await ctx.CreateResponseAsync(DiscordInteractionResponseType.DeferredChannelMessageWithSource, new DiscordInteractionResponseBuilder().AsEphemeral());
await ctx.DeferAsync();

// Assemble new note
long noteId = Program.db.StringIncrement("totalWarnings");
Expand Down
Loading

0 comments on commit e8fe72e

Please sign in to comment.