Files
wwdpublic/Content.Server/Toolshed/Commands/Verbs/RunVerbAsCommand.cs
Nemanja ca11938ffd Clean up command perms (#28451)
* Change BanExemption command to AdminFlags.Ban permissions

* Change LOOC to check for Moderator permission

* Change ListVerbs from Admin to Debug AdminFlags

* Change RunVerbAs from Admin to Fun AdminFlags

* More permission changes

* Change GhostKick to Moderator perm

* Clean up command perms

* fuck

---------

Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>

(cherry picked from commit 68992735d81a7709543ab7c6056385b9d3946d75)
2025-07-12 02:20:37 +10:00

61 lines
1.9 KiB
C#

using System.Linq;
using Content.Server.Administration;
using Content.Shared.Administration;
using Content.Shared.Verbs;
using Robust.Shared.Toolshed;
using Robust.Shared.Toolshed.Syntax;
using Robust.Shared.Toolshed.TypeParsers;
namespace Content.Server.Toolshed.Commands.Verbs;
[ToolshedCommand, AdminCommand(AdminFlags.Moderator)]
public sealed class RunVerbAsCommand : ToolshedCommand
{
private SharedVerbSystem? _verb;
[CommandImplementation]
public IEnumerable<NetEntity> RunVerbAs(
IInvocationContext ctx,
[PipedArgument] IEnumerable<NetEntity> input,
EntityUid runner,
string verb
)
{
_verb ??= GetSys<SharedVerbSystem>();
verb = verb.ToLowerInvariant();
foreach (var i in input)
{
if (EntityManager.Deleted(runner) && runner.IsValid())
ctx.ReportError(new DeadEntity(runner));
if (ctx.GetErrors().Any())
yield break;
var eId = EntityManager.GetEntity(i);
var verbs = _verb.GetLocalVerbs(eId, runner, Verb.VerbTypes, true);
// if the "verb name" is actually a verb-type, try run any verb of that type.
var verbType = Verb.VerbTypes.FirstOrDefault(x => x.Name == verb);
if (verbType != null)
{
var verbTy = verbs.FirstOrDefault(v => v.GetType() == verbType);
if (verbTy != null)
{
_verb.ExecuteVerb(verbTy, runner, eId, forced: true);
yield return i;
}
}
foreach (var verbTy in verbs)
{
if (verbTy.Text.ToLowerInvariant() == verb)
{
_verb.ExecuteVerb(verbTy, runner, eId, forced: true);
yield return i;
}
}
}
}
}