2024-06-16 20:19:31 -04:00
|
|
|
using CommonSocketLibrary.Abstract;
|
|
|
|
using CommonSocketLibrary.Common;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Serilog;
|
|
|
|
using TwitchChatTTS.Chat.Commands.Parameters;
|
2024-07-16 00:48:55 -04:00
|
|
|
using TwitchChatTTS.Hermes.Socket;
|
2024-06-24 18:11:36 -04:00
|
|
|
using TwitchChatTTS.OBS.Socket.Data;
|
|
|
|
using TwitchChatTTS.OBS.Socket.Manager;
|
2024-06-16 20:19:31 -04:00
|
|
|
using TwitchLib.Client.Models;
|
|
|
|
|
|
|
|
namespace TwitchChatTTS.Chat.Commands
|
|
|
|
{
|
|
|
|
public class OBSCommand : ChatCommand
|
|
|
|
{
|
2024-06-24 18:11:36 -04:00
|
|
|
private readonly User _user;
|
|
|
|
private readonly OBSManager _manager;
|
|
|
|
private readonly ILogger _logger;
|
2024-06-16 20:19:31 -04:00
|
|
|
|
|
|
|
public OBSCommand(
|
|
|
|
[FromKeyedServices("parameter-unvalidated")] ChatCommandParameter unvalidatedParameter,
|
2024-06-24 18:11:36 -04:00
|
|
|
User user,
|
|
|
|
OBSManager manager,
|
2024-06-16 20:19:31 -04:00
|
|
|
ILogger logger
|
|
|
|
) : base("obs", "Various obs commands.")
|
|
|
|
{
|
2024-06-24 18:11:36 -04:00
|
|
|
_user = user;
|
|
|
|
_manager = manager;
|
2024-06-16 20:19:31 -04:00
|
|
|
_logger = logger;
|
|
|
|
|
|
|
|
AddParameter(unvalidatedParameter);
|
2024-07-16 00:48:55 -04:00
|
|
|
AddParameter(unvalidatedParameter, optional: true);
|
|
|
|
AddParameter(unvalidatedParameter, optional: true);
|
|
|
|
AddParameter(unvalidatedParameter, optional: true);
|
2024-06-16 20:19:31 -04:00
|
|
|
}
|
|
|
|
|
2024-07-16 00:48:55 -04:00
|
|
|
public override async Task<bool> CheckDefaultPermissions(ChatMessage message)
|
2024-06-16 20:19:31 -04:00
|
|
|
{
|
|
|
|
return message.IsModerator || message.IsBroadcaster;
|
|
|
|
}
|
|
|
|
|
2024-07-16 00:48:55 -04:00
|
|
|
public override async Task Execute(IList<string> args, ChatMessage message, HermesSocketClient client)
|
2024-06-16 20:19:31 -04:00
|
|
|
{
|
2024-06-24 18:11:36 -04:00
|
|
|
if (_user == null || _user.VoicesAvailable == null)
|
2024-06-16 20:19:31 -04:00
|
|
|
return;
|
|
|
|
|
2024-07-06 23:42:33 -04:00
|
|
|
var action = args[0].ToLower();
|
2024-06-16 20:19:31 -04:00
|
|
|
|
2024-06-24 18:11:36 -04:00
|
|
|
switch (action)
|
|
|
|
{
|
2024-06-16 20:19:31 -04:00
|
|
|
case "get_scene_item_id":
|
2024-07-06 23:42:33 -04:00
|
|
|
if (args.Count < 3)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_logger.Debug($"Getting scene item id via chat command [args: {string.Join(" ", args)}]");
|
|
|
|
await _manager.Send(new RequestMessage("GetSceneItemId", string.Empty, new Dictionary<string, object>() { { "sceneName", args[1] }, { "sourceName", args[2] } }));
|
2024-06-24 18:11:36 -04:00
|
|
|
break;
|
2024-06-16 20:19:31 -04:00
|
|
|
case "transform":
|
2024-07-06 23:42:33 -04:00
|
|
|
if (args.Count < 5)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_logger.Debug($"Getting scene item transformation data via chat command [args: {string.Join(" ", args)}]");
|
2024-06-24 18:11:36 -04:00
|
|
|
await _manager.UpdateTransformation(args[1], args[2], (d) =>
|
2024-06-16 20:19:31 -04:00
|
|
|
{
|
2024-07-06 23:42:33 -04:00
|
|
|
if (args[3].ToLower() == "rotation")
|
|
|
|
d.Rotation = int.Parse(args[4]);
|
|
|
|
else if (args[3].ToLower() == "x")
|
|
|
|
d.Rotation = int.Parse(args[4]);
|
|
|
|
else if (args[3].ToLower() == "y")
|
|
|
|
d.PositionY = int.Parse(args[4]);
|
2024-06-16 20:19:31 -04:00
|
|
|
});
|
2024-06-24 18:11:36 -04:00
|
|
|
break;
|
2024-07-06 23:42:33 -04:00
|
|
|
case "sleep":
|
|
|
|
if (args.Count < 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_logger.Debug($"Sending OBS to sleep via chat command [args: {string.Join(" ", args)}]");
|
|
|
|
await _manager.Send(new RequestMessage("Sleep", string.Empty, new Dictionary<string, object>() { { "sleepMillis", int.Parse(args[1]) } }));
|
|
|
|
break;
|
|
|
|
case "visibility":
|
|
|
|
if (args.Count < 4)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_logger.Debug($"Updating scene item visibility via chat command [args: {string.Join(" ", args)}]");
|
|
|
|
await _manager.UpdateSceneItemVisibility(args[1], args[2], args[3].ToLower() == "true");
|
2024-06-24 18:11:36 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2024-06-16 20:19:31 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|