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?
November 21, 2008, 08:51:09 PM

Login with username, password and session length
Search



Advanced search
Support GoPHP5.org
BeBot - An Anarchy Online/Age Of Conan chat automaton > Forum > Modules > Modules for older versions > 0.2.x Custom/Unofficial Modules > Topic: Banlist Module - Banlist functionality
Pages: [1] 2   Go Down
« previous next »
Print
Author Topic: Banlist Module - Banlist functionality  (Read 2662 times)
0 Members and 1 Guest are viewing this topic.
craized
BeBot Contributor
Experienced
*******
Offline Offline

Gender: Male
Posts: 165



WWW
Banlist Module - Banlist functionality
« on: December 26, 2005, 12:56:46 AM »

BANLIST MODULE

Description:
A module which allows raidleaders and admins to add/remove people from a bot banlist.
* Still really need someone to help make the regex for 'ban <name> [reason] [time]'.
* Requires updated PrivGroup modifications to use $this -> bot -> commands['pgroup']['banlist'] -> bancheck($name); (return true = banned).

[|] On cron, bot will check to see if anyone's ban has expired.
[|] !ban <name> [reason] <time>
  Will ban <name> with [reason] for <time>. If <time> is set to 0, it will be an indefinite ban.
[|] !unban <name>
  Will unban <name>.
[|] !banned
  Will tell a user how long they are banned for.
[|] !history <name>
  Will show the ban history for a user.
[|] !banlist
  Displays a banlist blob. Time is weeks, days, hour:minute:second
  Ex.
Code:
::::: <botname>'s banlist :::::


Bigburtha has been banned indefinitely.
   Reason: Ninja looting.

Abeham has been banned for 0 week(s), 5 days, 12:24:55.
   Reason: Spammage.


Edit: Please use link for file access.
« Last Edit: March 14, 2006, 03:10:56 AM by craized » Logged

Trailin [213/14][ADVENTURER][RK2]
Bigburtha [216/17][NT][RK2][FROZEN]
Abeham [199/7][TRADER][RK2][FROZEN]

Xenixa
BeBot Contributor
Expert
*******
Offline Offline

Posts: 307



Re: Banlist Module - Banlist functionality
« Reply #1 on: December 26, 2005, 06:14:44 AM »

Cron Job command should look like this:
Code:
$cron["1min"][] = &$banlist;

Try this for the Commands:
Code:
<?php
/*
This gets called on a tell with the command
*/
function tell($name, $msg)
{
if (preg_match('/^'.$this -> bot -> commpre.'ban (.+) (.*) ([0-9]*)$/i', $msg))
$c = $this -> ban($name, $info[1], $info[2], $info[3]);
elseif (preg_match('/^'.$this -> bot -> commpre.'unban (.+)$/i', $msg))
$c = $this -> unban($name, $info[1]);
elseif (preg_match('/^'.$this -> bot -> commpre.'banlist$/i', $msg))
$c = $this -> banlist($name);
elseif (preg_match('/^'.$this -> bot -> commpre.'banned$/i', $msg))
$c = $this -> banned($name);

$c != '' ? $this -> bot -> send_tell($name, $c) : NULL;
}


/*
This gets called on a msg in the privgroup with the command
*/
function pgmsg($name, $msg)
{
if (preg_match('/^'.$this -> bot -> commpre.'ban (.+)$/i', $msg))
$c = $this -> ban($name, $info[1]);
elseif (preg_match('/^'.$this -> bot -> commpre.'unban (.+)$/i', $msg))
$c = $this -> unban($name, $info[1]);
elseif (preg_match('/^'.$this -> bot -> commpre.'banlist$/i', $msg))
$c = $this -> banlist($name);

$c != '' ? $this -> bot -> send_pgroup($c) : NULL;
}
?>
For Regex in php just need to remember this:
. =  match any character except newline/cr (default)
* =  0 or more quantifier matches
+ =  1 or more quantifier matches

Oh and just a friendly programming methodology tip. Should stick to using Double quotes when identifing string Values. Saves from having to add slashes when you need to use an aposrophy in that string value.
Code:
$blob = "::::: <botname>'s banlist :::::\n\n";
vs.
Code:
$blob = '::::: <botname>\'s banlist :::::'."\n\n\n";
Just easier to read methinks Smiley
Logged

<<< Hack's in Zend Studio

All my Custom Bebot files may be Found Here <-clicky
craized
BeBot Contributor
Experienced
*******
Offline Offline

Gender: Male
Posts: 165



WWW
Re: Banlist Module - Banlist functionality
« Reply #2 on: December 26, 2005, 03:41:54 PM »

Double quotes require PHP to check the string for variables and other things to be parsed, where single quotes take the string at face value, allowing for faster processing time. Also, since I use PHP mainly for HTML, I use a lot of double quotes in my tags. This way, every time I want to do <div class="main"></div>, I don't have to escape every double quote in my code. Thanks for the suggestion, but I guess that one is personal preference. I will change the cron as soon as I'm done writing this post, and I'll change the regex, although I don't think it will work.

