BeBot - An Anarchy Online and Age Of Conan chat automaton
Archive => Anarchy Online Archive => 0.2.x Custom/Unofficial Modules => Topic started by: Akarah on November 29, 2005, 08:44:51 am
-
i'm going to be adding a few more commands over the next week or so to the IRC module, here's the first, to add !alts to irc...
first, after the irc_online function, add a new function:
function irc_alts(&$irc, &$data)
{
if(!preg_match("/^" . $this -> bot -> commpre . "alts (([a-zA-Z0-9]+).+)$/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
{
$main = $this -> bot -> alts -> main($info[1]);
$alts = $this -> bot -> alts -> get_alts($main);
$msg = $main . "'s Alts: ";
if (!empty($alts))
{
foreach ($alts as $alt)
{
$msg .= $alt . ", ";
}
}
else
{
$msg .= "None!";
}
}
}
$this -> irc -> message(SMARTIRC_TYPE_CHANNEL, $this -> chan, $msg);
}
then, in the irc_connect function, find the line:
$this -> irc -> registerActionhandler(SMARTIRC_TYPE_CHANNEL, $this -> bot -> commpre.'is (.*)', $this -> bot -> commands["tell"]["irc"], 'irc_is');
add:
$this -> irc -> registerActionhandler(SMARTIRC_TYPE_CHANNEL, $this -> bot -> commpre.'alts (.*)', $this -> bot -> commands["tell"]["irc"], 'irc_alts');
and in the irc_receive function, change the line:
if ((strtolower($data -> message) != strtolower(str_replace("\\", "", $this -> bot -> commpre.'online'))) &&
(strtolower($data -> message) != strtolower(str_replace("\\", "", $this -> bot -> commpre.'is'))))
to:
if ((strtolower($data -> message) != strtolower(str_replace("\\", "", $this -> bot -> commpre.'online'))) &&
(strtolower($data -> message) != strtolower(str_replace("\\", "", $this -> bot -> commpre.'is'))) &&
(strtolower($data -> message) != strtolower(str_replace("\\", "", $this -> bot -> commpre.'alts'))))
and now !alts <name> will work on irc and behave as expected.
now i have a few issues with the way this is done, primarily because if you say !alts or !online or !is anywhere in your sentence on irc, it will interpret it as a command, because it's not strictly matching '!command' at the beginning of the msg, but anywhere in the line. also this will get extremely messy and inefficient if i end up hacking 30 different commands into the module to be used from IRC... so i may have to find another way of doing this.. like making a cmdlist array then walking thru it each time or something hmmm.. ideas? :P
/Aka
-
would you be able to perform a check on the incoming message itself using this?
http://us2.php.net/manual/en/function.substr.php
both substr() and using $string{0} looks like it would be able to snag just the first character to see if it's either "!" for a command, or another character used only for relaying IRC chat (instead of every line that is spewed)
I'll be at least messing with a little bit of this, as it's amusing when I tell someone in IRC "hey if you wanna see who's online just type !online" and then of course the bot does this :D
-
yup skeez its on my list of stuff todo ;)
-
oh i've also added !whois to irc, but i think before i add anything else i need to change how it parses commands ;p
-
yeah I'm pretty new to php and trying to learn my way through. I 'learned' some php with IGN, but obviously bebot is setup extremely different, using dynamic command lists in an awesome (but hard to understand for me) way.
once I look over the IRC module and see how in the world it's running I'll see what I can change. If I see you posted something before hand then it will save me some time ;)
-
Very nice! Bump for new features!
-
what about joining channels with passwords?
if there's no functionality for this,could someone please add it in? :P
-
Is the channel key option not sufficient?
-jj-
-
well, i used it, didnt work. but i tried a channel without password, that didn't work either, so that's odd