- Launch setup.sh by typing
bash setup.sh
- Edit
bot.php
file and enter your oAuth token, bot name and your channel
- Launch
launch.sh
by typingbash launch.sh
I write this bot to have clean PHP base to create custom Twitch bot in PHP.
This project use modules system with hooks to add your own features. You can see examples of modules in /modules
folder.
- onConnect (Execute when bot connect to the channel)
- onMessage (Execute when new message come in the channel)
- onPing (Execute when someone mention the bot (Ex: @YourBot))
- onPong (Execute every 5 minutes when Twitch send PING status)
- onUsernotice (Execute when user subscribe for example)
- onCommand (Execute when someone send message with command symbol, by default
!
)
-
Create folder named with the name of your module in
/modules
(Ex:/modules/responder
) -
Create php class named with the name of your module (Ex:
/modules/responder/responder.php
) -
Define class and use TwichtBot module trait like this:
<?php
/**
* Class Responder
*/
class Responder {
use \TwitchBot\Module {
\TwitchBot\Module::__construct as private moduleConstructor;
}
/**
* Responder constructor.
* @param array $infos
* @param \TwitchBot\IrcConnect $client
*/
public function __construct(array $infos, $client)
{
$this->moduleConstructor($infos, $client);
}
/**
* @param \TwitchBot\Message $message
*/
public function onPing($message)
{
$this->getClient()->sendMessage('You ping me @' . $message->getUsername() . ' ?! What do you want ?');
}
}
-
Develop your feature using available hook. The function name is
onNameOfTheHook()
(Ex:onPing($data)
) -
Refer to the php trait (
/src/class/Module.php
) for informations about functions and parameters -
Update autoload using this command:
composer dumpautoload
-
Start your bot in screen or tmux for example !
php bot.php
You can use your own config system like mysql storage but the bot have already config system using json file.
-
Create file
config.json
in your module folder -
Respect json format
-
You can use
getConfig(), setConfig()
methods in your code
https://www.twitch.tv/warths (with custom modules and default)
If you use this bot on you channel, please let me know ! Contact me on Twitter or by email. (@MyTheValentinus or contact[@]valentin-deville.eu)