Skip to content

Commit

Permalink
Merge branch 'refactor/directory-structure' into issue/14-website
Browse files Browse the repository at this point in the history
  • Loading branch information
feselene committed Oct 10, 2024
2 parents 387c184 + 7e6245c commit d7840f1
Show file tree
Hide file tree
Showing 26 changed files with 75 additions and 71 deletions.
Binary file modified directory_structure.txt
Binary file not shown.
10 changes: 5 additions & 5 deletions src/Core/Chat/TwitchChat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public sealed class TwitchChat : IChat, IChatModeChanger, IExecutor
private readonly TwitchChatSender _twitchChatSender;
private readonly TwitchChatModeChanger _twitchChatModeChanger;
private readonly TwitchChatExecutor _twitchChatExecutor;
public TwitchEventSubChat TwitchEventSubChat { get; }
public EventSubChat EventSubChat { get; }

public TwitchChat(
string name,
Expand Down Expand Up @@ -55,12 +55,12 @@ public TwitchChat(
chatConfig.AppClientId,
chatConfig.AppClientSecret);
_twitchChatSender = new TwitchChatSender(loggerFactory, TwitchApi, chatConfig, useTwitchReplies);
TwitchEventSubChat = new TwitchEventSubChat(loggerFactory, clock, TwitchApi, userRepo,
EventSubChat = new EventSubChat(loggerFactory, clock, TwitchApi, userRepo,
subscriptionProcessor, overlayConnection, _twitchChatSender,
chatConfig.ChannelId, chatConfig.UserId,
chatConfig.CoStreamInputsEnabled, chatConfig.CoStreamInputsOnlyLive, coStreamChannelsRepo);

TwitchEventSubChat.IncomingMessage += MessageReceived;
EventSubChat.IncomingMessage += MessageReceived;
_twitchChatModeChanger = new TwitchChatModeChanger(
loggerFactory.CreateLogger<TwitchChatModeChanger>(), TwitchApi, chatConfig);
_twitchChatExecutor = new TwitchChatExecutor(loggerFactory.CreateLogger<TwitchChatExecutor>(),
Expand All @@ -78,11 +78,11 @@ public async Task Start(CancellationToken cancellationToken)
_logger.LogWarning("TwitchAPI problem detected: {Problem}", problem);

List<Task> tasks = [];
tasks.Add(TwitchEventSubChat.Start(cancellationToken));
tasks.Add(EventSubChat.Start(cancellationToken));
await TaskUtils.WhenAllFastExit(tasks);

await _twitchChatSender.DisposeAsync();
TwitchEventSubChat.IncomingMessage -= MessageReceived;
EventSubChat.IncomingMessage -= MessageReceived;
_logger.LogDebug("twitch chat is now fully shut down");
}

Expand Down
12 changes: 6 additions & 6 deletions src/Core/Chat/TwitchEventSubChat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
using Core.Overlay.Events;
using Core.Utils;
using Persistence;
using TwitchEventSub;
using TwitchEventSub.Notifications;
using EventSub;
using EventSub.Notifications;
using TwitchLib.Api.Core.Exceptions;
using TwitchLib.Api.Helix.Models.Streams.GetStreams;
using TwitchLib.Api.Helix.Models.Users.GetUsers;
Expand All @@ -25,11 +25,11 @@

namespace Core.Chat;

public partial class TwitchEventSubChat : IWithLifecycle, IMessageSource
public partial class EventSubChat : IWithLifecycle, IMessageSource
{
public event EventHandler<MessageEventArgs>? IncomingMessage;

private readonly ILogger<TwitchEventSubChat> _logger;
private readonly ILogger<EventSubChat> _logger;
private readonly TwitchApi _twitchApi;
private readonly IClock _clock;
private readonly IUserRepo _userRepo;
Expand All @@ -50,7 +50,7 @@ public partial class TwitchEventSubChat : IWithLifecycle, IMessageSource
private readonly Dictionary<User, Instant> _lastInputPerUser = new();
private Session? _session;

public TwitchEventSubChat(
public EventSubChat(
ILoggerFactory loggerFactory,
IClock clock,
TwitchApi twitchApi,
Expand All @@ -64,7 +64,7 @@ public TwitchEventSubChat(
bool coStreamInputsOnlyLive,
ICoStreamChannelsRepo coStreamChannelsRepo)
{
_logger = loggerFactory.CreateLogger<TwitchEventSubChat>();
_logger = loggerFactory.CreateLogger<EventSubChat>();
_twitchApi = twitchApi;
_clock = clock;
_userRepo = userRepo;
Expand Down
18 changes: 9 additions & 9 deletions src/Core/Commands/Definitions/JoinChatCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public async Task<CommandResult> JoinChannel(CommandContext context)
{
if (context.Source is not TwitchChat twitchChat)
return new CommandResult { Response = "Having the bot join your channel is not supported from this chat" };
TwitchEventSubChat.JoinResult result = await twitchChat.TwitchEventSubChat.Join(context.Message.User.Id);
EventSubChat.JoinResult result = await twitchChat.EventSubChat.Join(context.Message.User.Id);
string response = result switch
{
TwitchEventSubChat.JoinResult.Ok => "Successfully joined channel",
TwitchEventSubChat.JoinResult.NotEnabled => "Channel joining is currently not enabled",
TwitchEventSubChat.JoinResult.AlreadyJoined => "Already joined",
TwitchEventSubChat.JoinResult.UserNotFound => "You don't exist according to Twitch",
TwitchEventSubChat.JoinResult.StreamOffline => "You are not live",
EventSubChat.JoinResult.Ok => "Successfully joined channel",
EventSubChat.JoinResult.NotEnabled => "Channel joining is currently not enabled",
EventSubChat.JoinResult.AlreadyJoined => "Already joined",
EventSubChat.JoinResult.UserNotFound => "You don't exist according to Twitch",
EventSubChat.JoinResult.StreamOffline => "You are not live",
};
return new CommandResult { Response = response };
}
Expand All @@ -47,11 +47,11 @@ public async Task<CommandResult> LeaveChannel(CommandContext context)
{
if (context.Source is not TwitchChat twitchChat)
return new CommandResult { Response = "Having the bot leave your channel is not supported from this chat" };
TwitchEventSubChat.LeaveResult result = await twitchChat.TwitchEventSubChat.Leave(context.Message.User.Id);
EventSubChat.LeaveResult result = await twitchChat.EventSubChat.Leave(context.Message.User.Id);
string response = result switch
{
TwitchEventSubChat.LeaveResult.Ok => "Successfully left channel",
TwitchEventSubChat.LeaveResult.NotJoined => "Not joined",
EventSubChat.LeaveResult.Ok => "Successfully left channel",
EventSubChat.LeaveResult.NotJoined => "Not joined",
};
return new CommandResult { Response = response };
}
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
<ProjectReference Include="..\Inputting\Inputting.csproj" />
<ProjectReference Include="..\Match\Match.csproj" />
<ProjectReference Include="..\PersistenceMongoDB\PersistenceMongoDB.csproj" />
<ProjectReference Include="..\TwitchEventSub\TwitchEventSub.csproj" />
<ProjectReference Include="..\EventSub\EventSub.csproj" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="..\Resources\**\*" />
<EmbeddedResource Include="Resources\**\*" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Core/TwitchApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Microsoft.Extensions.Logging;
using NodaTime;
using Core.Chat;
using TwitchEventSub;
using EventSub;
using TwitchLib.Api;
using TwitchLib.Api.Auth;
using TwitchLib.Api.Core.Enums;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Text.Json.Serialization;
using Common;

namespace TwitchEventSub;
namespace EventSub;

/// <summary>
/// Custom json converter that supports serializing and deserializing enums to and from the string each member value
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
using Microsoft.Extensions.Logging;
using NodaTime;
using Common.Utils;
using TwitchEventSub.Messages;
using static TwitchEventSub.Parsing;
using EventSub.Messages;
using static EventSub.Parsing;

namespace TwitchEventSub;
namespace EventSub;

internal record WebsocketChangeover(ClientWebSocket NewWebSocket, SessionWelcome Welcome);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text.Json;

namespace TwitchEventSub;
namespace EventSub;

public static class EventSubExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TwitchEventSub.Messages;
namespace EventSub.Messages;

public class SessionKeepalive(Metadata metadata, SessionKeepalive.KeepalivePayload payload)
: Message<Metadata, SessionKeepalive.KeepalivePayload>(metadata, payload), IHasMessageType
Expand Down
2 changes: 1 addition & 1 deletion src/TwitchEventSub/Models.cs → src/EventSub/Models.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using NodaTime;

namespace TwitchEventSub;
namespace EventSub;

public record Metadata(
string MessageId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Collections.Immutable;
using System.Linq;
using TwitchEventSub.Messages;
using EventSub.Messages;

namespace TwitchEventSub.Notifications;
namespace EventSub.Notifications;

using static ChannelChatMessage;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using TwitchEventSub.Messages;
using EventSub.Messages;

namespace TwitchEventSub.Notifications;
namespace EventSub.Notifications;

using static ChannelChatSettingsUpdate;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using NodaTime;
using TwitchEventSub.Messages;
using EventSub.Messages;

namespace TwitchEventSub.Notifications;
namespace EventSub.Notifications;

using static ChannelFollow;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Runtime.Serialization;
using TwitchEventSub.Messages;
using EventSub.Messages;

namespace TwitchEventSub.Notifications;
namespace EventSub.Notifications;

using static ChannelSubscribe;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using TwitchEventSub.Messages;
using EventSub.Messages;

namespace TwitchEventSub.Notifications;
namespace EventSub.Notifications;

using static ChannelSubscriptionGift;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Linq;
using TwitchEventSub.Messages;
using EventSub.Messages;

namespace TwitchEventSub.Notifications;
namespace EventSub.Notifications;

using static ChannelSubscriptionMessage;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using TwitchEventSub.Messages;
using EventSub.Messages;

namespace TwitchEventSub.Notifications;
namespace EventSub.Notifications;

using static UserWhisperMessage;

Expand Down
6 changes: 3 additions & 3 deletions src/TwitchEventSub/Parsing.cs → src/EventSub/Parsing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using NodaTime.Serialization.SystemTextJson;
using TwitchEventSub.Messages;
using TwitchEventSub.Notifications;
using EventSub.Messages;
using EventSub.Notifications;

namespace TwitchEventSub;
namespace EventSub;

public static class Parsing
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using NodaTime;
using NUnit.Framework;
using TwitchEventSub.Notifications;
using EventSub.Notifications;

namespace TwitchEventSub.Tests;
namespace EventSub.Tests;

/// <summary>
/// Tests that the examples from the Twitch documentation page
Expand Down
5 changes: 5 additions & 0 deletions tests/EventSub.Tests/EventSub.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\..\src\EventSub\EventSub.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using NodaTime;
using NUnit.Framework;
using TwitchEventSub.Messages;
using TwitchEventSub.Notifications;
using EventSub.Messages;
using EventSub.Notifications;

namespace TwitchEventSub.Tests;
namespace EventSub.Tests;

/// <summary>
/// Tests that the examples from the Twitch documentation page
Expand Down
28 changes: 16 additions & 12 deletions tests/PersistenceMongoDB.Tests/Repos/MongoTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,23 @@ public abstract class MongoTestBase
public void SetUpMongoClient()
{
CustomSerializers.RegisterAll();
// try to connect to a mongodb running on the default port
MongoClientSettings settings = MongoClientSettings
.FromConnectionString($"mongodb://localhost:27017/?replicaSet={ReplicaSetName}");
settings.LinqProvider = LinqProvider.V3;
_client = new MongoClient(settings);
bool success = _client.ListDatabaseNamesAsync(CancellationToken.None).Wait(TimeSpan.FromSeconds(5));
if (!success)
try
{
throw new AssertionException(
"Failed to connect to a local MongoDB instance running on the default port. " +
"Please start a local MongoDB instance on the default port (27017), " +
$"and make sure it is in replica set mode with a replica set named '{ReplicaSetName}'. " +
"Alternatively, skip these tests using 'dotnet test --filter TestCategory!=IntegrationTest'");
MongoClientSettings settings = MongoClientSettings
.FromConnectionString($"mongodb://localhost:27017/?replicaSet={ReplicaSetName}");
settings.LinqProvider = LinqProvider.V3;
_client = new MongoClient(settings);

// Attempt to list databases with a timeout to confirm connection
bool success = _client.ListDatabaseNamesAsync(CancellationToken.None).Wait(TimeSpan.FromSeconds(5));
if (!success)
{
Assert.Ignore("MongoDB instance not available on localhost:27017. Skipping integration tests.");
}
}
catch (Exception ex)
{
Assert.Ignore($"Skipping tests due to MongoDB connection failure: {ex.Message}");
}
}

Expand Down
5 changes: 0 additions & 5 deletions tests/TwitchEventSub.Tests/TwitchEventSub.Tests.csproj

This file was deleted.

4 changes: 2 additions & 2 deletions tpp-core.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PersistenceMongoDB", "src\P
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PersistenceMongoDB.Tests", "tests\PersistenceMongoDB.Tests\PersistenceMongoDB.Tests.csproj", "{F3C54668-4632-4EF4-A036-D180B2FC619A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TwitchEventSub", "src\TwitchEventSub\TwitchEventSub.csproj", "{8CD23341-8D1D-47CD-B21F-0DA6B233F1DC}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventSub", "src\EventSub\EventSub.csproj", "{8CD23341-8D1D-47CD-B21F-0DA6B233F1DC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TwitchEventSub.Tests", "tests\TwitchEventSub.Tests\TwitchEventSub.Tests.csproj", "{5CB175CD-FF22-4117-AC62-F103C4AC8712}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventSub.Tests", "tests\EventSub.Tests\EventSub.Tests.csproj", "{5CB175CD-FF22-4117-AC62-F103C4AC8712}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down

0 comments on commit d7840f1

Please sign in to comment.