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

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

Author Topic: Quotes  (Read 4574 times)

0 Members and 1 Guest are viewing this topic.

Offline Sabkor

  • Contributor
  • *******
  • Posts: 30
  • Karma: +0/-0
Quotes
« on: December 10, 2005, 04:11:15 am »
We all say stupid things, and everyone wants to immortalize them. The guild loves this one, so I thought I'd share with you all ;)

No helpfile, but it's easy to use:

!quotes - Show a random quote
!quotes <id> - Show a specific quote
!quotes add <text> - Add a new quote
!quotes del <id> - Delete a quote that you added (or if you're an admin, delete any quote)
Code: [Select]
<?php
  
/*
   * Quotes.php - Module template.
   *
   * BeBot - An Anarchy Online Chat Automaton
   * Copyright (C) 2004 Jonas Jax
   *
   * Developed by Sabkor (RK1)
   *
   * File last changed at $LastChangedDate: 2004-12-29 01:41:32 +0100 (Wed, 29 Dec 2004) $
   * Revision: $Id: _ClassName.php 8 2004-12-29 00:41:32Z blondengy $
   */
   
  /*
    Add a "_" at the beginning of the file (_quotes.php) if you do not want it to be loaded.
  */

  
$db -> query("CREATE TABLE IF NOT EXISTS quotes
              (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, quote VARCHAR(2000), contributor VARCHAR(15))"
);
  
  
$quotes = new Quotes($bot);

  
$commands["tell"]["quotes"] = &$quotes;
  
$commands["pgmsg"]["quotes"] = &$quotes;
  
$commands["gc"]["quotes"] = &$quotes;


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

    
/*
      Constructor:
        Hands over a referance to the "Bot" class.
    */
    
function Quotes (&$bot)
    {
      
$this -> bot = &$bot;
    }



    
/*
      This gets called on a tell with the command
    */
    
function tell($name$msg)
    {
   
  if (preg_match("/^" $this -> bot -> commpre "quotes ([0-9]+)$/i"$msg$info))
$this -> bot ->send_tell($name$this -> send_quote($info[1]));
   
  else if (preg_match("/^" $this -> bot -> commpre "quotes add (.+)$/i"$msg$info))
   
   $this -> bot ->send_tell($name$this -> add_quote($info[1], $name));
   
  else if (preg_match("/^" $this -> bot -> commpre "quotes (remove|del|rem|delete) ([0-9]+)$/i"$msg$info))
   
   $this -> bot ->send_tell($name$this -> del_quote($info[2], $name));      
   
  else
$this -> bot ->send_tell($name$this -> send_quote(-1));
    }



    
/*
      This gets called on a msg in the privgroup with the command
    */
    
function pgmsg($name$msg)
    {
   
  if (preg_match("/^" $this -> bot -> commpre "quotes ([0-9]+)$/i"$msg$info))
$this -> bot ->send_pgroup($this -> send_quote($info[1]));
   
  else if (preg_match("/^" $this -> bot -> commpre "quotes add (.+)$/i"$msg$info))
   
   $this -> bot ->send_pgroup($this -> add_quote($info[1], $name));
   
  else if (preg_match("/^" $this -> bot -> commpre "quotes (remove|del|rem|delete) ([0-9]+)$/i"$msg$info))
   
   $this -> bot ->send_pgroup($this -> del_quote($info[2], $name));      
   
  else
$this -> bot ->send_pgroup($this -> send_quote(-1));
    }



    
/*
      This gets called on a msg in the guildchat with the command
    */
    
function gc($name$msg)
    {
   
  if (preg_match("/^" $this -> bot -> commpre "quotes ([0-9]+)$/i"$msg$info))
$this -> bot ->send_gc($this -> send_quote($info[1]));
   
  else if (preg_match("/^" $this -> bot -> commpre "quotes add (.+)$/i"$msg$info))
   
   $this -> bot ->send_gc($this -> add_quote($info[1], $name));
   
  else if (preg_match("/^" $this -> bot -> commpre "quotes (remove|del|rem|delete) ([0-9]+)$/i"$msg$info))
   
   $this -> bot ->send_gc($this -> del_quote($info[2], $name));
   
  else
$this -> bot ->send_gc($this -> send_quote(-1));
    }

function add_quote($strquote$name)
{
    $this -> bot -> db -> query("INSERT INTO quotes (quote, contributor) VALUES ('" str_replace("'""''"$strquote) . "', '" $name "')");
    $num $this -> bot -> db -> select("SELECT id FROM quotes ORDER BY id DESC");
    $strmsg "Thank you, your quote has been added as id #" $num[0][0];
   
   
   
    return $strmsg;        
}

function del_quote($qnum$name)
{
   
    $result $this -> bot -> db -> select("SELECT * FROM quotes WHERE id=" $qnum);
    if (!empty($result)) {
    $candel false;
if($this -> bot -> admin -> in_group($name"superadmin")) $candel true;
if($this -> bot -> admin -> in_group($name"admin")) $candel true;
if($result[0][2]=$name$candel true;

if ($candel=true) {
$this -> bot -> db -> query("DELETE FROM quotes WHERE id="$qnum);
$reply "Quote removed.";
}
else
$reply "Unable to delete quote with ID of " $qnum ". You must be an admin, or the contributor of the quote to delete it.";

} else {
$num $this -> bot -> db -> select("SELECT id FROM quotes ORDER BY id DESC");
$reply "Quote with id of " $qnum " not found. (Highest quote ID is " $num[0][0] . ".)";
}

return $reply;
}

function send_quote($qnum)
{
$strquote "";
if($qnum == -1) {
$num $this -> bot -> db -> select("SELECT count(*) FROM quotes");
   
   $result $this -> bot -> db -> select("SELECT * FROM quotes");
   
  
   
   if($num[0][0] > 0) {
   
   $row rand(0,$num[0][0]);
   
   $strquote "#" $result[$row][0] . " - " $result[$row][1] . " [Contributed by: " $result[$row][2] . "]";
   
   } else {
   
   $strquote "No quotes exist. Add some!";
   
   }
} else {
   
   $result $this -> bot -> db -> select("SELECT * FROM quotes WHERE id=" $qnum);
       if (!empty($result)) {
       $strquote "#" $result[0][0] . " - " $result[0][1] . " [Contributed by: " $result[0][2] . "]";
    } else {
    $num $this -> bot -> db -> select("SELECT id FROM quotes ORDER BY id DESC");
    $strquote "Quote with id of " $qnum " not found. (Highest quote ID is " $num[0][0] . ".)";
    }
}

return $strquote;
}

  }
?>

« Last Edit: December 11, 2005, 03:47:23 am by Khalem »

Offline Akarah

  • Contributor
  • *******
  • Posts: 72
  • Karma: +0/-0
    • http://synergyfactor.net/
Quotes
« Reply #1 on: December 10, 2005, 04:30:12 am »
haha! i just wrote one of these too :)

