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: Updated News.php  (Read 6058 times)

0 Members and 1 Guest are viewing this topic.

Offline Naturalistic

  • Contributor
  • *******
  • Posts: 221
  • Karma: +0/-0
Updated News.php
« on: December 15, 2005, 06:46:32 am »
Note: change the ranks who can use it (aka admin to raidleader, or add superadmin etc.)
Also: the !news now involves 3 commands.

!news add <news item>
!news rem <news ID>
!news

Code: [Select]
<?
  /*
   * News.php - News
   *
   * BeBot - An Anarchy Online Chat Automaton
   * Copyright (C) 2004 Jonas Jax
   *
   * Developed by Blondengy (RK1)
   * Special thanks goes out to Khalem (RK1) for his support.
   *
   * File last changed at $LastChangedDate: 2005-12-15 (Wed, 15 Dec 2005) $
   * Revision: $Id: News.php by Naturalistic $
   */
   
 
  $db -> query("CREATE TABLE IF NOT EXISTS news
              (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
              name VARCHAR(30),
              news TEXT)");


  $news = new News($bot);

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



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

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



    /*
      This gets called on a tell with the command
    */
    function tell($name, $msg)
    {
if (preg_match("/^" . $this -> bot -> commpre . "news add (.+)$/i", $msg, $info))
$this -> bot -> send_tell($name, $this -> set_news($name, $info[1]));
else if (preg_match("/^" . $this -> bot -> commpre . "news rem ([0-9]+)$/i", $msg, $info))
$this -> bot -> send_tell($this -> del_news($name, $info[1]));
else
$this -> bot -> send_tell($name, $this -> get_news());
    }



    /*
      This gets called on a msg in the privgroup with the command
    */
    function pgmsg($name, $msg)
    {
if (preg_match("/^" . $this -> bot -> commpre . "news add (.+)$/i", $msg, $info))
$this -> bot -> send_pgroup($this -> set_news($name, $info[1]));
else if (preg_match("/^" . $this -> bot -> commpre . "news rem ([0-9]+)$/i", $msg, $info))
$this -> bot -> send_pgroup($this -> del_news($name, $info[1]));
else
$this -> bot -> send_pgroup($this -> get_news());
    }



    /*
      This gets called on a msg in the guildchat with the command
    */
    function gc($name, $msg)
    {
if (preg_match("/^" . $this -> bot -> commpre . "news add (.+)$/i", $msg, $info))
$this -> bot -> send_gc($this -> set_news($name, $info[1]));
else if (preg_match("/^" . $this -> bot -> commpre . "news rem ([0-9]+)$/i", $msg, $info))
$this -> bot -> send_gc($this -> del_news($name, $info[1]));
else
$this -> bot -> send_gc($this -> get_news());
    }



/*
Get news
*/
function get_news()
{
      $inside = "<font color=CCInfoHeadline>:::: News ::::\n\n";
     
      $result = $this -> bot -> db -> select("SELECT id, name, news FROM news ORDER BY id DESC LIMIT 0, 10");
      if (!empty($result))
      foreach ($result as $val)
      {
      $inside .= "<font color=CCInfoHeader>" . gmdate("dS M, H:i", $val[0]) . " GMT <font color=CCCCTextColor>" . $val[1] . "</font> wrote:\n";
      $inside .= "(ID: ".$val[0].") <font color=CCInfoText>" . $val[2] . "\n\n";
      }
     
return "News :: " . $this -> bot -> make_blob("click to view", $inside);
}



/*
Sets new news
*/
function set_news($name, $msg)
{
if ($this -> bot -> guildbot || $this -> bot -> admin -> in_group($name, "admin"))
{
$this -> bot -> db -> query("INSERT INTO news (id, name, news) VALUES (" . time() .
", '" . $name . "', '" . $msg . "')");
return "News has been added.";
}
else
return "You must be an admin to do this";
}

function del_news($name, $msg)
{
if ($this -> bot -> guildbot || $this -> bot -> admin -> in_group($name, "admin"))
{
$this -> bot -> db -> query("DELETE FROM news WHERE id = '" . $msg . "'");
return "News has been removed.";
}
else
return "You must be an admin to do this";
}
  }
?>
220/25 Eternalist Doctor
-----------------------------
Campalot Coding Co-ordinator and Super Admin
http://www.campalot.info/index.php

Offline Xenixa

  • Contributor
  • *******
  • Posts: 307
  • Karma: +0/-0
Re: Updated News.php
« Reply #1 on: December 15, 2005, 10:12:55 pm »
Just a suggetion on this. You may want to change the set_news funtions slightly.
Changed this line:
Code: [Select]
", '" . $name . "', '" . $msg . "')");To this:
Code: [Select]
", '" . $name . "', '" . addslashes($msg) . "')");
People like to use there apostrophies and other stuff that makes the msg stored look real funny when it's called back. :)
<<< Hack's in Zend Studio

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

Offline Naturalistic

  • Contributor
  • *******
  • Posts: 221
  • Karma: +0/-0
Re: Updated News.php
« Reply #2 on: December 15, 2005, 11:44:59 pm »
Ah, didn't think of that  :P

Thanks for pointing it out.
220/25 Eternalist Doctor
-----------------------------
Campalot Coding Co-ordinator and Super Admin
http://www.campalot.info/index.php

 

* 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: 448
  • 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