BeBot - An Anarchy Online and Age Of Conan chat automaton

Archive => Anarchy Online Archive => 0.2.x Custom/Unofficial Modules => Topic started by: MatHack on March 15, 2006, 10:17:06 pm

Title: InfoNote archive
Post by: MatHack on March 15, 2006, 10:17:06 pm
Missed this option on BeBot and it's used a lot on the current IGN orgbot (which I'm replacing with BeBot), so I made it (quick and dirty).

help/info.txt
Code: [Select]
<font color=CCInfoHeader><pre>info [note]</font>
<font color=CCInfoText>Shows the note named [note] or the list of notes if no name is provided.</font>

help/note.txt
Code: [Select]
<font color=CCInfoHeader><pre>note &lt;note&gt; &gt; &lt;contents&gt;</font>
<font color=CCInfoText>Creates &lt;note&gt; with initial &lt;contents&gt;.

<font color=CCInfoHeader><pre>note add &lt;note&gt; &gt; &lt;contents&gt;</font>
Appends &lt;contents&gt; to &lt;note&gt;.

<font color=CCInfoHeader><pre>note del &lt;note&gt;</font>
Removes &lt;note&gt;.</font>

InfoNote.php
Code: [Select]
<?php
/*
* InfoNote.php - InfoNote archive
* Module by MatHack
*/

$db -> query(
"CREATE TABLE IF NOT EXISTS info_note
(
name VARCHAR(50) NOT NULL PRIMARY KEY,
madeby VARCHAR(25),
contents TEXT
)"
);

$infoNote = new InfoNote($bot);

$commands["tell"]["info"] = &$infoNote;
$commands["tell"]["note"] = &$infoNote;
$commands["gc"]["info"] = &$infoNote;

