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: Implementation of the settings and modules  (Read 11319 times)

0 Members and 1 Guest are viewing this topic.

Offline Blueeagle

  • Omnipotent
  • BeBot Hero
  • ******
  • Posts: 323
  • Karma: +0/-0
Re: Implementation of the settings and modules
« Reply #15 on: March 28, 2007, 06:28:44 am »
Would it be "a good idea"TM to add a field to the settings module so that it could be used to modify some settings on a per-user basis? Ie, add an enum to the db-table to indicate if it's a user or a bot setting. If it's a bot setting handle it like it's handled now. If it's a user setting add the info to either the users table or to a new user_setting table.

That would open up a whole new dimention of bot configurability. Ie if they want to recieve online lists and news when they log in, have raid commands sendt in tells to those who want that.. and so on.

It will probably not be very hard to implement either.

Any thoughts?
The only problem that can't be solved by adding another wrapper is having too many wrappers.

Offline Blueeagle

  • Omnipotent
  • BeBot Hero
  • ******
  • Posts: 323
  • Karma: +0/-0
Re: Implementation of the settings and modules
« Reply #16 on: March 28, 2007, 06:43:12 am »
And while we're on the topic of the settings module, the interface might be a tad more bloated than it needs to be. I've "slimmed" it down a bit to:

Code: [Select]
Settings for SettingsTest

  bool_test: Testing saving bool
  [ On | Off ]

  float_test: Testing saving floating point numbers
  [ 1.5 | 2.5 | 3.5 | 4.5 | 5.5 ] (Currently: 123.123)

  int_test: Testing saving integers
  [ 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 ] (Currently: 1174912172)

  NULL_test: Testing saving NULL
  [ NULL | String 1 | String 3 ]

  string_test: Testing saving text strings.
  [ String Option 1 | String Option 2 | String Option 3 ] (Currently: This is a string.)

Now the current values are highlighted (in white) and not clickable. If a value is not one of the default selections it's maked as after the options as (Corrently: <value>)

The module with alterations is below:

modules/SettingsInterface.php
Code: [Select]
<?
/*
SettingsInterface.php - Settings Managment Interface.
Version: 0.0
Created by Andrew Zbikowski <[email protected]> (AKA Glarawyn, RK1)
*/

$setconf = new SetConf($bot);

$commands["tell"]["settings"] = &$setconf;
$commands["tell2"]["settings"] = &$setconf;
$commands["pgmsg"]["settings"] = &$setconf;
$commands["gc"]["settings"] = &$setconf;

$commands["tell"]["set"] = &$setconf;
$commands["tell2"]["set"] = &$setconf;
$commands["pgmsg"]["set"] = &$setconf;
$commands["gc"]["set"] = &$setconf;

