1 # ho_easykline.pl
  2 #
  3 # $Id: ho_easykline.pl,v 1.4 2004/09/14 16:49:02 jvunder REL_0_3 $
  4 #
  5 # Part of the Hybrid Oper Script Collection
  6 #
  7 # Easy K-lines.
  8 #
  9 
 10 use strict;
 11 use vars qw($VERSION %IRSSI $SCRIPT_NAME);
 12 
 13 use Irssi;
 14 use Irssi::Irc;           # necessary for redirect_register()
 15 use HOSC::again;
 16 use HOSC::again 'HOSC::Base';
 17 use HOSC::again 'HOSC::Tools';
 18 
 19 $SCRIPT_NAME = 'easykline';
 20 ($VERSION) = '$Revision: 1.4 $' =~ / (\d+\.\d+) /;
 21 %IRSSI = (
 22     authors     => 'Garion',
 23     contact     => 'garion@efnet.nl', 
 24     name        => 'ho_easykline',
 25     description => 'Makes K-lining drones as easy as cake.',
 26     license     => 'Public Domain',
 27     url         => 'http://www.garion.org/irssi/hosc.php',
 28     changed     => '25/02/2003 19:29',
 29 );
 30 
 31 # Master switch to prevent accidents.
 32 my $enabled = 0;
 33 
 34 my $klineuseronly = 1;
 35 
 36 # ---------------------------------------------------------------------
 37 
 38 # catch a line typed in the easykline window, and process it.
 39 sub event_send_text {
 40     my ($data, $server, $witem) = @_;
 41     my $active_window = Irssi::active_win();
 42     
 43     return unless $active_window->{name} eq "easykline";
 44   
 45     if ($data =~ /^on$/i || $data =~ /^enable$/i) {
 46         ho_print_active("Enabling easy K-lines.");
 47         $enabled = 1;
 48         Irssi::signal_stop();
 49         return;
 50     }
 51 
 52     if ($data =~ /^off$/i || $data =~ /^disable$/i) {
 53         ho_print_active("Disabling easy K-lines.");
 54         $enabled = 0;
 55         Irssi::signal_stop();
 56         return;
 57     }
 58 
 59     if ($data =~ /^help$/i) {
 60         print_help();
 61         Irssi::signal_stop();
 62         return;
 63     }
 64 
 65     if ($data =~ /^time ([0-9]+)$/i) {
 66         set_kline_time($1);
 67         ho_print_active("Setting K-line time to $1.");
 68         Irssi::signal_stop();
 69         return;
 70     }
 71 
 72     if ($data =~ /^reason (.+)$/i) {
 73         ho_print_active("Setting K-line reason to $1.");
 74         set_kline_reason($1);
 75         Irssi::signal_stop();
 76         return;
 77     }
 78 
 79     if ($data =~ /^klineuser ?(.*)$/i) {
 80         if ($1 =~ /on/i || $1 == 1) {
 81             Irssi::settings_set_bool('ho_easykline_useronly', 1);
 82             ho_print_active('K-lining *user@host.');
 83         } else {
 84             Irssi::settings_set_bool('ho_easykline_useronly', 0);
 85             ho_print_active('K-lining *@host.');
 86         }
 87     
 88         Irssi::signal_stop();
 89         return;
 90     }
 91 
 92     if ($data =~ /^status$/i) {
 93         show_status();
 94         Irssi::signal_stop();
 95         return;
 96     }
 97 
 98     if ($enabled == 0) {
 99         ho_print_active("Easy K-lines disabled. Type 'help' for help and 'on' to enable.");
100         Irssi::signal_stop();
101         return;
102     }
103 
104   kline_from_line($server, $data);
105 }
106 
107 
108 sub am_i_opered {
109     return 0 unless Irssi::active_server();
110     return 1 if Irssi::active_server()->{server_operator}
111              or Irssi::active_server()->{'usermode'} =~ /o/i;
112 
113     return 0;
114 }
115 
116 
117 sub set_kline_time {
118     my ($time) = @_;
119     Irssi::settings_set_int('ho_easykline_time', $time);
120 }
121 
122 sub set_kline_reason {
123     my ($reason) = @_;
124     Irssi::settings_set_str('ho_easykline_reason', $reason);
125 }
126 
127 
128 sub show_status {
129     my $klineuseronly = Irssi::settings_get_bool('ho_easykline_useronly');
130     my $klinetime     = Irssi::settings_get_int('ho_easykline_time');
131     my $klinereason   = Irssi::settings_get_str('ho_easykline_reason');
132     ho_print_active("Enabled is $enabled. Time is $klinetime.");
133     if ($klineuseronly) {
134         ho_print_active('K-lining *user@host.');
135     } else {
136         ho_print_active('K-lining *@host.');
137     }
138   
139     ho_print_active("Reason is $klinereason.");
140 }
141 
142 sub print_help {
143     ho_print_active("Short help for now.");
144     ho_print_active('Anything you paste in this window gets searched for '.
145         'user@host and those hostnames get K-lined.');
146     ho_print_active("Available settings: enable/disable, time, reason, ".
147              "klineuseronly.");
148     ho_print_active("Typing the following into this window will change settings:");
149     ho_print_active("on|off: turns the script on or off.");
150     ho_print_active("time <time>: sets the k-line time. 0 for perm kline.");
151     ho_print_active("reason <reason>: sets the k-line reason.");
152     ho_print_active('klineuser <on|off>: toggles the k-lining of '.
153         '*user@host and *@host.');
154     ho_print_active("Type 'status' to get the current status of easykline.");
155 }
156 
157 sub kline_from_line {
158     my ($server, $line) = @_;
159 
160     if (!am_i_opered()) {
161         ho_print_active("Please oper up before using this script.");
162         return;
163     }
164 
165     if ($line =~ /\b~?([a-zA-Z0-9._-]{1,10})@([a-zA-Z0-9_.-]+)\b/) {
166         my ($user, $host) = ($1, $2);
167         my $klineuseronly = Irssi::settings_get_bool('ho_easykline_useronly');
168         my $klinetime     = Irssi::settings_get_int('ho_easykline_time');
169         my $klinereason   = Irssi::settings_get_str('ho_easykline_reason');
170         if ($klineuseronly == 1) {
171             $user = "*" . $1;
172         } else {
173             $user = "*";
174         }
175         if ($klinetime == 0) {
176             ho_print_active("K-lined $user\@$host :$klinereason");
177             $server->command("quote kline $user\@$host :$klinereason");
178         } else {
179             ho_print_active("K-lined $klinetime $user\@$host :$klinereason");
180             $server->command("quote kline $klinetime $user\@$host :$klinereason");
181         }
182     }
183 }
184 
185 # ---------------------------------------------------------------------
186 
187 ho_print_init_begin();
188 
189 Irssi::signal_add('send text', 'event_send_text');
190 
191 Irssi::settings_add_int('ho', 'ho_easykline_time', 1440);
192 Irssi::settings_add_str('ho', 'ho_easykline_reason', 'drones/flooding');
193 Irssi::settings_add_bool('ho', 'ho_easykline_useronly', 1);
194 
195 my $win = Irssi::window_find_name('easykline');
196 if (!defined($win)) {
197     ho_print_warning("You are missing the easykline window. Use /WINDOW ".
198         "NEW HIDDEN and /WINDOW NAME easykline to create it.\n".
199         "Easy K-lines are only available when typing in that window.");
200 }
201 
202 ho_print("For help, switch to the window named easykline and type 'help' there.");
203 
204 if (!am_i_opered()) {
205     ho_print("You'll need to oper up to use this script.");
206 }
207 
208 ho_print_init_end();
209 
210 # ---------------------------------------------------------------------


syntax highlighted by Code2HTML, v. 0.9.1