slightly different, but similar enough that i'm not going to post mine now. good work :)

Offline Xenixa

  • Contributor
  • *******
  • Posts: 307
  • Karma: +0/-0
Quotes
« Reply #2 on: December 10, 2005, 08:31:02 am »
hheh, like "Pinks" on Gridbot. :D
<<< Hack's in Zend Studio

All my Custom Bebot files may be Found Here <-clicky

Offline mookie

  • BeBot User
  • **
  • Posts: 27
  • Karma: +0/-0
Quotes
« Reply #3 on: December 10, 2005, 08:54:28 am »
Here is a help file for Quotes

Code: [Select]

<font color=CCInfoHeader><pre>quotes</font>
<font color=CCInfoText>Shows a random quote.</font>
<font color=CCInfoHeader><pre>quotes &lt;ID&gt;</font>
<font color=CCInfoText>Shows a specific quote.</font>
<font color=CCInfoHeader><pre>quotes add &lt;text&gt;</font>
<font color=CCInfoText>Add a new quote.</font>
<font color=CCInfoHeader><pre>quotes del &lt;ID&gt;</font>
<font color=CCInfoText>Delete a quote that you added (or if you're an admin, delete any quote).</font>

Offline Wanuarmi

  • Contributor
  • *******
  • Posts: 121
  • Karma: +0/-0
Quotes
« Reply #4 on: December 10, 2005, 09:20:05 am »
great module, one of my members found a bug, it seems that deleted quotes ids are added to the random picked ones, so it shows an empty quote sometimes

btw my mysql is configured so it goes on with index numbers, it doesnt use the first available one

Offline Wanuarmi

  • Contributor
  • *******
  • Posts: 121
  • Karma: +0/-0
Quotes
« Reply #5 on: December 10, 2005, 09:32:49 am »
temp fix

Code: [Select]
<?
  /*
   * Quotes.php - Module template.
   *
   * BeBot - An Anarchy Online Chat Automaton
   * Copyright (C) 2004 Jonas Jax
   *
   * Developed by Sabkor (RK1)
   *
   * File last changed at $LastChangedDate: 2004-12-29 01:41:32 +0100 (Wed, 29 Dec 2004) $
   * Revision: $Id: _ClassName.php 8 2004-12-29 00:41:32Z blondengy $
   */
   
  /*
    Add a "_" at the beginning of the file (_quotes.php) if you do not want it to be loaded.
  */

  $db -> query("CREATE TABLE IF NOT EXISTS quotes
              (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, quote VARCHAR(2000), contributor VARCHAR(15))");
 
  $quotes = new Quotes($bot);

  $commands["tell"]["quotes"] = &$quotes;
  $commands["pgmsg"]["quotes"] = &$quotes;
  $commands["gc"]["quotes"] = &$quotes;


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

    /*
      Constructor:
        Hands over a referance to the "Bot" class.
    */
    function Quotes (&$bot)
    {
      $this -> bot = &$bot;
    }



    /*
      This gets called on a tell with the command
    */
    function tell($name, $msg)
    {
        if (preg_match("/^" . $this -> bot -> commpre . "quotes ([0-9]+)$/i", $msg, $info))
      $this -> bot ->send_tell($name, $this -> send_quote($info[1]));
        else if (preg_match("/^" . $this -> bot -> commpre . "quotes add (.+)$/i", $msg, $info))
           $this -> bot ->send_tell($name, $this -> add_quote($info[1], $name));
        else if (preg_match("/^" . $this -> bot -> commpre . "quotes (remove|del|rem|delete) ([0-9]+)$/i", $msg, $info))
           $this -> bot ->send_tell($name, $this -> del_quote($info[2], $name));          
        else
      $this -> bot ->send_tell($name, $this -> send_quote(-1));
    }



    /*
      This gets called on a msg in the privgroup with the command
    */
    function pgmsg($name, $msg)
    {
        if (preg_match("/^" . $this -> bot -> commpre . "quotes ([0-9]+)$/i", $msg, $info))
      $this -> bot ->send_pgroup($this -> send_quote($info[1]));
        else if (preg_match("/^" . $this -> bot -> commpre . "quotes add (.+)$/i", $msg, $info))
           $this -> bot ->send_pgroup($this -> add_quote($info[1], $name));
        else if (preg_match("/^" . $this -> bot -> commpre . "quotes (remove|del|rem|delete) ([0-9]+)$/i", $msg, $info))
           $this -> bot ->send_pgroup($this -> del_quote($info[2], $name));          
        else
      $this -> bot ->send_pgroup($this -> send_quote(-1));
    }



    /*
      This gets called on a msg in the guildchat with the command
    */
    function gc($name, $msg)
    {
        if (preg_match("/^" . $this -> bot -> commpre . "quotes ([0-9]+)$/i", $msg, $info))
      $this -> bot ->send_gc($this -> send_quote($info[1]));
        else if (preg_match("/^" . $this -> bot -> commpre . "quotes add (.+)$/i", $msg, $info))
           $this -> bot ->send_gc($this -> add_quote($info[1], $name));
        else if (preg_match("/^" . $this -> bot -> commpre . "quotes (remove|del|rem|delete) ([0-9]+)$/i", $msg, $info))
           $this -> bot ->send_gc($this -> del_quote($info[2], $name));
        else
      $this -> bot ->send_gc($this -> send_quote(-1));
    }

   function add_quote($strquote, $name)
   {
       $this -> bot -> db -> query("INSERT INTO quotes (quote, contributor) VALUES ('" . str_replace("'", "''", $strquote) . "', '" . $name . "')");
       $num = $this -> bot -> db -> select("SELECT id FROM quotes ORDER BY id DESC");
       $strmsg = "Thank you, your quote has been added as id #" . $num[0][0];
         
          return $strmsg;          
   }
   
   function del_quote($qnum, $name)
   {
          $result = $this -> bot -> db -> select("SELECT * FROM quotes WHERE id=" . $qnum);
         if (!empty($result)) {
            $candel = false;
         if($this -> bot -> admin -> in_group($name, "superadmin")) $candel = true;
         if($this -> bot -> admin -> in_group($name, "admin")) $candel = true;
         if($result[0][2]=$name) $candel = true;
         
         if ($candel=true) {
            $this -> bot -> db -> query("DELETE FROM quotes WHERE id=". $qnum);
            $reply = "Quote removed.";
         }
         else
            $reply = "Unable to delete quote with ID of " . $qnum . ". You must be an admin, or the contributor of the quote to delete it.";
         
      } else {
         $num = $this -> bot -> db -> select("SELECT id FROM quotes ORDER BY id DESC");
         $reply = "Quote with id of " . $qnum . " not found. (Highest quote ID is " . $num[0][0] . ".)";
      }
     
      return $reply;
   }

   function send_quote($qnum)
   {
      $strquote = "";
      if($qnum == -1) {
         $num = $this -> bot -> db -> select("SELECT id FROM quotes ORDER BY id DESC");
              $result = $this -> bot -> db -> select("SELECT * FROM quotes");
           
              if($num[0][0] > 0) {
    $found = false;
while ($found == false)
{
                $row = rand(0,$num[0][0]);
if (!empty($result[$row][0]))
{
$strquote = "#" . $result[$row][0] . " - " . $result[$row][1] . " [Contributed by: " . $result[$row][2] . "]";
$found = true;
}
}
              } else {
                 $strquote = "No quotes exist. Add some!";
              }
      } else {
              $result = $this -> bot -> db -> select("SELECT * FROM quotes WHERE id=" . $qnum);
              if (!empty($result)) {
                 $strquote = "#" . $result[0][0] . " - " . $result[0][1] . " [Contributed by: " . $result[0][2] . "]";
            } else {
               $num = $this -> bot -> db -> select("SELECT id FROM quotes ORDER BY id DESC");
               $strquote = "Quote with id of " . $qnum . " not found. (Highest quote ID is " . $num[0][0] . ".)";
            }        
      }

      return $strquote;
   }

  }
?>

Offline Sabkor

  • Contributor
  • *******
  • Posts: 30
  • Karma: +0/-0
Re: Quotes
« Reply #6 on: December 11, 2005, 09:26:24 am »
Good fix, Wanuarmi, thanks :)

