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: crafted.php  (Read 13305 times)

0 Members and 1 Guest are viewing this topic.

Offline Cuval

  • BeBot User
  • **
  • Posts: 29
  • Karma: +0/-0
crafted.php
« on: July 05, 2009, 01:25:14 pm »
First..:

I have not written anything to this module, i have just copied depot.php to crafted.php and changed everything called 'depot' to 'crafted'..
Thanks to Getrix for bringing this module to the 0.6.x...

This module can be very useful in our guild where we have many crafters with at least as many recipes. This should give everybody a nice overview of what can be asked for with the crafters as well as a nice automated request system.

I was wondering however howto change on little thing in here...
The Depot has a function that reserves the requested item for one person, what makes excellent sense if used for a depot. Is there a way to delete this option (or comment it out?) so that we can use this module also when 2 persons want to request the same item?
I cannot code PHP myself. I tried to find out how, but i think i will just brake the whole thing :)

The module as it is now:

Code: [Select]
<?php
   
/*
   * Depot.php v3.2
   * modified by Cuval to Crafted.php to differ from crafted possibilities and depot items.
   * 
   * Written for Bebot (Guildchat version) by Naturalistic (RK1 Omni) 2005-12-21
   * Updated for bebot version v0.5.2.svn(snapshot) by Kaagee (RK2 Neut) 2008-08-07
   * Debugging assistance by Vrykolas (BeBot Hyborian Developer)
   * Modified to work with AoC and bebot version v0.5.5.svn(snapshot) by Getrix (Soulstorm) 2008-11-07
   * Updated for bebot version v0.6.1 and added new Request function by Getrix (Soulstorm) 2008-12-17
   *
   * Download bebot from http://bebot.link
   *
   * 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.
   * The full GPL text is available at http://www.gnu.org/copyleft/gpl.html
   */

  
$Crafted = new Crafted($bot);

  
/*
    The Class itself...
  */
  
class Crafted extends BaseActiveModule
  
