X-Chat: PM Blocker

Platform:  Perl
Published  May 07, 2012
Updated  Mar 02, 2014
Type: /pm <nick> = Adds Nick to PM Block List (Appends) , /removepm = Removes First Nick From PM Block List , /listpm = Lists The PM Listing

You can Change:
> my $block = 0; #Block All, Except User List Defined in pmblock.conf
> my $block = 1; #Block only people listed in pmblock.conf, open to everyone else.

XChat is not supported due to /unignore not working.
Just remove the timer on line 82 if you would like to use internal banning with no flood control. ############ PM Blocker 2.4 - © 2014 - CodeMonkeyRocks ###########################
#!/usr/bin/perl

# Name: pm.pl
# Version: 2.4
# Author: CodeMonkeyRocks
# Date: 2-10-2014

# Description:
# This script takes and reads pmblock.conf and then shoves it into an array.
# Then takes and manipulates the array accordingly and sends it back to pmblock.conf

# Listed Fixes:
# Fixed: Configuration File to Read Linux "/" << In Windows it Understands the change.
# Fixed: Flood Controller
# Fixed: File appends instead of creates new file. (pm <nick)
# Formatting to a Standard Code Practice.

# Notes:
# Putting in my notes that you will need to create the file: "/home/<username>/.xchat2/pmblock.conf" manually.
# Note replace your irc client to .xchat2 or hexchat accordingly.
# > Like: #touch /home/eric/.xchat2/pmblock.conf - Linux
# > Like: #run %appdata%/.xchat2/ and create pmblock.conf - Windows

#XChat is not supported due to /unignore not working.
#Just remove the timer on line 82 if you would like to use internal banning with no flood control.
#
#Line 82: if ($PM_Flood < 4)

use strict; # Use Strict Code
use warnings; # Turn on Warnings
use vars qw(@PM_Block $PM_Flood $strNick); # PM_Block/PM_Flood/$strNick is the Main Array Written/Read from.

my $block = 1; #> 1 = Block only people listed in pmblock.conf :: 0 = Block All, Except User List Defined in pmblock.conf,

##################################################################################

$PM_Flood = 0; # Define a Start Value
my $pm_config = Xchat::get_info('xchatdir') .'/pmblock.conf'; # Filename pmblock.txt

##################################################################################

Xchat::register("PM Blocker", "2.4", "PM Blocking.");
Xchat::print('Type: /pm <nick> = Adds Nick to PM Block List (Appends) , /removepm = Removes First Nick From PM Block List , /listpm = Lists The PM Listing');

##################################################################################

Xchat::hook_print("Connected", \&PMBlock);
sub PMBlock {
open FILE, "<", $pm_config # Open The Configuration File
or die "Could Not Open $pm_config: $!"; # If File Does Not Exist, Stop!
@PM_Block = <FILE>; # Send the File into an Array
close FILE; # Close The Configuration File
}

Xchat::hook_command("pmflooder", \&pmflooder);
sub pmflooder {
Xchat::command("unignore $strNick PRIV"); # Ignore Client for 30 Seconds : Unset
$PM_Flood = 0; # Set Bit Back to Low.
return Xchat::EAT_ALL;
}

Xchat::hook_server( "PRIVMSG", \&PMSG, Xchat::PRI_HIGHEST );
sub PMSG {

my $strme = Xchat::get_info("nick");
if ($_[1][0] !~ m/^:([^!]+)!([^@]+)@(\S+)\sPRIVMSG\s($strme)\s:/) { return Xchat::EAT_NONE; } # Not a PM for me
$strNick = $1; my $strIdent = $2; my $strHost = $3;
my $foundnick = 0;

open FILE, "<", $pm_config # Open The Configuration File
or die "Could Not Open $pm_config: $!"; # If File Does Not Exist, Stop!
@PM_Block = <FILE>; # Send the File into an Array
close FILE; # Close The Configuration File

foreach (@PM_Block) { # Check each item $_ in the block list
chomp(@PM_Block); # Chomp off (New Lines)

if ($strNick eq $_) { # Found the nick in our list
$foundnick = 1;
last;
}
}

if ($block == $foundnick) { # Block the PM if blocking and found.
if ($PM_Flood < 4) {
Xchat::command("notice $strNick Your PM was blocked!");
Xchat::command("ignore $strNick PRIV"); # Ignore Client for 30 Seconds
Xchat::command("timer 30 pmflooder"); # Set A Timer
$PM_Flood ++;
}
return Xchat::EAT_ALL;
} else {
return Xchat::EAT_NONE; # Do Not Block if PM blocking is not found.
}
}