I had just added the remove feature and hadn't even really used it much, never even crossed my mind about that happening...

Offline Shelnaria

  • BeBot Rookie
  • *
  • Posts: 17
  • Karma: +0/-0
Re: Quotes
« Reply #7 on: December 13, 2005, 06:01:21 am »
Code: [Select]
function del_quote($qnum, $name)
   {
          $result = $this -> bot -> db -> select("SELECT * FROM quotes WHERE id=" . $qnum);
         if (!empty($result)) {
            $candel = false;
         if($this -> bot -> admin -> in_group($name, "superadmin")) $candel = true;
         if($this -> bot -> admin -> in_group($name, "admin")) $candel = true;
         if($result[0][2]=$name) $candel = true;
         
         if ($candel=true) {
            $this -> bot -> db -> query("DELETE FROM quotes WHERE id=". $qnum);
            $reply = "Quote removed.";
         }
         else
            $reply = "Unable to delete quote with ID of " . $qnum . ". You must be an admin, or the contributor of the quote to delete it.";
         
      } else {
         $num = $this -> bot -> db -> select("SELECT id FROM quotes ORDER BY id DESC");
         $reply = "Quote with id of " . $qnum . " not found. (Highest quote ID is " . $num[0][0] . ".)";
      }
     
      return $reply;
   }

