Archive > 0.2.x Custom/Unofficial Modules

Banlist Module - Banlist functionality

(1/6) > >>

craized:
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.
--- End code ---


Edit: Please use link for file access.

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

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;
}
?>
--- End code ---
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";
--- End code ---
vs.
--- Code: ---$blob = '::::: <botname>\'s banlist :::::'."\n\n\n";
--- End code ---
Just easier to read methinks :)

craized:
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))
--- End code ---
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.

Xenixa:
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))
--- End code ---
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.

craized:
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 ( ?.*)

Navigation

[0] Message Index

[#] Next page

Go to full version