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: Reworked (cleaned) modules/Relay_GUILD.php  (Read 13430 times)

0 Members and 1 Guest are viewing this topic.

Offline Blueeagle

  • Omnipotent
  • BeBot Hero
  • ******
  • Posts: 323
  • Karma: +0/-0
Reworked (cleaned) modules/Relay_GUILD.php
« on: March 04, 2007, 08:55:49 pm »
I did some rework on Relay_GUILD.php

Changes:
 - Added setting for who can toggle relay
 - Added relay status to the settings module so it's rememberd across restarts
 - Cleaned the re-invetion of "whois"
 - The toggle code was bloated so I trimmed it
 - Trimmed off legacy code
 - Implemented colors using the new colors module

This is the result:
Code: [Select]
<?php
/*
* Relay.php - Privategroup <=> Guildchat relay and Guest List Management.
*
* BeBot - An Anarchy Online Chat Automaton
* Copyright (C) 2004 Jonas Jax
* Copyright (C) 2005 Thomas J. Stens? and ShadowRealm Creations
*
* Developed by:
* - Blondengy (RK1)
* - Khalem (RK1)
*
* See Credits file for all aknowledgements.
*
*  This program is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software
*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
*  USA
*
* File last changed at $LastChangedDate: 2007-02-06 21:16:21 +0100 (tir, 06 feb 2007) $
* Revision: $Id: Relay_GUILD.php 348 2007-02-06 20:16:21Z shadowmaster $
*
* Further Revisions By: Xenixa (RK1)
* - Added guestlist command to show Guests in the guests table
* - Incorporated Notify.php Module coded by Craized into this module
*   - Expanded Notify to record Guest name into guests table if not exsists.
*/

$relay = new Relay($bot);

$commands["tell"]["relay"] = &$relay;
$commands["pgmsg"]["relay"] = &$relay;
$commands["gc"]["relay"] = &$relay;
//$commands["gmsg"]["relay"] = &$relay;
$commands["privgroup"]["relay"] = &$relay;
$commands["gmsg"][$guild_name][] = &$relay;

$commands["pgjoin"][] = &$relay;

/*
The Class itself...
*/
class Relay
{
var $bot;
var $settings;


/*
Constructor:
Hands over a referance to the "Bot" class.
*/
function Relay (&$bot)
{
$this -> bot = &$bot;
$this -> bot -> set -> create('Relay''Access_Toggle''GUEST''Who should be able to toggle relay on/off''ADMIN;LEADER;MEMBER;GUEST;ANONYMOUS');
$this -> bot -> set -> create('Relay''Status''Off''Relay to private group should be''On;Off');
}



/*
This gets called on a tell with the command
*/
function tell($name$msg)
{
if (preg_match("/^" $this -> bot -> commpre "relay$/i"$msg))
{
$this -> settings $this -> bot -> set -> get_all('Relay');
$this -> toggle_relay($name);
}
else
{
$this -> bot -> send_help($name);
}
}


/*
This gets called on a msg in the privgroup with the command
*/
function pgmsg($name$msg)
{
if (preg_match("/^" $this -> bot -> commpre "relay$/i"$msg))
{
$this -> settings $this -> bot -> set -> get_all('Relay');
$this -> toggle_relay($name);
}
}



/*
This gets called on a msg in the guildchat with the command
*/
function gc($name$msg)
{
if (preg_match("/^" $this -> bot -> commpre "relay$/i"$msg))
{
$this -> settings $this -> bot -> set -> get_all('Relay');
$this -> toggle_relay($name);
}
}


/*
This gets called on a msg in the group
*/
function gmsg($name$group$msg)
{
if ($this -> settings['Relay'])
{
if (strtolower($name) != strtolower($this -> bot -> botname))
{
$this -> bot -> send_pgroup("##seagreen##$name:##end####lime## $msg##end##");
}
}
}

/*
This gets called on a msg in the privgroup without a command
*/
function privgroup($name$msg)
{
if ($this -> settings['Relay'])
{
if (strtolower($name) != strtolower($this -> bot -> botname))
{
$this -> bot -> send_gc("[Guest] ##seagreen##$name:##end####lime## $msg##end##");
}
}
}

/*
Starts/Stops the relay
*/
function toggle_relay($name)
{
if ($this -> bot -> security -> check_access($name$this -> settings['Access_Toggle']))
{
$target=!$this -> settings['Relay'];
$this -> bot -> set -> save('Relay''Relay'$target);
$this -> bot -> send_tell($name"##yellow##You##end## have turned the relay##yellow## $target ##end##");
$this -> bot -> send_pgroup("##yellow##$name##end## has turned the relay##yellow## $target ##end##");
}
else
{
$this -> bot -> send_tell($name"##red##You need to be##yellow## {$this -> settins['Access_Toggle']} or higher to toggle relay##end##");
}
}

/*
Sends info to private group on guest who joined
*/
function pgjoin($name)
{
// Gets character info from anarchy online website
$who $this -> bot -> whois -> lookup($name);
if($who["error"]) {
$this -> bot -> send_pgroup("Unknown user " $name " has joined " $this -> bot -> botname);
$this -> bot -> send_gc("Unknown user " $name " has joined " $this -> bot -> botname);
}
else {
$this -> bot -> send_pgroup($this -> bot -> commands["gc"]["whois"] -> whois_player($name) . " joined " ucfirst($this -> bot -> botname));
$this -> bot -> send_gc($this -> bot -> commands["gc"]["whois"]-> whois_player($name) . " joined " ucfirst($this -> bot -> botname));
}
}
}
?>