class 
InfoNote
{
var $bot;

function InfoNote (&$bot)
{
$this -> bot = &$bot;
}

function tell($name$msg)
{
if (preg_match("/^" $this -> bot -> commpre "info$/i"$msg$info))
{
$res "<font color=CCInfoHeadline>::: List of notes :::</font>\n\n";
$result $this -> bot -> db -> select("SELECT name, madeby FROM info_note ORDER BY name");
if (!empty($result))
{
foreach ($result as $val)
$res .= " - <a href='chatcmd:///tell <botname> <pre>info " $val[0] . "'>" $val[0] . "</a> (Author: " $val[1] . ")\n";
}
$this -> bot -> send_tell($name$this -> bot -> make_blob("List of notes"$res));
}
else if (preg_match("/^" $this -> bot -> commpre "info (.+)$/i"$msg$info))
{
$result $this -> bot -> db -> select("SELECT name, madeby, contents FROM info_note WHERE name = '" $info[1] . "'");
if (!empty($result))
$this -> bot -> send_tell($name$this -> bot -> make_blob($result[0][0], $result[0][2]) . " (Author: " $result[0][1] . ")");
else
{
$res "<font color=CCInfoHeadline>::: List of notes :::</font>\n\n";
$result $this -> bot -> db -> select("SELECT name, madeby FROM info_note ORDER BY name");
if (!empty($result))
{
foreach ($result as $val)
$res .= " - <a href='chatcmd:///tell <botname> <pre>info " $val[0] . "'>" $val[0] . "</a> (Author: " $val[1] . ")\n";
}
$this -> bot -> send_tell($name$this -> bot -> make_blob("List of notes"$res));
}
}
else if (preg_match("/^" $this -> bot -> commpre "note del (.+)$/i"$msg$info))
{
$result $this -> bot -> db -> select("SELECT madeby FROM info_note WHERE name = '" $info[1] . "'");
if (empty($result))
$this -> bot -> send_tell($name"Note <font color=#ffff00>" $info[1] . "</font> does not exist.");
else
{
if($this -> bot -> admin -> in_group($name"admin") || $result[0][0] == $name)
{
$this -> bot -> db -> query("DELETE FROM info_note WHERE name = '" $info[1] . "'");
$this -> bot -> send_tell($name"Note <font color=#ffff00>" $info[1] . "</font> has been deleted.");
}
else
$this -> bot -> send_tell($name"You must be an admin to do this.");
}
}
else if (preg_match("/^" $this -> bot -> commpre "note add (.+) &gt; (.+)$/i"$msg$info))
{
$result $this -> bot -> db -> select("SELECT madeby FROM info_note WHERE name = '" $info[1] . "'");
if (empty($result))
$this -> bot -> send_tell($name"Note <font color=#ffff00>" $info[1] . "</font> does not exist.");
else
{
if($this -> bot -> admin -> in_group($name"admin") || $result[0][0] == $name)
{
$info[2] = str_replace('"'"&quot;"$info[2]);
$info[2] = str_replace('&lt;'"<"$info[2]);
$info[2] = str_replace('&gt;'">"$info[2]);
$this -> bot -> db -> query('UPDATE info_note SET contents = CONCAT(contents, "' $info[2] . '") WHERE name = "' $info[1] . '"');
$this -> bot -> send_tell($name"Note <font color=#ffff00>" $info[1] . "</font> has been edited.");
}
else
$this -> bot -> send_tell($name"You must be an admin to do this.");
}
}
else if (preg_match("/^" $this -> bot -> commpre "note (.+) &gt; (.+)$/i"$msg$info))
{
$result $this -> bot -> db -> select("SELECT madeby FROM info_note WHERE name = '" $info[1] . "'");
if (!empty($result))
$this -> bot -> send_tell($name"Note <font color=#ffff00>" $info[1] . "</font> already exists.");
else
{
$info[2] = str_replace('"'"&quot;"$info[2]);
$info[2] = str_replace('&lt;'"<"$info[2]);
$info[2] = str_replace('&gt;'">"$info[2]);
$this -> bot -> db -> query('INSERT INTO info_note (name, madeby, contents) VALUES ("' $info[1] . '", "' $name '", "' $info[2] . '")');
$this -> bot -> send_tell($name"Note <font color=#ffff00>" $info[1] . "</font> has been created.");
}
}
}

function gc($name$msg)
{
if (preg_match("/^" $this -> bot -> commpre "info$/i"$msg$info))
{
$res "<font color=CCInfoHeadline>::: List of notes :::</font>\n\n";
$result $this -> bot -> db -> select("SELECT name, madeby FROM info_note ORDER BY name");
if (!empty($result))
{
foreach ($result as $val)
$res .= " - <a href='chatcmd:///tell <botname> <pre>info " $val[0] . "'>" $val[0] . "</a> (Author: " $val[1] . ")\n";
}
$this -> bot -> send_gc($this -> bot -> make_blob("List of notes"$res));
}
else if (preg_match("/^" $this -> bot -> commpre "info (.+)$/i"$msg$info))
{
$result $this -> bot -> db -> select("SELECT name, madeby, contents FROM info_note WHERE name = '" $info[1] . "'");
if (!empty($result))
$this -> bot -> send_gc($this -> bot -> make_blob($result[0][0], $result[0][2]) . " (Author: " $result[0][1] . ")");
else
{
$res "<font color=CCInfoHeadline>::: List of notes :::</font>\n\n";
$result $this -> bot -> db -> select("SELECT name, madeby FROM info_note ORDER BY name");
if (!empty($result))
{
foreach ($result as $val)
$res .= " - <a href='chatcmd:///tell <botname> <pre>info " $val[0] . "'>" $val[0] . "</a> (Author: " $val[1] . ")\n";
}
$this -> bot -> send_gc($this -> bot -> make_blob("List of notes"$res));
}
}
}
}
?>
Title: Re: InfoNote archive
Post by: Zakus on March 15, 2006, 10:28:12 pm
I've missed that command as well. Thanks for that.
SimplePortal 2.3.7 © 2008-2024, SimplePortal