Skip to content

Commit

Permalink
Merge pull request #93 from DevChatter/benrick/status-dashboard
Browse files Browse the repository at this point in the history
Status Dashboard
  • Loading branch information
benrick authored Feb 17, 2023
2 parents e343b42 + b3b573e commit 03c1abc
Show file tree
Hide file tree
Showing 23 changed files with 251 additions and 152 deletions.
3 changes: 2 additions & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<PackageVersion Include="MiqM.Xceed.Wpf.Toolkit.NETCore" Version="3.5.1.3" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.2" />
<PackageVersion Include="Serilog" Version="2.12.0" />
<PackageVersion Include="Serilog.Extensions.Hosting" Version="5.0.1" />
<PackageVersion Include="Serilog.Extensions.Logging" Version="3.1.0" />
<PackageVersion Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageVersion Include="Serilog.Sinks.RichTextBox.Wpf" Version="1.1.0" />
Expand All @@ -22,7 +23,7 @@
<PackageVersion Include="TwitchLib" Version="3.5.3" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="FluentAssertions" Version="6.9.0" />
<PackageVersion Include="FluentAssertions" Version="6.10.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageVersion Include="Moq" Version="4.18.4" />
<PackageVersion Include="xunit" Version="2.4.2" />
Expand Down
4 changes: 1 addition & 3 deletions src/InteractiveSeven.Core/Chat/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,10 @@ public OnChatCommandReceivedArgs(CommandData commandData)

public class OnConnectedArgs : EventArgs
{
public string Channel { get; }
public string Username { get; }

public OnConnectedArgs(string channel, string username)
public OnConnectedArgs(string username)
{
Channel = channel;
Username = username;
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/InteractiveSeven.Core/ChatBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using InteractiveSeven.Core.IntervalMessages;
using InteractiveSeven.Core.Payments;
using InteractiveSeven.Core.Settings;
using Microsoft.Extensions.Logging;
using Serilog;

namespace InteractiveSeven.Core
{
Expand All @@ -18,7 +18,6 @@ public class ChatBot : INotifyPropertyChanged
private readonly IList<IChatCommand> _commands;
private readonly IntervalMessagingService _intervalMessaging;
private readonly GilBank _gilBank;
private readonly ILogger<ChatBot> _logger;
private bool _isConnected;

private TwitchSettings Settings => TwitchSettings.Instance;
Expand All @@ -34,13 +33,12 @@ public bool IsConnected
}

public ChatBot(IChatClient chatClient, IList<IChatCommand> commands,
IntervalMessagingService intervalMessaging, GilBank gilBank, ILogger<ChatBot> logger)
IntervalMessagingService intervalMessaging, GilBank gilBank)
{
_chatClient = chatClient;
_commands = commands;
_intervalMessaging = intervalMessaging;
_gilBank = gilBank;
_logger = logger;

_chatClient.OnLog += Client_OnLog;
_chatClient.OnJoinedChannel += Client_OnJoinedChannel;
Expand All @@ -56,6 +54,7 @@ public void Connect()
|| string.IsNullOrWhiteSpace(Settings.AccessToken)
|| string.IsNullOrWhiteSpace(Settings.Channel))
{
Log.Error("Cannot Connect. Please confirm that Username, Channel, and Access token are set.");
return;
}

Expand All @@ -67,7 +66,7 @@ public void Connect()
}
catch (Exception e)
{
_logger.LogError(e, "Error Connecting to Twitch");
Log.Error(e, "Error Connecting to Twitch");
}
}

Expand All @@ -87,7 +86,7 @@ private void Client_OnChatCommandReceived(object sender, OnChatCommandReceivedAr
}
catch (Exception exception)
{
_logger.LogError(exception, "Command Error");
Log.Error(exception, "Command Error");
}
}

Expand All @@ -97,6 +96,7 @@ private void Client_OnLog(object sender, OnLogArgs e)

private void Client_OnConnected(object sender, OnConnectedArgs e)
{
Log.Information($"ChatBot connected as {e.Username}");
IsConnected = true;
}