Please go over it to check for any bugs. I haven't got a good test guild set up yet so I am relying on outside help for that at the moment... And peer review is always a good think. :)

Edit: Silly typos
Edit: Now actually checking access rights and throwing an error if user has insufficient privileges
Edit: Now loading settings to make sure they are up-to-date when checking toggle.
Edit: More silly typos
« Last Edit: March 05, 2007, 04:51:28 am by Blueeagle »
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: Reworked (cleaned) modules/Relay_GUILD.php
« Reply #1 on: March 05, 2007, 04:53:31 pm »
Looking good.

If you feel like it the following also needs to be done at some point:
- Announce on !join or logon should only occur if the relay is active and should be optional.
- If relay is active, an onjoin notice should optionally be sent to both people logging on and people joining the guest channel. Likewise if relay is inactive, an onjoin notice should be sent to people joining the guest channel.
BeBot Founder and Fixer Kingpin

Offline Blueeagle

  • Omnipotent
  • BeBot Hero
  • ******
  • Posts: 323
  • Karma: +0/-0
Re: Reworked (cleaned) modules/Relay_GUILD.php
« Reply #2 on: March 05, 2007, 07:58:32 pm »
Are you thinking something like:

Code: [Select]
Settings for Relay

Announce_pg_join_active:  BOTH
  Description: Where should joins to privgoup be announced when relay is active
  Change to: [ BOTH | PRIVFROUP | GUILDCHAT | NONE ]

Announce_pg_join_inactive:  PRIVGROUP
  Description: Where should joins to privgoup be announced when relay is inactive
  Change to: [ BOTH | PRIVGROUP | GUILDCHAT | NONE ]

Announce_gc_join_active:  BOTH
  Description: Where should joins to guild chat be announced when relay is active
  Change to: [ BOTH | PRIVFROUP | GUILDCHAT | NONE ]

Announce_gc_join_inactive:  GUILDCHAT
  Description: Where should joins to guild chat be announced when relay is inactive
  Change to: [ BOTH | PRIVGROUP | GUILDCHAT | NONE ]

That is ofcourse doable.
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: Reworked (cleaned) modules/Relay_GUILD.php
« Reply #3 on: March 09, 2007, 11:54:04 pm »
Pretty much yeah :)
BeBot Founder and Fixer Kingpin

