collapse collapse
* User Info
 
 
Welcome, Guest. Please login or register.
* Search

* Board Stats
  • stats Total Members: 989
  • stats Total Posts: 18366
  • stats Total Topics: 2501
  • stats Total Categories: 7
  • stats Total Boards: 35
  • stats Most Online: 1144

Author Topic: A Topic Command  (Read 10806 times)

0 Members and 1 Guest are viewing this topic.

Offline Jmrxxx

  • BeBot Rookie
  • *
  • Posts: 1
  • Karma: +0/-0
A Topic Command
« 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 :)

Offline Derroylo

  • Contributor
  • *******
  • Posts: 43
  • Karma: +0/-0
A Topic Command
« Reply #1 on: August 22, 2005, 02:19:44 pm »
Well i have one but it isnĀ“t compatible with the normal bebot :(
Derroylo 220/23 NT RK2

Offline Zacix

  • Contributor
  • *******
  • Posts: 73
  • Karma: +0/-0
A Topic Command
« Reply #2 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*. 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]
Zacix
Current projects:
RINGBot, BeBot branch
Neutnet, RK2 Neutral massmessage network

Offline Alreadythere

  • BeBot Maintainer
  • BeBot Hero
  • ******
  • Posts: 1288
  • Karma: +0/-0
A Topic Command
« Reply #3 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());
}
}
?>

Offline Alreadythere

  • BeBot Maintainer
  • BeBot Hero
  • ******
  • Posts: 1288
  • Karma: +0/-0
A Topic Command
« Reply #4 on: October 22, 2005, 01:21:26 am »
Had an error in the script, corrected.

Offline Alreadythere

  • BeBot Maintainer
  • BeBot Hero
  • ******
  • Posts: 1288
  • Karma: +0/-0
A Topic Command
« Reply #5 on: October 22, 2005, 09:40:37 am »
One more error corrected...

 

* Recent Posts
Com bot module by bitnykk
[November 25, 2024, 05:36:11 pm ]


0.8.x updates for AO by bitnykk
[June 23, 2024, 03:19:47 pm ]


0.8.x updates for AoC by bitnykk
[June 23, 2024, 03:19:44 pm ]


[AoC] special char for items module by bitnykk
[February 09, 2024, 09:41:18 pm ]


BeBot still alive & kicking ! by bitnykk
[December 17, 2023, 12:58:44 am ]

* Who's Online
  • Dot Guests: 304
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.
* Forum Staff
bitnykk admin bitnykk
Administrator
Khalem admin Khalem
Administrator
WeZoN gmod WeZoN
Global Moderator
SimplePortal 2.3.7 © 2008-2024, SimplePortal