Skip to main content

基于 aiogram 的简单轻量级库,用于创建电报邮件

项目描述

PyPI 版本 Python 艾格图 CI

Aiogram 广播公司

一个简单直接的aiogram广播实现

安装

$ pip install aiogram-broadcaster

例子

开始之前的几个步骤...

注意:这些以及更多示例可以在examples/目录中找到

基本使用

from aiogram_broadcaster import TextBroadcaster

import asyncio


async def main():

    # Initialize a text broadcaster (you can directly pass a token)
    broadcaster = TextBroadcaster('USERS IDS HERE', 'hello!', bot_token='BOT TOKEN HERE')
    
    # Run the broadcaster and close it afterwards
    try:
        await broadcaster.run()
    finally:
        await broadcaster.close_bot()


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

在消息处理程序中嵌入广播器

from aiogram import Bot, Dispatcher, types

from aiogram_broadcaster import MessageBroadcaster

import asyncio


async def message_handler(msg: types.Message):
    """
    The broadcaster will flood to a user whenever it receives a message
    """
    
    users = [msg.from_user.id] * 5  # Your users list
    await MessageBroadcaster(users, msg).run()  # Run the broadcaster


async def main():

    # Initialize a bot and a dispatcher
    bot = Bot(token='BOT TOKEN HERE')
    dp = Dispatcher(bot=bot)

    # Register a message handler
    dp.register_message_handler(message_handler, content_types=types.ContentTypes.ANY)
    
    # Run the bot and close it afterwards
    try:
        await dp.start_polling()
    finally:
        await bot.session.close()


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

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

aiogram_broadcaster-0.0.7.ta​​r.gz (6.6 kB 查看哈希

已上传 source

内置分布

aiogram_broadcaster-0.0.7-py3-none-any.whl (7.7 kB 查看哈希

已上传 py3