Permalink
Browse files

Memcache enabled, nog steeds niks

  • Loading branch information...
thunderbug committed Oct 11, 2017
1 parent 68ee8a6 commit 5bf6f583c5a0fced56357e10bce0f246a3c57b73
Showing with 38 additions and 19 deletions.
  1. +14 −7 chat_cronned_outgoing.php
  2. +20 −10 chat_handle_incoming.php
  3. +4 −2 composer.json
View
@@ -8,9 +8,9 @@
* - voor elk resultaat (C) stuur een bericht naar elke subscriber (B)
*/
use Mpociot\BotMan\BotManFactory;
use Mpociot\BotMan\Drivers\FacebookDriver;
use Mpociot\BotMan\Messages\Message;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Cache\DoctrineCache;
use BotMan\BotMan\Drivers\DriverManager;
$botmanConfig = array();
@@ -28,9 +28,15 @@
)
);
$memcache = new Memcache();
$memcache->connect("localhost", 11211);
$cacheDriver = new \Doctrine\Common\Cache\MemcacheCache();
$cacheDriver->setMemcache($memcache);
//Init Botman
$botman = BotManFactory::create($botmanConfig);
$botman->verifyServices($botmanVerify);
DriverManager::loadDriver(\BotMan\Drivers\Facebook\FacebookDriver::class);
$botman = BotManFactory::create($botmanConfig, new DoctrineCache($cacheDriver));
$data = $database->query("SELECT distinct `gemeenteid` FROM `subscribers`;")->fetchAll();
@@ -43,8 +49,9 @@
foreach($users as $user){
if(is_array($apiData)) {
foreach ($apiData as $apiRow) {
$message = Message::create("Er is een boek gedropt:" . $apiRow["fbURL"]);
$botman->say($message, $user[0],FacebookDriver::class);
echo "Er is een boek gedropt:" . $apiRow["fbURL"];
$botman->say("Er is een boek gedropt:" . $apiRow["fbURL"], $user[0]);
break;
}
}
}
View
@@ -5,7 +5,11 @@
* dit wordt weggeschreven in de subscribers tabel met subscriberid (= facebook id) en gemeente id (= gemeente.id)
*/
use Mpociot\BotMan\BotManFactory;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Cache\DoctrineCache;
use BotMan\BotMan\Cache\Psr6Cache;
use BotMan\BotMan\Drivers\DriverManager;
$botmanConfig = array();
@@ -23,24 +27,28 @@
)
);
$memcache = new Memcache();
$memcache->connect("localhost", 11211);
$cacheDriver = new \Doctrine\Common\Cache\MemcacheCache();
$cacheDriver->setMemcache($memcache);
//Init Botman
$botman = BotManFactory::create($botmanConfig);
$botman->verifyServices($botmanVerify);
DriverManager::loadDriver(\BotMan\Drivers\Facebook\FacebookDriver::class);
$botman = BotManFactory::create($botmanConfig, new DoctrineCache($cacheDriver));
$botman->hears("abonneer op {naam}", function ($bot, $naam) {
global $database;
$user = $bot->getUser();
$amount = $database->count("gemeentes", "*", array("name" => $naam));
if($amount == 0) {
$bot->reply("Er zijn geen gemeentes met deze naam gevonden");
} elseif($amount == 1) {
$data = $database->get("gemeentes", "*", array("name" => $naam));
if($database->count("subscribers", "*", array("subscriberid" => $user->getId(), "gemeenteid" => $data["id"])) == 0) {
if($database->count("subscribers", "*", array("subscriberid" => $bot->getUser()->getId(), "gemeenteid" => $data["id"])) == 0) {
$database->insert("subscribers", array(
"subscriberid" => $user->getId(),
"subscriberid" => $bot->getUser()->getId(),
"gemeenteid" => $data["id"]
));
@@ -73,16 +81,16 @@
$botman->hears("de-abonneer op {naam}", function ($bot, $naam) {
global $database;
$user = $bot->getUser();
$amount = $database->count("gemeentes", "*", array("name" => $naam));
if($amount == 0) {
$bot->reply("Er zijn geen gemeentes met deze naam gevonden");
} elseif($amount == 1) {
$data = $database->get("gemeentes", "*", array("name" => $naam));
if($database->count("subscribers", "*", array("subscriberid" => $user->getId(), "gemeenteid" => $data["id"])) == 1) {
$database->delete("subscribers", array("subscriberid" => $user->getId(), "gemeenteid" => $data["id"]));
if($database->count("subscribers", "*", array("subscriberid" =>$bot->getUser()->getId(), "gemeenteid" => $data["id"])) == 1) {
$database->delete("subscribers", array("subscriberid" => $bot->getUser()->getId(), "gemeenteid" => $data["id"]));
$bot->reply("U bent gedeabonneerd op ".$data["name"]);
} else {
@@ -112,6 +120,8 @@
});
$botman->fallback(function($bot){
global $database,$botman;
$user = $bot->getUser();
$bot->reply("Hallo ".$user->getFirstName()." ".$user->getLastName());
View
@@ -1,6 +1,8 @@
{
"require": {
"botman/botman": "^1.5",
"catfan/Medoo": "^1.4"
"botman/botman": "^2.0",
"catfan/Medoo": "^1.4",
"botman/driver-facebook": "^1.2",
"doctrine/common": "^2.7"
}
}

2 comments on commit 5bf6f58

@futtta

This comment has been minimized.

Show comment
Hide comment
@futtta

futtta Oct 12, 2017

Owner

dju ... heb je al op slack/ github rondgevraagd?

Owner

futtta replied Oct 12, 2017

dju ... heb je al op slack/ github rondgevraagd?

@thunderbug

This comment has been minimized.

Show comment
Hide comment
@thunderbug

thunderbug Oct 12, 2017

Collaborator

Ik ben bezig met op slack te vragen nu :)

Collaborator

thunderbug replied Oct 12, 2017

Ik ben bezig met op slack te vragen nu :)

Please sign in to comment.