idevelopthings/laravel-twitch-irc

This is my package laravel-twitch-irc

dev-main 2023-07-03 20:18 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Twitch IRC Bot for laravel applications. This ships with the ability to create custom commands for your bot, with aliases, cooldowns, ability to connecto to multiple channels, etc.

Installation

You can install the package via composer:

composer require idevelopthings/laravel-twitch-irc

You can publish the config file with:

php artisan vendor:publish --tag="twitch-irc-config"

Usage

Publish the config file first, add to your .env:

TWITCH_BOT_USERNAME="your bots username"
TWITCH_BOT_ACCESS_TOKEN="your bots token"

You can obtain a token here: https://twitchapps.com/tmi/ When using the token, don't include the "oauth:" prefix.

Now we can create a command, the default location is app/Services/TwitchIrc/Commands, you can change this path in the config file

<?php
namespace App\Services\TwitchIrc\Commands;

use TwitchIrc\Bot\Command\BaseCommand;

class HelloWorldCommand extends BaseCommand
{
    public function identifier(): string {
        return "hello";
    }

    public function aliases(): array {
        return [
            'hi',
            'hw',
            'helloworld',
        ];
    }

    public function description(): string {
        return "Responds with hello world.";
    }

    public function handle(): void {
        $this->reply('Hello world.');
    }
}

Now you can run "php artisan twitchbot" to start the bot. We can also use "php artisan twitchbot --stop" to stop the bot, which is useful for CI setups.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.