##################################################################################

Xchat::hook_command("pm", \&pm);
sub pm {

my $nick = $_[0][1]; # Get Nick

if ((!(defined($nick))) || ($nick eq "")) { # If User is not Defined: Halt
Xchat::command("echo Use: <pm> <nick>");
return Xchat::EAT_ALL;
}

open FILE, ">>", $pm_config # Open The Configuration File
or die "Could Not Open $pm_config: $!"; # If File Does Not Exist, Stop!
print FILE "$nick\n"; # Append Data with New Line
close FILE; # Close The Configuration File

if ($block) {
Xchat::command("echo $nick will be blocked from future pm's, everyone else can pm.");
} else {
Xchat::command("echo $nick will be allowed though, no one else.");
}

return Xchat::EAT_ALL;
}

##################################################################################

Xchat::hook_command("removepm", \&removepm);
sub removepm {

open FILE, "<", $pm_config # Open The Configuration File
or die "Could Not Open $pm_config: $!"; # If File Does Not Exist, Stop!
@PM_Block = <FILE>; # Read Current Array
close FILE; # Close The Configuration File

if (!(@PM_Block)) { # Halt if file is blank.
Xchat::command("echo Sorry, There are no more people to unblock.");
return Xchat::EAT_ALL;
}

Xchat::command("echo Unblocked: $PM_Block[0]"); # Print: Nick Unblocked!

shift(@PM_Block); # Shift Data

open FILE, ">", $pm_config # Open The Configuration File
or die "Could Not Open $pm_config: $!"; # If File Does Not Exist, Stop!
print FILE @PM_Block; # Export Shifted Data Back in.
close FILE; # Close The Configuration File

return Xchat::EAT_ALL;
}

##################################################################################

Xchat::hook_command("listpm", \&listpm);
sub listpm {

open FILE, "<", $pm_config # Open The Configuration File
or die "Could Not Open $pm_config: $!"; # If File Does Not Exist, Stop!
@PM_Block = <FILE>; # Send the File into an Array
close FILE; # Close The Configuration File

if (!(@PM_Block)) { # Halt if file is blank.
Xchat::command("echo Sorry, this file is blank.");
return Xchat::EAT_ALL;
}

Xchat::command("echo -------- PM Block Listing: -------- "); # Print: Line

my $count = 0; # Counter - For Display

foreach (@PM_Block) { # For Each Nick
Xchat::command("echo [ $count ] - $_"); # Print Counter + Nick
$count ++; # Increment Counter
}

Xchat::command("echo -------- END Block Listing: -------- "); # Print: Line

return Xchat::EAT_ALL;
}

##################################################################################

Comments

Sign in to comment.
codemonkeyrawks   -  Mar 02, 2014
Updated a workaround on xchat users.
Evil_Eric  -  Mar 19, 2014
hey bud yeah you updated the work around for xchat users and i updated to hexchat lmao
Sign in to comment

codemonkeyrawks   -  Feb 08, 2014
Has been majorly updated to work and tested fully. @Evil_Eric let me know how it goes. :)

I will be updating a few other of my scripts that use the config file now that I understand it more.

It also now should create a file if not go create pmblock.conf under your irc install folder.
Evil_Eric  -  Feb 08, 2014
hey bud love the updated script its great glad you got to it and all but im getting an error and i know its a simple fix and ive tried adding the file its asking for but it looks like you have added a \ when it should of been a / or vice versa on line 62 well anyway here is that error i get
"Error in server callback Could Not Open /home/eric/.xchat2\pmblock.conf: No such file or directory at /home/eric/.xchat2/PMblocker.pl line 62."
codemonkeyrawks  -  Feb 08, 2014
@Evil_Eric : Fixed Line 12: Apparently Windows can have it either way but on Linux it has to be the "/" for the file system.

I am also putting in my notes that you will need to create the file: "/home/<username>/.xchat2/pmblock.conf" manually.
Like: #touch /home/eric/.xchat2/pmblock.conf - Linux
Evil_Eric  -  Feb 08, 2014
hey thanks bud will reload it now and give it a go, You ever need a lab rat for testing your scripts let me know.
codemonkeyrawks  -  Feb 08, 2014
Evil_Eric Try it now: Just got done adding comments is all. Also your welcome to join us on irc.geekshed.net @ #script-help for questions. Will be there later tonight.
Evil_Eric  -  Feb 08, 2014
ok yeah it works fin and all thanks for updating it i realy wont know if the spacing problem is fixed until i actually start adding users to it though and im on my way to that network now
Evil_Eric  -  Feb 08, 2014
yep working on my way to the network now
Sign in to comment

