BeBot - An Anarchy Online and Age Of Conan chat automaton
Archive => AO 0.6.x Custom/Unofficial modules => Anarchy Online Archive => AO official modules => Topic started by: Zacix on July 11, 2005, 10:32:37 am
-
Personally I've upgraded to PHP5, so I'm not using this version of the teamsmodule...but I think this is a lot better, and easier to change.
NewTeams.php
<?php
//Written by Zacix for BeBot
require_once("_TeamsClass.php");
$newteams = new NewTeams($bot);
$commands["tell"]["startteam"] = &$newteams;
$commands["tell"]["teams"] = &$newteams;
$commands["tell"]["clearteams"] = &$newteams;
$commands["tell"]["addteam"] = &$newteams;
$commands["tell"]["remteam"] = &$newteams;
$commands["tell"]["delteam"] = &$newteams;
$commands["tell"]["setleader"] = &$newteams;
$commands["tell"]["teamadmin"] = &$newteams;
$commands["tell"]["teamname"] = &$newteams;
$commands["pgmsg"]["startteam"] = &$newteams;
$commands["pgmsg"]["teams"] = &$newteams;
$commands["pgmsg"]["clearteams"] = &$newteams;
$commands["pgmsg"]["addteam"] = &$newteams;
$commands["pgmsg"]["remteam"] = &$newteams;
$commands["pgmsg"]["delteam"] = &$newteams;
$commands["pgmsg"]["setleader"] = &$newteams;
$commands["pgmsg"]["teamadmin"] = &$newteams;
$commands["pgmsg"]["teamname"] = &$newteams;
$commands["pgjoin"][] = &$newteams;
$commands["pgleave"][] = &$newteams;
/*
The Class itself...
*/
class NewTeams {
var $bot;
var $pgroup;
var $numteams;
var $infotext;
var $headertext;
var $teams;
/*
Constructor:
Hands over a referance to the "Bot" class.
*/
function NewTeams (&$bot) {
$this -> bot = &$bot;
$this -> teams = array();
$this -> numteams = 0;
$this -> pgroup = array(array());
$this -> infotext = "<font color=#66aa66>";
$this -> headertext = "<font color=#dd4444>";
$this -> highlight = "<font color=#00FFFF>";
}
function SetTeamLeader($name,$num,$executer) {
$highlight = $this -> highlight;
$infotext = $this->infotext;
$headertext = $this->headertext;
if(preg_match("#^[1-9]#", $num)) {
if($num <= count($this->teams) && $num > 0) {
$team =& $this->GetTeam($num);
$member =& $team->GetMember($name);
if($member){
$team->ClearLeader();
$member->SetLeader(true);
$this->bot->send_pgroup($infotext . "[" . $highlight . $name ."</font>] is new leader of team " . $highlight . $num . "</font></font>");
}
else {
$this->bot->send_tell($executer,$infotext . "[" . $highlight . $name ."</font>] is not in team " . $highlight . $num . "</font></font>");
}
}
else {
$this->bot->send_tell($executer,$infotext . "Team " . $highlight . $num . "</font> does not exist</font>");
}
}
else {
$this->bot->send_tell($executer,$infotext . "Usage: !setleader <number> <name></font>");
}
}
function PrintTeams() {
$highlight = $this -> highlight;
$infotext = $this->infotext;
$headertext = $this->headertext;
foreach($this->teams as $index=>$team) {
if($team->GetName() == "") {
$msg = $infotext . "Team " . $highlight . bcadd($index,1) . "</font> (" . $highlight . $team->Count() . "</font>) :: ";
}
else {
$msg = $infotext . "Team " . $highlight . bcadd($index,1) . "</font> :: \"" . $team->GetName() . "\" (" . $highlight . $team->Count() . "</font>) :: ";
}
$members =& $team->GetTeamMembers();
foreach($members as $index=>$teammember) {
if($teammember->IsLeader()) {
$msg .= "[" . $headertext . $teammember->GetName() . " :: Leader</font>]";
}
else {
$msg .= "[" . $highlight . $teammember->GetName() . "</font>]";
}
}
$msg .= "</font>";
$this->bot->send_pgroup($msg);
}
}
function AddTeam(&$team) {
array_push($this->teams,&$team);
}
function ClearTeams($name) {
$highlight = $this -> highlight;
$infotext = $this->infotext;
foreach($this->teams as $index=>$teams) {
$this->DelTeam(1,$name);
}
$this->bot->send_pgroup($infotext . "Teams cleared by [" . $highlight . $name . "</font>]</font>");
}
function DelTeam($num,$executer) {
if(preg_match("#^[1-9]#", $num)) {
if($num <= count($this->teams) && $num > 0) {
$team =& $this->teams[$num-1];
foreach($team->GetTeamMembers() as $index=>$member) {
if(isset($this->pgroup[$member->GetName()])) {
$this->pgroup[$member->GetName()][4] = true;
}
}
unset($this->teams[$num-1]);
$this->numteams--;
$this->teams = array_values($this->teams);
}
else {
$this->bot->aoc->send_tell($executer,$infotext . "Team " . $highlight . $num . "</font> does not exist</font>");
}
}
else {
$this->bot->aoc->send_tell($executer,$infotext . "Usage: !delteam <number></font>");
}
}
function &GetTeam($num) {
return $this->teams[$num-1];
}
function DelTeamMember($name,$executer,$suppress=true) {
$highlight = $this -> highlight;
$infotext = $this->infotext;
$headertext = $this->headertext;
$return = false;
if($this->bot->aoc->get_uid($name)) {
for($i=1;$i<=count($this->teams);$i++) {
$team =& $this->GetTeam($i);
if($team->DelMember($name)) {
if(isset($this->pgroup[$name])) {
$this->pgroup[$name][4] = true;
}
$return = true;
if(!$suppress) {
$this->bot->send_pgroup($infotext . "[" . $highlight . $name ."</font>] has been removed from team " . $highlight . $i . "</font></font>");
}
}
else {
$return = $return | false;
}
}
return $return;
}
else {
$this->bot->send_tell($executer,$infotext . "Usage: !remteam <name></font>");
return false;
}
}
function AddTeamMember($name,$num,$executer) {
$highlight = $this -> highlight;
$infotext = $this->infotext;
$headertext = $this->headertext;
if(preg_match("#^[1-9]#", $num)) {
if($num <= count($this->teams) && $num > 0) {
if($name != "") {
if(isset($this->pgroup[$name])) {
$member =& new TeamMember($this->pgroup[$name][0],$this->pgroup[$name][1],$this->pgroup[$name][2],$this->pgroup[$name][3]);
$team =& $this->GetTeam($num);
$teammembers =& $team->GetTeamMembers();
print_r(get_object_vars($teammembers));
if(array_search($member,$teammembers)) {
$this->bot->send_pgroup($infotext .$highlight . $name . "</font> is already in team " . $highlight . $num . "</font></font>");
return;
}
else {
$deleted = $this->DelTeamMember($name,$executer);
}
if($team->AddMember($member)) {
$this->pgroup[$name][4] = false;
if($deleted) {
$this->bot->send_pgroup($infotext . "[" . $highlight . $name . "</font>] changed to team " . $highlight . $num . "</font></font>");
}
else {
$this->bot->send_pgroup($infotext . "[" . $highlight . $name . "</font>] has been added to team " . $highlight . $num . "</font></font>");
}
}
else {
$this->bot->send_pgroup($infotext . "Team " . $highlight . $num . "</font> is full</font>");
}
}
else {
$this->bot->aoc->send_tell($executer,$infotext . "[" . $highlight . $name . "</font>] is not in the group</font>");
}
}
else {
}
}
else {
$this->bot->aoc->send_tell($executer,$infotext . "Team " . $highlight . $num . "</font> does not exist</font>");
}
}
else {
$this->bot->aoc->send_tell($executer,$infotext . "Usage: !teamadd <number> <name></font>");
}
}
function StartTeam($executer,$name,$teamname) {
$highlight = $this -> highlight;
$infotext = $this->infotext;
$headertext = $this->headertext;
if($name != "") {
if(isset($this->pgroup[$name])) {
$this->DelTeamMember($name,$executer);
$member = &new TeamMember($this->pgroup[$name][0],$this->pgroup[$name][1],$this->pgroup[$name][2],$this->pgroup[$name][3],true);
$team = &new Team($member,$teamname);
++$this->numteams;
$this->pgroup[$name][4] = false;
$this->AddTeam($team);
$this->bot->send_pgroup($infotext . "Team " . $highlight . $this->numteams . "</font> has been started. Leader is [" . $highlight . $name . "</font>]</font>");
}
else {
$this->bot->send_pgroup($infotext . "[" . $highlight . $name . "</font>] is not in the group</font>");
}
}
}
function SetTeamName($teamname,$num,$executer) {
if(preg_match("#^[1-9]#", $num)) {
if($num <= count($this->teams) && $num > 0) {
$team =& $this->GetTeam($num);
$team->SetName($teamname);
}
else {
$this->bot->aoc->send_tell($executer,$infotext . "Team " . $highlight . $num . "</font> does not exist</font>");
}
}
else {
$this->bot->aoc->send_tell($executer,$infotext . "Usage: !teamname <number> <name></font>");
}
}
function GetPlayerInfo($name) {
$uid = $this->bot->aoc->get_uid($name);
$member = $this->bot->db->select("SELECT nickname,level,profession,guild,updated FROM members WHERE id = " . $uid);
if($member && (bcsub(time(),$member[0][4]) < (60*60*12))) {
if($member[0][3] == "") {
$member[0][3] = "Unknown";
}
$member[0][0] = $name;
$member[0][4] = true;
return $member[0];
}
else if(($site = $this->bot->get_site("http://www.anarchy-online.com/character/bio/d/" . $this -> bot -> dimension . "/name/" . strtolower($name) . "/bio.xml")) != "") {
$member[0] = $name;
$member[1] = $this -> bot -> xmlparse($site, "level");
$member[2] = $this -> bot -> xmlparse($site, "profession");
$member[3] = $this -> bot -> xmlparse($site, "guild");
$member[4] = true;
return $member;
}
else if($member){
if($member[0][3] == "") {
$member[0][3] = "Unknown";
}
$member[0][0] = $name;
$member[0][4] = true;
return $member[0];
}
else {
$member[0] = $name;
$member[1] = "Unknown";
$member[2] = "Unknown";
$member[3] = "Unknown";
$member[4] = true;
return $member;
}
}
function pgmsg($name,$msg) {
$msg = explode(" ",$msg);
if(strtolower($msg[0]) == $this->bot->commpre . "startteam") {
$this->StartTeam($name,ucfirst(strtolower($msg[1])),implode(" ",array_slice($msg,2)));
}
else if(strtolower($msg[0]) == $this->bot->commpre . "teams") {
$this->PrintTeams();
}
else if(strtolower($msg[0]) == $this->bot->commpre . "addteam") {
$this->AddTeamMember(ucfirst(strtolower($msg[2])),$msg[1],$name);
}
else if(strtolower($msg[0]) == $this->bot->commpre . "remteam") {
$this->DelTeamMember(ucfirst(strtolower($msg[1])),$name,false);
}
else if(strtolower($msg[0]) == $this->bot->commpre . "delteam") {
$this->DelTeam($msg[1],$name);
}
else if(strtolower($msg[0]) == $this->bot->commpre . "setleader") {
$this->SetTeamLeader(ucfirst(strtolower($msg[2])),$msg[1],$name);
}
else if(strtolower($msg[0]) == $this->bot->commpre . "teamname") {
$this->SetTeamName(implode(" ",array_slice($msg,2)),$msg[1],$name);
}
else if(strtolower($msg[0]) == $this->bot->commpre . "clearteams") {
$this->ClearTeams($name);
}
else if(strtolower($msg[0]) == $this->bot->commpre . "teamadmin") {
$this->GetAdminConsole($name);
}
}
function tell($name,$msg) {
$msg = explode(" ",$msg);
if(strtolower($msg[0]) == $this->bot->commpre . "startteam") {
$this->StartTeam($name,ucfirst(strtolower($msg[1])),implode(" ",array_slice($msg,2)));
}
else if(strtolower($msg[0]) == $this->bot->commpre . "teams") {
$this->PrintTeams();
}
else if(strtolower($msg[0]) == $this->bot->commpre . "addteam") {
$this->AddTeamMember(ucfirst(strtolower($msg[2])),$msg[1],$name);
}
else if(strtolower($msg[0]) == $this->bot->commpre . "remteam") {
$this->DelTeamMember(ucfirst(strtolower($msg[1])),$name,false);
}
else if(strtolower($msg[0]) == $this->bot->commpre . "delteam") {
$this->DelTeam($msg[1],$name);
}
else if(strtolower($msg[0]) == $this->bot->commpre . "setleader") {
$this->SetTeamLeader(ucfirst(strtolower($msg[2])),$msg[1],$name);
}
else if(strtolower($msg[0]) == $this->bot->commpre . "teamname") {
$this->SetTeamName(implode(" ",array_slice($msg,2)),$msg[1],$name);
}
else if(strtolower($msg[0]) == $this->bot->commpre . "clearteams") {
$this->ClearTeams($name);
}
else if(strtolower($msg[0]) == $this->bot->commpre . "teamadmin") {
$this->GetAdminConsole($name);
}
}
function pgjoin($name) {
$this->pgroup[$name] = $this->GetPlayerInfo($name);
}
function pgleave($name) {
unset($this->pgroup[$name]);
}
function GetAdminConsole($name) {
$highlight = $this -> highlight;
$infotext = $this->infotext;
$headertext = $this->headertext;
$msg = $infotext . $headertext . ":::: Teams Administration ::::</font>\n\n";
$msg .= $highlight . "Commands:</font>\n";
$msg .= "<a href='chatcmd:///tell <botname> <pre>teamadmin'>Refresh Teams Administration</a>\n";
$msg .= "<a href='chatcmd:///tell <botname> <pre>teams'>Show Teams</a>\n";
$msg .= "<a href='chatcmd:///tell <botname> <pre>clearteams'>Clear Teams</a>\n\n";
foreach($this->teams as $index=>$team) {
if($team->GetName() == "") {
$msg .= $infotext . ":: Team " . $highlight . bcadd($index,1) . "</font> (" . $highlight . $team->Count() . "</font>) :: ";
$msg .= "<a href='chatcmd:///tell <botname> <pre>delteam " . bcadd($index,1) . "'>Del</a>\n";
}
else {
$msg .= $infotext . ":: Team " . $highlight . bcadd($index,1) . "</font> :: \"" . $team->GetName() . "\" (" . $highlight . $team->Count() . "</font>) :: ";
$msg .= "<a href='chatcmd:///tell <botname> <pre>delteam " . bcadd($index,1) . "'>Del</a>\n";
}
$members =& $team->GetTeamMembers();
foreach($members as $indexteam=>$teammember) {
if($teammember->IsLeader()) {
$msg .= "\t[" . $headertext . $teammember->GetName() . " :: Leader</font>] (" . $teammember->GetLevel() . " " . $teammember->GetProfession() . ") ";
$msg .= $this->GetExtraInfo($teammember->GetName(),$index+1);
}
else {
$msg .= "\t[" . $highlight . $teammember->GetName() . "</font>] (" . $teammember->GetLevel() . " " . $teammember->GetProfession() . ") ";
$msg .= $this->GetExtraInfo($teammember->GetName(),$index+1);
}
foreach($this->teams as $indexteam=>$teams) {
$msg .= "/";
$msg .= "<a href='chatcmd:///tell <botname> <pre>addteam " . bcadd($indexteam,1) . " " . $teammember->GetName() . "'>" . bcadd($indexteam,1) . "</a>";
}
$msg .= "\n";
}
$msg .= "\n";
}
$msg .= "\n";
$msg .= $headertext . "::Looking For Team::</font>\n\n";
foreach($this->pgroup as $index=>$array) {
$test = $array;
if($array[4]) {
$msg .= "\t[" . $highlight . $array[0] . "</font>] (" . $array[1] . " " . $array[2] . ") :: ";
$msg .= "<a href='chatcmd:///tell <botname> <pre>startteam $array[0]'>Start Team</a>";
foreach($this->teams as $indexteam=>$teams) {
$msg .= "/";
$msg .= "<a href='chatcmd:///tell <botname> <pre>addteam " . bcadd($indexteam,1) . " " . $test[0] . "'>" . bcadd($indexteam,1) . "</a>";
}
$msg .= "\n";
}
}
$msg .= "</font>";
$this->bot->aoc->send_tell($name,$this->bot->make_blob("Teams Administration",$msg));
}
function GetExtraInfo($name,$index) {
$msg .= "<a href='chatcmd:///tell <botname> <pre>remteam $name'>Rem</a>/";
$msg .= "<a href='chatcmd:///tell <botname> <pre>startteam $name'>Sta</a>/";
$msg .= "<a href='chatcmd:///tell <botname> <pre>setleader $index $name'>Lead</a>";
return $msg;
}
}
?>
_TeamsClass.php
<?php
//Written by Zacix for BeBot
define("MAXMEM", 6);
class Team {
var $teamMembers;
var $teamName;
var $numMembers;
var $leader;
function Team(&$teamMember,$teamName) {
$this->teamMembers = array();
$this->teamName = $teamName;
$this->numMembers = 0;
$this->AddMember(&$teamMember);
}
function SetLeader(&$teamMember) {
$this->leader = &$teamMember;
}
function AddMember(&$teamMember) {
if(count($this->teamMembers) < MAXMEM) {
$this->numMembers++;
return array_push($this->teamMembers,&$teamMember);
}
else {
return false;
}
}
function DelMember($name) {
$offset = $this->GetMemberOffset($name);
if(!is_bool($offset)) {
unset($this->teamMembers[$offset]);
$this->teamMembers = array_values($this->teamMembers);
$this->numMembers--;
return true;
}
else {
return false;
}
}
function GetMemberOffset($name) {
for($i=0;$i<count($this->teamMembers);$i++) {
if($this->teamMembers[$i]->GetName() == $name) {
return $i;
}
}
return false;
}
function &GetMember($name) {
for($i=0;$i<count($this->teamMembers);$i++) {
print_r(get_object_vars($this->teamMembers[$i]));
if($this->teamMembers[$i]->GetName() == $name) {
return $this->teamMembers[$i];
}
}
return false;
}
function Count() {
return $this->numMembers;
}
function Clear() {
for($i=0;$i<count($this->teamMembers);$i++) {
$this->teamMembers[$i]->DelMember();
}
}
function ClearLeader() {
for($i=0;$i<count($this->teamMembers);$i++) {
$this->teamMembers[$i]->SetLeader(false);
}
}
function GetName() {
return $this->teamName;
}
function &GetTeamMembers() {
return $this->teamMembers;
}
function SetName($name) {
$this->teamName = $name;
}
}
class TeamMember {
var $name;
var $level;
var $profession;
var $guild;
var $leader;
function TeamMember($name,$level,$profession,$guild,$leader=false) {
$this->name = $name;
$this->level = $level;
$this->profession = $profession;
$this->guild = $guild;
$this->leader = $leader;
}
function GetName() {
return $this->name;
}
function GetLevel() {
return $this->level;
}
function GetProfession() {
return $this->profession;
}
function GetGuild() {
return $this->guild;
}
function IsLeader() {
return $this->leader;
}
function SetLeader($leader) {
$this->leader = $leader;
}
}
?>
Make sure u make 2 files...main module name doesn't really matter, but _TeamsClass.php should be named exactly that unless you want to change the require_once("_TeamsClass.php") in the start of the first file.
-
um, do you want me to put this in a php file and upload it to a webserver?
-
if u put it in 2 files as described...go ahead :)
-
Care to write a help file for it?
ALso, why did you choose two files?
-
Helpfiles are really boring to write :shock: It could be I'll do it...but....boooring. Sorry for the lack of commenting of code too (boring too).
The reason I chose 2 files is that the 2nd file is more like an include file. This allows me to include this file in other modules if I want. It doesn't contain any botspecific code, hence it's free to reuse anywhere else. I don't know how much you know about objectoriented programming, but reusable code is a good thing ;)
-
there is only one thing i have to say about this
AWESOME WORK MAN :D
-
Little new to bebot.. didnt find an answer, and i realize this is an old thread. installed this module and getting this error:
Parse error: syntax error, unexpected '&' in C:\BeBot\modules\Teams.php on line 4
-
Looks like the code you pasted was badly formatted for some reason.
Try grabbing a fresh copy.
-
Hmm used the updated copy, and now !teams !addteams etc.. does nothing.
-
did you do !startteam <name of person in bot>
Do !teamadmin work?
Do you have any other modules that overwrite the commands in this module? Make sure you unload any other teamrelated module.
You did exactly as my initial post said? E.g. you need to put the code in 2 files. First one can be named whatever, 2nd MUST be named _TeamsClass.php unless you want to change a minor part of the first file.
Also, as you mentioned, the thread is old...so this module isn't really up to date when it comes to custom rights management and so on. I guess the whole module could use a revamp, but that's really up to the community as I have my own project running now.
-
The module should work, but it does not give much in the way of error messages iirc.
If i ever get the time i might do a revamp of it.
-
One thing i noticed when using this module:
if a person is assigned to team and then leaves/rejoins channel, this person stays assigned in the team AND gets added to the lft section in !teamadmin
otherwise really nice one :)
-
sorry for the HUGE bump...
but, when im doing the teamadmin command, all commands there just sending me to chat with the bot..
EDIT: sorry, was problem with my bot, sorry for the bump again and great module :)
-
One thing i noticed when using this module:
if a person is assigned to team and then leaves/rejoins channel, this person stays assigned in the team AND gets added to the lft section in !teamadmin
otherwise really nice one :)
I'm not maintaining this module anymore, so really up to the Bebot community fix errors if they appear. I got my my own botproject running, which is based on Bebot...so if you decide to run a standalone raidbot and go for RINGBot, you'll get the same teamadmin with the error mentioned fixed ;)
-
bump great work
-
One thing i noticed when using this module:
if a person is assigned to team and then leaves/rejoins channel, this person stays assigned in the team AND gets added to the lft section in !teamadmin
otherwise really nice one :)
I'm not maintaining this module anymore, so really up to the Bebot community fix errors if they appear. I got my my own botproject running, which is based on Bebot...so if you decide to run a standalone raidbot and go for RINGBot, you'll get the same teamadmin with the error mentioned fixed ;)
Maybe you should repost a new version because it's not fixed : ).
-
One thing i noticed when using this module:
if a person is assigned to team and then leaves/rejoins channel, this person stays assigned in the team AND gets added to the lft section in !teamadmin
otherwise really nice one :)
I'm not maintaining this module anymore, so really up to the Bebot community fix errors if they appear. I got my my own botproject running, which is based on Bebot...so if you decide to run a standalone raidbot and go for RINGBot, you'll get the same teamadmin with the error mentioned fixed ;)
Maybe you should repost a new version because it's not fixed : ).
Just download from CVS, not the zip file. The zip file is an old version. There are multiple updates in CVS in a lot of the modules.
-
ah ok, will do : )
-
Can we get this code change entered for this module? I posted this in http://bebot.link/ao-0-6-support/teams-module-modification/ It is a small fix, but makes the !teams output much easier to read.
diff (original)Teams.php My/modules/ao/Teams.php
123c123
< $msg .= "[##blob_title##".$teammember->GetName() . " :: Leader##end##]";
---
> $msg .= "[##blob_title##".$teammember->GetName() . " :: Leader##end##] ";
127c127
< $msg .= "[##highlight##".$teammember->GetName() . "##end##]";
---
> $msg .= "[##highlight##".$teammember->GetName() . "##end##] ";
146c146
< $this->bot->send_pgroup("Teams cleared by [##highlight##".$name . "##end##]");
---
> $this->bot->send_pgroup("Teams cleared by [##highlight##".$name . "##end##] ");
292c292
< $this->bot->send_pgroup("Team ##highlight##" . $this->numteams . "##end## has been started. Leader is ##highlight##[" . $name . "##end##]");
---
> $this->bot->send_pgroup("Team ##highlight##" . $this->numteams . "##end## has been started. Leader is ##highlight##[" . $name . "##end##] ");