Skip to main content

aptbot


A chatbot for twitch.tv

Dependencies


  • Python (any >=3.7 version should work)
  • python-dotenv
  • urllib3

Install


It is highly recommended you install and run aptbot in a virtual environment.

Clone this repository git clone https://github.com/atheridis/aptbot.git, change to the directory cd aptbot, then install the package pip install ..

First Steps


Adding an account

After installing, you can add an account using aptbot --add-account "account_name". A directory will be created in ~/.config/aptbot/ on Linux or %APPDATA%\aptbot\accounts\ on Windows with the twitch name of that account.

Each account directory should contain a main.py file with the most minimal code being:

from aptbot import Bot, Message, Commands

# Runs at the beginning, when the account connects.
# Can be used for an infinite loop within the account,
# so the bot can send messages, even when chat isn't moving.
def start(bot: Bot, message: Message, stop_event):
    pass

# Gets ran every time the IRC channel sends a message.
# This can either be a message from a user
# a raid, when a mod deletes a message, etc.
def main(bot: Bot, message: Message):
    pass

When you add an account using aptbot --add-account "account_name" or aptbot -a "account_name", the following python file called main.py will be created:

import time
from threading import Event

from aptbot import Bot, Commands, Message


# Starts when the bot is enabled
# Sends the message "Hello, world!" every 2 minutes to the channel
# stop_event is set to True, when you disable the account with aptbot -d "account_name"
def start(bot: Bot, message: Message, stop_event: Event):
    while not stop_event.is_set():
        bot.send_message(message.channel, "Hello, world!")
        time.sleep(120)


def main(bot: Bot, message: Message):
    # Check whether the message sent is a message by a user in chat
    # and not some notification.
    if message.command == Commands.PRIVMSG:
        # Check the content of the message and if the first word is '!hello'
        # send a reply by creating a new thread.
        # You can also use `message.nick` instead of `message.tags['display-name']`
        # but then the message sent back
        # will contain the name of the user in all lowercase
        if message.value.split()[0] == "!hello":
            bot.send_message(
                message.channel,
                f"hello {message.tags['display-name']}",
                reply=message.tags["id"],
            )

Activating your bot

Once you have an account set up you can enable the bot by using aptbot --enable. To stop the bot from running use aptbot --disable on another terminal.

After testing you would want to run aptbot --enable as a daemon, the easiest way to do that on Linux is to use nohup aptbot --enable &. This will leave a nohup.out file in the directory you're in, which may not be ideal. If you wish to have no output other than the logs provided in ~/.cache/aptbot/logs/aptbot.log you may use nohup aptbot --enable </dev/null >/dev/null 2>&1 &. You are now free to control aptbot through any terminal. Type aptbot --help to see all available commands.

More than one file

You can import modules from the same directory that the main.py files are in, but if you want aptbot --update to work on them you will need to reload the modules due to how python handles module imports. Some examples will be coming soon.

BUGS


  • Editing any of the directory names in ~/.config/aptbot/ or %APPDATA%\aptbot\accounts\ while the bot is running, may cause weird behaviour.

Metadata

Release files for aptbot 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aptbot 0.2.1
File Size Uploaded Provenance
aptbot-0.2.1.tar.gz 14.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for aptbot 0.2.1
File Interpreter ABI Platform
aptbot-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 28.5 kB

Release files / aptbot-0.2.1.tar.gz

Download URL aptbot-0.2.1.tar.gz
Size 14.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c61fd92c1691f2ab7abcac0d6c09e34edac95145c41c3cf2b9ced028da8faea7
BLAKE2b-256 checksum
How to use checksums
d7328e5840ed30dc761d98581b9c12e5a5fb61bb090c606dfd0f1d17b6939c3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.4

Release files / aptbot-0.2.1-py3-none-any.whl

Download URL aptbot-0.2.1-py3-none-any.whl
Size 14.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5552d6985757bd58804b0e98072dcf0176fd94e7ae6635e3027a8820e692507c
BLAKE2b-256 checksum
How to use checksums
5ec1158232817c39892b34636918e6b8581b6b2d13d895976329689f1567b04f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.4

Security for aptbot 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page