BeBot - An Anarchy Online and Age Of Conan chat automaton
Archive => Age of Conan Archive => BeBot Hyborian support => Topic started by: kardsen 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
<?
///////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();
}
?>
-
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..
-
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.
-
$this->parse_com splits on spaces, so I'd be inclined to use this...
return $this -> giveitem_supplies($name, $com['material'].' '.$com['amount'].' '.$com['reason']);
-
I took another approach that gave the same result.
also found
`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
$material = ($supplies['material']);
$name = ucfirst($supplies['name']);
$blob .= "\n'$material' (Offered By: $name)\n";
-
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
-
Yeah, thats why I made the item lookup the way I did. itemrefs from popups doesn't work.
-
Working on the function to pull the link to put in chat...
so far I have
////// 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.
-
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
////// 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;
}
}
-
try using
$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 ("")
-
The example you gave me returned an error. along with an empty string
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
$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 :)
-
if this helps any..
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)
-
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