Exemple #1
0
<?php

require_once 'vendor/autoload.php';
class SkypeBot
{
    static function notify($a)
    {
        global $n;
        $engine = new \Inviqa\SkypeEngine($n);
        try {
            $engine->parse($a);
        } catch (Exception $e) {
            echo $e->getMessage() . PHP_EOL;
        }
    }
}
$d = new Dbus(Dbus::BUS_SESSION, true);
$n = $d->createProxy("com.Skype.API", "/com/Skype", "com.Skype.API");
$n->Invoke("NAME PHP");
$n->Invoke("PROTOCOL 7");
$d->registerObject('/com/Skype/Client', 'com.Skype.API.Client', 'SkypeBot');
do {
    $s = $d->waitLoop(1000);
} while (true);
<?php

$dbus = new Dbus(Dbus::BUS_SESSION);
$interface = "im.pidgin.purple.PurpleInterface";
$method = "ReceivedImMsg";
// watching only for this particular signal on this particular interface
$dbus->addWatch($interface, $method);
$kill = false;
do {
    $signal = $dbus->waitLoop(1000);
    if ($signal instanceof DbusSignal) {
        // even if we watch only for one signal on one interface
        // we still can get rubbish, so making sure this is what we need
        if ($signal->matches($interface, $method)) {
            $data = $signal->getData()->getData();
            // if we received "kill" as a message, then kill it.
            if ($data[2] == 'kill') {
                $kill = true;
                echo "Goodbye, cruel world!\n";
            } else {
                echo "Got stuff!\n";
            }
        }
    }
} while (!$kill);
#!/usr/local/bin/php
<?php 
include "Skype.php";
include "Bot.php";
$dbus = new Dbus(Dbus::BUS_SESSION, true);
$proxy = $dbus->createProxy('com.Skype.API', '/com/Skype', 'com.Skype.API');
//Connect to skype
$proxy->Invoke("NAME PHP");
$proxy->Invoke('PROTOCOL 8');
Skype::$bot = new Bot($proxy);
$dbus->registerObject('/com/Skype/Client', 'com.Skype.API.Client', 'Skype');
// Register message listener
while (1) {
    $votes = Skype::$bot->getVotes();
    if (isset($votes)) {
        foreach ($votes as $chat => $vot) {
            if ($vot['time'] < time() - 10 * 60) {
                echo "Clear: " . $chat, "\n";
                Skype::$bot->clearVoting($chat);
            }
        }
    }
    $s = $dbus->waitLoop(1);
}