Skip to content
This repository has been archived by the owner on Apr 1, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1 from Savagedlight/master
Browse files Browse the repository at this point in the history
ITEMS_MODULE: Optional support for the Central Items Database
  • Loading branch information
bigwheels16 committed Dec 31, 2013
2 parents 27cdc5b + 6f69cfc commit 0e0d68e
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions modules/ITEMS_MODULE/ItemsController.class.php
Expand Up @@ -63,10 +63,13 @@ class ItemsController {
* @Options("30;40;50;60")
*/
public $defaultMaxitems = "40";

/** @Setup */
public function setup() {
$this->db->loadSQLFile($this->moduleName, "aodb");

// Initialize settings - Demoder
$this->settingManager->add($this->moduleName, "items_database", "Use database", "edit", "text", 'local', 'local;central');
}

/**
Expand All @@ -91,7 +94,7 @@ public function itemsCommand($message, $channel, $sender, $sendto, $args) {
}

$search = htmlspecialchars_decode($search);
$msg = $this->find_items_from_local($search, $ql);
$msg = $this->find_items($search, $ql);
$sendto->reply($msg);
}

Expand Down Expand Up @@ -199,6 +202,50 @@ public function download_newest_itemsdb() {
return $msg;
}

public function find_items($search, $ql) {
// Figure out which database to query - Demoder
$db = $this->settingManager->get('items_database');
echo "Database set to: " . $db . "\r\n";
switch($db) {
case 'local':
// Local database
return $this->find_items_from_local($search, $ql);
case 'central':
// Default CIDB
return $this->find_items_from_remote($search, $ql, "http://cidb.botsharp.net/");
default:
// Specified CIDB
return $this->find_items_from_remote($search, $ql, $db);
}
}

/*
* Method to query the Central Items Database - Demoder
*/
public function find_items_from_remote($search, $ql, $server) {
$icons=true;
$max = $this->defaultMaxItems;
// Store parameters as an array, for easy assembly later.
$parameters = array(
// Should always specify which bot software is querying.
"bot=BudaBot",
"output=aoml",
"max=".$max,
"search=".urlencode($search),
"icons=".$icons);
// Don't include QL in the query unless the user specified it.
if ($ql>0) {
$parameters[]="ql=".$ql;
}
// Assemble query URL and retrieve results.
$url=$server . '?' . implode('&', $parameters);
$msg = file_get_contents($url);
if (empty($msg)) {
$msg = "Unable to query Central Items Database.";
}
return $msg;
}

public function find_items_from_local($search, $ql) {
$tmp = explode(" ", $search);
list($query, $params) = $this->util->generateQueryFromParams($tmp, 'name');
Expand Down

0 comments on commit 0e0d68e

Please sign in to comment.