Archive > 0.3.x Custom/Unofficial Modules

Reworked (cleaned) modules/Relay_GUILD.php

(1/2) > >>

Blueeagle:
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: ---<?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));
}
}
}
?>

--- End code ---

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

Khalem:
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.

Blueeagle:
Are you thinking something like:


--- Code: ---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 ]

--- End code ---

That is ofcourse doable.

Khalem:
Pretty much yeah :)

Blueeagle:
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: ---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 ]

--- End code ---

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.

Navigation

[0] Message Index

[#] Next page

Go to full version