{

    
/*
      Constructor:
        Hands over a referance to the "Bot" class.
    */
    
function __construct(&$bot)
    {
        
parent::__construct(&$botget_class($this));
 
        
$this -> register_event("logon_notify");
        
        
$this -> register_command('tell''crafted''MEMBER');
        
$this -> register_command('gc''crafted''MEMBER');

        
$this -> bot -> db -> query("CREATE TABLE IF NOT EXISTS " $this -> bot -> db -> define_tablename("crafted""true") . "
              (id INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, itemDatetime DATETIME, itemHolder VARCHAR(30), itemName VARCHAR(255), itemLowid INT(8), itemHighid INT(8), itemQl INT(4), itemHighcrc VARCHAR(40), itemLowcrc VARCHAR(40), itemColour VARCHAR(8), itemURL VARCHAR(255), itemReq VARCHAR(100), itemActive ENUM('Y','N'))"
);

        
$this -> help['description'] = "This command creates a registry of items to enable members to show what they can craft and let it be requested.";
        
$this -> help['command']['crafted'] = "Displays all of the crafting items that are currently registered";
        
$this -> help['command']['crafted list'] = "Displays all of the crafting items that are currently registered";
        
$this -> help['command']['crafted search <text>'] = "Displays all of the registered crafting items whose name contains the text provided";
        
$this -> help['command']['crafted user <username>'] = "Displays all of the registered crafting items that the user specified can craft";
        
$this -> help['command']['crafted add <item>'] = "Adds the crafting item to the registry";
        
$this -> help['command']['crafted delete <id>'] = "Removes the crafting item from the registry";
        
$this -> help['command']['crafted req <id>'] = "Request crafting item from the registry. This will send a messages to crafter and reserve the crafting item.";
        
$this -> help['command']['crafted req'] = "Shows crafting items requested by others";
        
$this -> help['notes'] = "Rem, Remove or Del can be used instead of delete sub-command.  To remove an crafting item you must either be the owner of the crafting item or a super administrator of the bot";
        
$this -> bot -> core("settings") -> create("Crafted""Notify"TRUE"Should users be notified has requested a crafting item from crafter?");
    }

    
/*
    This function recieves the initial command and re-directs based on tell or gc
    */
    
function command_handler($name$msg$type)
    {
       
//Reset the error message so we don't trigger the handler by old error messages.
        
$this->error->reset();

        
//Debug statement, uncomment to see the values being passed in.
        // $this->bot->log("Crafted", "Command_Handler", "Name [$name] Type [$type] Msg [$msg] \n");

        
if (preg_match("/^crafted list$/i"$msg))
            return(
$this -> crafted_list($name));
        else if (
preg_match("/^crafted add (.+)$/i"$msg$info))
            return(
$this -> crafted_add($info[1], $name));
        else if (
preg_match("/^crafted (remove|del|rem|delete) ([0-9]+)$/i"$msg$info))
            return(
$this -> crafted_del($info[2], $name));
        else if (
preg_match("/^crafted search (.+)$/i"$msg$info))
            return(
$this -> crafted_search($info[1], $name));
        else if (
preg_match("/^crafted user (.+)$/i"$msg$info))
            return(
$this -> crafted_user($info[1], $name));
        else if (
preg_match("/^crafted req ([0-9]+)$/i"$msg$info))
            return(
$this -> crafted_req($info[1], $name));
        else if (
preg_match("/^crafted req$/i"$msg$info))
            return(
$this -> crafted_notify($name));
        else
            return(
$this -> crafted_list($name));
    }

    
/*
        This gets called when an item is added to the crafted.
    */
    
function crafted_add($itemname$name)
    {
      if(
is_numeric($dimension)) {
        
$itemPattern '(<a href="itemref:\/\/([0-9]*)\/([0-9]*)\/([0-9]*)\/([0-9a-f]*\:[0-9a-f]*\:[0-9a-f]*:[0-9a-f]*)\/([0-9a-f]*\:[0-9a-f]*\:[0-9a-f]*:[0-9a-f]*)"><font color=#([0-9a-f]*)>\[([\\-a-zA-Z0-9_\'&\s\-]*)\]<\/font><\/a>)';
        
$posPattern "/<a href=(.+)$/i";
      }         
      else {
        
$itemPattern '(<a style="text-decoration:none" href="itemref:\/\/([0-9]*)\/([0-9]*)\/([0-9]*)\/([0-9a-f]*\:[0-9a-f]*\:[0-9a-f]*:[0-9a-f]*)\/([0-9a-f]*\:[0-9a-f]*\:[0-9a-f]*:[0-9a-f]*)"><font color=#([0-9a-f]*)>\[([\\-a-zA-Z0-9_\'&\s\-]*)\]<\/font><\/a>)';
        
$posPattern "/<a (.+) href=(.+)$/i";
      }
     
      
$fitemname addslashes($itemname);
      
$pos preg_match($posPattern$itemname,$info);
      
$DatetimeNow date('Y-m-d H:i:s');
      
//Debug statement, uncomment to see the values are being posted by the user.
      //$this->bot->log("Crafted", "Add_Item", "Item string [$itemname] Cutdown[" .str_replace('a','b',$itemname). "] Info [$info]");
      
if ($pos) {
        
$count preg_match_all('/'.$itemPattern.'/i'$itemname$matchesPREG_SET_ORDER);
        foreach(
$matches as $match) {
          
$item['holder']                                 = $name;
          if (
is_numeric($match[2])) { $item['lowid']     = $match[2]; }
          if (
is_numeric($match[3])) { $item['highid']    = $match[3]; }
          if (
is_numeric($match[4])) { $item['ql']        = $match[4]; }
          
$item['lowcrc']                                 = $match[5];
          
$item['highcrc']                                = $match[6];
          
$item['colour']                                 = $match[7];
          
$item['name']                                   = addslashes($match[8]);
          
$items[] = $item;
        }
        
$query=("INSERT INTO #___crafted (itemDatetime, itemHolder, itemName, itemLowid, itemHighid, itemQl, itemLowcrc, itemHighcrc, itemColour, itemUrl, itemActive) VALUES ('".$DatetimeNow."', '".$items[0]['holder']."', '".$items[0]['name']."', '".$items[0]['lowid']."', '".$items[0]['highid']."', '".$items[0]['ql']."', '".$items[0]['lowcrc']."', '".$items[0]['highcrc']."', '".$items[0]['colour']."', '$fitemname', 'Y')");
                
        
$this -> bot -> db -> query($query);
        
$craftedID mysql_insert_id();
        
$strmsg "Thank you, your item has been added to the database as id #" $craftedID;
      }
      else { 
$strmsg"The link/item you are trying to share is not in a valid format!"; }
      return 
$strmsg;
    }

    
/*
        This gets called when an item is deleted/removed from the crafted.
    */

    
function crafted_del($qnum$name)
    {
        
$sql "SELECT itemHolder FROM #___crafted WHERE id='".$qnum."' AND itemActive='Y'";
        
$result $this -> bot -> db -> select($sql);

        if (!empty(
$result))
        {
            
$candel false;
            
//Check if the user has permissions to delete the item
            
if($this -> bot -> core("security") -> get_access_level($name) > 254$candel true;
            if(
$result[0][0]==$name$candel true;

            if (
$candel==true)
            {
                
$this -> bot -> db -> query("UPDATE #___crafted SET itemActive='N' WHERE id="$qnum);
                
$reply "Item removed from the crafted list.";
            }
            else
                
$reply "Unable to delete item with ID of " $qnum ". You must be an admin, or the item holder of the item to delete it from the list.";
        }
        else
            
$reply "Item with id of " $qnum " not found.";

        return 
$reply;
    }

    
    
    
/*
        Request the item from crafted.
        @Made by Getrix
    */
    
function crafted_req($qnum$name)
    {
        
$sql "SELECT itemHolder, id, itemReq FROM #___crafted WHERE id=$qnum";
        
$result $this -> bot -> db -> select($sql);

        if (!empty(
$result))
        {
            if (
$result[0][2] != "") {
                
$reply "Sorry, but the item is allready been requested by ".$result[0][2];
            }
            else {
                
$this -> bot -> db -> query("UPDATE #___crafted SET itemReq='".$name."' WHERE id="$qnum);
                
$this -> notify($result[0][0]);
                
$reply "Requesting the item. Please wait for the crafter to respond your request";
            }
        }
        else
            
$reply "Item with id of " $qnum " not found.";
            
        return 
$reply;
        
    }

    
/*
        Notify about requested items.
        @Made by Getrix
    */
    
function crafted_notify($name)
    {
        
$sql "SELECT id, itemName, itemURL, itemReq, itemColour, itemLowid, itemQl FROM #___crafted WHERE itemHolder='".$name."' AND itemReq!='' AND itemActive='Y'";
        
$result $this -> bot -> db -> select($sql);

    if (!empty(
$result)) {
          
$stritem "";
            foreach (
$result as $val) {
              
$stritem .= "<font color=#ffff66>#" $val[0] . "</font> - <font color=#" .$val[4]. ">[" .$val[1]. "]</font> <a href='chatcmd:///tell <botname> !item " .$val[5]. "'>Stats</a>\n Request by: " $val[3] . " [<a href='chatcmd:///tell <botname> !crafted del " $val[0] . "'>Del</a>]\n\n";
            }
        
$output $this -> bot -> core("tools") -> make_blob("$name you got request on items in your Crafted list",$stritem);
    }
        else {
           
$output "No items requested from your Crafted list"
        }
        return 
$output;
    }
    
    function 
notify($name$startup false)
    {
    if (
$this -> bot -> core("settings") -> get("Crafted""Notify") && !$startup) {
          
$sql "SELECT id, itemName, itemURL, itemReq, itemColour, itemLowid, itemQl FROM #___crafted WHERE itemHolder='".$name."' AND itemReq!='' AND itemActive='Y'";
          
$result $this -> bot -> db -> select($sql);
            
      if (!empty(
$result)) {
            
$stritem "";
            foreach (
$result as $val) {
              
$stritem .= "<font color=#ffff66>#" $val[0] . "</font> - <font color=#" .$val[4]. ">[" .$val[1]. "]</font> <a href='chatcmd:///tell <botname> !item " .$val[5]. "'>Stats</a>\n Request by: " $val[3] . " [<a href='chatcmd:///tell <botname> !crafted del " $val[0] . "'>Del</a>]\n\n";
            }
        
$output $this -> bot -> core("tools") -> make_blob("$name you got request on items in your Crafted list",$stritem);
            
$this -> bot -> send_tell($name$output);
      }
    }
    }
    
    
/*
        Lists the contents of the crafted.
    */
    
function crafted_list($name)
    {
        
$stritem "<font color=#ffff66>#ID</font> - Added - <font color=#33ff00>Item Holder</font> - Item [LVL] - <font color=#ff6600>Commands</font>\n\n";
        
$sql "SELECT id, itemName, itemURL, itemHolder, itemColour, itemLowid, itemQl, itemDatetime, itemReq FROM #___crafted WHERE itemActive='Y' ORDER BY itemDatetime DESC";
        
$result $this -> bot -> db -> select($sql);
        
// 0=id, 1=itemName, 2=itemURL, 3=itemHolder, 4=itemColour, 5=itemLowid, 6=itemQl, 7=itemDatetime, 8=itemReq
        
if($result)
        {
            foreach (
$result as $val)
            {
                if (
$val[5] == "")
                    
$stritem .= "<font color=#ffff66>#" $val[0] . "</font> - " $val[2] . " \n[Item holder: " $val[3] . "]\n\n";
                else {
                    if (
$val[8] != "") { $request "REQ BY: ".$val[8]; }
                    else { 
$request "[<a href='chatcmd:///tell <botname> !crafted req " $val[0] . "'>Request</a>]"; }
                    
$stritem .= "<font color=#ffff66>#" $val[0] . "</font> - " $val[7] . " - <font color=#33ff00>"$val[3] ."</font> - <font color=#" .$val[4]. ">[" .$val[1]. "][".$val[6]."]</font> - <font color=#ff6600>[<a href='chatcmd:///tell <botname> !item " .$val[5]. "'>Stats</a>] - $request</font>\n";
                }
            }
            
$output $this -> bot -> core("tools") -> make_blob("Crafted list",$stritem);
            
//Debug statement, uncomment to see the values are being retreived.
            //$this->bot->log("Crafted", "List_Items", "Item string [$stritem]");
        
}
        else
            
$output "No items exist in the org crafted.";

        return 
$output;
    }

    
/*
        Searches the crafted for a specific item or range of items by name
    */
    
function crafted_search($item$name)
    {
        
$item2 str_replace(" ""%"$item);
        
$sql "SELECT id, itemName, itemURL, itemHolder, itemColour, itemLowid FROM #___crafted WHERE itemName LIKE '%"$item2 ."%' AND itemActive='Y' ORDER BY itemName ASC";
        
$result $this -> bot -> db -> select($sql);

        if(
$result)
        {
            foreach (
$result as $val)
            {
                if (
$val[5] == "")
                    
$stritem .= "<font color=#ffff66>#" $val[0] . "</font> - " $val[2] . " \n[Item holder: " $val[3] . "]\n\n";
                else
                    
$stritem .= "<font color=#ffff66>#" $val[0] . "</font> - <font color=#" .$val[4]. ">[" .$val[1]. "]</font> <a href='chatcmd:///tell <botname> !item " .$val[5]. "'>Stats</a> \nItem holder: " $val[3] . " [<a href='chatcmd:///tell <botname> !crafted req " $val[0] . "'>Request</a>]\n\n";
            }
            
$output $this -> bot -> core("tools") -> make_blob("$name your crafted search results",$stritem);
        }
        else
            
$output "No items exist in the org crafted.";

        return 
$output;
    }

    function 
crafted_user($item$name)
    {
        
$item2 str_replace(" ""%"$item);
        
$sql "SELECT id, itemName, itemURL, itemHolder, itemColour, itemLowid FROM #___crafted WHERE UPPER(itemHolder) LIKE UPPER('%"$item2 ."%') AND itemActive='Y' ORDER BY itemName ASC";
        
$result $this -> bot -> db -> select($sql);

        if(
$result)
        {
            foreach (
$result as $val)
            {
                if (
$val[5] == "")
                    
$stritem .= "<font color=#ffff66>#" $val[0] . "</font> - " $val[2] . " \n[Item holder: " $val[3] . "]\n\n";
                else
                    
$stritem .= "<font color=#ffff66>#" $val[0] . "</font> - <font color=#" .$val[4]. ">[" .$val[1]. "]</font> <a href='chatcmd:///tell <botname> !item " .$val[5]. "'>Stats</a> \nItem holder: " $val[3] . " [<a href='chatcmd:///tell " $val[3] . " Hi, can i get the item " $val[1] . " you have added in crafted?'>Request</a>]\n\n";
            }
            
$output $this -> bot -> core("tools") -> make_blob("$name your crafted search results",$stritem);
        }
        else
            
$output "No items exist in the org crafted.";

        return 
$output;
    }
  }

?>

Offline snyder

  • BeBot User
  • **
  • Posts: 34
  • Karma: +0/-0
  • CRO guild
    • CRO Guild @ Crom
Re: crafted.php
« Reply #1 on: July 06, 2009, 10:55:07 am »
i made something similar but works with my guild web site, www.cro-guild.com

i can post it but as its connected to 3-4 different tables with users/characters i dont think there will be any use.

bot module is really small, but i send data to my web and class that i use there is quite big:)

one more thing, for web site showing i find items on aoc.yg.com through their xml system so you also need access for that

Offline Poonjab

