BeBot - An Anarchy Online and Age Of Conan chat automaton
Development => Coding and development discussion => Topic started by: MafooUK on September 03, 2007, 09:39:50 pm
-
i have a number of Updates to
- Sources/Bot.php
- Sources/AOChat.php
these implement the missing functions for external private groups
i have currently coded these against the 0.4.1 release (with the updates for the change of whois servers)
the functions added to Bot.php are
added function send_pgroup_accept($group)
added function send_pgroup_leave($group)
added function send_pgroup_decline($group)
modified send_output to support type 5/extpgroup
the functions added to AOChat.php are
added function privategroup_leave($group)
i would like to know would you like .patch files for the current svn trunks and branches (need readonly SVN access please)
or you just want a detailed description of what needs to be changed
p.s. would love to see these changes go in so my team module will be able to work as intended
-
Not really sure if you need those send_privategroup_(accept|leave|decline) really, you can just as easy call the AOChat functions directly. I don't see any added functionality those functions should get.
And each time you send something to an external group you have to define what the target is. No real sense to adapt send_output there, you can always use send_pgroup directly.
Adding privategroup_leave() to AOChat is nice though.
Best just attach a diff -Nbur to your post.
-
I don't really see harm in wrapping around the lib.
It's what most functions already do effectively anyways, might aswell complete the set and never require direct access to aochat.
-
Good argument. And having it twice is better then having it just once anyways.
Still don't see any reason to extend send_output() though.
-
i extended send_output to conform with the style of programming found in the example module
-
reference changes from stable 0.4.1
in AOCHat.php
find near line 616
<?php
function privategroup_join($group)
{
if(($gid = $this->get_uid($group)) === false)
{
return false;
}
return $this->send_packet(new AOChatPacket("out", AOCP_PRIVGRP_JOIN, $gid));
}
function join_privgroup($group) /* Deprecated - 2004/Mar/26 - [email protected] */
{
return $this->privategroup_join($group);
}
>
add after
<?php
function privategroup_leave($group)
{
if(($gid = $this->get_uid($group)) === false)
{
return false;
}
return $this->send_packet(new AOChatPacket("out", AOCP_PRIVGRP_PART, $gid));
}
>
in Bot.php
find near line 329
<?php
/*
send a tell. Set $low to 1 on tells that are likely to cause spam.
*/
function send_tell($to, $msg, $low=0, $color=true)
{
// parse all color tags:
$msg = $this -> colors -> parse($msg);
$send = true;
if (preg_match("/<a href=\"(.+)\">/isU", $msg, $info))
if (strlen($info[1]) > $this -> maxsize)
{
$this -> cut_size($msg, "tell", $to, $low);
$send = false;
}
if ($send)
{
$msg = str_replace("<botname>", $this -> botname, $msg);
$msg = str_replace("<pre>", str_replace("\\", "", $this -> commpre), $msg);
if ($color)
$msg = $this -> colors -> colorize("normal", $msg);
if ($this -> queue -> check_queue())
{
$this -> log("TELL", "OUT", "-> " . $this -> aoc -> get_uname($to) . ": " . $msg);
$msg = utf8_encode($msg);
$this -> aoc -> send_tell($to, $msg);
}
else
$this -> queue -> into_queue($to, $msg, "tell", $low);
}
}
>
and insert after
<?php
/*
accept invite to private group
*/
function send_pgroup_accept($group)
{
if ($group == NULL)
return false;
$this -> log("PGRP", "ACCEPT", "Accepting Invite for Private Group [" . $group . "]");
$this -> aoc -> privategroup_join($group);
}
/*
leave private group
*/
function send_pgroup_leave($group)
{
if ($group == NULL)
return false;
$this -> log("PGRP", "LEAVE", "Leaving Private Group [" . $group . "]");
$this -> aoc -> privategroup_leave($group);
}
/*
decline private group
*/
function send_pgroup_decline($group)
{
return $this->send_pgroup_leave($group);
}
>
in Bot.php
find near line 474
<?php
function send_output($source, $msg, $type)
{
// Output filter
if ($this -> settings -> get('Filter', 'Enabled'))
{
$msg = $this -> stringfilter -> output_filter($msg);
}
if (!is_numeric($type))
{
$type = strtolower($type);
}
switch($type)
{
case '0':
case '1':
case 'tell':
$this -> send_tell($source, $msg);
break;
case '2':
case 'pgroup':
case 'pgmsg':
$this -> send_pgroup($msg);
break;
case '3':
case 'gc':
$this -> send_gc($msg);
break;
case '4':
case 'both':
$this -> send_gc($msg);
$this -> send_pgroup($msg);
break;
default:
$this -> send_tell($source, "Broken plugin, type: $type is unknown to me");
}
}
>
change to
<?php
function send_output($source, $msg, $type)
{
// Output filter
if ($this -> settings -> get('Filter', 'Enabled'))
{
$msg = $this -> stringfilter -> output_filter($msg);
}
if (!is_numeric($type))
{
$type = strtolower($type);
}
switch($type)
{
case '0':
case '1':
case 'tell':
$this -> send_tell($source, $msg);
break;
case '2':
case 'pgroup':
case 'pgmsg':
$this -> send_pgroup($msg);
break;
case '3':
case 'gc':
$this -> send_gc($msg);
break;
case '4':
case 'both':
$this -> send_gc($msg);
$this -> send_pgroup($msg);
break;
case '5':
case 'extpgroup';
$this -> send_pgroup($msg, $source);
break;
default:
$this -> send_tell($source, "Broken plugin, type: $type is unknown to me");
}
}
>
yes it seems like duplication and you could directly access the aochat class but the goal is to promote good programming and blackbox style program.
if AOChat.php was every dramatically changed becuase FC changed some stuff module programmers would need to update there code, however following the model of programming only bot.php would need to be modified to allow any changes to work, thus maintaining a lot of backward module compatability
-
And each time you send something to an external group you have to define what the target is. No real sense to adapt send_output there, you can always use send_pgroup directly.
valid points but from the looks of the example modules it is encouraged to use send_output instead of send_pgroup or send_tell when sending data back.
i belive this is for the structure purposes of trying to get rid of needing a function per incoming source type and useing a generic handler function instead
however it does need to be changed from
handler($source, $msg, $type)
to
handler($source, $msg, $type, $group = NULL)
thus allowing group to be blank if it was a tell or gc message.
in addition $group can represent what org sent the message as well when it was a relayed message and set the type to 6/relay
just my 2cents (or more) but from looking at the project it looks like where it's heading
p.s. excelent work on the bot and various extra modules
-
i missed implimentation of group_status from aochat.php in bot.php
place anywhere relivant
<?php
/*
private group statuus
added - 2007/Sep/1 - [email protected]
*/
function pgroup_status($group)
{
if ($group == NULL)
$group = $this->botname;
return $this->aoc->group_status($group);
}
>