From 7d6ef635de7251beb8b26fb53617cd8a4361b2bf Mon Sep 17 00:00:00 2001 From: JarbasAI <33701864+JarbasAl@users.noreply.github.com> Date: Sun, 17 Nov 2024 18:37:43 +0000 Subject: [PATCH] fix: alias overwrite ... (#18) * feat: add dialog * fix: alias overwrite :facepalm: * fix: shell args --- __init__.py | 19 +++++++++++-------- locale/en-us/running.dialog | 1 + translations/en-us/dialogs.json | 5 +++++ 3 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 locale/en-us/running.dialog create mode 100644 translations/en-us/dialogs.json diff --git a/__init__.py b/__init__.py index 397d788..8fc52cc 100644 --- a/__init__.py +++ b/__init__.py @@ -12,14 +12,16 @@ # See the License for the specific language governing permissions and # limitations under the License. -from pwd import getpwnam import os +import shlex import subprocess +from pwd import getpwnam from ovos_utils.log import LOG -from ovos_workshop.skills import OVOSSkill -from ovos_workshop.intents import IntentBuilder + from ovos_workshop.decorators import intent_handler +from ovos_workshop.intents import IntentBuilder +from ovos_workshop.skills import OVOSSkill def set_user(uid, gid): @@ -31,10 +33,10 @@ def set_user(uid, gid): class CmdSkill(OVOSSkill): def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) self.uid = None self.gid = None self.alias = {} + super().__init__(*args, **kwargs) def initialize(self): user = self.settings.get('user') @@ -52,11 +54,12 @@ def initialize(self): @intent_handler(IntentBuilder('RunScriptCommandIntent') .require('Script').require('Run')) def run(self, message): - self.acknowledge() - script = message.data.get('Script') - script = self.alias.get(script, script) + alias = message.data.get('Script') + self.speak_dialog("running", {"alias": alias}) + script = self.alias[alias] + LOG.info(f"alias: {alias} | command: {script}") shell = self.settings.get('shell', True) - args = script.split(' ') if shell else script + args = script if shell else shlex.split(script) try: LOG.info(f'Running {args}') if self.uid and self.gid: diff --git a/locale/en-us/running.dialog b/locale/en-us/running.dialog new file mode 100644 index 0000000..7dae09e --- /dev/null +++ b/locale/en-us/running.dialog @@ -0,0 +1 @@ +running {alias} (command|script) \ No newline at end of file diff --git a/translations/en-us/dialogs.json b/translations/en-us/dialogs.json new file mode 100644 index 0000000..72e8a6d --- /dev/null +++ b/translations/en-us/dialogs.json @@ -0,0 +1,5 @@ +{ + "running.dialog": [ + "running {alias} (command|script)" + ] +} \ No newline at end of file