Package kasai

Welcome to the documentation for Kasai v0.11a!

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.

Expand source code
# Copyright (c) 2022-present, Ethan Henderson
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
#    list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
#    this list of conditions and the following disclaimer in the documentation
#    and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
#    contributors may be used to endorse or promote products derived from
#    this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from __future__ import annotations

__productname__ = "hikari-kasai"
__version__ = "0.11a"
__description__ = "A bridge between Discord and Twitch chat."
__url__ = "https://github.com/parafoxia/hikari-kasai"
__docs__ = "https://parafoxia.github.io/hikari-kasai/kasai"
__author__ = "Ethan Henderson"
__author_email__ = "ethan.henderson.1998@gmail.com"
__license__ = "BSD 3-Clause 'New' or 'Revised' License"
__bugtracker__ = "https://github.com/parafoxia/hikari-kasai/issues"
__ci__ = "https://github.com/parafoxia/hikari-kasai/actions"
__changelog__ = "https://github.com/parafoxia/hikari-kasai/releases"

TWITCH_HELIX_URI = "https://api.twitch.tv/helix/"
TWITCH_TOKEN_URI = "https://id.twitch.tv/oauth2/token"  # nosec: B105

from pathlib import Path

readme = Path(__file__).parent.parent / "README.md"

# This is only needed for documentation purposes.
if readme.is_file():
    __doc__ = (
        f"### Welcome to the documentation for Kasai v{__version__}!\n\n"
        + readme.read_text()[9:]
    )

from kasai.bot import *
from kasai.channels import *
from kasai.errors import *
from kasai.events import *
from kasai.games import *
from kasai.messages import *
from kasai.streams import *
from kasai.traits import *
from kasai.twitch import *
from kasai.users import *

Sub-modules

kasai.bot
kasai.channels
kasai.entity_factory
kasai.errors
kasai.events
kasai.games
kasai.messages
kasai.streams
kasai.traits
kasai.twitch
kasai.users
kasai.ux