modules/doctor.php
author Dan
Tue, 30 Dec 2008 06:16:28 -0500
changeset 36 a7d884914a74
parent 24 6fa9346a9bdc
child 52 a8f0e99883d1
permissions -rw-r--r--
Added extern script to allow exporting some stats through a JSON or XML API. WiP.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     1
<?php
24
6fa9346a9bdc doctor: init instance array in proper location
Dan
parents: 8
diff changeset
     2
$doctor = array();
6fa9346a9bdc doctor: init instance array in proper location
Dan
parents: 8
diff changeset
     3
8
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     4
require('eliza.php');
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     5
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     6
eb_hook('event_channel_msg', 'doctor_listen($chan, $message);');
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     7
eb_hook('snippet_dynamic', 'if ( $snippet === "doctor" ) return doctor_go($chan, $message, $snippet);');
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     8
eb_hook('event_greeting', 'doctor_greet($append);');
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
     9
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    10
function doctor_go(&$chan, &$message, &$snippet)
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    11
{
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    12
  global $doctor;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    13
  
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    14
  if ( $snippet == 'doctor' )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    15
  {
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    16
    if ( isset($doctor[$message['nick']]) )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    17
    {
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    18
      unset($doctor[$message['nick']]);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    19
      $chan->msg(eb_censor_words("{$message['nick']}, thank you for visiting the psychotherapist. Come again soon!"), true);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    20
    }
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    21
    else
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    22
    {
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    23
      $doctor[$message['nick']] = new Psychotherapist();
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    24
      $chan->msg(eb_censor_words("{$message['nick']}, I am the psychotherapist. Please explain your problems to me. When you are finished talking with me, type !doctor again."), true);
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    25
    }
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    26
    return true;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    27
  }
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    28
}
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    29
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    30
function doctor_listen(&$chan, &$message)
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    31
{
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    32
  global $doctor;
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    33
  
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    34
  if ( isset($doctor[$message['nick']]) && $message['message'] != '!doctor' )
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    35
  {
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    36
    $chan->msg(eb_censor_words($doctor[$message['nick']]->listen($message['message'])));
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    37
  }
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    38
}
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    39
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    40
function doctor_greet(&$append)
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    41
{
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    42
  $append .= ' Type !doctor for the psychotherapist.';
0acb8d9a3194 Welcome, modularization and stats.
Dan
parents:
diff changeset
    43
}