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: Some thoughts on IRC commands  (Read 8941 times)

0 Members and 1 Guest are viewing this topic.

Offline Tsuyoi

  • BeBot User
  • **
  • Posts: 30
  • Karma: +0/-0
  • BigT
    • Adrenaline Rush Forums
Some thoughts on IRC commands
« on: March 06, 2007, 04:26:00 pm »
Not sure if anyone is really worried about this atm, though I do know Khalem was planning a rewrite sometime in the future.  I did alittle bit of looking into it and came up with a possible way of loading modular based IRC commands in pretty much the same way normal commands are done.

Now, none of this is tested, cause it was just sort of a theory in my head last night when I was looking over how normal modules are handled, and I only looked at the IRC class briefly to understand what the different constants and function calls were, so keep that in mind when you're reading all my musings over.  I did this more as a demonstration of how I thought it could work, not an exact version, as I'm not as strong of a coder as others around here :)

First is to load up the modules, which I figured could be nestled in "modules/IRC/" unless anyone knows a more convenient spot.

Quote
// Load up all modules
$folder dir("./modules/");
while (
$mod $folder->read())
{
	
if (!
is_dir($mod) && !preg_match("/^_/"$mod) && preg_match("/php$/i"$mod) && (($guildbot && !preg_match("/_RAID/"$mod)) || (!$guildbot && !preg_match("/_GUILD/"$mod))))
	
{
	
	
require_once 
"modules/" $mod;
	
	
$bot -> log("MOD""LOAD"$mod);
	
}
}

// Load up all IRC modules
$irc_folder dir("./modules/IRC/");
while (
$irc_mod $irc_folder -> read())
{
    if (!
is_dir($irc_mod) && !preg_match("/^_/"$mod) && preg_match("/php$/i"$irc_mod))
    {
        require_once 
"modules/IRC/" $irc_mod;
        
$bot -> log("IRCMOD""LOAD"$irc_mod);
    }
}

So now the main IRC handler module is loaded, and it's commands.

So in the IRC.php we have now, we'd have to change the way that IRC is both Connected to, and how an IRC_Receive is handled.

Quote
	
/*
	
* Connect(!!!)
	
*/
	
function 
irc_connect($name "")
	
