1. Go to this page and download the library: Download cyrille-hugues/alyosha library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cyrille-hugues / alyosha example snippets
lyosha\Core\Kernel;
class AppKernel extends Kernel
{
protected function registerModules()
{
return [];
}
}
$kernel = new AppKernel(__DIR__ . '/vendor/CyrilleHugues/Alyosha/config.yml');
$kernel->run();
use Alyosha\Core\Kernel;
use Alyosha\IRC\IrcModule;
use Alyosha\IrcAdmin\IrcAdminModule;
use Alyosha\Time\TimeModule;
class AppKernel extends Kernel
{
protected function registerModules()
{
return [
new IrcModule(),
new IrcAdminModule(),
new TimeModule(),
];
}
}
$kernel = new AppKernel(__DIR__ . '/vendor/CyrilleHugues/Alyosha/config.yml');
$kernel = new AppKernel(__DIR__ . '/vendor/CyrilleHugues/Alyosha/config.yml');
$kernel = new AppKernel(__DIR__ . '/config.yml');
namespace Bot;
use Alyosha\Core\Event\EventInterface;
use Alyosha\Core\Module\AbstractModule;
use Alyosha\IRC\Event\Command\MessageCommand;
use Alyosha\IRC\Event\IrcCommandEvent;
use Alyosha\Time\TimeEvent;
class LeetModule extends AbstractModule
{
private $servers = [];
private $events;
// the name of the module for all other modules
public function getName()
{
return 'leet_module';
}
// You can add it in the `config.yml` and it will be available here to start your module
public function start(array $config)
{
// we get all the channels of the configuration
foreach ($config['irc']['servers'] as $serverName => $serverConfig) {
$this->servers[$serverName] = $serverConfig['chans']
}
}
// Which are the event i want for this module
// Here I only want the time
public function getSubscriptions()
{
return [
'time_module.date'
];
}
// Alyosha use this function to notify every module of an event they are subscribed to.
public function notify(EventInterface $event)
{
// always check the type of event before executing logic
if ($event instanceof TimeEvent && $event->getDate()->format('H:i:s') === "13:37:00") {
foreach ($this->servers as $serverName => $chanList) {
foreach ($chanList as $chan) {
// We create a message to ask the IRCModule to send a message on a chan.
new MessageCommand($serverName, $chan, "LEET TIME !!");
// We put the message in an envelope to send it to IRCModule via Alyosha.
$this->events[] = new IrcCommandEvent($messageCommand);
}
}
}
}
// here we send the new events created
public function getEvents()
{
$events = $this->events;
$this->events = [];
return $events;
}
}
use Bot\LeetModule;
...
protected function registerModules()
{
return [
new IrcModule(),
new IrcAdminModule(),
new TimeModule(),
new LeetModule(),
];
}
bash
php bot.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.