Skip to main content

A bridge between Discord and Twitch chat.

Project description

Kasai

PyPi version PyPI - Status Downloads GitHub last commit Docs License

Kasai serves as a bridge between Discord and Twitch, allowing a single bot to interact with both platforms.

This serves to extend Hikari, and cannot be used without it.

Installation

To install the latest released version of Kasai, use the following command:

pip install hikari-kasai

You can also install the latest development version using the following command:

pip install git+https://github.com/parafoxia/hikari-kasai

You may need to prefix these commands with a call to the Python interpreter depending on your OS and Python configuration.

Creating your bot

Kasai provides a subclass for hikari.GatewayBot that contains methods and attributes for Twitch chat interfacing.

import kasai

bot = kasai.GatewayBot(...)

To use Kasai with command handlers, you will need to create a custom subclass that inherits from both kasai.GatewayBot and your command handler's bot class. For example, if you want to use Lightbulb:

import kasai
import lightbulb

class Bot(kasai.GatewayBot, lightbulb.BotApp):
    ...

bot = Bot(...)

Usage

A working implementation could look something like this:

import os

import dotenv
import hikari
import kasai

# You will need a .env file for this.
dotenv.load_dotenv()

# Create the bot.
bot = kasai.GatewayBot(
    os.environ["TOKEN"],
    os.environ["IRC_TOKEN"],
    os.environ["TWITCH_CLIENT_ID"],
    os.environ["TWITCH_CLIENT_SECRET"],
)

@bot.listen(hikari.StartedEvent)
async def on_started(event: hikari.StartedEvent):
    # Connect to your Twitch chat.
    await bot.twitch.join("twitchdev")

@bot.listen(hikari.GuildMessageCreateEvent)
async def on_message(event: hikari.GuildMessageCreateEvent):
    # Send a message from Discord to Twitch chat.
    if event.content.startswith("!send"):
        await bot.twitch.create_message("twitchdev", event.content[6:])

@bot.listen(kasai.MessageCreateEvent)
async def on_twitch_message(event: kasai.MessageCreateEvent):
    # Basic Twitch command implementation.
    if event.content.startswith("!ping"):
        await event.message.respond("Pong!", reply=True)

# Run the bot.
bot.run()

There are more examples should you wish to see them. It may also be worth looking into how to speed Hikari up to get the best performance out of Kasai.

Contributing

Contributions are very much welcome! To get started:

License

The hikari-kasai module for Python is licensed under the BSD 3-Clause License.

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

hikari-kasai-0.10a0.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

hikari_kasai-0.10a0-py3-none-any.whl (32.3 kB view details)

Uploaded Python 3

File details

Details for the file hikari-kasai-0.10a0.tar.gz.

File metadata

  • Download URL: hikari-kasai-0.10a0.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for hikari-kasai-0.10a0.tar.gz
Algorithm Hash digest
SHA256 4ec4f4b9c41ec06d7769ec4ff5cd8600dd142e13d07c60c5075a4cfd8d8daac5
MD5 ce1fbf56436589df2be975fe716e26d1
BLAKE2b-256 ae757f88b8c77fead86347c2c1b08ac7087b200016ad2c0b4764d5e83b17e277

See more details on using hashes here.

File details

Details for the file hikari_kasai-0.10a0-py3-none-any.whl.

File metadata

File hashes

Hashes for hikari_kasai-0.10a0-py3-none-any.whl
Algorithm Hash digest
SHA256 cad81d34064f3611b785f0e36c66481b07962901b463cd906344f9c1c04c4572
MD5 f30fe2840825a57355ce09175e681f8d
BLAKE2b-256 8dbdb244dc75f96b1a6139ed075c5096934e7f59a66f847e32d4b1650c7ee991

See more details on using hashes here.

Supported by

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