{
	
	
if (!empty(
$this -> server))
	
	
{
	
	
	
if ((
$name != "") && ($name != "c"))
	
	
	
$this -> bot -> send_tell($name"Connecting to IRC server: " $this -> server);
	
	
	
else if (
$name == "")
	
	
	
$this -> bot -> send_gc("Connecting to IRC server: " $this -> server);

	
	
	
$this -> irc = &new Net_SmartIRC();
	
	
	
$this -> irc -> setUseSockets(TRUE);

	
	
	
// Tell IRC Modules that the bot is connected
	
	
	
if (!empty(
$this -> bot -> commands["ircconnect"]))
	
	
	
{
	
	
	
	
$keys array_keys($this -> bot -> commands["ircconnect"]);
	
	
	
	
foreach (
$keys as $key)
	
	
	
	
{
	
	
	
	
	
$this -> bot -> commands["ircconnect"][$key] -> ircconnect(&$this -> irc);
	
	
	
	
}
	
	
	
}

	
	
	
$this -> irc -> registerActionhandler(SMARTIRC_TYPE_CHANNEL'.*'$this -> bot -> commands["tell"]["irc"], 'irc_recieve');
	
	
	
$this -> irc -> registerActionhandler(SMARTIRC_TYPE_JOIN'.*'$this -> bot -> commands["tell"]["irc"], 'irc_join');
	
	
	
$this -> irc -> registerActionhandler(SMARTIRC_TYPE_PART'.*'$this -> bot -> commands["tell"]["irc"], 'irc_part');
	
	
	
$this -> irc -> setCtcpVersion($this -> bot -> botversionname " (" $this -> bot -> botversion ")");
	
	
	
$this -> irc -> setAutoReconnect($this -> reconnect);
	
	
	
$this -> irc -> connect($this -> server$this -> port);
	
	
	
$this -> irc -> login($this -> nick'BeBot'0'BeBot');
	
	
	
$this -> irc -> join(array($this -> chan), $this -> chankey);
	
	
	
$this -> bot -> cron["2sec"]["irc"] = &$this -> bot -> commands["tell"]["irc"];
	
	
	
$this -> bot -> commands["buddy"]["irc"] = &$this -> bot -> commands["tell"]["irc"];

	
	
	
$this -> status 'Connected';

	
	
	
return 
"Done connecting...";
	
	
}

Quote
	
/*
	
* Gets called for an inc IRC message
	
*/
	
function 
irc_recieve(&$irc, &$data)
	
{
	
	
$found false;
	
	
if (!empty(
$this -> commands["irc"]))
	
	
{
	
	
	
$comms array_keys($this -> bot -> commands["irc"]);
	
	
	
for (
$i 0$i count($comms); $i++)
	
	
	
{
	
	
	
	
if (
$this -> is_irccommand($comms[$i], $data -> message))
	
	
	
	
{
	
	
	
	
	
$this -> bot -> commands["irc"][$comms[$i]] -> inc_irc (&$irc, &$data);
	
	
	
	
	
$i count($comms);
	
	
	
	
	
$found true;
	
	
	
	
}
	
	
	
}
	
	
}
	
	
if (!
$found)
	
	
{
	
	
	
$msg str_replace("<""&lt;"$data -> message);
	
	
	
$msg str_replace(">""&gt;"$msg);
    
	
	
	
if (
$this -> chat <= 1)
	
	
	
$this -> bot -> send_gc($this -> guildprefix." <font color=#ffff00>".$data -> nick."</font>: ".$msg);
	
	
	
if (
$this -> chat >= 1)
	
	
	
$this -> bot -> send_pgroup($this -> guildprefix." <font color=#ffff00>".$data -> nick."</font>: ".$msg);

	
	
	
if (isset(
$this -> bot -> commands["gmsg"][$this -> bot -> guildname]["guildrelay"]))
	
	
	
{
	
	
	
	
$this -> bot -> commands["gmsg"][$this -> bot -> guildname]["guildrelay"] -> gmsg($this -> guildprefix 
	
	
	
	
" " $data -> nick""$msg);
	
	
	
}
	
	
}
	
}

Quote
	
function 
is_irccommand($comm$msg)
	
{
	
	
return (
preg_match("/^" $this -> commpre $comm "$/i"$msg) || preg_match("/^" $this -> commpre $comm " /i"$msg));
	
}

So now with our modified version of the main IRC Module, we have dynamic loading which calls the $commands["ircconnect"][] and an IRC_Receive which calls $commands["irc"]["function"].  The ircconnect function is important for 2 reasons, one being to pass over the &$irc handle, and the other being that we need to register our new command on IRC so that it will send a custom trigger to our new modules instead of just sending it over as a normal message.  So our new IRC Module template would look alittle like:

Quote
<?
/*
 * IRC_Is.php - Is Command for IRC
 *
 * BeBot - An Anarchy Online Chat Automaton
 * Copyright (C) 2004 Jonas Jax
 *
 * Developed by Blondengy (RK1)
 * Special thanks goes out to Khalem (RK1) for his support.
 *
 * File last changed at $LastChangedDate $
 * Revision: $Id $
 */

$irc_Is = new irc_Is($bot);

$commands["irc"]["is"] = &$irc_Is;
$commands["ircconnect"][] = &$irc_Is;

class irc_Is
{
    var $bot;
    var $irc;
    
    function irc_Is(&$bot)
    {
        $this -> bot = &$bot;
    }
    
    function ircconnect(&$irc)
    {
        $this -> irc = &$irc;
        $this -> irc -> registerActionhandler(SMARTIRC_TYPE_CHANNEL, $this -> bot -> commpre.'is (.*)', 
                                                                     $this -> bot -> commands["irc"]["is"], 'inc_irc');
    }
    
    function inc_irc(&$irc, &$data)
    {
        if(!preg_match("/^" . $this -> bot -> commpre . "is (([a-zA-Z]+).+)$/i", $data -> message, $info))
        {
            $msg = "Please enter a valid name.";
        }
        else
        {
            $info[1] = ucfirst(strtolower($info[1]));
            $msg = "";
            if (!$this -> bot -> aoc -> get_uid($info[1]))
            {
                $msg = "Player " . $info[1] . " does not exist.";
            }
            else if ($info[1] == ucfirst(strtolower($this -> bot -> botname)))
            {
                $msg = "I'm online!";
            }
            else if ($this -> bot -> aoc -> buddy_exists($info[1]))
            {
                if ($this -> bot -> aoc -> buddy_online($info[1]))
                {
                    $msg = $info[1] . " is online.";
                }
                else
                {
                    $msg = $info[1] . " is offline.";
                }
            }
            else
            {
                $this -> is[$info[1]] = 1;
                $this -> bot -> aoc -> buddy_add($info[1]);
            }
        }
        if (!empty($msg))
        {
            $this -> irc -> message(SMARTIRC_TYPE_CHANNEL, $this -> chan, $msg);
        }
    }
}
?>

I'd love to hear thoughts and concerns about this method of loading. :)

- T

Offline Blueeagle

  • Omnipotent
  • BeBot Hero
  • ******
  • Posts: 323
  • Karma: +0/-0
Re: Some thoughts on IRC commands
« Reply #1 on: March 07, 2007, 02:43:13 am »
I figure that the bloat wouldn't be all that bad as it would in most cases be a few extra small brackets of code, depending on how the module is written ofcourse.

An in-between would be to take the modules out of IRC.php and trun them into IRC_modulename.php files.

This however would in my opinion be more of a bloat than just putting handlers for the commands into existing modules.

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

Offline Tsuyoi

  • BeBot User
  • **
  • Posts: 30
  • Karma: +0/-0
  • BigT
    • Adrenaline Rush Forums
Re: Some thoughts on IRC commands
« Reply #2 on: March 07, 2007, 03:25:21 pm »
I figure that the bloat wouldn't be all that bad as it would in most cases be a few extra small brackets of code, depending on how the module is written ofcourse.

I tried to keep the overall changes to a minimum, and the only real other file that I modified was Main.php to add in the new module loading call.  I guess it could also move to the initialization of the IRC class itself to keep the calls from being needed if the IRC Module isn't planning to be load (IE has been renamed to "_IRC.php".  Would probably help keep from over-bloating the code unless absolutely necessary.

An in-between would be to take the modules out of IRC.php and trun them into IRC_modulename.php files.

Ye, that was my basic goal behind all of what I did, though my coding isn't the best so it may not work exactly as I envisioned it, apologizes if I'm completely off base.  What I wanted to do was allow a more dynamic system of commands to be usable for the IRC users.  Before doing this, I rewrote the current module from the .2 branch for our guild and ended up adding a few commands that I missed (Whois, Level, Beast, OE, and Admin (Just the list of Online ones)).  I figured it would be nice to have, but not everyone would really need all of them.  So it would be nice to have a way to not use the ones that no one needed, without having to sort through the entire IRC.php file.

This however would in my opinion be more of a bloat than just putting handlers for the commands into existing modules.

The problem with just adding handlers is that the SmartIRC class requires that you tell it what to do in the event of a command that isn't simply relayed.  It's called up with the registerActionhandler function as seen above.  You could, of course, simply hardcode these in the irc_connect function, but then if a new command came out, or if you wanted to ignore one, you would have to go back to that file and either add or remove according to which you wanted.  I wanted to leave that register command up to the modules themselves in order to keep it only as the commands they want to use that are registered, without forcing the user to edit those statements.


I doubt there's some massive need for such a system as this, but I figured it would help open the door to other little options for those of us who frequent IRC to have access to some of the ingame commands we may miss.

Offline Tsuyoi

  • BeBot User
  • **
  • Posts: 30
  • Karma: +0/-0
  • BigT
    • Adrenaline Rush Forums
Re: Some thoughts on IRC commands
« Reply #3 on: March 08, 2007, 10:09:30 pm »
Ok, I did some testing today, and got most of the kinks ironed out that I could find, so I figured I'd pass along my work to everyone here and see what they can find wrong.  The load method works, all commands are registered to their respective functions and can be ignored via the normal adding of a "_" infront of the file, like in normal modules.  For now I just have them setting in an IRC folder inside the normal module folder, obviously they can reside anywhere, with respect to the bot itself.  All loading is done from the IRC module, meaning if you turn it off (Read: Add a "_" to prevent it from loading) the SmartIRC Class and subsequent command classes won't even get loaded into the bot, preventing bulky unused code.  Here is the changes to the .2.11 IRC module, and a sample IRC_"Command" module and I'll attach a zip of all the modules I've ported so far.  Would love to see some comments/concerns on this.

Quote
<?
/*
* IRC.php - IRC Relay.
*
* BeBot - An Anarchy Online Chat Automaton
* Copyright (C) 2004 Jonas Jax
*
* Developed by Blondengy (RK1)
* Special thanks goes out to Khalem (RK1) for his support.
*
* File last changed at $LastChangedDate $
* Revision: $Id $
*/

/*
Add a "_" at the beginning of the file (_IRC.php) if you do not want it to be loaded.
*/

include_once('IRC/SmartIRC.php');

// Load up all IRC modules
$irc_folder = dir("./modules/IRC/");
while ($irc_mod = $irc_folder -> read())
{
    if (!is_dir($irc_mod) && !preg_match("/^_/", $irc_mod) && preg_match("/php$/i", $irc_mod))
    {
        require_once "modules/IRC/" . $irc_mod;
        $bot -> log("IRCMOD", "LOAD", $irc_mod);
    }
}


$irc = new IRC($bot);

$commands["tell"]["irc"] = &$irc;
$commands["gc"]["irc"] = &$irc;
$commands["gmsg"][$guild_name][] = &$irc;
$commands["privgroup"][] = &$irc;
$commands["connect"][] = &$irc;

Quote
	
/*
	
This gets called on a tell with the command
	
*/
	
function 
tell($name$msg)
	
{
	
	
if (
$this -> bot -> admin -> in_group($name"admin"))
	
	
{
	
	
	
if (
preg_match("/^" $this -> bot -> commpre "irc connect$/i"$msg$info))
	
	
	
$this -> bot -> send_tell($name$this -> irc_connect($name));
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc disconnect$/i"$msg$info))
	
	
	
$this -> bot -> send_tell($name$this -> irc_disconnect());
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc server (.*)$/i"$msg$info))
	
	
	
$this -> bot -> send_tell($name$this -> change_server($info[1]));
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc port (.*)$/i"$msg$info))
	
	
	
$this -> bot -> send_tell($name$this -> change_port($info[1]));
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc channel (.*)$/i"$msg$info))
	
	
	
$this -> bot -> send_tell($name$this -> change_chan($info[1]));
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc channelkey (.*)$/i"$msg$info))
	
	
	
$this -> bot -> send_tell($name$this -> change_chankey($info[1]));
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc nick (.*)$/i"$msg$info))
	
	
	
$this -> bot -> send_tell($name$this -> change_nick($info[1]));
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc ircprefix (.*)$/i"$msg$info))
	
	
	
$this -> bot -> send_tell($name$this -> change_ircprefix($info[1]));
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc guildprefix (.*)$/i"$msg$info))
	
	
	
$this -> bot -> send_tell($name$this -> change_guildprefix($info[1]));
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc announce (on|off)$/i"$msg$info))
	
	
	
$this -> bot -> send_tell($name$this -> change_announce($info[1]));
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc reconnect (on|off)$/i"$msg$info))
	
	
	
$this -> bot -> send_tell($name$this -> change_reconnect($info[1]));
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc relayguildname (.*)$/i"$msg$info))
	
	
	
$this -> bot -> send_tell($name$this -> change_relayguildname($info[1]));
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc itemref (aodb|auno)$/i"$msg$info))
	
	
	
$this -> bot -> send_tell($name$this -> change_itemref($info[1]));
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc chat (gc|pgroup|both)$/i"$msg$info))
	
	
	
$this -> bot -> send_tell($name$this -> change_chat($info[1]));
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc (settings|config|setup)$/i"$msg))
	
	
	
$this -> bot -> send_tell($name$this -> irc_settings($name));
	
	
	
else
	
	
	
$this -> bot -> send_tell($name"/tell <botname> <pre>help <pre>irc");
	
	
}
	
}

	
/*
	
This gets called on a msg in the guildchat with the command
	
*/
	
function 
gc($name$msg)
	
{
	
	
if (
$this -> bot -> admin -> in_group($name"admin"))
	
	
{
	
	
	
if (
preg_match("/^" $this -> bot -> commpre "irc connect$/i"$msg$info))
	
	
	
$this -> bot -> send_gc($this -> irc_connect());
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc disconnect$/i"$msg$info))
	
	
	
$this -> bot -> send_gc($this -> irc_disconnect());
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc server (.*)$/i"$msg$info))
	
	
	
$this -> bot -> send_gc($this -> change_server($info[1]));
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc port (.*)$/i"$msg$info))
	
	
	
$this -> bot -> send_gc($this -> change_port($info[1]));
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc channel (.*)$/i"$msg$info))
	
	
	
$this -> bot -> send_gc($this -> change_chan($info[1]));
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc channelkey (.*)$/i"$msg$info))
	
	
	
$this -> bot -> send_gc($this -> change_chankey($info[1]));
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc nick (.*)$/i"$msg$info))
	
	
	
$this -> bot -> send_gc($this -> change_nick($info[1]));
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc ircprefix (.*)$/i"$msg$info))
	
	
	
$this -> bot -> send_gc($this -> change_ircprefix($info[1]));
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc guildprefix (.*)$/i"$msg$info))
	
	
	
$this -> bot -> send_gc($this -> change_guildprefix($info[1]));
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc announce (on|off)$/i"$msg$info))
	
	
	
$this -> bot -> send_gc($this -> change_announce($info[1]));
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc reconnect (on|off)$/i"$msg$info))
	
	
	
$this -> bot -> send_gc($this -> change_reconnect($info[1]));
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc relayguildname (.*)$/i"$msg$info))
	
	
	
$this -> bot -> send_gc($this -> change_relayguildname($info[1]));
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc itemref (aodb|auno)$/i"$msg$info))
	
	
	
$this -> bot -> send_gc($this -> change_itemref($info[1]));
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc chat (gc|pgroup|both)$/i"$msg$info))
	
	
	
$this -> bot -> send_gc($this -> change_chat($info[1]));
	
	
	
else if (
preg_match("/^" $this -> bot -> commpre "irc (settings|config|setup)$/i"$msg))
	
	
	
$this -> bot -> send_tell($name$this -> irc_settings($name));
	
	
	
else
	
	
	
$this -> bot -> send_tell($name"/tell <botname> <pre>help <pre>irc");
	
	
}
	
}

Quote
	
/*
	
* Connect(!!!)
	
*/
	
function 
irc_connect($name "")
	
{
	
	
if (!empty(
$this -> server))
	
	
{
	
	
	
if ((
$name != "") && ($name != "c"))
	
	
	
$this -> bot -> send_tell($name"Connecting to IRC server: " $this -> server);
	
	
	
else if (
$name == "")
	
	
	
$this -> bot -> send_gc("Connecting to IRC server: " $this -> server);

	
	
	
$this -> irc = &new Net_SmartIRC();
	
	
	
$this -> irc -> setUseSockets(TRUE);

            
// Tell modules that the bot is connected
    
	
	
if (!empty(
$this -> bot -> commands["ircconnect"]))
    
	
	
{
    
	
	
	
$keys array_keys($this -> bot -> commands["ircconnect"]);
    
	
	
	
foreach (
$keys as $key)
                {
                    
$this -> bot -> commands["ircconnect"][$key] -> ircconnect($this -> irc$this -> chan);
                }
    
	
	
}

	
	
	
$this -> irc -> registerActionhandler(SMARTIRC_TYPE_CHANNEL'.*'$this -> bot -> commands["tell"]["irc"], 'irc_recieve');
	
	
	
$this -> irc -> registerActionhandler(SMARTIRC_TYPE_JOIN'.*'$this -> bot -> commands["tell"]["irc"], 'irc_join');
	
	
	
$this -> irc -> registerActionhandler(SMARTIRC_TYPE_PART'.*'$this -> bot -> commands["tell"]["irc"], 'irc_part');
	
	
	
$this -> irc -> setCtcpVersion($this -> bot -> botversionname " (" $this -> bot -> botversion ")");
	
	
	
$this -> irc -> setAutoReconnect($this -> reconnect);
	
	
	
$this -> irc -> connect($this -> server$this -> port);
	
	
	
$this -> irc -> login($this -> nick'BeBot'0'BeBot');
	
	
	
$this -> irc -> join(array($this -> chan), $this -> chankey);
	
	
	
$this -> bot -> cron["2sec"]["irc"] = &$this -> bot -> commands["tell"]["irc"];
	
	
	
$this -> bot -> commands["buddy"]["irc"] = &$this -> bot -> commands["tell"]["irc"];

	
	
	
$this -> status 'Connected';

	
	
	
return 
"Done connecting...";
	
	
}
	
}

Quote
	
function 
irc_settings($name)
	
{
        
$blob "<center><font color=CCInfoHeadline>::::  IRC Settings  ::::</font></center>\n";
        
$blob .= "<font color=CCInfoText>IRC</font>: [<a href='chatcmd:///tell <botname> <pre>irc connect>Connect</a>] :: [<a href='chatcmd:///tell <botname> <pre>irc disconnect>Disconnect</a>]\n";
        
$blob .= "<font color=CCInfoText>Status</font>: " $this -> status "\n\n";
        
$blob .= " <font color=CCInfoText>Server</font>: " $this -> server "\n";
        
$blob .= " <font color=CCInfoText>Port</font>: " $this -> port "\n";
        
$blob .= " <font color=CCInfoText>Channel</font>: " $this -> chan "\n";
        
$blob .= " <font color=CCInfoText>Channel Key</font>: " $this -> chankey "\n";
        
$blob .= " <font color=CCInfoText>Nick</font>: " $this -> nick "\n";
        
$blob .= " <font color=CCInfoText>IRC Prefix</font>: " $this -> ircprefix "\n";
        
$blob .= " <font color=CCInfoText>Guild Prefix</font>: " $this -> guildprefix "\n";
        
$blob .= " <font color=CCInfoText>Guild-Relay</font>: " $this -> guildrelay "\n";
        
$blob .= " <font color=CCInfoText>Announce</font>: [<a href='chatcmd:///tell <botname> <pre>irc announce on>On</a>] :: [<a href='chatcmd:///tell <botname> <pre>irc announce off>Off</a>]  -  Status: ";
        if (
$this -> announce == 1)
        {
            
$blob .= "On\n";
        }
        else
        {
            
$blob .= "Off\n";
        }
        
$blob .= " <font color=CCInfoText>Reconnect</font>: [<a href='chatcmd:///tell <botname> <pre>irc reconnect on>On</a>] :: [<a href='chatcmd:///tell <botname> <pre>irc reconnect off>Off</a>]  -  Status: ";
        if (
$this -> reconnect == 1)
        {
            
$blob .= "On\n";
        }
        else
        {
            
$blob .= "Off\n";
        }
        
$blob .= " <font color=CCInfoText>Chat</font>: [<a href='chatcmd:///tell <botname> <pre>irc chat gc>GC</a>] :: [<a href='chatcmd:///tell <botname> <pre>irc chat pgroup>Private Group</a>] :: [<a href='chatcmd:///tell <botname> <pre>irc chat both>Both</a>]  -  Status: ";
        if (
$this -> chat == 0)
        {
            
$blob .= "Guild Only\n";
        }
        else if (
$this -> chat == 1)
        {
            
$blob .= "Both\n";
        }
        else
        {
            
$blob .= "Private Group Only\n";
        }
        
$blob .= " <font color=CCInfoText>Itemrefs</font>: [<a href='chatcmd:///tell <botname> <pre>irc itemref auno>Auno</a>] :: [<a href='chatcmd:///tell <botname> <pre>irc itemref aodb>AODB</a>]  -  Status: ";
        if (
$this -> itemref == 0)
        {
            
$blob .= "Auno";
        }
        else
        {
            
$blob .= "AODB";
        }
        return 
$this -> bot -> make_blob("Settings"$blob);
    }

Quote
	
/*
	
* Gets called for an inc IRC message
	
*/
	
function 
irc_recieve(&$irc$data)
	
{
        
$found false;
	
	
if (!empty(
$this -> commands["irc"]))
	
	
{
            
$comms array_keys($this -> bot -> commands["irc"]);
	
	
	
for (
$i 0$i count($comms); $i++)
	
	
	
{
                if (
$this -> is_irccommand($comms[$i], $data -> message))
	
	
	
	
{
                    
$this -> bot -> commands["irc"][$comms[$i]] -> inc_irc ($irc$data);
	
	
	
	
	
$i count($comms);
	
	
	
	
	
$found true;
	
	
	
	
}
	
	
	
}
	
	
}
	
	
if (!
$found)
	
	
{
    
	
	
$msg str_replace("<""&lt;"$data -> message);
    
	
	
$msg str_replace(">""&gt;"$msg);
    
    
	
	
if (
$this -> chat <= 1)
    
	
	
$this -> bot -> send_gc($this -> guildprefix " <font color=#ffff00>" $data -> nick "</font>: " $msg);
    
	
	
if (
$this -> chat >= 1)
    
	
	
$this -> bot -> send_pgroup($this -> guildprefix " <font color=#ffff00>" $data -> nick "</font>: " $msg);

    
	
	
if (isset(
$this -> bot -> commands["gmsg"][$this -> bot -> guildname]["guildrelay"]))
    
	
	
{
    
	
	
	
$this -> bot -> commands["gmsg"][$this -> bot -> guildname]["guildrelay"] -> gmsg($this -> guildprefix .
    
	
	
	
" " $data -> nick""$msg);
    
	
	
}
        }
	
}

Quote
	
function 
is_irccommand($comm$msg)
	
{
	
	
return (
preg_match("/^" $this -> commpre $comm "$/i"$msg) || preg_match("/^" $this -> commpre $comm " /i"$msg));
	
}


And a sample module:
Quote
<?
/*
 * IRC_Beast.php - Beast-Day Command for IRC
 *
 * BeBot - An Anarchy Online Chat Automaton
 * Copyright (C) 2004 Jonas Jax
 *
 * Developed by Blondengy (RK1)
 * Special thanks goes out to Khalem (RK1) for his support.
 *
 * File last changed at $LastChangedDate $
 * Revision: $Id $
 */

$irc_Beast = new irc_Beast($bot);

$commands["irc"]["beast"] = &$irc_Beast;
$commands["ircconnect"][] = &$irc_Beast;

class irc_Beast
{
    var $bot;
    var $irc;
    var $chan;
    
    function irc_Beast(&$bot)
    {
        $this -> bot = &$bot;
    }
    
    function ircconnect(&$irc, $chan)
    {
        $this -> irc = &$irc;
        $this -> chan = $chan;
        $this -> irc -> registerActionhandler(SMARTIRC_TYPE_CHANNEL, "/^" . $this -> bot -> commpre.'beast' . "$/i", $this -> bot -> commands["irc"]["beast"], 'inc_irc');
    }
    
    function inc_irc(&$irc, $data)
    {
        $day_cycle = 7 + 7 + 7;
	
	
$start_date = gmmktime(0, 0, 0, 10, 9, 2006);
	
	

	
	
$seconds_since_start = gmmktime() - $start_date;
	
	
$seconds = $seconds_since_start % ($day_cycle * (24*60*60));
	
	
$days = floor( $seconds / (24*60*60) ) + 1;
	
	

	
	
if ($days <= 7)
	
	
{
	
	
	
$end = 7 - $days;
	
	
	
$msg = "Today is FFA day $days. There are $end more days until Clan.";
	
	
}
	
	
else if ($days >= 8 && $days <= 14)
	
	
{
	
	
	
$end = 14 - $days;
	
	
	
$day = $days - 7;
	
	
	
$msg = "Today is Clan day $day. There are $end more days until Omni.";
	
	
}
	
	
else if ($days >= 15)
	
	
{
	
	
	
$end = 21 - $days;
	
	
	
$day = $days - 14;
	
	
	
$msg = "Today is Omni day $day. There are $end more days until FFA.";
	
	
}
	
	
echo "It made it here!";
	
	
$this -> irc -> message(SMARTIRC_TYPE_CHANNEL, $this -> chan, $msg);
    }
}
?>
« Last Edit: March 10, 2007, 07:32:26 pm by Tsuyoi »

Offline Khalem

  • BeBot Founder
  • Administrator
  • ********
  • Posts: 1169
  • Karma: +0/-0
    • http://www.ancarim.com
Re: Some thoughts on IRC commands
« Reply #4 on: March 10, 2007, 12:20:30 am »
I'll have a closer look at this later.

I would really appreciate a diff when it comes to major changes as this though as it makes it easier to spot exactly what has changed (preferably diff -burN)

From the looks of it though, this is probably the best solution for the foreseeable future.
BeBot Founder and Fixer Kingpin

Offline nebhyper

  • BeBot User
  • **
  • Posts: 62
  • Karma: +0/-0
Re: Some thoughts on IRC commands
« Reply #5 on: March 10, 2007, 12:57:38 am »
My only question is why are people sticking with IRC? 
Siocuffin (Squad Commander of United Notum Federation)
alts: Nebhyper, Nebalmighty.

Offline pusikas

  • BeBot Apprentice
  • ***
  • Posts: 161
  • Karma: +0/-0
Re: Some thoughts on IRC commands
« Reply #6 on: March 10, 2007, 05:35:30 am »
Has many advantages. Can easily get a client just about everywhere, and for some reason, many companies do not block access over IRC. I cannot use aochat at work, but irc works. *shrug*
May not be the best to connect bots, tho. Dunno about that.
Luuv  Bot-Keeper of Vengeance ^^*

Offline Nytridr

  • BeBot Expert
  • ****
  • Posts: 262
  • Karma: +0/-0
    • Rising Sun
Re: Some thoughts on IRC commands
« Reply #7 on: March 10, 2007, 11:49:38 pm »
well one reason for us is because we have 5 orgs that are in our allance and we need to be connected somehow.. I would like to keep it in game.. but our current gcr isnt setup for that.. which could be done (by someone more knollegeable then me) 

have the gcr bots in the database and have it read it in.. and keep it in memory.. then just cycle through sending tells and reciving tells from them.. so on and so forth.. anyway this is about IRC.. not gcr..:)

