Skip to main content

Прослойка между aioFunPayAPI и клиентом.

Project description

aioFunPayAPI

Полностью асинхронный форк оригинальной библиотеки FunPayAPI от LIMBODS, переписанный на asyncio и aiohttp для легкого написания неблокирующих ботов FunPay.

Установка

Для установки библиотеки из локального каталога:

pip install .

Быстрый старт

Пример простого асинхронного бота, который отвечает на сообщение с текстом «привет»:

import asyncio
from FunPayAPI import Account, Runner
from FunPayAPI.enums import EventTypes

async def main():
    # Создаем класс аккаунта и асинхронно получаем его данные.
    acc = await Account(golden_key="YOUR_GOLDEN_KEY").get()
    print(f"Авторизован как {acc.username} (ID: {acc.id})")

    # Создаем прослушиватель событий.
    runner = Runner(acc)

    # Асинхронно прослушиваем события
    async for event in runner.listen(requests_delay=6.0):
        # Если событие — новое сообщение
        if event.type == EventTypes.NEW_MESSAGE:
            # Если текст сообщения "привет" и оно отправлено не нами
            if event.message.text and event.message.text.lower() == "привет" and event.message.author_id != acc.id:
                # Отправляем ответное сообщение асинхронно
                await acc.send_message(event.message.chat_id, "Ну привет...")
                runner.mark_as_by_bot(event.message.chat_id, event.message.id)

if __name__ == "__main__":
    asyncio.run(main())

Выдача товара при новом заказе

Пример асинхронного бота, который выдает товар при новом оплаченном заказе:

import asyncio
from FunPayAPI import Account, Runner
from FunPayAPI.enums import EventTypes, OrderStatuses

async def main():
    acc = await Account(golden_key="YOUR_GOLDEN_KEY").get()
    runner = Runner(acc)

    async for event in runner.listen(requests_delay=6.0):
        # Если событие — новый заказ
        if event.type == EventTypes.NEW_ORDER:
            # Обязательно очищаем ID от знака '#'
            clean_id = event.order.id.replace("#", "")
            
            if event.order.status == OrderStatuses.PAID:
                order_info = await acc.get_order(clean_id)
                # Отправляем товар в чат покупателю
                await acc.send_message(
                    order_info.chat_id,
                    f"Привет, {event.order.buyer_username}!\nВот твой товар: ..."
                )

if __name__ == "__main__":
    asyncio.run(main())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiofunpayapi-1.1.0.tar.gz (45.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiofunpayapi-1.1.0-py3-none-any.whl (49.3 kB view details)

Uploaded Python 3

File details

Details for the file aiofunpayapi-1.1.0.tar.gz.

File metadata

  • Download URL: aiofunpayapi-1.1.0.tar.gz
  • Upload date:
  • Size: 45.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for aiofunpayapi-1.1.0.tar.gz
Algorithm Hash digest
SHA256 891ff23782321def48607d60bbffd8060af1dcf9bc527455cda1a9e43ee10cce
MD5 04a3398ef49e2ca001cdc3fdcae5e197
BLAKE2b-256 a4f7c296735d820943fcd99a73f3a08e3edf591101ff92cb6785e7c5d4d530fc

See more details on using hashes here.

File details

Details for the file aiofunpayapi-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: aiofunpayapi-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 49.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for aiofunpayapi-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cee226e583cd76e372526bb4c79ef34dd0969a35e242ff7fc1072d96bb9906a7
MD5 c0221579f68100e9f8c18bdd6531599b
BLAKE2b-256 37c8133d2870106f3bea621078fb727bf32aa07fd42de92b032580ae1b903bdf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page