Skip to content

Commit

Permalink
Merge branch 'main' into floatingmilkshake/track-add-channel-option
Browse files Browse the repository at this point in the history
  • Loading branch information
Erisa committed Nov 16, 2024
2 parents df44f1f + 8d872dd commit 062b780
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Checks/ListChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class ListChecks
{
// Map of Cyrillic to Latin characters, to catch attempted bypasses using Cyrillic lookalikes
// <string, string> is <Cyrillic, Latin>
static Dictionary<string, string> alphabetMap = new()
public static Dictionary<string, string> alphabetMap = new()
{
{ "А", "A" },
{ "В", "B" },
Expand Down
13 changes: 9 additions & 4 deletions Cliptok.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>12.0</LangVersion>
<TargetFramework>net9.0</TargetFramework>
<LangVersion>13.0</LangVersion>
<UserSecretsId>d9345310-5908-4697-8613-28a24d06d183</UserSecretsId>

<!-- <RestoreAdditionalProjectSources>
Expand All @@ -16,14 +16,19 @@
<PackageReference Include="DSharpPlus" Version="5.0.0-nightly-02374" />
<PackageReference Include="DSharpPlus.CommandsNext" Version="5.0.0-nightly-02374" />
<PackageReference Include="DSharpPlus.SlashCommands" Version="5.0.0-nightly-02374" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Serilog" Version="4.0.1" />
<PackageReference Include="Serilog" Version="4.1.0" />
<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.Grafana.Loki" Version="8.3.0" />
<PackageReference Include="Serilog.Sinks.TextWriter" Version="3.0.0" />
<PackageReference Include="StackExchange.Redis" Version="2.8.12" />
<PackageReference Include="StackExchange.Redis" Version="2.8.16" />
<PackageReference Include="System.Linq" Version="4.3.0" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
</ItemGroup>
Expand Down
17 changes: 1 addition & 16 deletions Commands/Debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,7 @@ public async Task Shell(CommandContext ctx, [RemainingText] string command)
[Command("logs")]
public async Task Logs(CommandContext ctx)
{
if (Program.cfgjson.LogLevel is Level.Verbose)
{
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} Verbose logging is enabled, so the in-memory logger is disabled. Please access the logs through another method.");
return;
}

await DiscordHelpers.SafeTyping(ctx.Channel);

string result = Regex.Replace(Program.outputCapture.ToString(), "ghp_[0-9a-zA-Z]{36}", "ghp_REDACTED").Replace(Environment.GetEnvironmentVariable("CLIPTOK_TOKEN"), "REDACTED");

if (Environment.GetEnvironmentVariable("CLIPTOK_ANTIPHISHING_ENDPOINT") is not null)
{
result = result.Replace(Environment.GetEnvironmentVariable("CLIPTOK_ANTIPHISHING_ENDPOINT"), "REDACTED");
}

await ctx.RespondAsync(await StringHelpers.CodeOrHasteBinAsync(result));
await ctx.RespondAsync($"{Program.cfgjson.Emoji.Error} This command has been removed! Please find logs through other means.");
}

[Command("dumpwarnings"), Description("Dump all warning data. EXTREMELY computationally expensive, use with caution.")]
Expand Down
6 changes: 2 additions & 4 deletions Commands/InteractionCommands/AnnouncementInteractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ 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", ""];

if (windowsVersion == 10 && (!validWindows10Channels.Contains(insiderChannel1) || !validWindows10Channels.Contains(insiderChannel2)))
if (windowsVersion == 10 && insiderChannel1 != "RP")
{
await ctx.RespondAsync(text: $"{Program.cfgjson.Emoji.Error} Windows 10 only has Release Preview and Beta Channels.", ephemeral: true);
await ctx.RespondAsync(text: $"{Program.cfgjson.Emoji.Error} Windows 10 only has a Release Preview Channel.", ephemeral: true);
return;
}

Expand Down
3 changes: 0 additions & 3 deletions Commands/InteractionCommands/RoleInteractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public async Task GrantRole(
"insiderBeta" => Program.cfgjson.UserRoles.InsiderBeta,
"insiderRP" => Program.cfgjson.UserRoles.InsiderRP,
"insider10RP" => Program.cfgjson.UserRoles.Insider10RP,
"insider10Beta" => Program.cfgjson.UserRoles.Insider10Beta,
"patchTuesday" => Program.cfgjson.UserRoles.PatchTuesday,
"giveaways" => Program.cfgjson.UserRoles.Giveaways,
"cts" => Program.cfgjson.CommunityTechSupportRoleID,
Expand Down Expand Up @@ -68,7 +67,6 @@ public async Task RemoveRole(
"insiderBeta" => Program.cfgjson.UserRoles.InsiderBeta,
"insiderRP" => Program.cfgjson.UserRoles.InsiderRP,
"insider10RP" => Program.cfgjson.UserRoles.Insider10RP,
"insider10Beta" => Program.cfgjson.UserRoles.Insider10Beta,
"patchTuesday" => Program.cfgjson.UserRoles.PatchTuesday,
"giveaways" => Program.cfgjson.UserRoles.Giveaways,
"cts" => Program.cfgjson.CommunityTechSupportRoleID,
Expand Down Expand Up @@ -99,7 +97,6 @@ public async Task<IEnumerable<DiscordAutoCompleteChoice>> Provider(AutocompleteC
{ "Windows 11 Insiders (Beta)", "insiderBeta" },
{ "Windows 11 Insiders (Release Preview)", "insiderRP" },
{ "Windows 10 Insiders (Release Preview)", "insider10RP" },
{ "Windows 10 Insiders (Beta)", "insider10Beta" },
{ "Patch Tuesday", "patchTuesday" },
{ "Giveaways", "giveaways" },
{ "Community Tech Support (CTS)", "cts" }
Expand Down
9 changes: 8 additions & 1 deletion Commands/InteractionCommands/WarningInteractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ public async Task WarnSlashCommand(InteractionContext ctx,
.WithContent($"{Program.cfgjson.Emoji.Warning} {user.Mention} was warned: **{reason.Replace("`", "\\`").Replace("*", "\\*")}**");

if (replyMsgId != "0")
messageBuild.WithReply(Convert.ToUInt64(replyMsgId), true, false);
{
if (!ulong.TryParse(replyMsgId, out var msgId))
{
await ctx.FollowUpAsync(new DiscordFollowupMessageBuilder().WithContent($"{Program.cfgjson.Emoji.Error} Invalid reply message ID! Please try again.").AsEphemeral(true));
return;
}
messageBuild.WithReply(msgId, true, false);
}

var msg = await channel.SendMessageAsync(messageBuild);

Expand Down
2 changes: 1 addition & 1 deletion Commands/Warnings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public async Task WarningCmd(
[
Command("delwarn"),
Description("Delete a warning that was issued by mistake or later became invalid."),
Aliases("delwarm", "delwam", "deletewarn", "delwarning", "deletewarning"),
Aliases("delwarm", "delwam", "deletewarn", "delwarning", "deletewarning", "removewarning", "removewarn"),
HomeServer, RequireHomeserverPerm(ServerPermLevel.TrialModerator)
]
public async Task DelwarnCmd(
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM --platform=${BUILDPLATFORM} \
mcr.microsoft.com/dotnet/sdk:8.0.403 AS build-env
mcr.microsoft.com/dotnet/sdk:9.0.100 AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
Expand All @@ -11,7 +11,7 @@ COPY . ./
RUN dotnet build -c Release -o out

# We already have this image pulled, its actually quicker to reuse it
FROM mcr.microsoft.com/dotnet/sdk:8.0.403 AS git-collector
FROM mcr.microsoft.com/dotnet/sdk:9.0.100 AS git-collector
WORKDIR /out
COPY . .
RUN touch dummy.txt && \
Expand All @@ -22,7 +22,7 @@ RUN touch dummy.txt && \
fi

# Build runtime image
FROM mcr.microsoft.com/dotnet/runtime:8.0.10-alpine3.20
FROM mcr.microsoft.com/dotnet/runtime:9.0.0-alpine3.20
LABEL com.centurylinklabs.watchtower.enable=true
WORKDIR /app
RUN apk add --no-cache git redis openssh
Expand Down
9 changes: 6 additions & 3 deletions Events/DirectMessageEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ public class DirectMessageEvent
{
public static async void DirectMessageEventHandler(DiscordMessage message)
{
// Ignore message if user is blocked
if (await Program.db.SetContainsAsync("dmRelayBlocklist", message.Author.Id)) return;

// Auto-response to contact modmail if DM follows warn/mute and is within configured time limit

bool sentAutoresponse = false;
Expand Down Expand Up @@ -36,6 +33,12 @@ await message.RespondAsync(
}
}

// Don't relay message if user is a bot (user apps)
if (message.Author.IsBot) return;

// Don't relay message if user is blocked
if (await Program.db.SetContainsAsync("dmRelayBlocklist", message.Author.Id)) return;

// Log DMs to DM log channel, include note about auto-response if applicable
await LogChannelHelper.LogMessageAsync("dms", await DiscordHelpers.GenerateMessageRelay(message, sentAutoresponse: sentAutoresponse));
}
Expand Down
5 changes: 4 additions & 1 deletion Events/MessageEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,10 @@ public static async Task MessageHandlerAsync(DiscordClient client, MockDiscordMe
}

// attempted to ping @everyone/@here
if (Program.cfgjson.EveryoneFilter && !member.Roles.Any(role => Program.cfgjson.EveryoneExcludedRoles.Contains(role.Id)) && !Program.cfgjson.EveryoneExcludedChannels.Contains(channel.Id) && (message.Content.Contains("@everyone") || message.Content.Contains("@here")))
var msgContent = message.Content;
foreach (var letter in Checks.ListChecks.alphabetMap)
msgContent = msgContent.Replace(letter.Key, letter.Value);
if (Program.cfgjson.EveryoneFilter && !member.Roles.Any(role => Program.cfgjson.EveryoneExcludedRoles.Contains(role.Id)) && !Program.cfgjson.EveryoneExcludedChannels.Contains(channel.Id) && (msgContent.Contains("@everyone") || msgContent.Contains("@here")))
{
if (wasAutoModBlock)
{
Expand Down
5 changes: 5 additions & 0 deletions Helpers/DiscordSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public DiscordSink(ITextFormatter textFormatter)

public async void Emit(LogEvent logEvent)
{
// wait for exceptions to propagate
// TODO(erisa): find a better way to do this
if (logEvent.Exception is not null )
await Task.Delay(100);

if (logEvent is null) throw new ArgumentNullException(nameof(logEvent));
lock (_syncRoot)
{
Expand Down
7 changes: 7 additions & 0 deletions Lists/scams.txt
Original file line number Diff line number Diff line change
Expand Up @@ -526,3 +526,10 @@ I'm looking for someone who can help my work.
To make massive sales like $10k weekly with this wonderful opportunity
reach out to me to know more about it. Together we succeed
$Become the best Trader with us
📊Become a successful trader.📊
TradingView Premium
AtlasVPN+IPTVPlayer
repackme8
JPYVouTegYI
nolerawin.com
?promo=TOWER10
7 changes: 0 additions & 7 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ class Program : BaseCommandModule
public static Random rand = new();
public static HasteBinClient hasteUploader;

public static StringBuilder outputStringBuilder = new(16, 200000000);
public static StringWriter outputCapture;

static public readonly HttpClient httpClient = new();

public static List<ServerApiResponseJson> serverApiList = new();
Expand All @@ -77,7 +74,6 @@ public static void UpdateLists()
static async Task Main(string[] _)
{
Console.OutputEncoding = Encoding.UTF8;
outputCapture = new(outputStringBuilder);

httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var logFormat = "[{Timestamp:yyyy-MM-dd HH:mm:ss zzz}] [{Level}] {Message}{NewLine}{Exception}";
Expand Down Expand Up @@ -125,9 +121,6 @@ static async Task Main(string[] _)
break;
}

if (cfgjson.LogLevel is not Level.Verbose)
loggerConfig.WriteTo.TextWriter(outputCapture, outputTemplate: logFormat);

if (cfgjson.LokiURL is not null && cfgjson.LokiServiceName is not null)
{
loggerConfig.WriteTo.GrafanaLoki(cfgjson.LokiURL, [new LokiLabel { Key = "app", Value = cfgjson.LokiServiceName }]);
Expand Down
3 changes: 0 additions & 3 deletions Structs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,6 @@ public class UserRoleConfig

[JsonProperty("giveaways")]
public ulong Giveaways { get; private set; }

[JsonProperty("insider10beta")]
public ulong Insider10Beta { get; private set; }
}

public class PhishingRequestBody
Expand Down
2 changes: 0 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"canary": 434426594271166474,
"dev": 1082364328474329179,
"beta": 643712828217360394,
"beta10": 1247617691997438082,
"rp": 288729239921098752,
"rp10": 910319453491839069,
"patch": 445773142233710594
Expand Down Expand Up @@ -229,7 +228,6 @@
"insiderBeta": 643712828217360394,
"insiderRP": 288729239921098752,
"insider10RP": 910319453491839069,
"insider10Beta": 1247617691997438082,
"patchTuesday": 445773142233710594,
"giveaways": 1169336992455200820
},
Expand Down

0 comments on commit 062b780

Please sign in to comment.