IRC is the only option for us right now..
Co-Prez of Rising Sun RK1 (1st & only org I will ever belong to)

Offline nebhyper

  • BeBot User
  • **
  • Posts: 62
  • Karma: +0/-0
Re: Some thoughts on IRC commands
« Reply #8 on: March 11, 2007, 01:04:25 am »
if you want to chat between orgs don't use IRC.  I have a code for that which I use on my BeBot.  7 orgs can chat with each other and the bots can be any type, Bebot, IGn, etc.  So long each one has this code.
Siocuffin (Squad Commander of United Notum Federation)
alts: Nebhyper, Nebalmighty.

Offline Khalem

  • BeBot Founder
  • Administrator
  • ********
  • Posts: 1169
  • Karma: +0/-0
    • http://www.ancarim.com
Re: Some thoughts on IRC commands
« Reply #9 on: March 11, 2007, 02:10:12 am »
Two main reasons.

First, because it doesn't require the use of sockets, worrying about binding to the correct IP and having an open port for the "hub" bot, nor does everything fall apart if the hub bot dies.
Second, because most people actually have people on IRC wanting to participate in the relay.

As such IRC relaying is a sensible default, especially since it just works out of the box unless you have a firewall blocking outbound IRC connections, but no it is not ideal, and a proper socket based relay would be a nice option.
BeBot Founder and Fixer Kingpin

