Example #1
0
 def __init__(self, tokens: typing.Union[str, typing.List[str]]):
     self.client = AIOHTTPClient()
     self.tokens = (
         BotSyncSingleToken(Token(tokens))
         if isinstance(tokens, str)
         else BotSyncPoolTokens([Token(token) for token in tokens])
     )
     self.api = API(clients=self.client, tokens=self.tokens)
Example #2
0
async def get_api():
    client = AIOHTTPClient()
    token = Token(TOKEN)
    bot_token = BotSyncSingleToken(token)
    vk_session = API(
        clients=client,
        tokens=bot_token,
    )

    api = vk_session.get_context()
    return api
Example #3
0
from vkwave.bots.core.dispatching.dp.dp import Dispatcher
from vkwave.bots.core.dispatching.extensions.longpoll_bot import BotLongpollExtension
from vkwave.bots.core.dispatching.router.router import DefaultRouter
from vkwave.bots.core.tokens.types import GroupId
from vkwave.api.methods import API
from vkwave.bots.core.dispatching.filters.builtin import (
    EventTypeFilter,
    PayloadFilter,
    CommandsFilter,
)
from vkwave.longpoll.bot import BotLongpoll, BotLongpollData
from vkwave.types.bot_events import BotEventType
from vkwave.bots.utils.keyboards import Keyboard

logging.basicConfig(level=logging.DEBUG)
bot_token = Token("123")
gid = 123
router = DefaultRouter()


@router.registrar.with_decorator(CommandsFilter(["hello"]),
                                 EventTypeFilter(BotEventType.MESSAGE_NEW))
async def kb_handler(event: BaseEvent):
    kb = Keyboard(one_time=True)
    kb.add_text_button(text="123456", payload={"hello": "world"})
    await event.api_ctx.messages.send(
        peer_id=event.object.object.message.peer_id,
        message="123",
        keyboard=kb.get_keyboard(),
        random_id=0,
    )
Example #4
0
    for param in error["error"]["request_params"]:
        if param["key"] in ("oauth", "v", "method"):
            continue
        request_params[param["key"]] = param["value"]

    key = await solve_captcha(error["error"]["captcha_img"])

    request_params.update({"captcha_sid": error["error"]["captcha_sid"], "captcha_key": key})
    await api_ctx.api_request(method, params=request_params)


# Easy way

bot = SimpleLongPollBot(tokens="MyToken", group_id=123456789)
bot.api_session.default_api_options.error_dispatcher.add_handler(14, captcha_handler)


# Not easy way


api_session = API(BotSyncSingleToken(Token("MyToken")), AIOHTTPClient())
api = api_session.get_context()
dp = Dispatcher(api_session, TokenStorage[GroupId]())
lp_extension = BotLongpollExtension(dp, BotLongpoll(api, BotLongpollData(123456789)))

api_session.default_api_options.error_dispatcher.add_handler(14, captcha_handler)




Example #5
0
from vkwave.api.token.token import Token, BotSyncSingleToken
from vkwave.bots.utils.uploaders.photo_uploader import PhotoUploader
from vkwave.client.default import AIOHTTPClient
from vkwave.api.methods import API
import asyncio

client = AIOHTTPClient()
api = API(
    clients=client,
    tokens=BotSyncSingleToken(Token("token")),
)

uploader = PhotoUploader(api.get_context())


async def main():
    big_attachment = await uploader.get_attachments_from_links(
        peer_id=1234,
        links=[
            "https://user-images.githubusercontent.com/28061158/75329873-7f738200-5891-11ea-9565-fd117ea4fc9e.jpg",
            "https://camo.githubusercontent.com/9c8d6519e5997860b7a4b28f74719c0c2f83142b/68747470733a2f2f692e696d6775722e636f6d2f386955334578366c2e6a7067",
            "https://user-images.githubusercontent.com/28061158/74590410-239e3300-501f-11ea-9774-27ee507a1e1e.jpg",
        ],
    )
    await api.get_context().messages.send(user_id=1234,
                                          attachment=big_attachment,
                                          random_id=0)
    # TODO: voice


asyncio.get_event_loop().run_until_complete(main())