X-Chat: PM Blocker

Platform:  Perl
Published  May 07, 2012
Updated  Aug 08, 2012
Type: /pm <hostname or mask> = Adds Nick to PM Block List. , /removepm = Removes Last Nick From PM Block List. You will need to edit >>

my $block = 0; #Block All, Except User List Defined in pmblock.conf
OR
my $block = 1; #Block only people listed in pmblock.conf, open to everyone else. ############ PM Blocker 2.3 - © 2011, Arcademan. ############################
#!/usr/bin/perl

use strict;
use warnings;
use vars qw(@PM_Block);

########## Configuration ##################################################

my $conf_file_2 = Xchat::get_info('xchatdir') .'\pmblock.conf'; # Filename pmblock.conf
my $block = 1; # 0 = Block All, Except User List Defined in pmblock.conf, 1 = Block only people listed in pmblock.conf

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

Xchat::register("PM Blocker", "2.3", "PM Blocking.");
Xchat::print('Type: /pm <nick> = Adds Nick to PM Block List. , /removepm = Removes Last Nick From PM Block List. ');

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

Xchat::hook_print("Connected", \&PMBlock);
sub PMBlock {
if (-e $conf_file_2) {
open FILE, "<$conf_file_2"; # Reads pmblock.conf
@PM_Block = <FILE>; # Bring pmblock.conf in.
close FILE; # Close File
} else {
open FILE, ">$conf_file_2"; # Write the File if Non-Existant
close FILE; # Close File
}
}

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

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
my $strNick = $1; my $strIdent = $2; my $strHost = $3;
my $foundnick = 0;
foreach (@PM_Block) { # Check each item $_ in the block list
if ($strNick eq $_) { # Found the nick in our list
$foundnick = 1;
last;
}
}
if ($block == $foundnick) { # Block the PM if blocking and found, or not blocking and not found
Xchat::command("msg $strNick Your PM was blocked!");
return Xchat::EAT_ALL;
} else {
return Xchat::EAT_NONE;
}
}

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

Xchat::hook_command("pm", "pm");
sub pm {
my $nick = $_[0][1]; # Get Nick

if ((!(defined($nick))) || ($nick eq "")) {
Xchat::command("echo Use: <pm> <nick>");
return Xchat::EAT_ALL;
}

push(@PM_Block,"$nick"); # Push Data: PM-List
open FILE, ">$conf_file_2"; # Writes pmblock.conf
print FILE @PM_Block; # Print Content to pmblock.txt
close FILE; # Close File

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

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

Xchat::hook_command("removepm", "removepm");
sub removepm {
shift(@PM_Block); # Shift Data: PM List
open FILE, ">$conf_file_2"; # Writes pmblock.conf
print FILE @PM_Block; # Print Content to pmblock.txt
close FILE; # Close File

Xchat::command("echo @PM_Block will be blocked from future pm's.");

return Xchat::EAT_ALL;
}

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

Comments

Sign in to comment.
FreakServ   -  Sep 02, 2012
@ cmrocks : thanks
 Respond  
cmrocks   -  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  
cmrocks   -  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  
cmrocks   -  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.
 Respond  
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  
cmrocks   -  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  
cmrocks   -  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  
cmrocks   -  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  
cmrocks   -  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.