#!perl # If on Unix-based OS, specify full path to perl - ex: #!/usr/bin/perl # Use warnings and be strict! use warnings; use strict; ########################################################## # Query Killer script by adron # # Version: 1.5 # # Tested successfully on: XChat 2.0.x/2.6.x Windows # # Didn't work on: XChat 1.8.11 FreeBSD (obviously) # # Requires XChat 2.x+, should work on *ix versions # ########################################################## ######################################################################### # This script is probably released under the GPL, or something similar. # # Change it all you want, and if you think you've improved it, let me # # know! (tgordon1@gmail.com) Maybe leave me just a little credit? # ######################################################################### my $scriptname = "Query Killer"; my $version = "1.5"; my $description = "Author: adron. Catches PRIVMSG/NOTICE/INVITE, ignores, and sends auto-response to those that are not in your whitelist."; Xchat::register($scriptname, $version, $description, \&qk_unload_notice); my $home = Xchat::get_info("xchatdir"); my $whitelistpath = "$home/qkcfg/whitelist.txt"; my $confpath = "$home/qkcfg/qk.cfg"; require "$confpath"; Xchat::print("\00315Query Killer v1.5 loaded!\n"); my $tmpnick = Xchat::get_info("nick"); my $mynick = lc($tmpnick); # Check to see if whitelist.txt exists, if not create it unless (-e $whitelistpath) { open(CONF, ">>$whitelistpath") || warn "Cannot open $whitelistpath\n"; print CONF "$mynick\n"; print CONF "global\n"; print CONF "nickserv\n"; print CONF "chanserv\n"; print CONF "memoserv\n"; print CONF "botserv\n"; print CONF "secureserv\n"; print CONF "hostserv\n"; print CONF "loveserv\n"; print CONF "stupidserv\n"; close(CONF); Xchat::print("\00315Whitelist file not found! Default one created :)\n"); } Xchat::print("\00315/qkhelp for command list.\n"); Xchat::hook_server("INVITE", \&qk_filter_messages); Xchat::hook_server("NOTICE", \&qk_filter_messages); Xchat::hook_server("PRIVMSG", \&qk_filter_messages); Xchat::hook_command("QK", \&qk_toggle); Xchat::hook_command("QKT", \&qk_toggle_types); Xchat::hook_command("QKN", \&qk_toggle_notify); Xchat::hook_command("QKADD", \&qk_add_friend); Xchat::hook_command("QKDEL", \&qk_del_friend); Xchat::hook_command("QKLIST", \&qk_list_friends); Xchat::hook_command("QKSTAT", \&qk_print_stat); Xchat::hook_command("QKHELP", \&qk_print_help); sub qk_compare { my $nick = $_[0]; open(CONF, "<$whitelistpath") || warn "Cannot open $whitelistpath\n"; my @nigs = ; chomp(@nigs); my $nig; foreach $nig (@nigs) { if (lc($nig) eq lc($nick)) { return 0; } } close(CONF); return 1; } sub qk_toggle { if ($main::qk == 1) { Xchat::print("\00315Query Killer disabled!\n"); $main::qk = 0; } elsif ($main::qk == 0) { Xchat::print("\00315Query Killer enabled!\n"); $main::qk = 1; } return 1; } sub qk_toggle_types { my $totoggle = lc($_[0][1]); if ($totoggle eq "privmsg") { if ($main::qkprivmsg == 1) { Xchat::print("\00315Blocks for $totoggle disabled!\n"); $main::qkprivmsg = 0; } elsif ($main::qkprivmsg == 0) { Xchat::print("\00315Blocks for $totoggle enabled!\n"); $main::qkprivmsg = 1; } } if ($totoggle eq "notice") { if ($main::qknotice == 1) { Xchat::print("\00315Blocks for $totoggle disabled!\n"); $main::qknotice = 0; } elsif ($main::qknotice == 0) { Xchat::print("\00315Blocks for $totoggle enabled!\n"); $main::qknotice = 1; } } if ($totoggle eq "invite") { if ($main::qkinvite == 1) { Xchat::print("\00315Blocks for $totoggle disabled!\n"); $main::qkinvite = 0; } elsif ($main::qkinvite == 0) { Xchat::print("\00315Blocks for $totoggle enabled!\n"); $main::qkinvite = 1; } } return 1; } sub qk_toggle_notify { if ($main::notify == 1) { Xchat::print("\00315Notify and WHOIS disabled!\n"); $main::notify = 0; } elsif ($main::notify == 0) { Xchat::print("\00315Notify and WHOIS enabled!\n"); $main::notify = 1; } return 1; } sub qk_filter_messages { # Unless Query Killer was disabled and $main::qk is 0 unless ($main::qk == 0) { my $nicktmp1 = lc($_[0][0]); my $to = lc($_[0][2]); my $type = $_[0][1]; my $fourtharg = $_[0][3]; my $delim = "\001"; return Xchat::EAT_NONE if ($to =~ /#/); my ($nickpart, $hostpart) = split(/!/, $nicktmp1, 2); my $nick = substr($nickpart, 1); if (qk_compare($nick) == 1) { if ($type eq "PRIVMSG" && $main::qkprivmsg == 1 && $fourtharg !~ /$delim/) { Xchat::command("QUOTE PRIVMSG $nick :$main::deny_response"); unless ($main::notify == 0) { Xchat::command("WHOIS $nick $nick"); Xchat::print("\0034$nick has tried to PM you, Zahid.\n"); Xchat::print("\0034$nick has been WHOIS'd, check server window.\n"); } return Xchat::EAT_ALL; } if ($type eq "NOTICE" && $main::qknotice == 1) { Xchat::command("QUOTE PRIVMSG $nick :$main::deny_response"); unless ($main::notify == 0) { Xchat::command("WHOIS $nick $nick"); Xchat::print("\0034$nick has tried to NOTICE you, Zahid.\n"); Xchat::print("\0034$nick has been WHOIS'd, check server window.\n"); } return Xchat::EAT_ALL; } if ($type eq "INVITE" && $main::qkinvite == 1) { Xchat::command("QUOTE PRIVMSG $nick :$main::deny_response"); unless ($main::notify == 0) { Xchat::command("WHOIS $nick $nick"); Xchat::print("\0034$nick has tried to INVITE you, Zahid.\n"); Xchat::print("\0034$nick has been WHOIS'd, check server window.\n"); } return Xchat::EAT_ALL; } } return Xchat::EAT_NONE; } return Xchat::EAT_NONE; } sub qk_add_friend { my $nick = lc($_[0][1]); if ($nick ne "") { if (qk_compare($nick) == 1) { open(CONF, ">>$whitelistpath") || warn "Cannot open $whitelistpath\n"; print CONF $nick,"\n"; close(CONF); Xchat::print("\00315$nick added to list.\n"); } elsif (qk_compare($nick) == 0) { Xchat::print("\00315$nick is already in the list.\n"); } } elsif ($nick eq "") { Xchat::print("\00315No nick specified.\n"); } return 1; } sub qk_del_friend { my $nick = lc($_[0][1]); if ($nick ne "") { if (qk_compare($nick) == 0) { open(CONF, "<$whitelistpath") || warn "Cannot open $whitelistpath\n"; my @nigs = ; chomp(@nigs); close(CONF); open(CONF, ">$whitelistpath") || warn "Cannot open $whitelistpath\n"; my $nig; foreach $nig (@nigs) { if ($nig ne $nick) { print CONF $nig,"\n"; } } close(CONF); Xchat::print("\00315$nick removed from the list.\n"); } elsif (qk_compare($nick) == 1) { Xchat::print("\00315$nick is not in the list.\n"); } } elsif ($nick eq "") { Xchat::print("\00315No nick specified.\n"); } return 1; } sub qk_list_friends { Xchat::print("---------------------------------\n"); Xchat::print("Whitelist:\n"); Xchat::print("\n"); open(CONF, "<$whitelistpath") || warn "Cannot open $whitelistpath\n"; my @nigs = ; chomp(@nigs); my $nig; foreach $nig (@nigs) { Xchat::print("$nig\n"); } close(CONF); Xchat::print("\n"); Xchat::print("These users can currently PM/Message you.\n"); Xchat::print("---------------------------------\n"); return 1; } sub qk_print_stat { if ($main::qk == 1) { Xchat::print("\00315The Query Killer is on.\n"); } elsif ($main::qk == 0) { Xchat::print("\00315The Query Killer is off.\n"); } if ($main::qkprivmsg == 1) { Xchat::print("\00315Blocks for private messages are on.\n"); } elsif ($main::qkprivmsg == 0) { Xchat::print("\00315Blocks for private messages are off.\n"); } if ($main::qknotice == 1) { Xchat::print("\00315Blocks for notices are on.\n"); } elsif ($main::qknotice == 0) { Xchat::print("\00315Blocks for notices are off.\n"); } if ($main::qkinvite == 1) { Xchat::print("\00315Blocks for invites are on.\n"); } elsif ($main::qkinvite == 0) { Xchat::print("\00315Blocks for invites are off.\n"); } if ($main::notify == 1) { Xchat::print("\00315Notification/WHOIS is on.\n"); } elsif ($main::notify == 0) { Xchat::print("\00315Notification/WHOIS is off.\n"); } return 1; } sub qk_print_help { Xchat::print("------------------------------------------------------\n"); Xchat::print("Query Killer v1.5 Help\n"); Xchat::print("\n"); Xchat::print("Commands:\n"); Xchat::print("/qk\t->Enables/disables the Query Killer.\n"); Xchat::print("/qkt type\t->Enables/disables blockage for a specific type of message (type = privmsg, notice, invite).\n"); Xchat::print("/qkn\t->Enables/disables notification of message and WHOIS.\n"); Xchat::print("/qkadd nick\t->Adds nick to your whitelist.\n"); Xchat::print("/qkdel nick\t->Deletes nick from your whitelist.\n"); Xchat::print("/qklist\t->Lists all nicks in your whitelist.\n"); Xchat::print("/qkstat\t->Displays current status of the script settings.\n"); Xchat::print("/qkhelp\t->Displays this help menu.\n"); Xchat::print("\n"); Xchat::print("Notes:\n"); Xchat::print("Whitelist comparison is not case-sensitive,\n"); Xchat::print("so it matters not how you add/remove a nickname to/from it.\n"); Xchat::print("------------------------------------------------------\n"); return 1; } sub qk_unload_notice { Xchat::print("\00315Query Killer v1.5 unloaded!\n"); return 1; }