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
<?
/*
* 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";
}
}
?>