L
R
HOME
FORUM
DOWNLOADS
Content
Links
Browse SVN
SVN Commit log
Documentation (Wiki)
Developers
Taskmanager
User
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
September 06, 2008, 09:45:48 PM
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Search
Advanced search
BeBot - An Anarchy Online/Age Of Conan chat automaton
>
Forum
>
Modules
>
Modules for older versions
>
0.3.x Custom/Unofficial Modules
> Topic:
Reworked (cleaned) modules/Relay_GUILD.php
Pages: [
1
]
Go Down
« previous
next »
Print
Author
Topic: Reworked (cleaned) modules/Relay_GUILD.php (Read 768 times)
0 Members and 1 Guest are viewing this topic.
Blueeagle
Omnipotent
BeBot Developer
Expert
Offline
Gender:
Posts: 313
Reworked (cleaned) modules/Relay_GUILD.php
«
on:
March 04, 2007, 02: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:
<?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 04, 2007, 10:51:28 PM by Blueeagle
»
Logged
The only problem that can't be solved by adding another wrapper is having too many wrappers.
Khalem
BeBot Founder
Administrator
Grandmaster
Offline
Gender:
Posts: 670
Re: Reworked (cleaned) modules/Relay_GUILD.php
«
Reply #1 on:
March 05, 2007, 10:53:31 AM »
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.
Logged
BeBot Founder and Fixer Kingpin
Madman coder and destroyer of good code
Blueeagle
Omnipotent
BeBot Developer
Expert
Offline
Gender:
Posts: 313
Re: Reworked (cleaned) modules/Relay_GUILD.php
«
Reply #2 on:
March 05, 2007, 01:58:32 PM »
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 ]
That is ofcourse doable.
Logged
The only problem that can't be solved by adding another wrapper is having too many wrappers.
Khalem
BeBot Founder
Administrator
Grandmaster
Offline
Gender:
Posts: 670
Re: Reworked (cleaned) modules/Relay_GUILD.php
«
Reply #3 on:
March 09, 2007, 05:54:04 PM »
Pretty much yeah
Logged
BeBot Founder and Fixer Kingpin
Madman coder and destroyer of good code
Blueeagle
Omnipotent
BeBot Developer
Expert
Offline
Gender:
Posts: 313
Re: Reworked (cleaned) modules/Relay_GUILD.php
«
Reply #4 on:
March 20, 2007, 10:24:25 AM »
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 ]
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.
Logged
The only problem that can't be solved by adding another wrapper is having too many wrappers.
Blueeagle
Omnipotent
BeBot Developer
Expert
Offline
Gender:
Posts: 313
Re: Reworked (cleaned) modules/Relay_GUILD.php
«
Reply #5 on:
March 22, 2007, 04: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:
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:
<?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
(