Need to change two lines so only those who are supposed to be able to CAN delete the quotes. Thanks to Shadowmaster and Naturalistic on their help in solving this for me.

Code needed to change:
Code: [Select]
if($result[0][2]=$name) $candel = true;
         
         if ($candel=true) {
To
Code: [Select]
if($result[0][2]==$name) $candel = true;
         
         if ($candel==true) {

Offline Sabkor

  • Contributor
  • *******
  • Posts: 30
  • Karma: +0/-0
Re: Quotes
« Reply #8 on: December 17, 2005, 09:58:48 pm »
ha, you know what... I always forget to do that when I'm coding PHP ;)  Thanks

Offline Glarawyn

  • BeBot Hero
  • ******
  • Posts: 521
  • Karma: +0/-0
Re: Quotes
« Reply #9 on: January 08, 2006, 11:06:01 pm »
I was getting a database error when adding quotes. Changing the quote column from VARCHAR to BLOB fixed.

Code: [Select]
$db -> query("CREATE TABLE IF NOT EXISTS quotes
              (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, quote VARCHAR(2000), contributor VARCHAR(15))");

Code: [Select]
$db -> query("CREATE TABLE IF NOT EXISTS quotes
              (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, quote BLOB, contributor VARCHAR(15))");

Offline Akarah

  • Contributor
  • *******
  • Posts: 72
  • Karma: +0/-0
    • http://synergyfactor.net/
Re: Quotes
« Reply #10 on: January 09, 2006, 12:29:47 am »
might want to addslashes() some of the input stuff too   :o

Offline jjones666

  • Contributor
  • *******
  • Posts: 353
  • Karma: +0/-0
Re: Quotes
« Reply #11 on: January 25, 2006, 02:26:04 am »
Great module!  We have been using this a lot and have filled up about 50 quotes so far.  I wondered if there was a possibility to add a command so that all quotes could be displayed in a blob (kind of like how !news outputs)?

Cheers,

-jj-

Offline Glarawyn

  • BeBot Hero
  • ******
  • Posts: 521
  • Karma: +0/-0
Re: Quotes
« Reply #12 on: January 25, 2006, 09:54:50 pm »
might want to addslashes() some of the input stuff too   :o

I think what Akarah is trying to say is that more characters than single quote need extra handling when inserting into a MySQL database. Single quote ('), double quote ("), backslash (\) and NUL (the NULL byte) need to be escaped by adding a \ character.

See addslashes and stripslashes.

While what you have seems to work ok with " and ', if someone does something like
Quote
/tell bot !quotes add 1\2
Bot: Thank you, your quote has been added as id #73

You get:
Quote
/tell bot !quotes 73
Bot: #73 - 12 [Contributed by: Glarawyn]


For example:

Line 99:

Find
Code: [Select]
$this -> bot -> db -> query("INSERT INTO quotes (quote, contributor) VALUES ('" . str_replace("'", "''", $strquote) . "', '" . $name . "')");

Replace with
Code: [Select]
$this -> bot -> db -> query("INSERT INTO quotes (quote, contributor) VALUES ('" . addslashes($strquote) . "', '" . $name . "')");


I tried the change, and I didn't really notice any difference. I really wasn't able to trigger any errors, but that could be due to a PHP or MySQL configuration on my end.

 

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


0.8.x updates for AoC by bitnykk
[January 30, 2024, 11:16:08 pm]


0.8.x updates for AO by bitnykk
[January 30, 2024, 11:15:37 pm]


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


Bebot and Rasberry by bitnykk
[November 29, 2023, 11:04:14 pm]

* Who's Online
  • Dot Guests: 498
  • 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