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: Help with supplies module..  (Read 3174 times)

0 Members and 1 Guest are viewing this topic.

Offline kardsen

  • BeBot Apprentice
  • ***
  • Posts: 81
  • Karma: +0/-0
Help with supplies module..
« on: July 12, 2008, 03:43:59 am »
Whole module is complete.  I just don't know how to keep the itemlink as 1 variable...

Right now  when I use the command !supplies givei <itemlink>

all it appears to capture is  <a

my current code looks like this.
I've also included the phps file so its easier to read

Code: [Select]
<?
///////created by kardsen   www.devotion-guild.com////
//// thanks to Vrykolas for coding help, noer for the kos 4.x conversion, and the creator of the kos 4.x for the base code i am using/////////////

$supplies = new Supplies($bot);

class Supplies Extends BaseActiveModule
{
//   load the varials////
var $bot;
var $gnsupplies_list;   //guild needs supply list
var $momsupplies_list;   // member offering materials supply list
var $moisupplies_list;   // member offering item supply list


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

$this -> register_command('all', 'supplies', 'MEMBER', array('add' => 'LEADER', 'change' => 'LEADER', 'changem' => 'MEMBER', 'del' => 'LEADER', 'givei' => 'MEMBER', 'givem' => 'MEMBER', 'delmy' => 'MEMBER', 'delplayer' => 'LEADER'));

$this -> help['description'] = 'Needed Supplies List';
$this -> help['command']['supplies'] = "- Display supply list.";
$this -> help['command']['supplies add material amount reason'] = "- Add Material, amount and reason to supplies list.<br>";
$this -> help['command']['supplies givei itemlink'] = "- Advertise item to guild";
$this -> help['command']['supplies givem material amount'] = "- Advertise materials to guild with available amount.<br>";
$this -> help['command']['supplies change material amount'] = "- Changes Material amount.";
$this -> help['command']['supplies changem material amount'] = "- Changes Players offered Material amount.";
$this -> help['command']['supplies del material'] = "- Remove material from supply list.";
$this -> help['command']['supplies delmy material'] = "- Removes material listing by your character";
$this -> help['command']['supplies delplayer material playername'] = "- remove all listings by playername";

$this -> bot -> db -> query("CREATE TABLE IF NOT EXISTS `supplies` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT ,
`material` VARCHAR( 100 ) NOT NULL ,
`amount` VARCHAR( 100 ) NOT NULL ,
`addedby` VARCHAR( 100 ) NOT NULL ,
`reason` VARCHAR( 255 ) NULL ,
`type` VARCHAR( 100 ) NOT NULL ,
PRIMARY KEY ( `id` )
);
");
$this -> load_gnsupplies();
$this -> load_momsupplies();
$this -> load_moisupplies();

}

function command_handler($name, $msg, $origin)
{
$com = $this->parse_com($msg, array('com', 'sub', 'material', 'amount', 'reason'));

if('add' == strtolower($com['sub']))
return $this -> add_gnsupplies($name, $com['material'], $com['amount'], $com['reason']);
else if('change' == strtolower($com['sub']))
return $this -> change_gnsupplies($name, $com['material'], $com['amount']);
else if('changem' == strtolower($com['sub']))
return $this -> change_msupplies($name, $com['material'], $com['amount']);
else if('givei' == $com['sub'])
return $this -> giveitem_supplies($name, $com['material']);
else if('givem' == strtolower($com['sub']))
return $this -> givemat_supplies($name, $com['material'], $com['amount']);
else if('del' == strtolower($com['sub']))
return $this -> delete_gnsupplies($com['material']);
else if('delmy' == strtolower($com['sub']))
return $this -> delete_msupplies($name, $com['material']);
else if('delplayer' == strtolower($com['sub']))
return $this -> deleteplayer_supplies($com['material'], $com['amount']);
else
return $this -> show_supplies();

}

?>
« Last Edit: July 12, 2008, 07:21:25 pm by kardsen »

Offline kardsen

  • BeBot Apprentice
  • ***
  • Posts: 81
  • Karma: +0/-0
