PHP Classes

File: plugins/privatetalk.class.php

Recommend this page to a friend!
  Classes of Sergei Miami  >  Joker the IRC bot  >  plugins/privatetalk.class.php  >  Download  
File: plugins/privatetalk.class.php
Role: Example script
Content type: text/plain
Description: Private Talk plugin
Class: Joker the IRC bot
Base for building IRC bot
Author: By
Last change: Used joker->answer instead of $joker->msg
Date: 6 years ago
Size: 1,754 bytes


Class file image Download

 * @package Joker
 * @subpackage Plugins
 * @author Miami <>
 * @version 1.1 on 26/05/2010
 * @license Released under the MIT License
 * @link
 * Private Talk
 * This is example plugin that uses internal variable to hold some
 * user information. This plugin accepts only private chat and stores
 * last time and a message, then output this back to user on next requests.
 * Warning! Avoid collecting of lots information inside the memory,
 * cuz, normally PHP limits it. If you want more data stored
 * use database or external files. This example is only the example... ;)
 * What we have here:
 * - On first private MSG if shows "Hi, nick" and stores its time/message in array
 * - If info exists, reply with last time and a message

class PrivateTalk {
$infos = array(); //here we hold assoc.array of last chats
public function PRIVMSG(Joker $joker) {

//accept only private messages from users
if ($joker->chan) return;
    if (!isset(
//first time you talk to Joker, it replies Hi, nickname...
$joker->answer("Hi, $joker->nick. Nice to meet you! Type something again...");
$this->infos[$joker->nick] = array('time'=>time(),'text'=>$joker->text);
//if info exists, msg him about last chat
$info = $this->infos[$joker->nick];
$seconds = time() - $info['time'];
$joker->answer("$seconds seconds ago you told me: $info[text]");
//remember text, that was sayed
$this->infos[$joker->nick] = array('time'=>time(),'text'=>$joker->text);