refactor: move classes to separate files

This commit is contained in:
Stevan Freeborn
2025-05-21 14:33:03 -05:00
parent ca4aff5d2e
commit 6ae1cd413b
19 changed files with 149 additions and 90 deletions
+4 -2
View File
@@ -1,7 +1,9 @@
{ {
"editor.formatOnSave": true, "editor.formatOnSave": true,
"dotnet.defaultSolution": "src/StevesBot.sln", "dotnet.defaultSolution": "./src/StevesBot.sln",
"cSpell.words": [ "cSpell.words": [
"Steves" "Reconnectable",
"Steves",
"Szalay"
], ],
} }
-5
View File
@@ -1,5 +0,0 @@
# Steves Bot
⚠️ Under Construction ⚠️
This is a custom discord bot that I use in my personal discord server.
+1
View File
@@ -1,6 +1,7 @@
<Project> <Project>
<PropertyGroup> <PropertyGroup>
<RepoRoot>$(MSBuildThisFileDirectory)</RepoRoot>
<TargetFramework>net9.0</TargetFramework> <TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
@@ -0,0 +1 @@
namespace StevesBot.Worker.Tests.Unit;
@@ -0,0 +1,50 @@
using StevesBot.Worker.Discord.Gateway.Events.Data;
namespace StevesBot.Worker.Tests.Unit;
public class IdentifyDataTests
{
[Fact]
public void Constructor_WhenCalled_ItShouldReturnInstance()
{
var result = new IdentifyData();
result.Token.Should().Be(string.Empty);
result.Properties.Should().BeEquivalentTo(new IdentifyProperties());
result.Presence.Should().BeEquivalentTo(new UpdatePresenceData());
result.Intents.Should().Be(0);
}
[Fact]
public void Constructor_WhenCalledWithParameters_ItShouldReturnInstance()
{
var token = "test_token";
var properties = new IdentifyProperties
{
Os = "test_os",
Browser = "test_browser",
Device = "test_device",
};
var presence = new UpdatePresenceData
{
Status = "test_status",
Activities = [],
};
var intents = 123456789;
var result = new IdentifyData
{
Token = token,
Properties = properties,
Presence = presence,
Intents = intents
};
result.Token.Should().Be(token);
result.Properties.Should().BeSameAs(properties);
result.Presence.Should().BeSameAs(presence);
result.Intents.Should().Be(intents);
}
}
+1
View File
@@ -18,6 +18,7 @@ global using RichardSzalay.MockHttp;
global using StevesBot.Worker.Discord.Gateway; global using StevesBot.Worker.Discord.Gateway;
global using StevesBot.Worker.Discord.Gateway.Events; global using StevesBot.Worker.Discord.Gateway.Events;
global using StevesBot.Worker.Discord.Gateway.Events.Data;
global using StevesBot.Worker.Discord.Rest; global using StevesBot.Worker.Discord.Rest;
global using StevesBot.Worker.Discord.Shared; global using StevesBot.Worker.Discord.Shared;
global using StevesBot.Worker.Tests.Integration.Infrastructure; global using StevesBot.Worker.Tests.Integration.Infrastructure;
@@ -0,0 +1,13 @@
namespace StevesBot.Worker.Discord.Gateway.Events.Data;
internal sealed record Activity
{
[JsonPropertyName("name")]
public string Name { get; init; } = string.Empty;
[JsonPropertyName("type")]
public int Type { get; init; } = ActivityType.Custom;
[JsonPropertyName("state")]
public string? State { get; init; }
}
@@ -0,0 +1,6 @@
namespace StevesBot.Worker.Discord.Gateway.Events.Data;
internal static class ActivityType
{
public const int Custom = 4;
}
@@ -0,0 +1,7 @@
namespace StevesBot.Worker.Discord.Gateway.Events.Data;
internal sealed record HelloData
{
[JsonPropertyName("heartbeat_interval")]
public int HeartbeatInterval { get; init; }
}
@@ -0,0 +1,16 @@
namespace StevesBot.Worker.Discord.Gateway.Events.Data;
internal sealed record IdentifyData
{
[JsonPropertyName("token")]
public string Token { get; init; } = string.Empty;
[JsonPropertyName("properties")]
public IdentifyProperties Properties { get; init; } = new();
[JsonPropertyName("presence")]
public UpdatePresenceData Presence { get; init; } = new();
[JsonPropertyName("intents")]
public long Intents { get; init; }
}
@@ -0,0 +1,13 @@
namespace StevesBot.Worker.Discord.Gateway.Events.Data;
internal sealed record IdentifyProperties
{
[JsonPropertyName("os")]
public string Os { get; init; } = Environment.OSVersion.ToString();
[JsonPropertyName("browser")]
public string Browser { get; init; } = Assembly.GetExecutingAssembly().GetName().FullName;
[JsonPropertyName("device")]
public string Device { get; init; } = Assembly.GetExecutingAssembly().GetName().FullName;
}
@@ -0,0 +1,7 @@
namespace StevesBot.Worker.Discord.Gateway.Events.Data;
internal static class PresenceStatus
{
public const string Online = "online";
public const string Idle = "idle";
}
@@ -0,0 +1,13 @@
namespace StevesBot.Worker.Discord.Gateway.Events.Data;
internal sealed record ReadyData
{
[JsonPropertyName("v")]
public int Version { get; init; }
[JsonPropertyName("session_id")]
public string SessionId { get; init; } = string.Empty;
[JsonPropertyName("resume_gateway_url")]
public string ResumeGatewayUrl { get; init; } = string.Empty;
}
@@ -0,0 +1,16 @@
namespace StevesBot.Worker.Discord.Gateway.Events.Data;
internal sealed record UpdatePresenceData
{
[JsonPropertyName("since")]
public long? Since { get; init; } = null;
[JsonPropertyName("activities")]
public List<Activity> Activities { get; init; } = [];
[JsonPropertyName("status")]
public string Status { get; init; } = PresenceStatus.Online;
[JsonPropertyName("afk")]
public bool Afk { get; init; }
}
@@ -5,9 +5,3 @@ internal sealed record HelloDiscordEvent : DiscordEvent
[JsonPropertyName("d")] [JsonPropertyName("d")]
public new HelloData Data { get; init; } = new HelloData(); public new HelloData Data { get; init; } = new HelloData();
} }
internal sealed record HelloData
{
[JsonPropertyName("heartbeat_interval")]
public int HeartbeatInterval { get; init; }
}
@@ -16,30 +16,3 @@ internal sealed record IdentifyDiscordEvent : DiscordEvent
}; };
} }
} }
internal sealed record IdentifyData
{
[JsonPropertyName("token")]
public string Token { get; init; } = string.Empty;
[JsonPropertyName("properties")]
public IdentifyProperties Properties { get; init; } = new();
[JsonPropertyName("presence")]
public UpdatePresenceData Presence { get; init; } = new();
[JsonPropertyName("intents")]
public long Intents { get; init; }
}
internal sealed record IdentifyProperties
{
[JsonPropertyName("os")]
public string Os { get; init; } = Environment.OSVersion.ToString();
[JsonPropertyName("browser")]
public string Browser { get; init; } = Assembly.GetExecutingAssembly().GetName().FullName;
[JsonPropertyName("device")]
public string Device { get; init; } = Assembly.GetExecutingAssembly().GetName().FullName;
}
@@ -5,15 +5,3 @@ internal sealed record ReadyDiscordEvent : DispatchDiscordEvent
[JsonPropertyName("d")] [JsonPropertyName("d")]
public new ReadyData Data { get; init; } = new ReadyData(); public new ReadyData Data { get; init; } = new ReadyData();
} }
internal sealed record ReadyData
{
[JsonPropertyName("v")]
public int Version { get; init; }
[JsonPropertyName("session_id")]
public string SessionId { get; init; } = string.Empty;
[JsonPropertyName("resume_gateway_url")]
public string ResumeGatewayUrl { get; init; } = string.Empty;
}
@@ -17,41 +17,3 @@ internal sealed record UpdatePresenceDiscordEvent : DiscordEvent
}; };
} }
} }
internal sealed record UpdatePresenceData
{
[JsonPropertyName("since")]
public long? Since { get; init; } = null;
[JsonPropertyName("activities")]
public List<Activity> Activities { get; init; } = [];
[JsonPropertyName("status")]
public string Status { get; init; } = PresenceStatus.Online;
[JsonPropertyName("afk")]
public bool Afk { get; init; }
}
internal static class PresenceStatus
{
public const string Online = "online";
public const string Idle = "idle";
}
internal sealed record Activity
{
[JsonPropertyName("name")]
public string Name { get; init; } = string.Empty;
[JsonPropertyName("type")]
public int Type { get; init; } = ActivityType.Custom;
[JsonPropertyName("state")]
public string? State { get; init; }
}
internal static class ActivityType
{
public const int Custom = 4;
}
+1
View File
@@ -11,6 +11,7 @@ global using StevesBot.Worker;
global using StevesBot.Worker.Discord; global using StevesBot.Worker.Discord;
global using StevesBot.Worker.Discord.Gateway; global using StevesBot.Worker.Discord.Gateway;
global using StevesBot.Worker.Discord.Gateway.Events; global using StevesBot.Worker.Discord.Gateway.Events;
global using StevesBot.Worker.Discord.Gateway.Events.Data;
global using StevesBot.Worker.Discord.Rest; global using StevesBot.Worker.Discord.Rest;
global using StevesBot.Worker.Discord.Rest.Requests; global using StevesBot.Worker.Discord.Rest.Requests;
global using StevesBot.Worker.Discord.Rest.Responses; global using StevesBot.Worker.Discord.Rest.Responses;