You've already forked STARK
mirror of
https://github.com/MarkParker5/STARK.git
synced 2025-07-12 22:50:22 +02:00
api/command
This commit is contained in:
@ -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'),
|
||||
]
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user