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: Wishlist module function  (Read 4060 times)

0 Members and 1 Guest are viewing this topic.

Offline crocks

  • BeBot User
  • **
  • Posts: 23
  • Karma: +0/-0
Wishlist module function
« on: June 22, 2012, 01:31:37 am »
Hey guys Im wondering if its possible to modify a wishlist module function:

Code: [Select]
// returns a list of unhandled requests
function getUnhandled($name)
{
// $lastUn = $this -> bot -> core('settings') -> get("Wishlist", "lastunhandled");
$return = "<left>##yellow##Unhandled Requests##end##:</left>\n";
$sql = "select " . // FIXME ugly dependancy
       "distinct(" . $this -> dataname . ".id), " .
       $this -> dataname . ".creator, " .
       $this -> dataname . ".timestamp, " .
       $this -> dataname . ".request, " .
       "online.status_gc_changetime " .
       "from " . $this -> dataname . " left join online on " . $this -> dataname . ".creator=online.nickname " .
       "where " . $this -> dataname . ".status=1 order by " . $this -> dataname . ".timestamp, online.status_gc_changetime;";
$result = $this -> bot -> db -> select($sql);

The function itself now lists all unhandled wishes from all players on a command !wishlist.

Im asking. Is it possible to modify this function to show only my own wishes. Like I was logged on character called Crocks it would show only wishes I have added from Crocks or Crockss alts.
My point in this is to make the wishes little bit private to avoid everyone else seeing it but original character who writes !wishlist.

Im not good at SQL else I would try harder, but my tries already took me good 2 hours without any results.

My idea was put in $select something like " ... WHERE creator = " $player " ...."

Thanks
Crocks
« Last Edit: June 23, 2012, 12:07:39 am by crocks »

Offline crocks

  • BeBot User
  • **
  • Posts: 23
  • Karma: +0/-0
Re: Wishlist module function
« Reply #1 on: June 25, 2012, 01:01:18 am »
Here is the forum link to the module and its full code so you dont have to download it If it helps to ansfer my question.

http://bebot.link/ao-0-6-x-customunofficial-modules/wishlist-module/

Code: [Select]
<?

/*
* Wishlist.php - Request tracking module for the bot.
* Version: 1.2a
* Developed by: Helkarakse (RK2)
* Original module purchased by Tutomech (RK2)
* Module has been upgraded/modified by Tutomech (RK)
*
* Copyright (C) 2010 Zhe Yang Lee
*
*
* Written for the following platform:
* BeBot - An Anarchy Online & Age of Conan Chat Automaton
* Copyright (C) 2004 Jonas Jax
* Copyright (C) 2005-2007 Thomas Juberg Stens?s, ShadowRealm Creations and the BeBot development team.
*
* Developed by:
* - Alreadythere (RK2)
* - Blondengy (RK1)
* - Blueeagl3 (RK1)
* - Glarawyn (RK1)
* - Khalem (RK1)
* - Naturalistic (RK1)
* - Temar (RK1)
*
* See Credits file for all aknowledgements.
*
*  This program is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; version 2 of the License only.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software
*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
*  USA
*
* File last changed at $LastChangedDate: 2010-03-03 09:53:30 +1030 (Wed, 3 Mar 2010) $
*/

$wishlist = new wishlist($bot);

class wishlist extends BaseActiveModule
{
// defines db tablename
private $dataname = '';
private $rulesname = '';

function __construct (&$bot)
{
parent::__construct(&$bot, get_class($this));

$this -> bot -> core('settings') -> create("Wishlist", "lastfilled", "15", "How far back should filled requests be displayed in requests?", "0;1;2;3;4;5;7;10;15", FALSE, 1);
$this -> bot -> core('settings') -> create("Wishlist", "lastdenied", "5", "How far back should denied requests be displayed in requests?", "0;1;2;3;4;5;6;7", FALSE, 2);
$this -> bot -> core('settings') -> create("Wishlist", "checkonline", "TRUE", "Should wishlist include online status?", "TRUE;FALSE", FALSE, 3);
$this -> bot -> core('settings') -> create("Wishlist", "miawarning", "7", "How long has the person to be offline in days to be tagged as MIA?", "3;7;14;21", FALSE, 4);
$this -> bot -> core('settings') -> create("Wishlist", "miastatus", "14", "How long has the person to be offline in days to be classified as MIA?", "3;7;14;21", FALSE, 5);
$this -> bot -> core('settings') -> create("Wishlist", "hidemia", "TRUE", "Do not display wishes of persons who had MIA status over a week?", "TRUE;FALSE", FALSE, 6);
$this -> bot -> core('settings') -> create("Wishlist", "otherbot", "", "Name of the bot that is hosting data (has to be in same database).", "", FALSE, 10);
$this -> bot -> core("settings") -> create("Wishlist", "adminaccess", "ADMIN", "Who should be able to refuse/delete/undo requests?", "OWNER:SUPERADMIN;ADMIN;LEADER;MEMBER;GUEST;ANONYMOUS", FALSE, 15);

// we might want to draw data from other bot (has to be installed in same database)
$otherbot = $this -> bot -> core('settings') -> get("Wishlist", "otherbot");
$this -> dataname = $this -> bot -> db -> define_tablename("wishlist", "true");
$this -> rulesname = $this -> bot -> db -> define_tablename("wishlist_rules", "true");
if ($otherbot != '') // FIXME ugly patch here, name dependant on hard coded name
{
  $this -> dataname = $otherbot.'_wishlist';
  $this -> rulesname = $otherbot.'_wishlist_rules';
}

// first run, creates table, botname specific
// status in this table has 3 options:
// - value 1 for unhandled
// - value 2 for filled.
// - value 3 for denied
// - value 0 for deleted
$this -> bot -> db -> query("CREATE TABLE IF NOT EXISTS ".$this -> dataname."(
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
`creator` VARCHAR(50),
`timestamp` INT,
`request` TEXT,
`status` VARCHAR(1),
`statname` VARCHAR(50),
`stattime` INT
)");

$this -> bot -> db -> query("CREATE TABLE IF NOT EXISTS ".$this -> rulesname."(
`id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
`creator` VARCHAR(50),
`timestamp` INT,
`rules` TEXT
)");

$this -> register_command("all", "wishadmin", "ADMIN");
$this -> register_command("all", "wishlist", "ANONYMOUS");

$this -> help['description'] = 'Wishlist Tracking';
$this -> help['command']['wishadmin'] = 'Displays the wishlist admin menu.';
$this -> help['command']['wishadmin rules <rules>'] = 'Changes the rules for wishlist tracking.';
$this -> help['command']['wishadmin refuse <id>'] = 'Refuses the request with id <id>.';
$this -> help['command']['wishadmin delete <id>'] = 'Deletes the request with id <id>. This is irreversible.';
$this -> help['command']['wishadmin undo <id>'] = 'Changes the status of a request back to unfulfilled.';

$this -> help['command']['wishlist'] = 'Displays the wishlist menu.';
$this -> help['command']['wishlist add <request>'] = 'Adds a new request.';
$this -> help['command']['wishlist delete <id>'] = 'Deletes a request. You can only delete your own requests.';
$this -> help['command']['wishlist filled <id>'] = 'Completes a request with id <id>';
}

function command_handler($name, $msg, $origin)
{
// explode to separate vars
$vars = explode(' ', strtolower($msg));
$command = $vars[0];
$sub = $vars[1];
if ($command == 'wishlist')
{
switch ($sub)
{
case '':
return $this -> showUI($name);
break;

case 'add':
return $this -> requestAdd($msg, $name);
break;

// FIXME database query silently refuses to delete other people's wish
// FIXME should return an error message
case 'delete':
$id = $vars[2];
return $this -> requestDel($id, $name);
break;

case 'filled':
$id = $vars[2];
return $this -> requestFill($id, $name);
break;

default:
break;
}
}
else if ($command == 'wishadmin')
{
  if (! $this -> checkAccess($name)) // FIXME should not be needed
  {
      return 'Access denied';
  }
  else
  {
switch ($sub)
{
case 'rules':
return $this -> changeRules($msg, $name);
break;

case 'refuse':
$id = $vars[2];
return $this -> requestRefuse($id, $name);
break;

case 'delete':
$id = $vars[2];
return $this -> requestDelAdmin($id);
break;

case 'undo':
$id = $vars[2];
return $this -> requestUndo($id);
break;

default:
break;
}
}
      }
}

// This function creates a text blob containing the user interface and returns it to the user
function showUI($name)
{
// get current time
$timeUn = time();
$timeFi = time();
$timeDe = time();
// get the number of pprocessed wishes to show
$lastFi = $this -> bot -> core('settings') -> get("Wishlist", "lastfilled");
$lastDe = $this -> bot -> core('settings') -> get("Wishlist", "lastdenied");

// obtain information
$rules = $this -> getRules();
$unhandled = $this -> getUnhandled($name);
$recent = $this -> getRecent($timeFi, $name);
$denied = $this -> getDenied($timeDe, $name);

// text header
$text  = "<left>##blob_title##Wishlist##end##</left>\n\n";
$text .= $rules;
$text .= $unhandled;
$text .= $recent;
$text .= $denied;
$return = $this -> make_blob("Wishlist", $text);
return $return;
}

function getOnlineNames() {

  $onlinelist = array();

  $sql = 'select nickname from online where status_gc <> 0 or status_pg <> 0;';
  $result = $this -> bot -> db -> select($sql);

  foreach ($result as $row) {
array_push($onlinelist, $row[0]);
  }

  return $onlinelist;
}

function getAltsOnlineCache() {
 
    $altscache = array();
  $names = $this -> getOnlineNames();

  foreach ($names as $name) {
   
    // FIXME is optimization possible?
    if (! array_key_exists($name, $altscache)) {
      $main = $this -> bot -> core("alts") -> main($name);
     
      if (! ($main == "")) {

      $altscache[$main] = $name;
      }

      $alts = $this -> bot -> core("alts") -> get_alts($main);
      foreach ($alts as $alt) {

// add all alts as online alt
$altscache[$alt] = $name;
      }
    }
 
    // self is always online
    $altscache[$name] = $name;

    $main = ""; $alt = "";
  }

  return $altscache;
}

// This function returns the rules for the wishlist
function getRules()
{
$return = "<left>##yellow##Rules:##end##</left>\n";
$sql = "SELECT * FROM ".$this -> rulesname." WHERE `id` = 1";
$result = $this -> bot -> db -> select($sql);
if ($result)
{
foreach($result as $row)
{
$return .= $row[3]."\n\n";
}
}
return $return;
}

// returns a list of unhandled requests
function getUnhandled($name)
{
// $lastUn = $this -> bot -> core('settings') -> get("Wishlist", "lastunhandled");
$return = "<left>##yellow##Unhandled requests##end##:</left>\n";
$sql = "select " . // FIXME ugly dependancy
       "distinct(" . $this -> dataname . ".id), " .
       $this -> dataname . ".creator, " .
       $this -> dataname . ".timestamp, " .
       $this -> dataname . ".request, " .
       "online.status_gc_changetime " .
       "from " . $this -> dataname . " left join online on " . $this -> dataname . ".creator=online.nickname " .
       "where " . $this -> dataname . ".status=1 order by " . $this -> dataname . ".timestamp, online.status_gc_changetime;";
$result = $this -> bot -> db -> select($sql);

$checkonline = $this -> bot -> core('settings') -> get("Wishlist", "checkonline");
$miawarning = $this -> bot -> core('settings') -> get("Wishlist", "miawarning");
$miastatus = $this -> bot -> core('settings') -> get("Wishlist", "miastatus");
$miahide = $this -> bot -> core('settings') -> get("Wishlist", "hidemia");

$miastatus = time() - ($miastatus * 24 * 60 * 60);
$miawarning = time() - ($miawarning * 24 * 60 * 60);

if ($checkonline) {

  $onlinecache = $this -> getAltsOnlineCache();
}

if ($result)
{
  foreach ($result as $row)
  {

    $lastseen = $row[4];

    if (($miahide == 'FALSE')  || // do we hide persons MIA?
($lastseen > $miastatus)) {

      $fillcmd = "[".$this->make_chat("wishlist filled ".$row[0], "Filled", "tell")."]";
      $admdelcmd = "[".$this->make_chat("wishadmin delete ".$row[0], "admDel", "tell")."]";
      $admrefcmd = "[".$this->make_chat("wishadmin refuse ".$row[0], "admRef", "tell")."]";
      $owndelcmd = "[".$this->make_chat("wishlist delete ".$row[0], "ownDel", "tell")."]";

      $name = $row[1];
      $online = "";

      if ($checkonline == 'TRUE') {
 
// is name not online?
if (! array_key_exists($name, $onlinecache)) {

  if ($lastseen < $miastatus) {
   
    $online = " ##red##MIA##end##";
  }
  else if ($lastseen < $miawarning) {
   
    $online = " ##red##MIA##end##";
  }
  else {

    $online = " ##orange##off##end##";
    }
}
else { // yay! person is online
   
  // is online as self?
  if ($onlinecache[$name] == $name) {
     
    $online = " ##green##onl##end##";
  }
  // online as alt
  else {
    $online = " ##yellow##alt##end##";
  }
}}
$row[2] = date("Y-m-d", $row[2]);
 
// generating tell command
if ($onlinecache[$name])
  $name ="<a href='chatcmd:///tell $onlinecache[$name]'>$name</a>";
else
  $name ="<a href='chatcmd:///tell $name'>$name</a>";

$return .= $row[2] . " [" . $name . $online. "] " . $row[3] . " " . $fillcmd . " " . $owndelcmd . " " . $admrefcmd . " " . $admdelcmd . "\n";
$delcmd = ""; $refcmd = ""; $filcmd = "";
      }
    }
}
$return .= "\n";

unset($onlinecache);

return $return;
}

// returns a list of recently filled requests
function getRecent($time, $name)
{
$lastFi = $this -> bot -> core('settings') -> get("Wishlist", "lastfilled");
$return = "<left>##yellow##Recently##end## ##green##filled##end## ##yellow##requests##end## (last $lastFi requests):</left>\n";
$sql = "SELECT * FROM ".$this -> dataname." WHERE `status` = '2' ORDER BY `stattime` DESC LIMIT $lastFi";
$result = $this -> bot -> db -> select($sql);
if ($result)
{
foreach ($result as $row)
{
$undocmd = "[".$this->make_chat("wishadmin undo ".$row[0], "admUndo", "tell")."]";


$tellcmd = $row[1];
$row[2] = date("Y-m-d", $row[2]);
$row[6] = date("Y-m-d", $row[6]);
$return .= $row[6] . " " . $row[5] . " " . " ##green##Filled##end## " . $row[1] . "'s ##green##request since##end## " . $row[2] . ": " .  $row[3] . ". " . $undocmd . "\n";
}
}
$return .= "\n";
return $return;
}

// returns a list of denied requests
function getDenied($time, $name)
{
$lastDe = $this -> bot -> core('settings') -> get("Wishlist", "lastdenied");
$return = "<left>##yellow##Recently##end## ##red##denied##end## ##yellow##requests##end## (last $lastDe requests):</left>\n";
$sql = "SELECT * FROM ".$this -> dataname." WHERE `status` = '3' ORDER BY `id` DESC LIMIT $lastDe";
$result = $this -> bot -> db -> select($sql);
if ($result)
{
foreach ($result as $row)
{
$undocmd = "[".$this->make_chat("wishadmin undo ".$row[0], "admUndo", "tell")."]";

$tellcmd = $row[1];
$row[2] = date("Y-m-d", $row[2]);
$row[6] = date("Y-m-d", $row[6]);
$return .= $row[2] . " [" . $tellcmd . "] " . $row[3] . ". ##red##Denied##end## by " . $row[5] . " on " . $row[6] . ". " . $undocmd . "\n";
}
}
$return .= "\n";
return $return;
}

// edits the rules in the db
function changeRules($msg, $name)
{
$rules = implode(' ',array_slice(explode(' ', $msg), 2));
$time = time();
$this -> bot -> db -> query("TRUNCATE TABLE ".$rulesname);
$sql = "INSERT INTO ".$this -> rulesname." VALUES ('', '$name', '$time', '$rules')";
if ($this -> bot -> db -> query($sql))
{
$return = "Rules updated.";
}
else
{
$return = "Unable to update rules.";
}
return $return;
}

// adds a new request
function requestAdd($msg, $name)
{
$request = addcslashes(implode(' ',array_slice(explode(' ', $msg), 2)), '\'');
$time = time();
$sql = "INSERT INTO ".$this -> dataname." VALUES('', '$name', '$time', '$request', '1', '', '')";
$result = $this -> bot -> db -> query($sql);
if ($result)
{
$return = "Request added.";
}
return $return;
}

// deletes a request
function requestDel($id, $name)
{
  $time = time();
  // FIXME unnecesery query to check ownership of the request
  $sql = "SELECT id from " . $this -> dataname . " WHERE `creator`='$name' and `id` = $id;";
  $result = $this -> bot -> db -> select($sql);

  if ($result) //FIXME ugly workaround
  {
    foreach ($result as $row) {
    $sql = "UPDATE ".$this -> dataname." SET `status` = '0', `statname` = '$name', `stattime` = '$time' WHERE `creator`='$name' and `id` = $id";
    $result = $this -> bot -> db -> query($sql);
    return "Request deleted.";
    }
  }
 
  return "You cannot delete this request. You can only delete your own requests.";
}

// changes status of a request to filled
function requestFill($id, $name)
{
$time = time();
$sql = "UPDATE ".$this -> dataname." SET `status` = '2', `statname` = '$name', `stattime` = '$time' WHERE `id` = $id";
$result = $this -> bot -> db -> query($sql);
if ($result)
{
$return = "Request filled.";
}
return $return;
}

// changes status of a request to refused
function requestRefuse($id, $name)
{
$time = time();
$sql = "UPDATE ".$this -> dataname." SET `status` = '3', `statname` = '$name', `stattime` = '$time' WHERE `id` = $id";
$result = $this -> bot -> db -> query($sql);
if ($result)
{
$return = "Request denied.";
}
return $return;
}

// deletes any request
function requestDelAdmin($id)
{
$time = time();
$sql = "UPDATE ".$this -> dataname." SET `status` = '0', `statname` = '$name', `stattime` = '$time' WHERE `id` = $id";
$result = $this -> bot -> db -> query($sql);
if ($result)
{
$return = "Request deleted.";
}
else
{
$return = "Unable to delete request.";
}
return $return;
}

// changes the status of a request back to unhandled
function requestUndo($id)
{
$sql = "UPDATE ".$this -> dataname." SET `status` = '1', `statname` = '', `stattime` = '' WHERE `id` = $id";
$result = $this -> bot -> db -> query($sql);
if ($result)
{
$return = "Request status changed to unhandled.";
}
return $return;
}

// compares access level
function checkAccess($name)
{
$accesslevelrequired =  $this -> bot -> core('settings') -> get("Wishlist", "adminaccess");
return $this -> bot -> core("security") -> check_access($name, "ADMIN");
}

// utility functions
function make_whois($name)
{
return $this -> bot -> core("tools") -> chatcmd("whois $name", $name, "tell");
}

function make_blob($title, $content)
{
return $this -> bot -> core("tools") -> make_blob($title, $content);
}

function make_chat($command, $title, $origin)
{
return $this -> bot -> core("tools") -> chatcmd($command, $title, $origin);
}
}
?>

Offline crocks

  • BeBot User
  • **
  • Posts: 23
  • Karma: +0/-0
Re: Wishlist module function
« Reply #2 on: June 25, 2012, 01:39:46 am »
I guess this might help me in this case.

http://bebot.link/feedback-and-suggestions/wish-list/msg1416/#msg1416

Does anyone of you still have the code files posted down there?

Thanks

Offline crocks

  • BeBot User
  • **
  • Posts: 23
  • Karma: +0/-0
Re: Wishlist module function
« Reply #3 on: July 18, 2012, 08:42:05 pm »
bump

 

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