Offline Blueeagle

  • Omnipotent
  • BeBot Hero
  • ******
  • Posts: 323
  • Karma: +0/-0
Re: Reworked (cleaned) modules/Relay_GUILD.php
« Reply #4 on: March 20, 2007, 04:24:25 pm »
I've reworked and implemented settings.

Still testing the module and I did some weird thing with the colors that I need to figure out. The final code will be posted in a matter of days (hopefully)

The end result for the settings was:

Code: [Select]
Settings for Relay

Status:  Enabled
  Description: Relay to private group should be
  Change to: [ Disabled | Enabled ]

Access_Toggle:  GUEST
  Description: Who should be able to toggle relay on/off
  Change to: [ ADMIN | LEADER | MEMBER | GUEST | ANONYMOUS ]

Announce_gc_active:  BOTH
  Description: Where should guild chat joins/parts be announced when relay is active
  Change to: [ BOTH | GUILDCHAT ]

Announce_gc_inactive:  GUILDCHAT
  Description: Where should guild chat joins/parts be announced when relay is inactive
  Change to: [ BOTH | GUILDCHAT ]

Announce_pg_active:  BOTH
  Description: Where should privgroup joins/parts be announced when relay is active
  Change to: [ BOTH | PRIVGROUP | GUILDCHAT | NONE ]

Announce_pg_inactive:  PRIVGROUP
  Description: Where should privgroup joins/parts be announced when relay is inactive
  Change to: [ BOTH | PRIVGROUP | GUILDCHAT | NONE ]

Announce_toggle:  BOTH
  Description: Where should relay toggles be announced
  Change to: [ BOTH | PRIVGROUP | GUILDCHAT | NONE ]

As you can see there are no options for setting gc joins/leaves to pgroup only as the guild announcement is done elsewhere.

Also I am concidering changing !relay to show the current status and add !relay [Enable|Disable|Toggle], but I'm not sure if there's any point to it.
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: Reworked (cleaned) modules/Relay_GUILD.php
« Reply #5 on: March 22, 2007, 10:17:23 pm »
And here is the monstrousity.

Note that it's prudent to comment out line 144 of core/Online.php to avoid duplicate "left privgroup" messages. (imo such output doesn't belong in a core module anyways.

Line 144 is the one marked with an asterix

Code: [Select]
function pgleave($name)
{
if (isset($this -> pgroup[$name]))
unset($this -> pgroup[$name]);
* $this -> bot -> send_gc($name ." has left the guest channel.");
}

And here is Relay_GUILD.php
Code: [Select]
<?php
/*
* Relay.php - Privategroup <=> Guildchat relay and Guest List Management.
*
* BeBot - An Anarchy Online Chat Automaton
* Copyright (C) 2004 Jonas Jax
* Copyright (C) 2005 Thomas J. Stens? and ShadowRealm Creations
*
* Developed by:
* - Blondengy (RK1)
* - Khalem (RK1)
*
* See Credits file for all aknowledgements.
*
*  This program is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software
*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
*  USA
*
* File last changed at $LastChangedDate: 2007-02-06 21:16:21 +0100 (tir, 06 feb 2007) $
* Revision: $Id: Relay_GUILD.php 348 2007-02-06 20:16:21Z shadowmaster $
*
* Further Revisions By: Xenixa (RK1)
* - Added guestlist command to show Guests in the guests table
* - Incorporated Notify.php Module coded by Craized into this module
*   - Expanded Notify to record Guest name into guests table if not exsists.
*/

$relay = new Relay($bot);

$commands["tell"]["relay"] = &$relay;
$commands["pgmsg"]["relay"] = &$relay;
$commands["gc"]["relay"] = &$relay;
//$commands["gmsg"]["relay"] = &$relay;
$commands["privgroup"]["relay"] = &$relay;
$commands["gmsg"][$guild_name][] = &$relay;

