collapse collapse
* User Info
 
 
Welcome, Guest. Please login or register.
* Search

* Board Stats
  • stats Total Members: 989
  • stats Total Posts: 18365
  • stats Total Topics: 2500
  • stats Total Categories: 7
  • stats Total Boards: 35
  • stats Most Online: 1144

Author Topic: Banlist Module - Banlist functionality  (Read 30710 times)

0 Members and 1 Guest are viewing this topic.

Offline craized

  • Contributor
  • *******
  • Posts: 165
  • Karma: +0/-0
    • http://www.craized.net
Banlist Module - Banlist functionality
« on: December 26, 2005, 06: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: [Select]
::::: <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, 09:10:56 am by craized »
Trailin [213/14][ADVENTURER][RK2]
Bigburtha [216/17][NT][RK2][FROZEN]
Abeham [199/7][TRADER][RK2][FROZEN]


Offline Xenixa

  • Contributor
  • *******
  • Posts: 307
  • Karma: +0/-0
Re: Banlist Module - Banlist functionality
« Reply #1 on: December 26, 2005, 12:14:44 pm »
Cron Job command should look like this:
Code: [Select]
$cron["1min"][] = &$banlist;
Try this for the Commands:
Code: [Select]
<?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: [Select]
$blob = "::::: <botname>'s banlist :::::\n\n"; vs.
Code: [Select]
$blob = '::::: <botname>\'s banlist :::::'."\n\n\n"; Just easier to read methinks :)
<<< Hack's in Zend Studio

All my Custom Bebot files may be Found Here <-clicky

Offline craized

  • Contributor
  • *******
  • Posts: 165
  • Karma: +0/-0
    • http://www.craized.net
Re: Banlist Module - Banlist functionality
« Reply #2 on: December 26, 2005, 09: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: [Select]
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.
Trailin [213/14][ADVENTURER][RK2]
Bigburtha [216/17][NT][RK2][FROZEN]
Abeham [199/7][TRADER][RK2][FROZEN]


Offline Xenixa

  • Contributor
  • *******
  • Posts: 307
  • Karma: +0/-0
Re: Banlist Module - Banlist functionality
« Reply #3 on: December 26, 2005, 11: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: [Select]
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, 11:53:12 pm by Xenixa »
<<< Hack's in Zend Studio

All my Custom Bebot files may be Found Here <-clicky

Offline craized

  • Contributor
  • *******
  • Posts: 165
  • Karma: +0/-0
    • http://www.craized.net
Re: Banlist Module - Banlist functionality
« Reply #4 on: December 26, 2005, 11: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($nametrim($info['1']), trim($info['2']), trim($info['3']));

Hope that works.

EDIT: changed (\s*.*) to ( ?.*)
« Last Edit: December 27, 2005, 12:23:51 am by craized »
Trailin [213/14][ADVENTURER][RK2]
Bigburtha [216/17][NT][RK2][FROZEN]
Abeham [199/7][TRADER][RK2][FROZEN]


Offline Xenixa

  • Contributor
  • *******
  • Posts: 307
  • Karma: +0/-0
Re: Banlist Module - Banlist functionality
« Reply #5 on: December 27, 2005, 12:34:11 am »
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?
<<< Hack's in Zend Studio

All my Custom Bebot files may be Found Here <-clicky

Offline craized

  • Contributor
  • *******
  • Posts: 165
  • Karma: +0/-0
    • http://www.craized.net
Re: Banlist Module - Banlist functionality
« Reply #6 on: December 27, 2005, 12:38:01 am »
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.
Trailin [213/14][ADVENTURER][RK2]
Bigburtha [216/17][NT][RK2][FROZEN]
Abeham [199/7][TRADER][RK2][FROZEN]


Offline Xenixa

  • Contributor
  • *******
  • Posts: 307
  • Karma: +0/-0
Re: Banlist Module - Banlist functionality
« Reply #7 on: December 27, 2005, 12:45:41 am »
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. :)
<<< Hack's in Zend Studio

All my Custom Bebot files may be Found Here <-clicky

Offline craized

  • Contributor
  • *******
  • Posts: 165
  • Karma: +0/-0
    • http://www.craized.net
Re: Banlist Module - Banlist functionality
« Reply #8 on: December 27, 2005, 09: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.
Trailin [213/14][ADVENTURER][RK2]
Bigburtha [216/17][NT][RK2][FROZEN]
Abeham [199/7][TRADER][RK2][FROZEN]


Offline craized

  • Contributor
  • *******
  • Posts: 165
  • Karma: +0/-0
    • http://www.craized.net
Re: Banlist Module - Banlist functionality
« Reply #9 on: January 07, 2006, 10: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.  :D

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;
    }
?>
Trailin [213/14][ADVENTURER][RK2]
Bigburtha [216/17][NT][RK2][FROZEN]
Abeham [199/7][TRADER][RK2][FROZEN]


Offline Zacix

  • Contributor
  • *******
  • Posts: 73
  • Karma: +0/-0
Re: Banlist Module - Banlist functionality
« Reply #10 on: January 09, 2006, 04:07:41 pm »
Code: [Select]
<?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 :P
« Last Edit: January 09, 2006, 04:10:12 pm by Zacix »
Zacix
Current projects:
RINGBot, BeBot branch
Neutnet, RK2 Neutral massmessage network

Offline craized

  • Contributor
  • *******
  • Posts: 165
  • Karma: +0/-0
    • http://www.craized.net
Re: Banlist Module - Banlist functionality
« Reply #11 on: January 10, 2006, 01:37:18 am »
Shrug, I'll update it, looks better than mine IMO, ty.
« Last Edit: January 10, 2006, 01:40:17 am by craized »
Trailin [213/14][ADVENTURER][RK2]
Bigburtha [216/17][NT][RK2][FROZEN]
Abeham [199/7][TRADER][RK2][FROZEN]


Offline ZubZero

  • BeBot Rookie
  • *
  • Posts: 10
  • Karma: +0/-0
Re: Banlist Module - Banlist functionality
« Reply #12 on: January 17, 2006, 08: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.

Offline Nogoal

  • BeBot Apprentice
  • ***
  • Posts: 77
  • Karma: +0/-0
Re: Banlist Module - Banlist functionality
« Reply #13 on: January 19, 2006, 06:51:06 pm »
there's 2 function ban list inside the script :P

Offline ZubZero

  • BeBot Rookie
  • *
  • Posts: 10
  • Karma: +0/-0
Re: Banlist Module - Banlist functionality
« Reply #14 on: January 22, 2006, 04:53:47 pm »
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 ^^

 

* Recent Posts
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 ]


Bebot and Rasberry by bitnykk
[November 29, 2023, 11:04:14 pm ]

* Who's Online
  • Dot Guests: 270
  • 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