Skip to content

Commit

Permalink
Merge branch 'master' of github.com:fscdev/vkwave
Browse files Browse the repository at this point in the history
  • Loading branch information
prostomarkeloff committed Apr 13, 2020
2 parents 5e35b49 + 6d18102 commit c49c9bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 6 additions & 2 deletions docs/bots/easy.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ from vkwave.bots.easy.easy_bot import SimpleLongPollBot

bot = SimpleLongPollBot(tokens=["MyToken1","MyToken2","MyToken3"], group_id=123456789)

@bot.message_handler()
@bot.message_handler(bot.text_filter("bye"))
def handle(_) -> str:
return "Hello world!"
return "bye world"

@bot.message_handler(bot.text_filter("hello"))
def handle(event: bot.SimpleBotEvent):
await event.answer("hello world!")

bot.run_forever()
```
Expand Down
7 changes: 6 additions & 1 deletion vkwave/bots/easy/easy_bot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import typing
import inspect

from vkwave.api.methods import API
from vkwave.api.token.token import BotSyncPoolTokens, BotSyncSingleToken, Token
Expand All @@ -15,6 +16,7 @@
RegexFilter,
TextFilter,
)
from vkwave.bots.fsm.filters import StateFilter
from vkwave.bots.core.dispatching.handler.callback import BaseCallback
from vkwave.bots.core.dispatching.router.router import DefaultRouter
from vkwave.bots.core.tokens.storage import TokenStorage
Expand Down Expand Up @@ -109,14 +111,17 @@ def __init__(
self.chat_action_filter = ChatActionFilter
self.command_filter = CommandsFilter
self.regex_filter = RegexFilter
self.state_filter = StateFilter

class SimpleBotCallback(BaseCallback):
def __init__(self, func: typing.Callable[[BaseEvent], typing.Awaitable[typing.Any]]):
self.func = func

async def execute(self, event: BotEvent) -> typing.Any:
new_event = SimpleBotEvent(event)
return await self.func(new_event)
if inspect.iscoroutinefunction(self.func):
return await self.func(new_event)
return self.func(new_event)

def message_handler(self, *filters: BaseFilter):
def decorator(func: typing.Callable[..., typing.Any]):
Expand Down

0 comments on commit c49c9bb

Please sign in to comment.