Skip to content

Latest commit

 

History

History
68 lines (46 loc) · 1.71 KB

README.md

File metadata and controls

68 lines (46 loc) · 1.71 KB

logo with a label 'one bot codebase - multiple platforms'

seamless api for developing bots that run on multiple platforms. discord, telegram and twitch are supported

works with asyncio

learn more in the sections below or docs

install

install the base library:

pip install wiring

then choose extra dependencies for platforms that you want your bot to run on

pip install wiring[discord] wiring[telegram]

usage example

import asyncio

from wiring import (Bot, MultiPlatformMessage, MultiPlatformBot, MultiPlatformUser,
                    Command)
from wiring.platforms.discord import DiscordBot
from wiring.platforms.telegram import TelegramBot


DISCORD_TOKEN = 'place your token here or better load it from enviroment variables'
TELEGRAM_TOKEN = 'place your token here or better load it from enviroment variables'

async def send_commands_list(bot: Bot, message: MultiPlatformMessage,
                             args: list[str]):
    commands_list = '\n'.join(['/' + str(command.name) for command
                               in bot.commands])

    await bot.send_message(
        message.chat.id,
        'available commands:\n' + commands_list,
        reply_message_id=message.id
    )


async def start_bots():
    bot = MultiPlatformBot()

    bot.platform_bots = [
        DiscordBot(DISCORD_TOKEN),
        TelegramBot(TELEGRAM_TOKEN)
    ]

    async with bot:
        await bot.setup_commands([
            Command('help', send_commands_list)
        ])

        # blocks the execution
        await bot.listen_to_events()


asyncio.run(start_bots())