Skip to content

Commit

Permalink
added execute meth and example
Browse files Browse the repository at this point in the history
  • Loading branch information
kesha1225 committed Apr 6, 2020
1 parent b63cf87 commit 6c2e612
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions vkwave/api/methods/_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .board import Board
from .database import Database
from .docs import Docs
from .execute import Execute
from .fave import Fave
from .friends import Friends
from .gifts import Gifts
Expand Down Expand Up @@ -96,6 +97,7 @@ def __init__(self, api_options: APIOptions):
self.board = Board("board", self)
self.database = Database("database", self)
self.docs = Docs("docs", self)
self.execute = Execute("execute", self)
self.fave = Fave("fave", self)
self.friends = Friends("friends", self)
self.gifts = Gifts("gifts", self)
Expand Down
13 changes: 13 additions & 0 deletions vkwave/api/methods/execute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from ._category import Category
from vkwave.types.responses import ExecuteResponse


class Execute(Category):
async def __call__(self, code: str, return_raw_response: bool = False):

raw_result = await self.api_request("", {"code": code})
if return_raw_response:
return raw_result

result = ExecuteResponse(**raw_result)
return result
6 changes: 3 additions & 3 deletions vkwave/bots/vkscript/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import inspect
import types

from vkwave.api.methods import APIOptionsRequestContext
from vkwave.bots.vkscript.converter import Scope
from vkwave.bots.vkscript.converter import VKScriptConverter

Expand Down Expand Up @@ -46,10 +47,9 @@ async def __call__(self, *args, **kwargs):
return await self._preprocessor(*args, **kwargs)
return await self.execute(*args, **kwargs)

async def execute(self, *args, **kwargs):
vk = _get_vk().get_current()
async def execute(self, api: APIOptionsRequestContext, *args, **kwargs):
code = self.build(*args, **kwargs)
response = await vk.api_request("execute", {"code": code})
response = await api.execute(code=code)
return response

e = execute
4 changes: 4 additions & 0 deletions vkwave/types/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -4033,3 +4033,7 @@ class StoriesSearchResponseModel(pydantic.BaseModel):
groups: typing.List[GroupsGroup] = pydantic.Field(
None, description="",
)


class ExecuteResponse(pydantic.BaseModel):
response: int = pydantic.Field(..., description="")

0 comments on commit 6c2e612

Please sign in to comment.