Code:
if (preg_match('/^'.$this -> bot -> commpre.'ban (.+) (.*) ([0-9]*)$/i', $msg))
This should match !ban<space>(.+)<space>(optional)<space>(optional)
I need the spaces to be optional as well, because if I'm leaving out an argument, I don't want them to have to type !ban <name><space><space> to get the command to work. However, if this works and I'm just imagining things, let me know and I'll change it right away.
Logged

Trailin [213/14][ADVENTURER][RK2]
Bigburtha [216/17][NT][RK2][FROZEN]
Abeham [199/7][TRADER][RK2][FROZEN]

Xenixa
BeBot Contributor
Expert
*******
Offline Offline

Posts: 307



Re: Banlist Module - Banlist functionality
« Reply #3 on: December 26, 2005, 05:39:06 PM »

I think your right. I was coding my sleep again. You could move the space inside the sub-pattern like so:
Code:
if (preg_match('/^'.$this -> bot -> commpre.'ban (.+)([\s].*)([\s][0-9]*)$/i', $msg))
I.E. lead the pattern with a space were \s = any white space character.

Opps forgot to surround the \s with the [] to define that it's a character class in the pattern.
« Last Edit: December 26, 2005, 05:53:12 PM by Xenixa » Logged

<<< Hack's in Zend Studio

All my Custom Bebot files may be Found Here <-clicky
craized
BeBot Contributor
Experienced
*******
Offline Offline

Gender: Male
Posts: 165



WWW
Re: Banlist Module - Banlist functionality
« Reply #4 on: December 26, 2005, 05:44:56 PM »

I was thinking that wouldn't work because it would send the space as part of the variable, but all I have to do is trim the value before I sent it. Thank you, I'm updating now.

if (preg_match('/^'.$this -> bot -> commpre.'ban (.+)( ?.*)( ?[0-9]*)$/i', $msg)) $c = $this -> ban($name, trim($info['1']), trim($info['2']), trim($info['3']));

Hope that works.

EDIT: changed (\s*.*) to ( ?.*)
« Last Edit: December 26, 2005, 06:23:51 PM by craized » Logged

Trailin [213/14][ADVENTURER][RK2]
Bigburtha [216/17][NT][RK2][FROZEN]
Abeham [199/7][TRADER][RK2][FROZEN]

Xenixa
BeBot Contributor
Expert
*******
Offline Offline

Posts: 307



Re: Banlist Module - Banlist functionality
« Reply #5 on: December 26, 2005, 06:34:11 PM »

Heh oh ya, space ? for 0 or 1 quantifier. That should work with the trims on the array results.

Btw, question. Why do you use single quotes around the array result number?
Logged

<<< Hack's in Zend Studio

All my Custom Bebot files may be Found Here <-clicky
craized
BeBot Contributor
Experienced
*******
Offline Offline

Gender: Male
Posts: 165



WWW
Re: Banlist Module - Banlist functionality
« Reply #6 on: December 26, 2005, 06:38:01 PM »

I'm not sure if that's actually the correct syntax or not, but that's just the way I learned it from a friend who is much better at coding than I am, so that's the way I do it.
Logged

Trailin [213/14][ADVENTURER][RK2]
Bigburtha [216/17][NT][RK2][FROZEN]
Abeham [199/7][TRADER][RK2][FROZEN]

Xenixa
BeBot Contributor
Expert
*******
Offline Offline

Posts: 307



Re: Banlist Module - Banlist functionality
« Reply #7 on: December 26, 2005, 06:45:41 PM »

Hmm you know what, don't mind me. I keep forgetting the key can be an integer or string in the array result. In this instance here php still parses it as an Int. Smiley
Logged

<<< Hack's in Zend Studio

All my Custom Bebot files may be Found Here <-clicky
craized
BeBot Contributor
Experienced
*******
Offline Offline

Gender: Male
Posts: 165



WWW
Re: Banlist Module - Banlist functionality
« Reply #8 on: December 27, 2005, 03:37:20 PM »

In the ban and unban function, I used $this -> query instead of $this -> bot -> db -> query, fixed now. Also messed up my timer math, where it should have been $week-=604800, it was $week-604800.... same with the other timer math... Also fixed. Also put limits on the DB queries, and had it only unban if the user is banned, and you can only ban a person if they are not currently banned.
Logged

Trailin [213/14][ADVENTURER][RK2]
Bigburtha [216/17][NT][RK2][FROZEN]
Abeham [199/7][TRADER][RK2][FROZEN]

craized
BeBot Contributor
Experienced
*******
Offline Offline

Gender: Male
Posts: 165



WWW
Re: Banlist Module - Banlist functionality
« Reply #9 on: January 07, 2006, 04:21:47 PM »

I was wondering if anyone knew a better way to do this. I was surprised there wasn't a function for PHP (that I could find) that took an int, and parsed it into an ammount of time. If anyone finds one, or can think of a better way to pass all the required information please speak up.  Cheesy