Re: Help with supplies module..
« Reply #1 on: July 12, 2008, 06:38:14 am »
anyone kind enough to give this a go and tell me what I'm doing wrong.

Minimal code change would be preferred as everything else works except the capture of the item link..

Offline Praxi

  • BeBot Rookie
  • *
  • Posts: 4
  • Karma: +0/-0
Re: Help with supplies module..
« Reply #2 on: July 12, 2008, 07:53:17 am »
I'm not a coder, but I was playing with the guides module, had trouble with it, and noticed someone said they dorked up the </a>, read the 3rd party modules, and the thread about converted mods.

Offline Vrykolas

  • BeBot Apprentice
  • ***
  • Posts: 100
  • Karma: +0/-0
Re: Help with supplies module..
« Reply #3 on: July 12, 2008, 12:42:13 pm »
$this->parse_com splits on spaces, so I'd be inclined to use this...
Code: [Select]
return $this -> giveitem_supplies($name, $com['material'].' '.$com['amount'].' '.$com['reason']);

Offline kardsen

  • BeBot Apprentice
  • ***
  • Posts: 81
  • Karma: +0/-0
Re: Help with supplies module..
« Reply #4 on: July 12, 2008, 07:19:39 pm »
I took another approach that gave the same result.
also found
Code: [Select]
`material` VARCHAR( 100 ) NOT NULL ,  was set to low.  changed to 500 :)

I've verified it is parsing the whole string to the database.   But when I try to list it in a blob, i only get
<a style=

when it should output
<a style="text-decoration:none" href="itemref://3534520/3534520/50/be38a73e:db6fc1fd:4902ab4c:5bd2ddfa/be38a73e:db6fc1fd:4902ab4c:5bd2ddfa"><font color=html_link_color>[Cloak of Ibis]</font></a>

for example

Code: [Select]
$material = ($supplies['material']);
$name = ucfirst($supplies['name']);
$blob .= "\n'$material'  (Offered By: $name)\n";
« Last Edit: July 12, 2008, 07:21:59 pm by kardsen »

Offline kardsen

  • BeBot Apprentice
  • ***
  • Posts: 81
  • Karma: +0/-0
Re: Help with supplies module..
« Reply #5 on: July 12, 2008, 07:46:07 pm »
Ok,  I believe the issue is I can't link a item into a blob...  Looking at how the !items command works.

So my next option would be to do something similar to what it does.
Which sounds pretty flippin complicated.

I need to strip everything before [  and after ] in
<a style="text-decoration:none" href="itemref://3534520/3534520/50/be38a73e:db6fc1fd:4902ab4c:5bd2ddfa/be38a73e:db6fc1fd:4902ab4c:5bd2ddfa"><font color=html_link_color>[Cloak of Ibis]</font></a>

Then turn the remaining [itemname] into a link into a /tell command to the bot.... that refers to the ID # of the item...
something like
/tell BOTNAME !supplies iteml 5

I could use help on how to strip the info listed above..   In the meantime  I'm going to work on the new function  !supplies iteml


Offline Noer

  • BeBot Apprentice
  • ***
  • Posts: 107
  • Karma: +0/-0
Re: Help with supplies module..
« Reply #6 on: July 12, 2008, 08:15:36 pm »
Yeah, thats why I made the item lookup the way I did. itemrefs from popups doesn't work.

Offline kardsen

  • BeBot Apprentice
  • ***
  • Posts: 81
  • Karma: +0/-0
Re: Help with supplies module..
« Reply #7 on: July 12, 2008, 11:22:57 pm »
Working on the function to pull the link to put in chat...

so far I have 

Code: [Select]
//////  Function to link item available back to user/////////////////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
function linkitem_supplies($material)
{
$id = $material;
if(!is_numeric($id) || (int) $id != (real) $id)
return 'Please check how to use this command';
$result = $this -> bot -> db -> select("SELECT material FROM supplies WHERE id = '$id'");
if (empty($result))
{
return  "Item ID " . $id . " is not in my list";
}
$link = $result;
return $link;
}

If I send a valid ID to the function, it returns.
Array

