Example #1
0
async def spam_handler(message: Message):
    state_peer = await bot.state_dispenser.get(message.from_id)

    if state_peer and state_peer.state == SpamState.BAD:
        try:
            await bot.api.messages.remove_chat_user(message.peer_id - 2e9, message.from_id)
            return "He dares to ignore me!"
        except VKAPIError(15):
            return "I hate myself"

    await message.answer("Pleease stop spamming..((")
    await bot.state_dispenser.set(message.from_id, SpamState.BAD)
Example #2
0
async def spam_handler(message: Message):
    state_peer = await bot.state_dispenser.get(message.from_id)

    if state_peer and state_peer.state == SpamState.BAD:
        try:
            await bot.api.messages.remove_chat_user(message.peer_id - 2e9,
                                                    message.from_id)
            return "Как можно игнорировать мои просьбы"
        except VKAPIError(15):
            return "Где мои права администратора?"

    await message.answer("Пожалуйста перестаньте спамить")
    await bot.state_dispenser.set(message.from_id, SpamState.BAD)
Example #3
0
async def group_join_handler(event: GroupTypes.GroupJoin):
    try:

        # Basic API call, please notice that bot.api (or blueprint.api) is
        # not accessible in case multibot is used, API can be accessed from
        # event.ctx_api
        await bot.api.messages.send(peer_id=event.object.user_id,
                                    message="Спасибо за подписку!",
                                    random_id=0)

    # Read more about exception handling in documentation
    # low-level/exception_factory/exception_factory
    except VKAPIError(901):
        pass
Example #4
0
async def test_api_error_handling(api: API):
    try:
        await api.request("some.method", {})
    except VKAPIError(0):
        return True
    raise AssertionError