BeBot - An Anarchy Online and Age Of Conan chat automaton

Development => Module Requests => Topic started by: Jmrxxx on August 18, 2005, 09:32:46 pm

Title: A Topic Command
Post by: Jmrxxx on August 18, 2005, 09:32:46 pm
I was thinking it would be nice to have a !topic or !settopic command so that when someone sends a tell to the bot they can see whattheyare joining in on. Also this way when someone from inside the chat does an !invite <player> when the bot invites them, it will also show them the topic?

Unless I am miissing this.. I dont believe one exists :)
Title: A Topic Command
Post by: Derroylo on August 22, 2005, 02:19:44 pm
Well i have one but it isnĀ“t compatible with the normal bebot :(
Title: A Topic Command
Post by: Zacix on August 22, 2005, 03:47:25 pm
This topicmodule works ONLY if you have followed my guide for upgrading to a PHP5 and raidbot *clicky* (http://bebot.fieses.net/viewtopic.php?t=119). Although, shouldn't be too hard to change the code so it works for PHP4.

Code: [Select]
<?php

require_once("./includes/_colors.php");

$topic = new Topic($bot);


$commands["tell"]["topic"] = &$topic;
$commands["tell"]["cleartopic"] = &$topic;
$commands["pgmsg"]["topic"] = &$topic;
$commands["pgjoin"][] = &$topic;

class 
Topic{
  private 
$bot;
  private 
$topic;
  private 
$time;
  private 
$name;

  public function 
Topic(&$bot) {
    
$this->bot = &$bot;
    
$this->topic "";
    
$this->time gmmktime();
    
$this->name "";
  }
  
  public function 
tell($name,$msg) {
    
$msg explode(" ",$msg);
    if(
strtolower($msg[0]) == "!topic") {
      if(
$msg[1] != "") {
        
$this->topic implode(" ",array_slice($msg,1));
        
$this->time gmmktime();
        
$this->name $name;
        
$this->bot->aoc->send_tell($name,Infotext("New topic set."));
      }
      else {
        if(
$this->topic != "") {
          
$this->bot->aoc->send_tell($name,Infotext($this->topic " [" Highlight(date("Y-M-d H:i",$this->time)) . " GMT]." "Set by [" Highlight($this->name) . "]"));
        }
        else {
          
$this->bot->aoc->send_tell($name,Infotext("No topic since [" Highlight(date("Y-M-d H:i",$this->time)) . " GMT]"));
        }
      }
    }
    else if(
strtolower($msg[0]) == "!cleartopic") {
      
$this->topic "";
      
$this->time gmmktime();
      
$this->bot->aoc->send_tell($name,Infotext("Topic is cleared"));
    }
  }
  
  public function 
pgmsg($name$msg) {
    if(
$this->topic != "") {
      
$this->bot->send_pgroup(Infotext($this->topic " [" Highlight(date("Y-M-d H:i",$this->time)) . " GMT]." "Set by [" Highlight($this->name) . "]"));
    }
    else {
      
$this->bot->send_pgroup(Infotext("No topic since [" Highlight(date("Y-M-d H:i",$this->time)) . " GMT]"));
    }
  }
  
  public function 
pgjoin($name) {
    if(
$this->topic != "") {
      
$this->bot->aoc->send_tell($name,Infotext($this->topic " [" Highlight(date("Y-M-d H:i",$this->time)) . " GMT]." "Set by [" Highlight($this->name) . "]"));
    }
    else {
      
$this->bot->aoc->send_tell($name,Infotext("No topic since [" Highlight(date("Y-M-d H:i",$this->time)) . " GMT]"));
    }
  }
}
[/url]
Title: A Topic Command
Post by: Alreadythere on September 06, 2005, 11:06:50 am
Here my topic module - which should work with the unmodified bot.

There is no check for access rights in any of those functions though, so everybody can change the topic.

Code: [Select]
<?php
/*
* Topic Module for BE Bot <http://bebot.fieses.net>
* Module coded by Alreadythere
*/


  // add the default settings, if not existing
  
$db -> query("INSERT IGNORE INTO settings (setting, value) VALUES ('topic', '')");
  
$db -> query("INSERT IGNORE INTO settings (setting, value) VALUES ('topictime', '0')");
  
$db -> query("INSERT IGNORE INTO settings (setting, value) VALUES ('topic_setter', '')");




$topic = new Topic($bot);

$commands["pgjoin"][] = &$topic;
$commands["pgmsg"]["edittopic"] = &$topic;
$commands["pgmsg"]["topic"] = &$topic;
$commands["tell"]["edittopic"] = &$topic;
$commands["tell"]["topic"] = &$topic;

/*
The Class itself...
*/
class Topic
{
var $bot;


/*
Constructor:
Hands over a referance to the "Bot" class.
*/
function Topic (&$bot)
{
$this -> bot = &$bot;
$this -> topic $this -> get_setting("topic");
$this -> topictime $this -> get_setting("topictime");
$this -> topicsetter $this -> get_setting("topic_setter");
}

function get_setting($set)
{
$res $this -> bot -> db -> select("SELECT * FROM settings WHERE setting = '" $set "'");

if (!empty($res))
return $res[0][1];
else
return "";
}

function set_setting($set$value)
{
$this -> bot -> db -> query("UPDATE settings SET value = '" $value "' WHERE setting = '" $set "'");
}

/*
This gets called on a tell with the command
*/
function tell($name$msg)
{
if (preg_match("/^" $this -> bot -> commpre "topic/i"$msg))
$this -> bot -> send_tell($name$this -> get_topic());
else if (preg_match("/^" $this -> bot -> commpre "edittopic$/i"$msg$info))
$this -> set_topic($name"");
else if (preg_match("/^" $this -> bot -> commpre "edittopic (.+)$/i"$msg$info))
$this -> set_topic($name$info[1]);
else
$this -> bot -> send_help($name);
}

/*
This gets called on msg in the privategroup with the command
*/
function pgmsg($name$msg)
{
if (preg_match("/^" $this -> bot -> commpre "topic/i"$msg))
$this -> bot -> send_pgroup($this -> get_topic());
else if (preg_match("/^" $this -> bot -> commpre "edittopic$/i"$msg$info))
$this -> set_topic($name"");
else if (preg_match("/^" $this -> bot -> commpre "edittopic (.+)$/i"$msg$info))
$this -> set_topic($name$info[1]);
}

/* This function gets called when someone joins the group */
function pgjoin($name) {
$this -> bot -> send_tell($name$this -> get_topic());
}

/* Makes the time string readable */
function make_time()
{
$diftime time() - $this -> topictime;
$timestr ' ';
$diftime floor($diftime 60);
$timestr .= $diftime 60 "min";
$diftime floor($diftime 60);
if ($diftime 0)
$timestr $diftime "h" $timestr;
return $timestr " ago";
}

function get_topic()
{
$topicstr "";

if ($this -> topic == '')
$topicstr .= "No topic!";
else
{
$topicstr .= $this -> topic " [set by " $this -> topicsetter " ";
$topicstr .= $this -> make_time() . "]"
}

return $topicstr;
}

function set_topic($name$topic)
{
$this -> topictime time();
$this -> topic $topic;
$this -> topicsetter $name;

$this -> set_setting("topic"$topic);
$this -> set_setting("topictime"$this -> topictime);
$this -> set_setting("topic_setter"$name);

$this -> bot -> send_pgroup("New topic: " $this -> get_topic());
}
}
?>
Title: A Topic Command
Post by: Alreadythere on October 22, 2005, 01:21:26 am
Had an error in the script, corrected.
Title: A Topic Command
Post by: Alreadythere on October 22, 2005, 09:40:37 am
One more error corrected...
SimplePortal 2.3.7 © 2008-2024, SimplePortal