Skip to content

Commit

Permalink
Requirement for live agent (#38)
Browse files Browse the repository at this point in the history
* Create new requirements file to run abilities only if agent paw exists

* Remove debug print statements

* Remove blank lines

* Add requirement for Lightneuron implant

* Adjust blank lines

* Fix syntax
  • Loading branch information
kaylakraines authored Oct 25, 2023
1 parent c4b14e2 commit ee8f3c9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/requirements/check_lightneuron_registered.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from plugins.stockpile.app.requirements.base_requirement import BaseRequirement
from app.utility.base_service import BaseService


class Requirement(BaseRequirement):

async def enforce(self, link, operation):
"""
Given a link and the current operation, ensure the ability will only run if the
agent with the given ID/PAW is listed in the Agents tab on the Caldera Server GUI.
:param link
:param operation
:return: True if it complies, False if it doesn't
"""
agent_paws = [agent.paw for agent in BaseService.get_service('data_svc').ram['agents']]
for uf in link.used:
# Remove the "@" character if it appears in the given fact
# In order to accomodate the Lightneuron implant ID
if uf.value.replace("@", "") in agent_paws:
return True
return False
17 changes: 17 additions & 0 deletions app/requirements/check_registered.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from plugins.stockpile.app.requirements.base_requirement import BaseRequirement


class Requirement(BaseRequirement):

async def enforce(self, link, operation):
"""
Given a link and the current operation, ensure will only run if the agent with the given ID/PAW is alive.
:param link
:param operation
:return: True if it complies, False if it doesn't
"""
agent_paws = [agent.paw for agent in await operation.active_agents()]
for uf in link.used:
if uf.value in agent_paws:
return True
return False

0 comments on commit ee8f3c9

Please sign in to comment.