BeBot - An Anarchy Online and Age Of Conan chat automaton
Archive => Anarchy Online Archive => 0.2.x Custom/Unofficial Modules => Topic started by: craized on December 26, 2005, 06:56:46 am
-
BANLIST MODULE (http://www.craized.net/junk/bebot/highlight.php?Banlist)
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 (http://bebot.link/index.php/topic,222.0.html) 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.
::::: <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.
-
Cron Job command should look like this:
$cron["1min"][] = &$banlist;
Try this for the Commands:<?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.$blob = "::::: <botname>'s banlist :::::\n\n";
vs. $blob = '::::: <botname>\'s banlist :::::'."\n\n\n";
Just easier to read methinks :)
-
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.
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.
-
I think your right. I was coding my sleep again. You could move the space inside the sub-pattern like so:
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.
-
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 ( ?.*)
-
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?
-
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.
-
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. :)
-
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.
-
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;
}
?>
-
<?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
-
Shrug, I'll update it, looks better than mine IMO, ty.
-
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.
-
there's 2 function ban list inside the script :P
-
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 ^^
-
Sorry about this, I'm hitting another AO dry spell, so I'm not working on this stuff anymore. I did however fix this one already and didn't upload it because I'm getting an error I can't figure out. I don't doubt that you guys will finish/fix/find out nothing is wrong with this no problem. I'll have my web version up, but I'm also going to start posting the code in the topic post since this will probably need tweaking.
-
I've updated the code for my banlist, but I still need help. For some reason, it's not storing banned names in the database. Also, I've left out the optional ban time because I can't get the regex right. If you find more bugs, please post them. I've also added a history function for the sake of checking if a user has been banned previously.
Edit: Fixed the database issues. Everything works except the time so far
Edit: Fixed the ban time as well. Everything is ready, although I'm sure there are still bugs and improvements to be made
-
Just an add:
If someone is banned, you can make it so they can't re-join the bot. Inside PrivGroup.php, inside the function tell ():
$result = $this->bot->db->select("SELECT name FROM banlist where name='" . $nameofpersonbanned . "'");
Then after, do a check if (!empty($result)) { send_tell ( "You're banned loser!" ) } else { all the join, invite, stuff }
Hope that helps out someone :)
-
Also, you can use:
if($this -> commands['tell']['banlist'] -> bancheck($who)) {
"You're banned loser."
}
else {
invite stuff
}
I put the function in the module, it will return true if you're banned, or false if you're not banned. When the bot starts, it keeps the entire banlist in a variable, so saves more DB calls.
-
That works too :)
-
This is the first stable release in my opinion. Fixed a lot of stuff, and it actually works now.
Enjoy :D
-
*tagging this for merging into SVN later*
-
Can't test it out myself :p
Using my own modified ban module >_<
-
I tested ur module, and i get some errors.
To [xxx]: !banlist
[xxx]: Usage: !ban <name> [reason] <duration>
To [xxx]: !unban
[xxx]: Usage: !unban <name>
To [xxx]: !ban
[xxx]: Usage: !ban <name> [reason] <duration>
To [xxx]: !banned
[xxx]: Usage: !ban <name> [reason] <duration>
What i mean is.. It doesnt show a banlist when u type !banlist,
Also after i ban someone, it doesnt kick him from chat(dunno if you forgot this or didnt wanted it)
Checked code a bit.. but since im not a coder cant find the problem
also used your updated prvgroup.php (http://bebot.link/index.php/topic,222.0.html)
Anything i did wrong or is it bugged?
-
i have the same prob
ban seem to work but i can get it to list who is banned and just get same replies as you
-
Is there a way to have an unbanned (ban del, or timer expires) member go back to member as opposed to anonymous?