and nothing else....
:(  Don't know where to go with this now.

And even after I fix this, I still have to figure out how to pull just the name out of the hyperlink to display it in a blob.

Offline kardsen

  • BeBot Apprentice
  • ***
  • Posts: 81
  • Karma: +0/-0
Re: Help with supplies module..
« Reply #8 on: July 13, 2008, 12:15:00 am »
Figured out the linking of the item...

All I need to do is figure out how to pull on the itemname of the link to display it in the blob
Code: [Select]
//////  Function to link item available back to user/////////////////
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
function linkitem_supplies($material)
{
$id = $material;
if(!is_numeric($id) || (int) $id != (real) $id)
return 'Please check how to use this command';
$result = $this -> bot -> db -> select("SELECT material FROM supplies WHERE id = '$id'");
if (empty($result))
{
return  "Item ID " . $id . " is not in my list";
}
foreach ($result AS $row)
{
$link = $row[0];
return $link;
}
}

Offline Vrykolas

  • BeBot Apprentice
  • ***
  • Posts: 100
  • Karma: +0/-0
Re: Help with supplies module..
« Reply #9 on: July 13, 2008, 01:40:51 am »
try using
Code: [Select]
$itemName = preg_replace('/<a style="text-decoration:none" href="itemref://[^"]+"><font color=[^>]+>\[([^\]]+)\]</font></a>/', '\1', $itemLink);

I haven't tested this fully yet, but if the example link you gave above is accurate the regular expression should work, or return an empty string ("")

Offline kardsen

  • BeBot Apprentice
  • ***
  • Posts: 81
  • Karma: +0/-0
Re: Help with supplies module..
« Reply #10 on: July 13, 2008, 02:18:28 am »
The example you gave me returned an error.  along with an empty string

Code: [Select]
Darcness [TELL] [INC]   Kardsen: !supplies

Warning: preg_replace(): Unknown modifier '/' in C:\AOC BOTS\TESTbebot\custom\modules\suppliesnew2.php on line 129
Darcness [TELL] [OUT]   -> Kardsen: Supplies List :: [link]click to view[/link]

I replaced with 

Code: [Select]
$itemName = preg_replace('/<a style=\"text-decoration:none\" href=\"itemref:\/\/[^"]+"><font color=[^>]+>\[([^\]]+)\]<\/font><\/a>/', '\1', $itemLink);

Now I don't get an error.... but I don't get any data for $itemName with
$blob .= "\n$id  $itemName (Offered By: $name)\n";

Figured I post it here while I spend the next couple hours trying to figure out whats wrong with this piece  :)

Offline kardsen

  • BeBot Apprentice
  • ***
  • Posts: 81
  • Karma: +0/-0
Re: Help with supplies module..
« Reply #11 on: July 13, 2008, 02:25:24 am »
if this helps any..


Code: [Select]
foreach ($this -> moisupplies_list AS $supplies)
{
$itemName = preg_replace('/<a style=\"text-decoration:none\" href=\"itemref:\/\/[^"]+"><font color=[^>]+>\[([^\]]+)\]<\/font><\/a>/', '\1', $itemLink);
$id = $supplies['id'];
$name = ucfirst($supplies['addedby']);
$blob .= "\n$id  $itemName (Offered By: $name)\n";
}


output is
3 (Offered By: Kardsen)

expecting
3 BladeCheater Tunic (Offered By: Kardsen)
« Last Edit: July 13, 2008, 02:27:04 am by kardsen »

Offline kardsen

  • BeBot Apprentice
  • ***
  • Posts: 81
  • Karma: +0/-0
Re: Help with supplies module..
« Reply #12 on: July 13, 2008, 02:41:29 am »
Forgot  $itemLink = $supplies['material'];

in the foreach statement.


Getting expected result of
3 BladeCheater Tunic (Offered By: Kardsen)

now.


Hopefully I shouldn't have a problem making a link to a /tell command in the blob now.
.... just need to dig through the code for an example


Again Vrykolas,  you rock.
I highly doubt I would have ever figured the base of 
$itemName = preg_replace('/<a style=\"text-decoration:none\" href=\"itemref:\/\/[^"]+"><font color=[^>]+>\[([^\]]+)\]<\/font><\/a>/', '\1', $itemLink);
myself


 

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