public function __construct(&$core)
 {
     $core->registerCommand("activbt", "talkbot", "Activa el bottalk en un canal. Sintaxis: activbt <canal> <cleverbot|jaberwacky|pandorabot>");
     $core->registerCommand("deactivbt", "talkbot", "Desctiva el bottalk en un canal. Sintaxis: deactivbt <canal>");
     $core->registerMessageHandler('PRIVMSG', "talkbot", "recvmsg");
     $factory = new ChatterBotFactory();
     $clever = $factory->create(ChatterBotType::CLEVERBOT);
     $this->bots[1] = $clever->createSession();
     $jabber = $factory->create(ChatterBotType::JABBERWACKY);
     $this->bots[2] = $jabber->createSession();
     $pandora = $factory->create(ChatterBotType::PANDORABOTS, 'b0dafd24ee35a479');
     $this->bots[3] = $pandora->createSession();
 }
Ejemplo n.º 2
0
 public function main()
 {
     $this->bot = new Philip($this->config);
     $factory = new \ChatterBotFactory();
     $clever = $factory->create(\ChatterBotType::PANDORABOTS, 'b0dafd24ee35a477');
     $session = $clever->createSession();
     $this->bot->onMessages('/ai(.*)/u', function (Event $event) use(&$clever, &$session) {
         $matches = $event->getMatches();
         $message = $matches[0];
         $response = "";
         try {
             $response = $session->think($message);
         } catch (\Exception $e) {
             $response = "I can't reach the Cloud. I don't know how to answer";
             $session = $clever->createSession();
         }
         $event->addResponse(Response::msg($event->getRequest()->getSource(), $response));
     });
     $this->bot->run();
 }
Ejemplo n.º 3
0
    $websocket->loop->addPeriodicTimer(1, function () use($plugins, &$pluginRunTime, $app) {
        // Run all the onTimer plugins here and pass along the list of plugins
        foreach ($plugins["onTimer"] as $plugin) {
            $timerFrequency = $plugin->information()["timerFrequency"];
            $pluginName = $plugin->information()["name"];
            // If the currentTime is larger or equals lastRunTime + timerFrequency for this plugin, we'll run it again
            if (time() >= @$pluginRunTime[$pluginName] + $timerFrequency) {
                $pluginRunTime[$pluginName] = time();
                $plugin->onTimer();
            }
        }
    });
});
// Init the cleverbot stuff
require_once BASEDIR . "/src/chatterBot/chatterbotapi.php";
$cleverBotFactory = new ChatterBotFactory();
$bot = $cleverBotFactory->create(ChatterBotType::CLEVERBOT);
$botSession = $bot->createSession();
// Silly replies to do
$websocket->on(Event::MESSAGE_CREATE, function ($msgData, $botData) use($app, $discord, $websocket, $plugins, $botSession) {
    $message = $msgData->content;
    // If they write directly to me, i'll send it to cleverbot (Also the message has to start with this...
    if (stristr($message, "<@" . $app->config->get("botID", "bot") . ">")) {
        $msg = str_replace("<@" . $app->config->get("botID", "bot") . ">", $app->config->get("botName", "bot"), $message);
        $response = $botSession->think($msg);
        $msgData->reply($response);
    }
    // We randomly pick things to answer to.... why? why the f**k not
    if (mt_rand(1, 100) <= 5) {
        $response = $botSession->think($message);
        $channel = \Discord\Parts\Channel\Channel::find($msgData->channel_id);
Ejemplo n.º 4
0
<?php

require 'chatter-bot-api/php/chatterbotapi.php';
// Init the cleverbot
$factory = new ChatterBotFactory();
$bot1 = $factory->create(ChatterBotType::CLEVERBOT);
$bot1session = $bot1->createSession('cnd-session.txt');
$question = isset($_POST['text']) ? $_POST['text'] : "Test connection";
$answer = $bot1session->think($question);
// Define some faces
$faces = array(0 => ':bowtie:', 1 => ':glitch_crab:', 2 => ':japanese_goblin:', 3 => ':smiling_imp:', 4 => ':angel::cop:', 5 => ':sleuth_or_spy:', 6 => ':ghost::robot_face:', 7 => ':construction_worker:', 8 => ':alien:', 9 => ':panda_face:', 10 => ':neckbeard:', 11 => ':octocat:', 12 => ':rage1:');
//$face_index = rand(0, count($faces));
$face_index = (int) date('g');
$face = $faces[$face_index - 1];
// Return the answer to Slack
$curlUrl = 'SLACK-URL';
$curlData = array('payload' => json_encode(array('username' => 'BO', 'channel' => '#' . $_POST['channel_name'], 'icon_emoji' => $face, 'text' => $answer)));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $curlUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlData);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$curlResponseData = json_decode(curl_exec($ch));
$curlResponseCode = curl_getinfo($ch);
curl_close($ch);
/*
 ChatterBotAPI
 Copyright (C) 2011 pierredavidbelanger@gmail.com
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU Lesser General Public License for more details.
 
 You should have received a copy of the GNU Lesser General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
require 'chatterbotapi.php';
$factory = new ChatterBotFactory();
$bot1 = $factory->create(ChatterBotType::CLEVERBOT);
$bot1session = $bot1->createSession();
$bot2 = $factory->create(ChatterBotType::PANDORABOTS, 'b0dafd24ee35a477');
$bot2session = $bot2->createSession();
$s = 'Hi';
while (1) {
    echo "bot1> {$s}\n";
    $s = $bot2session->think($s);
    echo "bot2> {$s}\n";
    $s = $bot1session->think($s);
}