Offline nebhyper

  • BeBot User
  • **
  • Posts: 62
  • Karma: +0/-0
Re: Some thoughts on IRC commands
« Reply #10 on: March 11, 2007, 02:29:47 am »
socket? who mentioned socket?  The code I use relays via tells from one bot to another.  If one bot is not online the sending bot knows this and doesn't send to it.


Anyways, I'm off topic here so if anyone wants me to post the code I use for relaying chat let me know.
Siocuffin (Squad Commander of United Notum Federation)
alts: Nebhyper, Nebalmighty.

Offline Vhab

  • Contributor
  • *******
  • Posts: 180
  • Karma: +0/-0
    • VhaBot Forum
Re: Some thoughts on IRC commands
« Reply #11 on: March 11, 2007, 09:40:19 am »
socket? who mentioned socket?  The code I use relays via tells from one bot to another.  If one bot is not online the sending bot knows this and doesn't send to it.


Anyways, I'm off topic here so if anyone wants me to post the code I use for relaying chat let me know.
Why that is a bad idea:
- You'll be limited by the game's flood protection. If it gets crowded on GC the bot will lag up
- FC stated several years ago they don't approve this way of relaying, especially when multiple targets are involved all relaying the same message. Back then, they even banned a few large nets of IGN bots using this form of relaying.
- It puts an unnesseary load on the chat server. (It's written in python, be a bit gentle with it)

 

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