Skip to main content

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

Project description

aioFunPayAPI

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

Установка

pip install aioFunPayAPI

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

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

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.1.tar.gz (45.6 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.1-py3-none-any.whl (49.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiofunpayapi-1.1.1.tar.gz
  • Upload date:
  • Size: 45.6 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.1.tar.gz
Algorithm Hash digest
SHA256 645df939e2ea0ca8384269f4c02db22c22687d151522e70da59ab7d9fa680e63
MD5 21a83901664448c15b76273aada3d1d3
BLAKE2b-256 7c5b73758282974c1176187e3b166942a858c66a937015def11834da5644f18f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aiofunpayapi-1.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e5ed258dab6aa2fb2c30c67c9f381930875372c1a14df37147c6e11b7b31187d
MD5 ab1ab2b87f3c922c4370aa01e6229054
BLAKE2b-256 30a5b613e3e4f429d926bcf73d41aed883d318bae9d958ab4ef732624db0b27b

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