FreakServ   -  Sep 02, 2012
@ cmrocks : thanks
 Respond  
codemonkeyrawks   -  Aug 24, 2012
Yes it works with both Linux and Windows:

I use Hex Chat for Windows MiNdFrEaKeR you can download here: http://www.hexchat.org/
For Perl: http://www.activestate.com/activeperl and choose your version of Windows, follow the install.
For TCL: http://www.activestate.com/activetcl
For Python: http://www.activestate.com/activepython

Your only need "ActivePerl" and Hex Chat installed in order for this to work, the regular xchat also works; just make sure you install "ActivePerl".
 Respond  
FreakServ   -  Aug 21, 2012
I didn't worked much with xChat. Can you tell me how to install and run this script on Windows step by step. I get an error of some plugin.
 Respond  
Majki   -  Aug 14, 2012
Dunno, but doesn't work for me. It does not create conf file in .xchat2 directory. :(
 Respond  
codemonkeyrawks   -  Aug 11, 2012
Majki redownload the script with the updates made, I can confirm it works on my Ubuntu box just fine as well.
 Respond  
Majki   -  Aug 08, 2012
Well, it still doesn't work - pmblock.conf is not created in Xchat's profile.I'm not sure, maybe you created this for Windows? On Windows writing on root partition is okay, but not on Linux.

 Respond  
codemonkeyrawks   -  Aug 08, 2012
Majki it has been fixed so it remembers any bans after xchat restart, also shows a pm blocked in the main window.
Evil_Eric  -  Jan 19, 2014
ummmm i have a space issue after i restart in the conf file it is like "me you" after restart its "meyou" can you help me out any please
Sign in to comment

Majki   -  Aug 06, 2012
I updated script, no extra file was created. Could you make info about "your pm was blocked" in the PM one, not in the main chat window? Ppl might miss it. My .xchat2 profile in Ubuntu:

http://pastebin.com/q9uVFNNN
 Respond  
Majki   -  Aug 06, 2012
Fantastic!
 Respond  
codemonkeyrawks   -  Aug 06, 2012
Right Majki that's just a comment in my line, I will fix the comment now, still try creating the file pmblock.conf under the xchat directory where your scripts should be located and try it then. You should see data writing to the pmblock.conf every time you issue a command. I will get to this script soon, just busy atm. >>
 Respond  
Majki   -  Aug 06, 2012
I'm not a coder, but in code you have pmblock.conf and pmblock.txt at the same time.

 Respond  
Majki   -  Aug 06, 2012
No pmblock.conf in my .xchat2 profile :(
 Respond  
codemonkeyrawks   -  Aug 04, 2012
I will take a look at it when I can get a chance Majki .
I have a feeling its not writing the pmblock.conf, verify in your xchat directory that the config file is there and is writing the data. You might have to create the pmblock.conf file and then try it. Let me know how that goes.

Thanks, Arcade.
 Respond  
Majki   -  Aug 04, 2012
I'm a n00b when it comes to programming. So - why this script/plugin forgets my whitelist after Xchat restart?
Arch Linux here, 32bits.
 Respond  
Hawkee   -  May 09, 2012
@SunnyD Me? I'm on quite a few. You can find me in #hawkee on Freenode.
 Respond  
SunnyD   -  May 09, 2012
What server are you on?
 Respond  
Hawkee   -  May 09, 2012
Very good, now I can block spam PMs.
 Respond  
codemonkeyrawks   -  May 09, 2012
Added: Ability for a user to PM and get a notice back saying its not possible to pm and Ability to have total access to what user can/can't pm. Thanks @Hawkee for the suggestion. Its all tested out and works perfectly.
 Respond  
Hawkee   -  May 08, 2012
I installed this and it seems to work fine. I thought it would block all PMs but it seems to only allow for specific people. I have no way to know who's going to spam me so it would be nice to have a block all feature. Then maybe some sort of unlock feature for people who actually know me.
 Respond  
Hawkee   -  May 08, 2012
I agree a notice back would be nice. Most of the PMs I get are spam, but there might be a rare case where it's an actual message.
 Respond  
SunnyD   -  May 07, 2012
If it strictly blocks pm's I don't see a need to notify them that they're being ignored. On the other hand, if it's one of those snippets that halts a pm until the user has consented to it then yes you'd need to notify them.
 Respond  
codemonkeyrawks   -  May 07, 2012
One thing I noticed I may add later is a notice back to the original user that tried to pm or is the one being ignored.
 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.