diff --git a/TPP.Core/Chat/TwitchChat.cs b/TPP.Core/Chat/TwitchChat.cs index 42e1a402..e4908e07 100644 --- a/TPP.Core/Chat/TwitchChat.cs +++ b/TPP.Core/Chat/TwitchChat.cs @@ -70,7 +70,7 @@ public async Task Join(string userLogin) return JoinResult.StreamOffline; } - await _coStreamChannelsRepo.Add(userLogin); + await _coStreamChannelsRepo.Add(userLogin, user.ProfileImageUrl); await _twitchClient.JoinChannelAsync(userLogin); await _twitchClient.SendMessageAsync(userLogin, "Joined channel, hello!"); diff --git a/TPP.Core/InputFeed.cs b/TPP.Core/InputFeed.cs index 37c3f719..c1c77862 100644 --- a/TPP.Core/InputFeed.cs +++ b/TPP.Core/InputFeed.cs @@ -48,12 +48,12 @@ public AnarchyInputFeed( _fps = fps; } - public async Task Enqueue(InputSet inputSet, User user, string? channel) + public async Task Enqueue(InputSet inputSet, User user, string? channel, string? channelImageUrl) { QueuedInput queuedInput = new(_inputIdSeq++, inputSet); bool enqueued = _inputBufferQueue.Enqueue(queuedInput); if (enqueued) - await _overlayConnection.Send(new NewAnarchyInput(queuedInput.InputId, queuedInput.InputSet, user, channel), + await _overlayConnection.Send(new NewAnarchyInput(queuedInput.InputId, queuedInput.InputSet, user, channel, channelImageUrl), CancellationToken.None); } diff --git a/TPP.Core/Modes/Runmode.cs b/TPP.Core/Modes/Runmode.cs index 95449604..4f8d3edc 100644 --- a/TPP.Core/Modes/Runmode.cs +++ b/TPP.Core/Modes/Runmode.cs @@ -26,6 +26,7 @@ public sealed class Runmode : IWithLifecycle private readonly IRunCounterRepo _runCounterRepo; private readonly IInputLogRepo _inputLogRepo; private readonly IInputSidePicksRepo _inputSidePicksRepo; + private readonly ICoStreamChannelsRepo _coStreamChannelsRepo; private IInputParser _inputParser; private readonly InputServer _inputServer; private readonly WebsocketBroadcastServer _broadcastServer; @@ -48,6 +49,7 @@ public Runmode(ILoggerFactory loggerFactory, BaseConfig baseConfig, _runCounterRepo = repos.RunCounterRepo; _inputLogRepo = repos.InputLogRepo; _inputSidePicksRepo = repos.InputSidePicksRepo; + _coStreamChannelsRepo = repos.CoStreamChannelsRepo; (_broadcastServer, _overlayConnection) = Setups.SetUpOverlayServer(loggerFactory, baseConfig.OverlayWebsocketHost, baseConfig.OverlayWebsocketPort); _modeBase = new ModeBase( @@ -180,9 +182,14 @@ private async Task ProcessMessage(IChat chat, Message message) await ProcessPotentialSidedInputs(chat, message, input); foreach (InputSet inputSet in input.InputSets) if (message.MessageSource is MessageSource.SecondaryChat secondaryChat) - await _anarchyInputFeed.Enqueue(inputSet, message.User, secondaryChat.ChannelName); + { + string? channelImageUrl = await _coStreamChannelsRepo.GetChannelImageUrl(secondaryChat.ChannelName); + await _anarchyInputFeed.Enqueue(inputSet, message.User, secondaryChat.ChannelName, channelImageUrl); + } else - await _anarchyInputFeed.Enqueue(inputSet, message.User, null); + { + await _anarchyInputFeed.Enqueue(inputSet, message.User, null, null); + } if (!_muteInputsToken.Muted) await CollectRunStatistics(message.User, input, rawInput: potentialInput); return true; diff --git a/TPP.Core/Overlay/Events/RunInputEvents.cs b/TPP.Core/Overlay/Events/RunInputEvents.cs index 0174df30..675728c1 100644 --- a/TPP.Core/Overlay/Events/RunInputEvents.cs +++ b/TPP.Core/Overlay/Events/RunInputEvents.cs @@ -22,8 +22,9 @@ public sealed class NewAnarchyInput : IOverlayEvent [DataMember(Name = "side", EmitDefaultValue = false)] public string? Side { get; set; } [DataMember(Name = "direct", EmitDefaultValue = false)] public bool? Direct { get; set; } [DataMember(Name = "channel")] public string? Channel { get; set; } + [DataMember(Name = "channel_image_url")] public string? ChannelImageUrl { get; set; } - public NewAnarchyInput(int inputId, InputSet inputSet, User user, string? channel) + public NewAnarchyInput(int inputId, InputSet inputSet, User user, string? channel, string? channelImageUrl) { IEnumerable InputsForOverlay() => inputSet.Inputs.Where(i => i is not SideInput); ButtonSet = InputsForOverlay().Select(i => i.ButtonName).ToImmutableList(); @@ -36,6 +37,7 @@ public NewAnarchyInput(int inputId, InputSet inputSet, User user, string? channe Side = (sideInput?.Side)?.GetSideString(); Direct = sideInput?.Direct; Channel = channel; + ChannelImageUrl = channelImageUrl; } } diff --git a/TPP.Persistence.MongoDB/Repos/CoStreamChannelsRepo.cs b/TPP.Persistence.MongoDB/Repos/CoStreamChannelsRepo.cs index 694d08aa..f5115aec 100644 --- a/TPP.Persistence.MongoDB/Repos/CoStreamChannelsRepo.cs +++ b/TPP.Persistence.MongoDB/Repos/CoStreamChannelsRepo.cs @@ -23,29 +23,40 @@ public CoStreamChannelsRepo(IMongoDatabase database) } public Task IsJoined(string channelName) => - Collection.Find(doc => doc["_id"] == channelName).AnyAsync(); + Collection.Find(doc => doc["_id"] == channelName.ToLower()).AnyAsync(); + + public async Task GetChannelImageUrl(string channelName) + { + BsonDocument? doc = await Collection.Find(doc => doc["_id"] == channelName.ToLower()).FirstOrDefaultAsync(); + return doc?["profile_image_url"].AsString; + } public async Task> GetJoinedChannels() => (await Collection.Find(FilterDefinition.Empty).ToListAsync()) .Select(doc => doc["_id"].AsString).ToImmutableHashSet(); - public async Task Add(string channelName) + public async Task Add(string channelName, string? profileImageUrl) { - await Collection.InsertOneAsync(new BsonDocument { ["_id"] = channelName }); - await LogJoin(channelName); + await Collection.InsertOneAsync(new BsonDocument + { + ["_id"] = channelName.ToLower(), + ["profile_image_url"] = profileImageUrl + }); + await LogJoin(channelName.ToLower(), profileImageUrl); } public async Task Remove(string channelName) { - await Collection.DeleteOneAsync(doc => doc["_id"] == channelName); - await LogLeave(channelName); + await Collection.DeleteOneAsync(doc => doc["_id"] == channelName.ToLower()); + await LogLeave(channelName.ToLower()); } - private Task LogJoin(string channelName) => + private Task LogJoin(string channelName, string? profileImageUrl) => LogCollection.InsertOneAsync(new BsonDocument { ["_id"] = new ObjectId(), ["channel"] = channelName, + ["profile_image_url"] = profileImageUrl, ["type"] = "join", ["timestamp"] = SystemClock.Instance.GetCurrentInstant().ToDateTimeUtc() }); diff --git a/TPP.Persistence/ICoStreamChannelsRepo.cs b/TPP.Persistence/ICoStreamChannelsRepo.cs index 0855f310..594ae75c 100644 --- a/TPP.Persistence/ICoStreamChannelsRepo.cs +++ b/TPP.Persistence/ICoStreamChannelsRepo.cs @@ -6,7 +6,8 @@ namespace TPP.Persistence; public interface ICoStreamChannelsRepo { public Task IsJoined(string channelName); + public Task GetChannelImageUrl(string channelName); public Task> GetJoinedChannels(); - public Task Add(string channelName); + public Task Add(string channelName, string? profileImageUrl); public Task Remove(string channelName); }