$commands["pgjoin"][] = &$relay;
$commands["pgleave"][] = &$relay;
$commands["buddy"][] = &$relay;

/*
The Class itself...
*/
class Relay
{
var $bot;
var $settings;


/*
Constructor:
Hands over a referance to the "Bot" class and defines settings for this module.
*/
function Relay (&$bot)
{
$this -> bot = &$bot;

/*
Define settings used in this module
*/
$this -> bot -> set -> create('Relay''Announce_pg_active''BOTH''Where should privgroup joins/parts be announced when relay is active''BOTH;PRIVGROUP;GUILDCHAT;NONE');
$this -> bot -> set -> create('Relay''Announce_pg_inactive''PRIVGROUP''Where should privgroup joins/parts be announced when relay is inactive''BOTH;PRIVGROUP;GUILDCHAT;NONE');

$this -> bot -> set -> create('Relay''Announce_gc_active''BOTH''Where should guild chat joins/parts be announced when relay is active''BOTH;GUILDCHAT');
$this -> bot -> set -> create('Relay''Announce_gc_inactive''GUILDCHAT''Where should guild chat joins/parts be announced when relay is inactive''BOTH;GUILDCHAT');

$this -> bot -> set -> create('Relay''Announce_toggle''BOTH''Where should relay toggles be announced''BOTH;PRIVGROUP;GUILDCHAT;NONE');
$this -> bot -> set -> create('Relay''Access_Toggle''GUEST''Who should be able to toggle relay on/off''ADMIN;LEADER;MEMBER;GUEST;ANONYMOUS');
$this -> bot -> set -> create('Relay''Status''Enabled''Relay to private group should be''Disabled;Enabled');

/*
Load settings into this module (this probably doesn't have to be done here.)
*/
$this -> settings $this -> bot -> set -> get_all('Relay');
}



/*
This gets called on a tell with the command
*/
function tell($name$msg)
{
if (preg_match("/^" $this -> bot -> commpre "relay$/i"$msg))
{
$this -> settings $this -> bot -> set -> get_all('Relay');
$this -> toggle_relay($name);
}
else
{
$this -> bot -> send_help($name);
}
}


/*
This gets called on a msg in the privgroup with the command
*/
function pgmsg($name$msg)
{
if (preg_match("/^" $this -> bot -> commpre "relay$/i"$msg))
{
$this -> settings $this -> bot -> set -> get_all('Relay');
$this -> toggle_relay($name);
}
}



/*
This gets called on a msg in the guildchat with the command
*/
function gc($name$msg)
{
if (preg_match("/^" $this -> bot -> commpre "relay$/i"$msg))
{
$this -> settings $this -> bot -> set -> get_all('Relay');
$this -> toggle_relay($name);
}
}


/*
This gets called on a msg in the group
*/
function gmsg($name$group$msg)
{
//This is why the settings should be cached instead of querying the DB every time.
$this -> settings $this -> bot -> set -> get_all('Relay'); 
if ($this -> settings['Status']=="Enabled")
{
if (strtolower($name) != strtolower($this -> bot -> botname))
{
$this -> bot -> send_pgroup("##highlight##$name:##end####normal## $msg##end##");
}
}
}

/*
This gets called on a msg in the privgroup without a command
*/
function privgroup($name$msg)
{
//This is why the settings should be cached instead of querying the DB every time.
$this -> settings $this -> bot -> set -> get_all('Relay');
if ($this -> settings['Status']=="Enabled")
{
if (strtolower($name) != strtolower($this -> bot -> botname))
{
$this -> bot -> send_gc("##highlight##[Guest] $name: ##end####normal##$msg##end##");
}
}
}

function pgjoin($name)
{
$this -> announce_pg($this -> make_join($name));
}

function pgleave($name)
{
//Taking this from Online.php because I feel it belongs here.
$this -> announce_pg("##normal##$name has left ".$this -> bot -> botname.".##end##");
}

function buddy($name$msg)
{
if($msg)
{
$this -> announce_gc($this -> make_join($name));
}
else
{
$this -> announce_gc("##normal##$name has left ".$this -> bot -> botname.".##end##");
}
}

/*
Starts/Stops the relay
*/
function toggle_relay($name)
{
if ($this -> settings['Status']=="Enabled")
{
$target "Disabled";
}
else
{
$target "Enabled";
}
$this -> bot -> set -> save('Relay''Status'$target);
$this -> bot -> send_tell($name"##tell##The relay is now:##highlight## $target ##end##");
if (($this -> settings['Announce_toggle'] == 'PRIVGROUP') || ($this -> settings['Announce_toggle'] == 'BOTH'))
{
$this -> bot -> send_pgroup("##highlight##$name##end####normal## has set the relay to:##highlight## $target ##end##");
}
if (($this -> settings['Announce_toggle'] == 'GUILDCHAT') || ($this -> settings['Announce_toggle'] == 'BOTH'))
{
$this -> bot -> send_gc("##highlight##$name##end####normal## has set the relay to:##highlight## $target ##end##");
}
}


/*
Pretty print joins
*/
function make_join($name)
{
// Gets character info from anarchy online website
$who $this -> bot -> whois -> lookup($name);
if($who["error"]) {
$this -> bot -> send_pgroup("##error##Unknown user ##end####highlight##$name##end####normal## has joined ##end####highlight##" $this -> bot -> botname)."##end##";
$this -> bot -> send_gc("##error##Unknown user ##end####highlight##$name##end####group## has joined ##end####highlight##" $this -> bot -> botname)."##end##";
}
else {
$announcement sprintf("%s "$who['firstname']);
$announcement.= sprintf("##highlight##'%s'##end## "$who['nickname']);
$announcement.= sprintf("%s "$who['lastname']);
$announcement.= sprintf("a level ##highlight##%s##end## "$who['level']);
$announcement.= sprintf("##lime##%s (%s)##end## "$who['at'], $who['at_id']);
$announcement.= sprintf("%s of %s "$who['rank'], $who['org']);
$announcement.= sprintf("joined ##highlight##%s##end##"$this -> bot -> botname);
}
return $announcement;
}

function announce_pg($announcement)
{
switch ($this -> settings['Status'])
{
case 'Enabled':
if (($this -> settings['Announce_pg_active'] == 'PRIVGROUP')||($this -> settings['Announce_pg_active'] == 'BOTH'))
$this -> bot -> send_pgroup("##normal##$announcement##end##");
if (($this -> settings['Announce_pg_active'] == 'GUILDCHAT')||($this -> settings['Announce_pg_active'] == 'BOTH'))
$this -> bot -> send_gc("##normal##$announcement##end##");
break;
case 'Disabled':
if (($this -> settings['Announce_pg_inactive'] == 'PRIVGROUP')||($this -> settings['Announce_pg_inactive'] == 'BOTH'))
$this -> bot -> send_pgroup("##normal##$announcement##end##");
if (($this -> settings['Announce_pg_inactive'] == 'GUILDCHAT')||($this -> settings['Announce_pg_inactive'] == 'BOTH'))
$this -> bot -> send_gc("##normal##$announcement##end##");
break;
}
}

function announce_gc($announcement)
{
switch ($this -> settings['Status'])
{
case 'Enabled':
if (($this -> settings['Announce_gc_active'] == 'BOTH'))
$this -> bot -> send_pgroup("##normal##$announcement##end##");
break;
case 'Disabled':
if (($this -> settings['Announce_gc_inactive'] == 'BOTH'))
$this -> bot -> send_pgroup("##normal##$announcement##end##");
break;
}
}
}
?>


I have been running this for a couple of days and not found any bugs yet. Please test it and see if you can find what I've missed.

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

 

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