/*
The Class itself...
*/
class SetConf
{ // Start Class
var $bot;

/*
Constructor:
Hands over a referance to the "Bot" class.
*/
function SetConf (&$bot)
{
$this -> bot = &$bot;
}

/*
This gets called on a tell with the command
*/
function tell($name, $msg)
{ // Start function tell()
$reply = $this -> process_command($name, $msg, "tell");
if ($reply <> FALSE)
$this -> bot -> send_tell($name, $reply);
} // End function tell()

/*
This gets called on a tell with the command from person outside guild
*/
function tell2($name, $msg)
{ // Start function tell2()
$reply = $this -> process_command($name, $msg, "tell2");
if ($reply <> FALSE)
$this -> bot -> send_tell($name, $reply);
} // End function tell2()

/*
This gets called on a msg in the privmodule with the command
*/
function pgmsg($name, $msg)
{ // Start function pgmsg()
$reply = $this -> process_command($name, $msg, "pgmsg");
if ($reply <> FALSE)
$this -> bot -> send_pgroup($reply);
} // End function pgmsg()

/*
This gets called on a msg in the guildchat with the command
*/
function gc($name, $msg)
{ // Start function gc()
$reply = $this -> process_command($name, $msg, "gc");
if ($reply <> FALSE)
$this -> bot -> send_gc($reply);
} // End function gc()

/*
This function handles all the inputs and returns FALSE if the
handler should not send output, otherwise returns a string
sutible for output via send_tell, send_pmodule, and send_gc.
*/
function process_command($name, $msg, $source)
{ // Start function process_command()
$access = $this -> bot -> security -> check_access($name, $this -> bot -> settings['Security']['Settings']);
if ($access)
{
if (preg_match("/^" . $this -> bot -> commpre . "set[A-Za-z]{0,5} (.+?) (.+?) (.+)$/i", $msg, $info))
{
return $this -> change_setting($info[1], $info[2], $info[3]);
}
elseif (preg_match("/^" . $this -> bot -> commpre . "set[A-Za-z]{0,5} (.+)$/i", $msg, $info))
{
return $this -> show_module($info[1]);
}
else
{
return $this -> show_all_modules();
}
}
return "Only administrators can access the settings interface.";
} // End function process_command()

/*
Retruns a click window with the setting modules.
*/
function show_all_modules()
{ // Start function show_all_modules()
$sql = "SELECT DISTINCT module FROM #___settings WHERE hidden = FALSE ORDER BY module";
$result = $this -> bot -> db -> select($sql);
if (empty($result))
{
return "No settings defined.";
}

$output = "##ao_infoheader##Setting groups for <botname>:##end##\n\n";
foreach ($result as $module)
{
if ($module[0] <> "")
{
$output .= "<a href='chatcmd:///tell <botname> <pre>settings ".$module[0]."'>".$module[0]."</a>\n";
}
}
return $this -> bot -> make_blob("Settings groups for <botname>", $output);
} // End function show_all_modules()

/*
Returns a click window with settings for a specific module.
*/
function show_module($module)
{ // Start function show_module()
$module = str_replace (" ", "_", $module); // FIXME: Do regexp right and shouldn't need this?
$sql = "SELECT setting, value, datatype, longdesc, defaultoptions FROM #___settings ";
$sql .= "WHERE module = '".$module."' AND hidden = FALSE ";
$sql .= "ORDER BY disporder, setting";
$result = $this -> bot -> db -> select($sql);
if (empty($result))
{
return "No settings for module ".$module;
}
$inside = "##ao_infoheader##Settings for ".$module."##end##\n\n";
foreach ($result as $setting)
{ // 0 = setting, 1 = value, 2 = datatype, 3 = longdesc, 4 = defaultoptions
// Provide generic description if none exists.
if (empty($setting[3]))
{
if ($setting[2] == "int" || $setting[2] == "float")
{
$longdesc = "Numeric";
}
elseif ($setting[2] == "bool")
{
$longdesc = "On/Off";
}
elseif ($setting[2] == "string")
{
$longdesc = "Text String";
}
else
{
$longdesc = "Not configured.";
}
}
else
{
$longdesc = $setting[3];
}

//Convert bools to something prettier
if (strtoupper($setting[1]) == "TRUE")
{
$setting[1] = "On";
}
elseif (strtoupper($setting[1]) == "FALSE")
{
$setting[1] = "Off";
}
elseif (strtoupper($setting[1]) == "NULL")
{
$setting[1] = "NULL";
}

// Make configuration links if options are provided.
$options = explode(";", $setting[4]);

$optionlinks = "  ##ao_infotextbold##[";
$found_match=false;
foreach ($options as $option)
{
if ($option == $setting[1])
{
$found_match = true;
$optionlinks .= " $option |";
}
else
{
$optionlinks .= " <a href='chatcmd:///tell <botname> <pre>set ".$module." ".$setting[0]." ".$option."'>".$option."</a> |";
}
}
$optionlinks = rtrim($optionlinks, "|");
$optionlinks .= "]##end##";

if(!$found_match)
{
$optionlinks .= " (Currently: {$setting[1]})";
}

// Setting: longdesc
// Change To: optionlinks [(Currently: value)]
// Make inside data...
if (strtolower($setting[0]) == "password") // Mask passwords
{
$inside .= "##ao_infoheadline##".$setting[0].":##end##  ##ao_infotextbold##************##end##\n";
}
elseif (preg_match("/^#[0-9a-f]{6}$/i", $setting[1])) // Show HTML Color Codes in Color
{
$inside .= "##ao_infoheadline##".$setting[0].":##end##  <font color=".$setting[1].">".$setting[1]."</font>\n";
}
else // Normal Setting Display.
{
//$inside .= "##ao_infoheadline##".$setting[0].":##end##  ##ao_infotextbold##".$setting[1]."##end##\n";
}

$inside .= "  ##ao_infotextbold##{$setting[0]}:##end## ##ao_infotext##".$longdesc."##end##\n";
if (count($options) >= 1)
{
$inside .= $optionlinks."\n\n";
}
else
{
$inside .= "/tell <botname> <pre>set ".$module." ".$setting[0]." &lt;new value&gt;\n\n";
}
}
return $this -> bot -> make_blob("Settings for ".$module, $inside);
} // End fucnction show_module()

function change_setting($module, $setting, $value)
{ // Start function change_setting()
//return "Changing settings not implimented yet.";
$module = ucfirst(strtolower($this -> bot -> set -> remove_space($module)));
$setting = ucfirst(strtolower($this -> bot -> set -> remove_space($setting)));
if (!isset($this -> bot -> settings[$module][$setting] ))
{
if (!is_null($this -> bot -> settings[$module][$setting]))
{
return "Setting ".$setting." for module ".$module." does not exisit.";
}
}

$datatype = $this -> bot -> set -> get_data_type($this -> bot -> settings[$module][$setting]);
// Deal with possibly bad input from the user before continuing.
switch ($datatype)
{
case "bool": // A bool value comes in as on or off.
$value = strtolower($value);
if ($value == "on")
{
$value = TRUE;
}
elseif ($value == "off")
{
$value = FALSE;
}
else
{
return "Unrecgonized value for setting ".$setting." for module ".$module.". No change made.";
}
break;
case "null":
// If the string is null, change it to a null value.
// Otherwise, $value will be saved as a string. (No modification needed)
if (strtolower($value) == "null")
{
$value = NULL;
}
break;
case "array": // Changing arrays are not supported! :D
return "Modifying array values is not supported in this interface. See the help for ".$module;
break;
default:
$value = $this -> bot -> set -> set_data_type($value, $datatype);
break;
}
$result = $this -> bot -> set -> save($module, $setting, $value);
if ($result['error'])
{
return $result['errordesc'];
}
else
{
if ($datatype == "bool")
{
if ($value) {$value = "On";}
else {$value = "Off";}
}
return "Changed setting ".$setting." for module ".$module." to ".strval($value)." [".$this -> show_module($module)."]";
}

} // End function change_setting()

} // End of Class
?>

Now I haven't really bug-hunted these changes, but they appear to work in the few cases I've tested it.

Thoughts and feed back please?
The only problem that can't be solved by adding another wrapper is having too many wrappers.

Offline Khalem

  • BeBot Founder
  • Administrator
  • ********
  • Posts: 1169
  • Karma: +0/-0
    • http://www.ancarim.com
Re: Implementation of the settings and modules
« Reply #17 on: April 07, 2007, 03:16:52 am »
Regarding AOChat and PHP5, we use a forked version of AOChat which has been modified to be PHP4 compatible. The only thing missing is Auno's changes to the queue.
BeBot Founder and Fixer Kingpin

 

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