Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Новые команды для gpt? (Запрос Рхупа) #330

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 74 additions & 13 deletions Content.Server/Backmen/Administration/Bwoink/Gpt/GptCommands.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System.Collections;
using System.Linq;
using System.Text.Json;
using Content.Server.Administration.Managers;
using Content.Server.Backmen.Administration.Bwoink.Gpt.Models;
Expand All @@ -10,7 +11,6 @@
using Content.Shared.Humanoid;
using Content.Shared.Mind;
using Content.Shared.Mobs.Systems;
using Content.Shared.Roles.Jobs;
using Robust.Server.Player;

namespace Content.Server.Backmen.Administration.Bwoink.Gpt;
Expand All @@ -24,6 +24,7 @@ public sealed class GptCommands : EntitySystem
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
[Dependency] private readonly IAdminManager _adminManager = default!;
[Dependency] private readonly RoleSystem _roleSystem = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;

public override void Initialize()
{
Expand All @@ -38,7 +39,7 @@ public override void Initialize()
parameters = new
{
@type = "object",
properties = new {}
properties = new { }
}
});
_gptAhelpSystem.AddFunction(new
Expand All @@ -48,7 +49,7 @@ public override void Initialize()
parameters = new
{
@type = "object",
properties = new {}
properties = new { }
}
});
_gptAhelpSystem.AddFunction(new
Expand All @@ -58,7 +59,7 @@ public override void Initialize()
parameters = new
{
@type = "object",
properties = new {}
properties = new { }
}
});
_gptAhelpSystem.AddFunction(new
Expand All @@ -68,7 +69,7 @@ public override void Initialize()
parameters = new
{
@type = "object",
properties = new {}
properties = new { }
}
});
_gptAhelpSystem.AddFunction(new
Expand All @@ -78,7 +79,7 @@ public override void Initialize()
parameters = new
{
@type = "object",
properties = new {}
properties = new { }
}
});
_gptAhelpSystem.AddFunction(new
Expand All @@ -93,10 +94,33 @@ public override void Initialize()
character = new
{
@type = "string",
description = "имя персанажа о котором спрашивают или мой текущий персонаж, например имя персонажа"
description =
"имя персанажа о котором спрашивают или мой текущий персонаж, например имя персонажа"
}
},
required = new []{ "character" }
required = new[] { "character" }
}
});

_gptAhelpSystem.AddFunction(new
{
name = "get_current_gamemode",
description = "получить текущий игровой режим",
parameters = new
{
@type = "object",
properties = new { }
}
});

_gptAhelpSystem.AddFunction(new
{
name = "get_active_gamerules",
description = "получить все активные события",
parameters = new
{
@type = "object",
properties = new { }
}
});
}
Expand All @@ -112,17 +136,21 @@ private void OnFunctionCall(EventGptFunctionCall ev)
switch (fnName)
{
case "get_current_round":
ev.History.Messages.Add(new GptMessageFunction(fnName, new { round = _gameTicker.RoundId, state = _gameTicker.RunLevel.ToString() }));
ev.History.Messages.Add(new GptMessageFunction(fnName,
new { round = _gameTicker.RoundId, state = _gameTicker.RunLevel.ToString() }));
ev.Handled = true;
break;

case "get_current_round_time":
ev.History.Messages.Add(new GptMessageFunction(fnName, new { time = _gameTicker.RoundDuration() }));
ev.Handled = true;
break;

case PlayerInfoFn:
GetPlayerInfo(ev);
ev.Handled = true;
break;

case "get_current_map":
{
var query =
Expand All @@ -140,6 +168,7 @@ private void OnFunctionCall(EventGptFunctionCall ev)
ev.Handled = true;
break;
}

case "get_current_admins":
{
var admins = _adminManager.ActiveAdmins
Expand All @@ -149,12 +178,40 @@ private void OnFunctionCall(EventGptFunctionCall ev)
ev.Handled = true;
break;
}

case PlayerAntagInfoFn:
{
IsPlayerAntag(ev);
ev.Handled = true;
break;
}

case "get_current_gamemode":
{
if (_gameTicker.CurrentPreset == null)
{
return;
}

var gamemode = _gameTicker.CurrentPreset.Alias;

ev.History.Messages.Add(new GptMessageFunction(fnName, new { gamemode }));

ev.Handled = true;
break;
}

case "get_active_gamerules":
{
var activeGameRules = _gameTicker.GetActiveGameRules();
var entityUids = activeGameRules as EntityUid[] ?? activeGameRules.ToArray();
var rulesNames = entityUids.Select(MetaData).Select(comp =>
comp.EntityPrototype!.ID).ToList();
ev.History.Messages.Add(new GptMessageFunction(fnName, new { rulesNames }));

ev.Handled = true;
break;
}
default:
return;
}
Expand All @@ -164,7 +221,8 @@ private void OnFunctionCall(EventGptFunctionCall ev)

private void IsPlayerAntag(EventGptFunctionCall ev)
{
var character = JsonSerializer.Deserialize<GetIsAntagArgs>(ev.Msg.message.function_call?.arguments ?? "{}")?.character;
var character = JsonSerializer.Deserialize<GetIsAntagArgs>(ev.Msg.message.function_call?.arguments ?? "{}")
?.character;
if (string.IsNullOrWhiteSpace(character))
{
ev.History.Messages.Add(new GptMessageFunction(PlayerAntagInfoFn));
Expand All @@ -184,11 +242,13 @@ private void IsPlayerAntag(EventGptFunctionCall ev)
}
}

ev.History.Messages.Add(new GptMessageFunction(PlayerAntagInfoFn, new { matchNames = antag, isAntag = antag.Count > 0 }));
ev.History.Messages.Add(new GptMessageFunction(PlayerAntagInfoFn,
new { matchNames = antag, isAntag = antag.Count > 0 }));
}


private const string PlayerInfoFn = "get_current_char";

private void GetPlayerInfo(EventGptFunctionCall ev)
{
if (!_playerManager.TryGetSessionById(ev.UserId, out var playerSession))
Expand Down Expand Up @@ -222,7 +282,8 @@ true when _mindSystem.TryGetMind(ev.UserId, out var mindId, out var mind) =>
info["desc"] = md.EntityDescription;
}

if (isHaveAttachedEntity && TryComp<HumanoidAppearanceComponent>(attachedEntity, out var humanoidAppearanceComponent))
if (isHaveAttachedEntity &&
TryComp<HumanoidAppearanceComponent>(attachedEntity, out var humanoidAppearanceComponent))
{
info["age"] = humanoidAppearanceComponent.Age;
info["gender"] = humanoidAppearanceComponent.Gender.ToString();
Expand Down
Loading