1
0
mirror of https://github.com/MarkParker5/STARK.git synced 2025-07-12 22:50:22 +02:00

api/command

This commit is contained in:
MarkParker5
2021-02-27 01:07:14 +02:00
parent b74ab45c98
commit 8295f302d1
2 changed files with 17 additions and 6 deletions

View File

@ -3,5 +3,6 @@ from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name = 'index')
path('text', views.text, name = 'text'),
path('command', views.text, name = 'commands'),
]

View File

@ -5,11 +5,21 @@ from Command import Command
import modules
import json
def index(request):
def text(request):
text = request.GET.get("text")
if text == None: return HttpResponse("")
if not text: return HttpResponse("")
cmd, params = Command.reg_find(text).values()
try: responce = cmd.start(params)
except: {'text': f'Ошибка в модуле {cmd.getName()}', 'voice': 'Произошла ошибка'}
json_string = json.dumps(responce)
try: response = cmd.start(params)
except: {'text': f'Ошибка в модуле {cmd.getName()}', 'voice': 'Произошла ошибка'}
json_string = json.dumps(response)
return HttpResponse(json_string)
def command(request):
name = request.GET.get("name")
params = request.GET.get("params") or {}
if not name: return HttpResponse("")
try: cmd = Command.getCommand(name)
except: return HttpResponse("")
if not cmd: return HttpResponse("")
json_string = json.dumps(response)
return HttpResponse(json_string)