  • BeBot User
  • **
  • Posts: 59
  • Karma: +0/-0
Re: crafted.php
« Reply #2 on: July 16, 2009, 02:36:10 am »
Yea, this would be real nice if the item stayed in the inventory after a request was completed.  As it stands right now there is a good chance people are going to want to keep adding the items back each time someone requests the item, or if there was a way to just turn off requests and make it so they stayed in there till an admin or the crafter removed it.

Offline Cuval

  • BeBot User
  • **
  • Posts: 29
  • Karma: +0/-0
Re: crafted.php
« Reply #3 on: September 20, 2009, 07:07:56 pm »
sure there is a way, i just can't code php myself, i just replaced some words and, like magic, it worked for a change, hehe

Offline Kyr

  • BeBot Apprentice
  • ***
  • Posts: 177
  • Karma: +0/-0
Re: crafted.php
« Reply #4 on: October 22, 2009, 07:27:17 am »
Started using this today and the guild is lovin' it.  Thanks!

2 requests:

- some other sorting methods, seems to only be sorted by date added, grouping by recipe type would be nice

- request should allow something to be requested more than once and/or by multiple people.  like for potions.

~Kyr

Offline Kyr

  • BeBot Apprentice
  • ***
  • Posts: 177
  • Karma: +0/-0
Re: crafted.php
« Reply #5 on: October 22, 2009, 07:41:45 pm »
This module is not good for crafted stuff. 

Use this one:
http://bebot.link/aoc-0-6-x-customunofficial-modules/items-crafted-by-guild/

 

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