Expand Down Expand Up @@ -126,7 +126,7 @@ private void Client_OnMessageReceived(object sender, OnMessageReceivedArgs e)
}
catch (Exception exception)
{
_logger.LogError(exception, "Error updating account balances.");
Log.Error(exception, "Error updating account balances.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,20 @@
using InteractiveSeven.Core.Data;
using InteractiveSeven.Core.Events;
using InteractiveSeven.Core.Settings;
using Microsoft.Extensions.Logging;
using Serilog;

namespace InteractiveSeven.Core.Commands.Bidding.Naming
{
public class CharacterNameBidding : INotifyPropertyChanged
{
private readonly ILogger<CharacterNameBidding> _logger;
public CharNames CharName { get; }
public string DefaultName { get; }

public ThreadedObservableCollection<CharacterNameBid> NameBids { get; }
= new ThreadedObservableCollection<CharacterNameBid>();
public ThreadedObservableCollection<CharacterNameBid> NameBids { get; } = new();

private readonly object _padlock = new object();

private string GetHighestBid() => NameBids.OrderByDescending(x => x.TotalBits)
.FirstOrDefault()?.Name ?? DefaultName;
private string GetHighestBid() => NameBids.MaxBy(x => x.TotalBits)?.Name ?? DefaultName;

private string _leadingName;
public string LeadingName
Expand All @@ -38,9 +35,8 @@ public string LeadingName

private NameBiddingSettings Settings => ApplicationSettings.Instance.NameBiddingSettings;

public CharacterNameBidding(CharNames charNames, ILogger<CharacterNameBidding> logger, bool withDefault = true)
public CharacterNameBidding(CharNames charNames, bool withDefault = true)
{
_logger = logger;
CharName = charNames;
DefaultName = charNames.DefaultName;
_leadingName = charNames.DefaultName;
Expand Down Expand Up @@ -107,7 +103,7 @@ public void HandleNameVote(NameVoteReceived e)
}
catch (Exception exception)
{
_logger.LogError(exception, "Failed to record name bid.");
Log.Logger.Error(exception, "Failed to record name bid.");
}
}

Expand Down
12 changes: 7 additions & 5 deletions src/InteractiveSeven.Core/Data/GameDatabase.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
using System.Collections.Generic;
using InteractiveSeven.Core.FinalFantasy.Models;
using Serilog;

namespace InteractiveSeven.Core.Data
{
public class GameDatabase
{
private readonly IGameDatabaseLoader _loader;
private bool _isLoaded = false;
private readonly List<Accessory> _accessoryDatabase = new List<Accessory>();
private readonly List<Armlet> _armletDatabase = new List<Armlet>();
private readonly List<Materia> _materiaDatabase = new List<Materia>();
private readonly List<Weapon> _weaponDatabase = new List<Weapon>();
private readonly List<Accessory> _accessoryDatabase = new();
private readonly List<Armlet> _armletDatabase = new();
private readonly List<Materia> _materiaDatabase = new();
private readonly List<Weapon> _weaponDatabase = new();

private readonly object _padlock = new object();

Expand All @@ -21,6 +22,7 @@ public GameDatabase(IGameDatabaseLoader loader)

public void LoadData()
{
Log.Logger.Information("Loading game metadata from Kernel");
if (!_isLoaded)
{
lock (_padlock)
Expand Down Expand Up @@ -77,4 +79,4 @@ public IReadOnlyList<Weapon> WeaponDatabase
}
}
}
}
}
1 change: 1 addition & 0 deletions src/InteractiveSeven.Core/InteractiveSeven.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<PackageReference Include="Autofac.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="Serilog" />
<PackageReference Include="System.Configuration.ConfigurationManager" />
<PackageReference Include="Shojy.FF7.Elena" />
</ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions src/InteractiveSeven.Core/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ public MainWindowViewModel(MenuColorViewModel menuColorViewModel,
NameBiddingViewModel nameBiddingViewModel,
SettingsViewModel settingsViewModel,
ThemeViewModel themeViewModel,
MonitorViewModel monitorViewModel,
ChatBot chatBot)
{
MenuColorViewModel = menuColorViewModel;
NameBiddingViewModel = nameBiddingViewModel;
SettingsViewModel = settingsViewModel;
ThemeViewModel = themeViewModel;
MonitorViewModel = monitorViewModel;
StreamOverlayViewModel = streamOverlayViewModel;
ChatBot = chatBot;
ConnectBotCommand = new BotConnectCommand(chatBot);
Expand All @@ -30,6 +32,7 @@ public MainWindowViewModel(MenuColorViewModel menuColorViewModel,
public StreamOverlayViewModel StreamOverlayViewModel { get; }
public SettingsViewModel SettingsViewModel { get; }
public ThemeViewModel ThemeViewModel { get; }
public MonitorViewModel MonitorViewModel { get; }
public ChatBot ChatBot { get; }
}
}
43 changes: 43 additions & 0 deletions src/InteractiveSeven.Core/ViewModels/MonitorViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace InteractiveSeven.Core.ViewModels
{
public class MonitorViewModel : INotifyPropertyChanged
{
private string _processName;
public string ProcessName
{
get => string.IsNullOrEmpty(_processName) ? "None" : _processName;
set
{
if (_processName != value)
{
_processName = value;
OnPropertyChanged();
}
}
}

private bool _isConnected;
public bool IsConnected
{
get => _isConnected;
set
{
if (_isConnected != value)
{
_isConnected = value;
OnPropertyChanged();
}
}
}

public event PropertyChangedEventHandler PropertyChanged;

protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
19 changes: 8 additions & 11 deletions src/InteractiveSeven.Core/ViewModels/NameBiddingViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using InteractiveSeven.Core.Services;
using InteractiveSeven.Core.Settings;
using Microsoft.Extensions.Logging;
using Serilog;

namespace InteractiveSeven.Core.ViewModels
{
Expand All @@ -22,8 +23,6 @@ public class NameBiddingViewModel
private readonly IDataStore<CharacterNameBid> _dataStore;
private readonly IDialogService _dialogService;
private readonly IStatusHubEmitter _statusHubEmitter;
private readonly ILogger<NameBiddingViewModel> _logger;
private readonly ILogger<CharacterNameBidding> _charNameBiddingLogger;

public ThreadedObservableCollection<CharacterNameBidding> CharacterNameBiddings { get; set; } = new ();

Expand All @@ -45,8 +44,6 @@ public NameBiddingViewModel(INameAccessor nameAccessor, IChatClient chatClient,
_dataStore = dataStore;
_dialogService = dialogService;
_statusHubEmitter = statusHubEmitter;
_logger = logger;
_charNameBiddingLogger = charNameBiddingLogger;

ResetDataCommand = new SimpleCommand(x =>
{
Expand All @@ -58,7 +55,7 @@ public NameBiddingViewModel(INameAccessor nameAccessor, IChatClient chatClient,

foreach (CharNames charName in CharNames.Core)
{
CharacterNameBiddings.Add(new CharacterNameBidding(charName, _charNameBiddingLogger));
CharacterNameBiddings.Add(new CharacterNameBidding(charName));
}
}

Expand All @@ -69,7 +66,7 @@ public void Load(List<CharacterNameBid> nameBids)
CharacterNameBiddings.Clear();
foreach (CharNames charName in CharNames.Core)
{
var nameBidding = new CharacterNameBidding(charName, _charNameBiddingLogger, false);
var nameBidding = new CharacterNameBidding(charName, false);

var namesForChar = nameBids.Where(x => x.CharNameId == charName.Id)
.OrderByDescending(x => x.TotalBits);
Expand All @@ -92,7 +89,7 @@ public void Reset()
CharacterNameBiddings.Clear();
foreach (CharNames charName in CharNames.Core)
{
CharacterNameBiddings.Add(new CharacterNameBidding(charName, _charNameBiddingLogger));
CharacterNameBiddings.Add(new CharacterNameBidding(charName));
}
_dataStore.SaveData(CharacterNameBiddings.SelectMany(cnb => cnb.NameBids).ToList());
HandleNameRefresh(new RefreshEvent());
Expand All @@ -109,7 +106,7 @@ private void HandleNameRefresh(RefreshEvent e)
}
catch (Exception exception)
{
_logger.LogError(exception, "Failed to refresh names.");
Log.Logger.Error(exception, "Failed to refresh names.");
}
}

Expand All @@ -124,7 +121,7 @@ private void HandleTopNameChange(TopNameChanged e)
}
catch (Exception exception)
{
_logger.LogError(exception, "Failed to update top name.");
Log.Logger.Error(exception, "Failed to update top name.");
}
}

Expand All @@ -137,7 +134,7 @@ private void HandleNameVote(NameVoteReceived e)
}
catch (Exception exception)
{
_logger.LogError(exception, "Failed to record name vote and save.");
Log.Logger.Error(exception, "Failed to record name vote and save.");
}
}

Expand All @@ -153,7 +150,7 @@ private void HandleNameRemoval(RemovingName e)
}
catch (Exception exception)
{
_logger.LogError(exception, "Failed to remove Name.");
Log.Logger.Error(exception, "Failed to remove Name.");
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/InteractiveSeven.Twitch/Chat/TwitchChatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using InteractiveSeven.Core.Chat;
using InteractiveSeven.Core.Settings;
using InteractiveSeven.Twitch.Events;
using Serilog;
using TwitchLib.Client.Interfaces;
using TwitchLib.Client.Models;

Expand Down Expand Up @@ -38,13 +39,15 @@ public void SendMessage(string channel, string message)

public void Connect(string username, string accessToken, string channel)
{
Log.Information($"Trying to connect to Twitch channel {channel} as {username}");
ConnectionCredentials credentials = new ConnectionCredentials(Settings.Username, Settings.AccessToken);
_twitchClient.Initialize(credentials, Settings.Channel);
_twitchClient.Connect();
}

public void Disconnect()
{
Log.Information("Disconnecting from Twitch");
_twitchClient.Disconnect();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/InteractiveSeven.Twitch/Events/EventExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static OnChatCommandReceivedArgs ToCore(this TwitchOnChatCommandReceivedA

public static OnConnectedArgs ToCore(this TwitchOnConnectedArgs e)
{
return new OnConnectedArgs(e.AutoJoinChannel, e.BotUsername);
return new OnConnectedArgs(e.BotUsername);
}

public static OnDisconnectedEventArgs ToCore(this TwitchOnDisconnectedEventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion src/InteractiveSeven.Web/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using InteractiveSeven.Web.Hubs;
using InteractiveSeven.Web.Hubs;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
Expand Down
Loading

0 comments on commit 03c1abc

Please sign in to comment.