Also updated known bugs in my first post.

    function time($name) {
        
$time['week'] = '0';
        
$time['day'] = '0';
        
$time['hr'] = '0';
        
$time['min'] = '0';
        
$time['sec'] = '0';
        
$stamp = $this -> banlist[$name]-mktime();
        while(
$stamp>='604800') {
            
$time['week']++;
            
$stamp-=604800;
        }
        while(
$stamp>='86400') {
            
$time['day']++;
            
$stamp-=86400;
        }
        while(
$stamp>='3600') {
            
$time['hr']++;
            
$stamp-=3600;
        }
        while(
$stamp>='60') {
            
$time['min']++;
            
$stamp-=60;
        }
        
$time['sec'] = $stamp;
        return 
$time;
    }
?>
Logged

Trailin [213/14][ADVENTURER][RK2]
Bigburtha [216/17][NT][RK2][FROZEN]
Abeham [199/7][TRADER][RK2][FROZEN]

Zacix
Rookie
**
Offline Offline

Posts: 72


Re: Banlist Module - Banlist functionality
« Reply #10 on: January 09, 2006, 10:07:41 AM »

Code:
<?php
function time($name) {
$stamp = $this->banlist[$name] - mktime();
$time['week'] = floor($stamp/604800);
$time['day']  = floor(($stamp-($time['$week']*604800))/86400);
$time['hr']   = floor(($stamp-($time['$week']*604800+$time['day']*86400))/3600);
$time['min']  = floor(($stamp-($time['$week']*604800+$time['day']*86400+$time['hr']*3600))/60);
$time['sec']  = floor(($stamp-($time['$week']*604800+$time['day']*86400+$time['hr']*3600+$time['min']*60)));
return 
$time;
}
?>


same shit, different wrappings...untested, but should in theory return the same array unless I've mixed up some parenthesis. Better or not....no clue. Personally I don't like loops, so I'd think this scale better Tongue
« Last Edit: January 09, 2006, 10:10:12 AM by Zacix » Logged

Zacix
Current projects:
RINGBot, BeBot branch
Neutnet, RK2 Neutral massmessage network
craized
BeBot Contributor
Experienced
*******
Offline Offline

Gender: Male
Posts: 165



WWW
Re: Banlist Module - Banlist functionality
« Reply #11 on: January 09, 2006, 07:37:18 PM »

Shrug, I'll update it, looks better than mine IMO, ty.
« Last Edit: January 09, 2006, 07:40:17 PM by craized » Logged

Trailin [213/14][ADVENTURER][RK2]
Bigburtha [216/17][NT][RK2][FROZEN]
Abeham [199/7][TRADER][RK2][FROZEN]

ZubZero
Freshman
*
Offline Offline

Posts: 10


Re: Banlist Module - Banlist functionality
« Reply #12 on: January 17, 2006, 02:21:10 PM »

I got alot of problems with this script it starts with

Parse error: parse error, unexpected ')' in /home/zubzero/BeBot_v0.2.2/modules/Banlist.php on line 53.

When I remove all those unexpected ')' it starts telling me it cant redeclare banlist() function.
And I dont have any other banlist scripts running.
Logged
Nogoal
Rookie
**
Offline Offline

Posts: 61


Re: Banlist Module - Banlist functionality
« Reply #13 on: January 19, 2006, 12:51:06 PM »

there's 2 function ban list inside the script Tongue
Logged
ZubZero
Freshman
*
Offline Offline

Posts: 10


Re: Banlist Module - Banlist functionality
« Reply #14 on: January 22, 2006, 10:53:47 AM »

Yeah that`s what I noticed too, I really want to use this banlist module and the privgroup module.
So please fix it if you have time too ^^
Logged
Pages: [1] 2   Go Up
Print
BeBot - An Anarchy Online/Age Of Conan chat automaton > Forum > Modules > Modules for older versions > 0.2.x Custom/Unofficial Modules > Topic: Banlist Module - Banlist functionality
« previous next »
 
Jump to:  

Recent
Change text in remember "...
by gerborg
[Today at 05:14:57 PM]

Log playtime from buddys ...
by Temar
[November 20, 2008, 10:33:57 AM]

Vote Core module and Simp...
by Temar
[November 19, 2008, 09:26:52 AM]

Restrict access for one m...
by Organizer
[November 19, 2008, 03:21:19 AM]

Custom / Revised Modules ...
by Elesar1
[November 17, 2008, 03:51:46 PM]

TWC
by Temar
[November 16, 2008, 11:39:12 AM]

Are there any FUN modules...
by Elesar1
[November 15, 2008, 07:39:15 PM]

Call to a member function...
by exxie
[November 15, 2008, 09:29:31 AM]

Ported Modules
by Alreadythere
[November 14, 2008, 06:10:07 PM]

cURL and other non-defaul...
by Temar
[November 14, 2008, 04:11:44 PM]
Stats
Members
Total Members: 1235
Latest: DDDepressionnn
Stats
Total Posts: 11037
Total Topics: 1496
Online Today: 16
Online Ever: 168
(July 01, 2007, 09:30:02 PM)
Users Online
Users: 0
Guests: 23
Total: 23

Powered by SMF 1.1.7 | SMF © 2006-2008, Simple Machines LLC
TinyPortal v0.9.8 © Bloc | NewDef design by Bloc
Page created in 0.372 seconds with 30 queries. (Pretty URLs adds 0.04s, 4q)
Loading...