html/findbot.pl


   1 ###############################################################################
   2 # Find script that searches your local files and sends them to users
   3 # Copyright (C) 2003  Thomas Karlsson
   4 #
   5 # Findbot script, which responds to @find commands in irc channels
   6 #
   7 # This program is free software; you can redistribute it and/or modify
   8 # it under the terms of the GNU General Public License as published by
   9 # the Free Software Foundation; either version 2 of the License, or
  10 # (at your option) any later version.
  11 #
  12 # This program is distributed in the hope that it will be useful,
  13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15 # GNU General Public License for more details.
  16 #
  17 # You should have received a copy of the GNU General Public License
  18 # along with this program; if not, write to the Free Software
  19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  20 #
  21 # Thomas Karlsson (findbot@planet.eu.org)
  22 ###############################################################################
  23 # The file collection at the end of this file is made by Henrik Andreasson
  24 # findbot@han.pp.se
  25 # 
  26 ###############################################################################
  27 # Description:
  28 #
  29 # This script loads into an Irssi client and then monitors selected channels
  30 # and replies to public channel commands.
  31 # The commands are:
  32 # @find :	searches the summaryfile after file "@find birthday" looks for
  33 #		a file containing birthday.
  34 # @<botnick>-stats : Replies with the users queue.
  35 # @<botnick>-remove : Will remove the users whole queue
  36 # @<botnick>-remove 2 : Will remove queue position 2 from the queue
  37 # @<botnick>-help : Will message the help to the user.
  38 # !<botnick> <filename> :Will queue the file. For eg."!santa_claus jingle.bells.mp3"
  39 #
  40 ###############################################################################
  41 # Installation:
  42 #
  43 # AT THE END OF THIS FILE IS ALL INSTALLATION INSTRUCTIONS!!
  44 # 
  45 # Variables:
  46 # findbot_channels - Space separated channels (#mp3 #othermp3)
  47 # findbot_summaryfile - Full path to the "mymp3s.txt" file (/misc/mp3/mymp3s.txt)
  48 # findbot_sendlist - Full path and filename to the list that is sent to clients
  49 # findbot_maxresults - Max findresults returned to the requesting client
  50 # findbot_maxqueue - Max files allowed in the queue
  51 # findbot_maxsends - Max simultanous sends allowed
  52 # findbot_maxuserqueue - Max queued files per Nick
  53 # findbot_maxusersends - Max simultanous sends per Nick
  54 # findbot_showbanner - Present a banner in every "findbot_channels" channel
  55 # findbot_bannertime - How many seconds between each banner
  56 # findbot_minspeed - Minimum CPS for a send, 10000 means 10kb/s, 0 means disabled
  57 # findbot_mustbeinchannel - If ON, the user is required to be in the channel during download
  58 # findbot_debuglevel - Debuglevel, Higher value equals more debugoutput
  59 # findbot_enabled - Set ON or OFF
  60 # findbot_timeslots - When the server should be enabled (sat=10:00-18:00sun=00:00-23:59)
  61 #		      If a day can't be found the bot will be ON by default
  62 # findbot_voicegetpriority - If ON then voiceuserusers and ops will get priority in the queue.
  63 #			Ops get 20 in priority and voice gets 10. I.e ops are more prioritized than voice
  64 #
  65 # Admincommands:
  66 # /findbotqueue  - Shows you the whole queue in the findbot window
  67 # /findbotremove - Admin removes queueitems
  68 # /findbotreset  - If you like you can specify how many sends the script thinks it have. This was just added
  69 #                  if you wanted to send somefiles your self without the script sending files.
  70 # /findbotreload - Reloads the summaryfile if you have added files
  71 # /findbotactivesends - Show which users are currently having a download
  72 #
  73 ###############################################################################
  74 # TODO or maybe features
  75 #
  76 # * When requesting it SHOULD be case sensitive
  77 # * Support CTCP SLOTS and CTCP MP3, seems unnecessary to help windows-mirc users :)
  78 #   Slots Free Next Queues Max Sendspeed Files
  79 #   4     4    NOW  0      999 0         120575 36856591362 0 1073595728 1
  80 # * Make an ignore and ban function
  81 # * Should the users see the whole que or just their own files?
  82 # * If there is a netsplit all downloads will be cancelled if an active user disappered
  83 # * If one send is below like 4kb/s then change findbot_maxsends to one more, so we use the bandwidth
  84 # * DONE Servers (i.e +v) should get priority, but how? First in queue?
  85 # * DONE Fix admin_showqueue to really show VIP instead of 1
  86 ###############################################################################
  87 # CHANGES
  88 #
  89 # 1.57	* Added a VIP function which allows +v users to be first in line to get a file
  90 # 	* Remove a users queue if they get kicked (only if findbot_mustbeinchannel is ON)
  91 #	* Fixed a bug when a user with a download changed nick.
  92 # 1.56  * The findbot_maxqueue now works
  93 #	* Sending files with spaces in them, now works
  94 # 1.55	* Minor changes
  95 # 1.54	* Added support to update the mp3list without restarting the bot (/findbotreload)
  96 # 1.53	* Fixed some debug output
  97 # 1.52	* Fixed some typos
  98 #	* Now people can't look for * . etc. Now a searchpattern MUST contain atleast 1 normal character
  99 #	* Fixed so you can change banner time without restarting the bot
 100 # 1.50	* Added a timeslot function
 101 #	* Added logging support. Now logging to file. Must specify filename and path INSIDE this script
 102 # 1.06	* "Optimized" search. Instead of opening and read the whole summaryfile everytime
 103 #	  someone searched the script reads the file once at startup.
 104 #	* Fixed more regular expressions
 105 #	* Added multiserver support, i.e you can have the bot on two nets and two different channels
 106 # 1.05	* Added a new perlscript at the end of this file.
 107 #	  It searches your mp3s and makes the 2 necessary files.
 108 #	  The script is made by Henrik Andreasson (findbot@han.pp.se)
 109 # 1.04	* Changed so the files contains full path to mp3s
 110 #	* findbot_maxsends was ignored under some circumstanses
 111 #	* Added so debugoutput shows which file are sent
 112 #	* Sending to client "Now sending you file...." only if they accually are in the channel
 113 # 1.03	* Changed a "for-loop" one bit
 114 #	* If findbot_minimumspeed was disabled, then the user could leave channel
 115 #	  and still get files even if findbot_mustbeinchannel was enabled
 116 #	* Forgot to write to debugwindow if someone downloaded the whole list
 117 #	* Corrected some bad english :)
 118 #	* Fixed more regular expressions
 119 #	* The user will be told the queueposition when requesting a file
 120 #	* Fixed some queueproblems
 121 #	* Added some errormessages if someone types !nickname in a private message
 122 # 1.01	* Do not reply with "no match" if no match was found to avoid unnecessary spam
 123 #	* Removed alot of commented code
 124 #	* Changed the description of the script
 125 #	* Changed the "results found" string a bit.
 126 #	* Added a new value findbot_sendlist and separated the filelist and the one which accually is sent to the users
 127 #	* Fixed some regular expressions to fit the new searchfiles
 128 #	* Bug fix. If someone resumed a file, they always will be under findbot_minspeed in the start
 129 #	* Didn't search if someone typed @FIND (in uppercase)
 130 #	* Ops the url wasn't right. There is no ~ in the address :)
 131 # 1.0	Release
 132 ###############################################################################
 133 use Irssi;
 134 use Irssi::Irc;
 135 use strict;
 136 use vars qw($VERSION %IRSSI);
 137 
 138 $VERSION = "1.57";
 139 
 140 %IRSSI = (
 141     authors     =>  "Thomas Karlsson",
 142     contact     =>  "findbot\@planet.eu.org",
 143     name        =>  "Findbot",
 144     description =>  "Public command \@find script",
 145     license     =>  "GPL",
 146     url         =>  "http://hem.passagen.se/thka2315/",
 147 );
 148 
 149 my %nickqueue = ();	# Queuenumber + nickname
 150 my %filequeue = ();	# Queuenumber + filename
 151 my %servertagqueue = (); # Queuenumber + array with servertag,voiceprio,extrafield
 152 my %activesends = ();	# nickname + 1 The user is here if he has an active send
 153 my $lastqueuenumber = 0;	# Holds the last queueitem
 154 my %scriptdetect = ();
 155 my $timeout_tag;
 156 my $banner_timeout;
 157 my $currentsends = 0;
 158 my $servertag;
 159 my $globalstart = 0;
 160 my $globalvippos = 0;
 161 my $debuglevel;
 162 my %bannedpeople = ();	# This will contain banned people and time of ban
 163 my @bigarray;		# In here the whole filelist will reside
 164 my @daynames = qw(Sun Mon Tue Wed Thu Fri Sat);
 165 my $logfile = "findbot.log";
 166 my $scriptdetecttime = "3"; # Three seconds must pass before a new filerequest is issued, after a DCC CLOSE
 167 my $showscriptdetect = 1;
 168 my $lastbannerprint = time();	# The last time the banner was printed into monitored channels
 169 
 170 sub timeslotenabled {
 171 	my $weekday = shift;		# Save weekday
 172 	my $slothour = shift;		# Save hours
 173 	my $slotminute = shift;		# Save minutes
 174 
 175 	$weekday = $daynames[$weekday];
 176 	my $timeslotstring = Irssi::settings_get_str('findbot_timeslots');
 177 	if ( $timeslotstring =~ /$weekday/i ) {
 178 		if ( $timeslotstring =~ m/.*$weekday=(.?.):(.?.)(a\.?m\.?|p\.?m\.?)?-(.?.):(.?.)(a\.?m\.?|p\.?m\.?)?.*/i ) {
 179 			my $fromhour = $1;
 180 			my $frommin = $2;
 181 			my $fromampm = $3;
 182 			my $tohour = $4;
 183 			my $tomin = $5;
 184 			my $toampm = $6;
 185 			if ( $fromampm =~ /p/i ) { $fromhour += 12; }		# If it is a pm time add 12 to get 24h format
 186 			if ( $toampm =~ /p/i ) { $tohour += 12; }		# If it is a pm time add 12 to get 24h format
 187 			my $midnightfrom = ( $fromhour * 60 ) + $frommin;		# Get minutes from midnight
 188 			my $midnightto = ( $tohour * 60 ) + $tomin;		# Get minutes from midnight
 189 			my $inputtime = ( $slothour * 60 ) + $slotminute;		# Get minutes from midnight
 190 			debugprint(20,"inputtime:$inputtime midfrom:$midnightfrom midto:$midnightto");
 191 			if ( $inputtime <= $midnightto && $inputtime >= $midnightfrom ) {
 192 				return 1;					# The time is between the timeenabled slot
 193 			} else {
 194 				return 0;					# Time was outside. Bot should be off.
 195 			}
 196 		} else {
 197 			return 0;	# Hmm didnt get the times in that day, maybe wrong input from user
 198 		}	
 199 	} else {
 200 		return 1;	# If the current day wasn't found in findbot_timeslots then return true, i.e bot is default ON.
 201 	}
 202 	return 0;		# Return false i.e 
 203 }
 204 
 205 sub private_get {
 206 	(my $server, my $message, my $nick, my $address) = @_;
 207 	if ( $message =~ /^!$server->{nick}\ .*/i ) {
 208 		$server->command("/MSG " . $nick . " Please request files in the channel, not personally to me. Type \@$server->{nick}-help in channel for help");
 209 	} elsif ( $message =~ /^\@$server->{nick}.*/i ) {
 210 		$server->command("/MSG " . $nick . " Please request my filelist in the channel, not personally to me. Type \@$server->{nick}-help in channel for help");
 211 	} elsif ( $message =~ /^\@find.*/i ) {
 212 		$server->command("/MSG " . $nick . " Please search files in the channel, not personally to me. Type \@$server->{nick}-help in channel for help");
 213 	}
 214 }
 215 
 216 sub check_user_queued_items {
 217 	my $user = shift;					# Get the nickname to check
 218 	my $localsrvtag = shift;
 219 	my $counter = 0;					# Reset the counter
 220 	for ( my $i=1; $i <= $lastqueuenumber; $i++ ) { # Loop through entire queue
 221 		if ( $nickqueue{$i} eq $user && $localsrvtag eq $servertagqueue{$i}[0] ) {
 222 			$counter++;
 223 		}
 224 	}
 225 	return $counter;
 226 }
 227 
 228 sub already_queued_file {
 229 	my $checknick = shift;
 230 	my $checkfile = shift;
 231 	my $srvtag = shift;
 232 	my $alreadyqueued = 0;
 233 	for ( my $i=1; $i <= $lastqueuenumber; $i++ ) {	# Loop through entire queue
 234 		if ( $nickqueue{$i} eq $checknick && $filequeue{$i} eq $checkfile && $servertagqueue{$i}[0] eq $srvtag) { # Check if its queued
 235 			$alreadyqueued = 1;		# Yep it was
 236 		}
 237 	}
 238 	if ( $alreadyqueued ) { return 1; } else { return 0; } # Return true if queued else false
 239 }
 240 
 241 sub add_file_to_queue {
 242 	(my $addnick, my $addfile, my $srvtag, my $priority) = @_;			# Split nickname and filename into two variables
 243 	$lastqueuenumber++;
 244 	$nickqueue{$lastqueuenumber} = $addnick;	# for eg. $nickqueue{1} = 'El_Tomten'
 245 	$filequeue{$lastqueuenumber} = $addfile;	# for eg. $filequeue{1} = '/misc/legal-mp3s/happy.birthday.mp3'
 246 	if ( ! Irssi::settings_get_bool('findbot_voicegetpriority') ) { $priority = 0; }
 247 	my @field = ($srvtag,$priority,"To be used later, maybe");
 248 	$servertagqueue{$lastqueuenumber} = \@field;	# for eg. $servertagqueue{1} = 'stockholm'
 249 	if ( $priority > 1 ) {		# Did a priority user queued the file
 250 		fix_vip_position($priority);	# Move vip position up to number one, or just after the last already existing vip position
 251 	}
 252 }
 253 
 254 sub fix_vip_position {
 255 	my $priority = shift;		# Get priority from input
 256 	my ($tnickqueue,$tfilequeue,$tservertagqueue);
 257 	if ( $lastqueuenumber eq 1 ) { return; }	# If the queue only have one entry, why try to make it a priority?
 258 	for ( my $i = $lastqueuenumber; $i > 1; $i--) {
 259 		if ( $servertagqueue{$i-1}[1] >= $priority ) { $globalvippos = $i; last; } # Is the queue entry before a vip entry? Lets quit the prioritymove
 260 		$tnickqueue = $nickqueue{$i-1};			# Backup entry
 261 		$tfilequeue = $filequeue{$i-1};
 262 		$tservertagqueue = $servertagqueue{$i-1};
 263 
 264 		$nickqueue{$i-1} = $nickqueue{$i};		# Move entry up
 265 		$filequeue{$i-1} = $filequeue{$i};
 266 		$servertagqueue{$i-1} = $servertagqueue{$i};
 267 		
 268 		$nickqueue{$i} = $tnickqueue;			# Restore entry ( the two entris have now changed place )
 269 		$filequeue{$i} = $tfilequeue;
 270 		$servertagqueue{$i} = $tservertagqueue;
 271 	}
 272 }
 273 
 274 sub remove_queueitem {
 275 	my $queueitem = shift;
 276 	if (defined($nickqueue{$queueitem}) && defined($filequeue{$queueitem} && defined($servertagqueue{$queueitem})) ) { # Is there really a queueitem here?
 277 		for ( my $i = $queueitem; $i <= Irssi::settings_get_int('findbot_maxqueue'); $i++) {
 278 			if ( defined($nickqueue{$i+1}) && defined($filequeue{$i+1}) && defined($servertagqueue{$i+1}) ) { # Move up in queue if there is one
 279 				$nickqueue{$i} = $nickqueue{$i+1};			# Move up in queue
 280 				$filequeue{$i} = $filequeue{$i+1};			# Move up in queue
 281 				$servertagqueue{$i} = $servertagqueue{$i+1};		# Move up in queue
 282 			}
 283 				
 284 		}
 285 		delete $nickqueue{$lastqueuenumber};		# Delete the last entry. It has been moved up one slot
 286 		delete $filequeue{$lastqueuenumber};		# Delete the last entry. It has been moved up one slot
 287 		delete $servertagqueue{$lastqueuenumber};	# Delete the last entry. It has been moved up one slot
 288 		$lastqueuenumber--;				# Since we removed a queue item the lastqueuenumber decreases
 289 	} else { debugprint(10,"debug: No remove $queueitem"); }
 290 }
 291 
 292 sub user_have_max_active_sends {
 293 	my $nickname = shift;					# Save the nick
 294 	my $localserver = shift;				# Save current servertag
 295 	if ( $activesends{$nickname} < Irssi::settings_get_int('findbot_maxusersends') ) {
 296 		return 0;					# The user didn't have enough sends
 297 	} else {
 298 		return 1;					# The user have NOT an active send
 299 	}
 300 }
 301 
 302 sub user_is_in_active_channel {
 303 	my $nickname = shift;
 304 	my $srvtag = shift;
 305 	my $find_channels = Irssi::settings_get_str('findbot_channels'); # What channels to monitor
 306         my @checkchannels = split (/ /, $find_channels); # Split into an array
 307 
 308 	foreach my $localserver ( Irssi::servers() ) {		# Loop through all connected servers
 309 		foreach my $singlechan ( @checkchannels ) {	# Loop through all monitored channels
 310 			my $channel = $localserver->channel_find($singlechan);	# Get a channelobject
 311 			if ( defined($channel) && defined($channel->nick_find($nickname)) ) {	# Is the nick there?
 312 				return 1;	# User are in monitored channels # Yep is was
 313 			} 
 314         	}
 315 	}
 316 		return 0;	# User have left monitored channels
 317 
 318 }
 319 
 320 sub nicefilename {
 321         my $filename = shift;
 322 
 323         if ( $filename =~ /.*\/(.*)\ *:.*/g ) { # If filelist is made by "file"
 324 		debugprint(15,"Summary file is made by the program file");
 325                 return $1;
 326         } elsif ( $filename =~ /.*\/(.*)$/g ) { # If filelist is Not made by file
 327 		debugprint(15,"Summary file is NOT made by the program file");
 328                 return $1;
 329         }
 330 }
 331 
 332 sub strippath {
 333 	my $filename = shift;			# Get parameter into $filename
 334 
 335 	$filename =~ s/.*\/(.*)/$1/g;		# Remove everything until the last /
 336 	return $filename;			# Return the stripped line
 337 }
 338 
 339 sub debugprint {
 340 	(my $dbglvl,my $debugmessage) = @_;	# Save input to variables
 341 	$debuglevel = Irssi::settings_get_int('findbot_debuglevel');
 342 	my $win;
 343 	if ( ! ($win = Irssi::window_find_name($IRSSI{name})) ) { # If the windows doesn't exist
 344 		$win = Irssi::Windowitem::window_create($IRSSI{name},1);
 345 	}
 346 	if ( $dbglvl <= $debuglevel ) {
 347 		$win->set_name($IRSSI{name});	# Select the window
 348 		$win->print($debugmessage,MSGLEVEL_CLIENTCRAP);
 349 		my $debugtid = localtime(time);
 350 		open (LOGFILE,">> $logfile");
 351                 print LOGFILE "$debugtid: $debugmessage\n";
 352                 close (LOGFILE);
 353 	}
 354 }
 355 
 356 sub process_queue {
 357 	if (Irssi::settings_get_bool('findbot_enabled') ) { # Is the findbot enabled?
 358 		my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); # Get current time
 359 		if ( ! timeslotenabled($wday,$hour,$min) ) {		# If NOT true the bot is offline
 360 			debugprint(15,"The bot is Offline due to timerestrictions in findbot_timeslots");
 361 			return 0;
 362 		}
 363 		print_banner();
 364 		if ( $currentsends < Irssi::settings_get_int('findbot_maxsends') ) {    # Check if we'll send another file simultanously
 365 			my $i = 1;
 366 			while ( $i <= $lastqueuenumber ) {
 367 				if ( ! user_have_max_active_sends($nickqueue{$i},$servertagqueue{$i}[0]) ) { # If NOT user have max active sends
 368 					my $nicefile = nicefilename($filequeue{$i});
 369 					if ( user_is_in_active_channel($nickqueue{$i},$servertagqueue{$i}[0]) ) { # Are the user in a monitored channel?
 370 						debugprint(10,"[ADMIN] $nickqueue{$i} are in monitored channels, sending $nicefile");
 371 						my $localserver = Irssi::server_find_tag($servertagqueue{$i}[0]);
 372 						$localserver->command("/QUOTE NOTICE " . $nickqueue{$i} . " :Sending you the requested file: $nicefile");
 373 						$localserver->command("/DCC SEND $nickqueue{$i} \"$filequeue{$i}\"" );
 374 						remove_queueitem($i);
 375 						last;	# Exit the loop
 376 					} else {
 377 						debugprint(10,"[ADMIN] $nickqueue{$i} is NOT in monitored channels. Removing queueentry $filequeue{$i}");
 378 						remove_queueitem($i);
 379 					 } # Remove the queued item if the user have parted the channel
 380 				} else { # A user had too many sends, increase $i by one to check next queue pos.
 381 					$i++;	# Increase by one so we can loop through whole queue
 382 				}
 383 			} # End while or for
 384 		}
 385 	}
 386 	check_dcc_speed_and_in_channel();			# Check minimumspeed
 387 }
 388 
 389 sub dcc_created {
 390 	(my $dcc) = @_;	# Put active dcc in variable
 391 
 392 	debugprint(15,"dcc_created was called");
 393 	if ( $dcc->{type} eq "SEND" ) {				# Is it a SEND?
 394 		if ( defined( $activesends{$dcc->{nick}} ) ) {
 395 			$activesends{$dcc->{nick}} = $activesends{$dcc->{nick}} + 1;
 396 		} else {
 397 			$activesends{$dcc->{nick}} = 1;
 398 		}
 399 		$currentsends++;
 400 	}
 401 }
 402 
 403 sub dcc_closed {
 404 	(my $dcc) = @_; # Put active dcc in variable
 405 
 406 	debugprint(15,"dcc_closed was called");
 407 	if ( $dcc->{type} eq "SEND" && defined ($activesends{$dcc->{nick}}) ) {	# Is it a SEND and a findbot SEND?
 408 		my $tiden = time();
 409 		$tiden = $tiden - $dcc->{starttime};
 410 		if ( $tiden > 0 ) {
 411 			my $kbsec = $dcc->{transfd} / $tiden;
 412 		} else {
 413 			$tiden = 1;
 414 			my $kbsec = $dcc->{transfd} / $tiden;
 415 		}
 416 		if ( $dcc->{transfd} == 0 ) {		# If transfered byts are zero, then it was probably aborted
 417 			debugprint(10,"[ADMIN] SEND aborted Nick: $dcc->{nick} File: $dcc->{arg}");
 418 		} else {
 419 			debugprint(10,"[ADMIN] SEND done Nick: $dcc->{nick} File: $dcc->{arg} Bytes: $dcc->{transfd} Time(sec): $tiden Speed: " . calc_kb_sec($tiden,$dcc->{transfd}) . " KB/s");
 420 		}
 421 		if ($activesends{$dcc->{nick}} == 1) {
 422 			delete $activesends{$dcc->{nick}};
 423 		} else {
 424 			 $activesends{$dcc->{nick}} = $activesends{$dcc->{nick}} - 1;
 425 		}
 426 		$currentsends--;
 427 		$scriptdetect{$dcc->{nick}} = time();		# Record the time when dcc was closed
 428 	}
 429 }
 430 
 431 sub calc_kb_sec {
 432 	my $seco = shift;
 433 	my $bytest = shift;
 434 
 435 my 	$kbsec = $bytest / $seco / 1000;
 436 	$kbsec =~ s/(.*\..?.?).*/$1/;
 437 
 438 	return $kbsec;
 439 }
 440 
 441 sub dcc_destroyed {
 442         (my $dcc) = @_; # Put active dcc in variable
 443 
 444 	debugprint(15,"dcc_destroyed was called");
 445 }
 446 
 447 sub check_dcc_speed_and_in_channel {
 448 #	my $localserver = Irssi::server_find_tag($servertag); # Get serverobject
 449 	my $minimumspeed = Irssi::settings_get_int('findbot_minspeed');
 450 	my $channelcheck = Irssi::settings_get_bool('findbot_mustbeinchannel');
 451 	foreach my $dccconnection (Irssi::Irc::dccs()) {
 452 		if ( $dccconnection->{type} eq "SEND" &&  defined($activesends{$dccconnection->{nick}}) && ($dccconnection->{transfd} - $dccconnection->{skipped}) > 50000) { # Check if its a findbot send.
 453 			my $bytetransferred = $dccconnection->{transfd} - $dccconnection->{skipped};
 454 			my $timedownloaded = time() - $dccconnection->{starttime};
 455 			if ( $timedownloaded == 0 ) { $timedownloaded++; } # Fix for Illegal division by zero
 456 			my $currentcps = sprintf("%02d",($bytetransferred / $timedownloaded)); # Get current CPS
 457 			if ( $currentcps < $minimumspeed && $minimumspeed > 0 ) {	# Check if below minimumspeed
 458 				my $localserver = Irssi::server_find_tag($dccconnection->{servertag});
 459 				$localserver->command("/QUOTE NOTICE $dccconnection->{nick} :Minimum CPS is $minimumspeed and you only have $currentcps. Closing your connection");
 460 				$localserver->command("/DCC CLOSE SEND $dccconnection->{nick}");
 461 				debugprint(10,"[ADMIN] $dccconnection->{nick} ($currentcps) is below minimumspeed($minimumspeed). Closing...");
 462 			} elsif ( $channelcheck ) {
 463 				if ( ! user_is_in_active_channel($dccconnection->{nick},$dccconnection->{servertag}) ) {
 464 					debugprint(10,"[ADMIN] $dccconnection->{nick} has LEFT monitored channels, closing SEND");
 465 					my $localserver = Irssi::server_find_tag($dccconnection->{servertag});
 466 					$localserver->command("/DCC CLOSE SEND $dccconnection->{nick}");
 467 					# Just close without warning, why bother to tell him if he's left.
 468 				}
 469 			}
 470 		}
 471 	}
 472 }
 473 
 474 sub nickname_changed {
 475 	my ($chan, $newnick, $oldnick) = @_;
 476 
 477 	foreach my $queuepos (keys(%nickqueue)) {	# Go through all nicks in my queuelist to see if we're affected
 478 		if ( $nickqueue{$queuepos} eq $oldnick ) {	# Check the nick
 479 			$nickqueue{$queuepos} = $newnick->{nick};	# Insert the new nick in that position
 480 			debugprint(10,"[ADMIN] Nickchange $nickqueue{$queuepos} -> $newnick->{nick}");
 481 		}
 482 	}
 483 	if ( defined($activesends{$oldnick}) ) {		# He has an active send
 484 		$activesends{$newnick->{nick}} = $activesends{$oldnick}; # Make a new entry so he can't evade the dcc speed check
 485 		delete $activesends{$oldnick};
 486 	}
 487 }
 488 
 489 sub user_got_kicked {
 490 	my ($kchannel,$knick,$kkicker,$kaddress,$kreason) = @_;
 491 	my $mustbeinchannel = Irssi::settings_get_bool('findbot_mustbeinchannel');
 492 	
 493 	if ( $mustbeinchannel ) {				# Are we to punish this kicked user?
 494 		foreach my $queuepos (keys(%nickqueue)) {	# Go through all nicks in my queuelist to see if we're affected
 495 			if ( $nickqueue{$queuepos} eq $knick ) {	# Check the nick if the kicked user has a queue.
 496 				debugprint(10,"[ADMIN] $knick was KICKED. Removing queueposition $queuepos $filequeue{$queuepos}");
 497 				remove_queueitem($queuepos);	# Removes the users queue
 498 			}
 499 		}
 500 	}
 501 }
 502 
 503 sub print_banner {
 504 	my $timenow = time();
 505 	my $timecalc = Irssi::settings_get_str('findbot_bannertime') + $lastbannerprint;
 506 #	debugprint(10,"print_banner function... now: $timenow last: $lastbannerprint timecalc: $timecalc");
 507 	if ( $timenow > $timecalc ) {
 508 		$lastbannerprint = time();		# Reset timer
 509 		my $find_channels = Irssi::settings_get_str('findbot_channels'); # What channels to monitor
 510 		my @checkchannels = split (/ /, $find_channels); # Split into an array
 511 		if ( Irssi::settings_get_bool('findbot_showbanner') ) { # Check if I will print the banner
 512 			debugprint(10,"[ADMIN] Sending banner to monitored channels");
 513 			my $showvoiceprio = "OFF";
 514 			if (Irssi::settings_get_bool('findbot_voicegetpriority') ) {
 515 				$showvoiceprio = "ON";
 516 			}
 517 			foreach my $localserver ( Irssi::servers() ) {
 518 				my $bannerad = "For my list of $#bigarray files type: \@" . $localserver->{nick} . ", Sends: $currentsends/" . Irssi::settings_get_int('findbot_maxsends') . " , Queue: $lastqueuenumber/" . Irssi::settings_get_int('findbot_maxqueue') . ", Voicepriority: $showvoiceprio, For help: \@" . $localserver->{nick} . "-help";
 519 				foreach my $singlechan ( @checkchannels ) {	# Loop through all monitored channels
 520 					my $channel = $localserver->channel_find($singlechan);	# Get the channelobject
 521 					if ( defined($channel) ) { # Am I in the specific channel, if so its defined
 522 						$channel->command("/MSG $singlechan $bannerad" . " Using: Irssi " . $IRSSI{name} . " v$VERSION"); # Print banner
 523 					} # End if
 524 				} # End foreach channel
 525 			} # End foreach server
 526 		} # End if
 527 	} # End check if I'll print the banner
 528 }
 529 
 530 sub admin_showqueue {
 531 	debugprint(10,"[ADMIN] Show queue");
 532 	debugprint(10,"[ADMIN] Current sends are: $currentsends");
 533 	for ( my $i = 1; $i <= $lastqueuenumber; $i++ ) { # Loop through the queue
 534 		debugprint(10,"[ADMIN] ($i) $nickqueue{$i}:$filequeue{$i}:$servertagqueue{$i}[0]:Prio $servertagqueue{$i}[1]");
 535 #		if ( $servertagqueue{$i}[1] > 0 ) {	# Is this a VIP entry?
 536 #			debugprint(10,"[ADMIN] ($i) $nickqueue{$i}:$filequeue{$i}:$servertagqueue{$i}[0]:VIP queued($servertagqueue{$i}[1])");
 537 #		} else {
 538 #			debugprint(10,"[ADMIN] ($i) $nickqueue{$i}:$filequeue{$i}:$servertagqueue{$i}[0]:Normal queued");
 539 #		}
 540 	}
 541 	debugprint(10,"[ADMIN] End of list");
 542 }
 543 
 544 sub admin_reset {
 545 	my $howmany = shift;
 546 	if ( $howmany =~ /\d+/ ) {
 547 		$currentsends = $howmany;	# Reset current sends
 548 		debugprint(10,"[ADMIN] Current sends are now set to $currentsends");
 549 	} else {
 550 		debugprint(10,"[ADMIN] Specify how many sends there are now");
 551 	}
 552 }
 553 
 554 #sub start_findbot {
 555 #	my($data,$localserver,$witem) = @_;
 556 
 557 #	if ( $localserver != 0 ) {
 558 #		$servertag = $localserver->{tag};		# Remeber on which server the findbot is on
 559 #		$globalstart = 1;
 560 #		debugprint(10,"Findserver is started");
 561 #	} else {
 562 #		debugprint(10,"Please start the server in a window where I can get hold of a servertag");
 563 #3	}
 564 #}
 565 
 566 sub admin_removequeue {
 567 	my $queueposition = shift;
 568 	if ( $queueposition =~ /\d+/ ) {
 569 		remove_queueitem($queueposition);
 570 		debugprint(10,"[ADMIN] Removed position $queueposition");
 571 	} else {
 572 		debugprint(10,"[ADMIN] Specify which queueitem should be removed");
 573 	}
 574 }
 575 
 576 sub admin_activesends {
 577 		debugprint(10,"[ADMIN] Listing active dccsends");
 578 	foreach my $send (keys(%activesends)) {
 579 		debugprint(10,"[ADMIN] $send ($activesends{$send})");
 580 	}
 581 		debugprint(10,"[ADMIN] End of list");
 582 }
 583 
 584 sub admin_reload {
 585 	if ( -r Irssi::settings_get_str('findbot_summaryfile') ) {
 586 	        open (FINDFILE,Irssi::settings_get_str('findbot_summaryfile')); # Open the file
 587 	        @bigarray = <FINDFILE>;                         # Load it whole into memory :)
 588 	        close (FINDFILE);
 589 		debugprint(10,"[ADMIN] Summary file has been reloaded into memory.");
 590 	} else {        
 591 	        debugprint(10,"[ADMIN] The Summaryfile cannot be read. Please check if the path is correct and the file is accually there.");
 592 	}
 593 }
 594 
 595 sub send_ctcp_slots {
 596 # Not implemented yet
 597 }
 598 
 599 sub sanitize_input {
 600 	my $tainted_input = shift;
 601 	$tainted_input =~ s/[\^\\\[\]\$\(\)\?\+\/\|\'\}\{]+/\./g; # Translate ^\[]$()?+ to .
 602 	return $tainted_input;		# Return regularexpression sanitized input
 603 }
 604 
 605 sub find_public {
 606 	my ($server, $msg, $nick, $address, $targetchan) = @_;		# Save all input to variables
 607 	my $find_channels = Irssi::settings_get_str('findbot_channels');# What channels to monitor
 608 	my $find_file = Irssi::settings_get_str('findbot_summaryfile');	# Filename which holds all the files
 609 	my $mp3list = Irssi::settings_get_str('findbot_sendlist');	# The nice list which is sent to users
 610 	my $max_results = Irssi::settings_get_int('findbot_maxresults');# Get max results retured to client
 611 	my $userqueuelimit = Irssi::settings_get_int('findbot_maxuserqueue'); # Get userqueue limit
 612 	my $serverqueuelimit = Irssi::settings_get_int('findbot_maxqueue'); # Get server maxqueue
 613 	my @checkchannels = split (/ /, $find_channels);		# Split into an array
 614 
 615 	my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); # Get current time
 616 
 617 	my $validchan = 0;
 618 	foreach my $singlechan ( @checkchannels ) {
 619 		if ( $singlechan eq $targetchan ) {
 620 			$validchan = 1;
 621 		}
 622 	}
 623 
 624 	if ( $validchan && Irssi::settings_get_bool('findbot_enabled') && timeslotenabled($wday,$hour,$min) ) {	# Did the user say something in one of our channels?
 625 		my $mynick = $server->{nick};
 626 		if ( $msg =~ /^\ *\@find\ +.+/i ) { 			# Was it a @find command?
 627 			$msg =~ s/^\ *\@find\ (.*)/$1/i;		# Remove @find space spaces infront of it
 628 			$msg =~ tr/*/\ /;				# Translate * to spaces
 629 			$msg =~ s/[\ \+]+/\.\*/g;			# Translate ALL spaces to .*
 630 			$msg = sanitize_input($msg);
 631 			debugprint(10,"$nick is searching for $msg");
 632 			my @matched;
 633 #			if ( length($msg) > 2  && $msg =~ m/[a-z]+/i) { # MUST be over 2 chars and contain atleast 1 or more normal characters
 634 				@matched = grep (/$msg/i,@bigarray);		# Search for the matches
 635 #			} else {
 636 #				debugprint(10,"[ADMIN] $nick tried to search with too wide searchpattern ($msg)");
 637 #				return;
 638 #			}
 639 			my $matchcount = 0;				# Reset a counter
 640 			my $found_results = $#matched;			# Return how many hits
 641 			$found_results++;				# If nomatch then it is -1
 642 			if ( $found_results > 0 ) {	# Print number of results to the user
 643 				debugprint(10,"Found $found_results matches");
 644 				$server->command("/QUOTE PRIVMSG " . $nick . " :Found $found_results matching files. Using: $IRSSI{name} v$VERSION for Irssi");
 645 			}
 646 			foreach my $match (@matched) {			# Loop through each file match
 647 				$match = strippath($match);		# Remove the path and keep filename and mp3info
 648 				$match =~ s/:/\ \ \ :\ \ /;		# Replace the ":" with "   :  "
 649 				if ( $matchcount < $max_results ) { 	# Is the matchlimit reached and is it a mp3 file?
 650 					$matchcount++;			# Increase by one
 651 					$server->command("/QUOTE PRIVMSG " . $nick . " :!$mynick $match");
 652 				} else {				# Limit reached!
 653 					$server->command("/QUOTE PRIVMSG " . $nick . " :Resultlimit by " . $max_results . " reached. Download my list for more, by typing \@$server->{nick}");
 654 					close (FINDFILE);
 655 					return;
 656 				}
 657 			}
 658 #			if ( $matchcount == 0 ) {
 659 #				$server->command("/QUOTE NOTICE " . $nick . " :No match found.");
 660 #			}
 661 		} elsif ( $msg =~ /^\ *!$server->{nick}.*/i ) {		# Send file trigger
 662 			my $localsrvtag = $server->{tag};		# Get current servertag
 663 			debugprint(20,"$nick tries to queue $msg");	# Just debugoutput
 664 			$msg =~ s/\ *!$server->{nick}\ *(.*)/$1/;	# Remove the trigger
 665 			$msg =~ tr/\(\)/\.\./;				# Translate all () to . (any char)
 666 			$msg = sanitize_input($msg);
 667 			my @matched = grep (/$msg/i,@bigarray);		# Get the real path from the file
 668 			if ( $matched[0] eq "" ) {
 669 				$server->command("/QUOTE NOTICE " . $nick . " :That file does not exist");
 670 				return;
 671 			}
 672 			my $realfile = $matched[0]; 			# Append the real path to the relative path
 673 			$realfile =~ s/(.*)\ +:.*/$1/;			# Remove : and beyoned
 674 			
 675 			my $scriptrequest = time() - $scriptdetect{$nick};
 676 			if ( $scriptrequest <= $scriptdetecttime && $showscriptdetect ) {
 677 				debugprint(10,"[ADMIN] Requestscript detected on $nick");
 678 				# return;	# 
 679 			}
 680 			chomp ($realfile);
 681 			if ( check_user_queued_items($nick,$localsrvtag) < $userqueuelimit ) { # Is it below allowed user queue limit
 682 				if ( already_queued_file($nick,$realfile,$localsrvtag) ) {
 683 					$server->command("/QUOTE PRIVMSG " . $nick . " :You have already queued that file!");
 684 				} else {
 685 					my $priority = 1;			# Default prio
 686 					if ( $lastqueuenumber < $serverqueuelimit ) {
 687 						foreach my $vchannel ($server->channels()) {	# Loop through all joined channels
 688 							if ( $vchannel->{name} eq $targetchan ) {	# Did he say it in a monitored channel
 689 								my $nickrec = $vchannel->nick_find($nick);
 690 								if ( $nickrec->{voice} ) {
 691 									$priority = 10;	# A voiced user get 10 prioritypoints
 692 								} # Voiced user?
 693 								if ( $nickrec->{op} ) {
 694 									$priority = 20; # An op get 20 prioritypoints
 695 								}
 696 								last;		# Skip rest of loop
 697 							}
 698 						}
 699 						add_file_to_queue($nick,$realfile,$localsrvtag,$priority);	# Add file to queue
 700 						if ( Irssi::settings_get_bool('findbot_voicegetpriority') && $priority > 1 ) {
 701 							$server->command("/QUOTE PRIVMSG " . $nick . " :Added file to VIP queueposition $globalvippos.");
 702 							debugprint(10,"[ADMIN] $nick VIP queued: $realfile");
 703 						} else {
 704 							$server->command("/QUOTE PRIVMSG " . $nick . " :Added file to queueposition $lastqueuenumber.");
 705 							debugprint(10,"[ADMIN] $nick queued: $realfile");
 706 						}
 707 					} else {
 708 						$server->command("/QUOTE PRIVMSG " . $nick . " :The serverqueue is full. Please try again in a few minutes.");
 709 						debugprint(10,"[ADMIN] Queue is FULL.");
 710 					}
 711 				}
 712 			} else {						# Tell the user the user queue limit is reached
 713 				$server->command("/QUOTE PRIVMSG " . $nick . " :You have reached the " . $userqueuelimit . " files queue limit.");
 714 				debugprint(10,"[ADMIN] $nick has reached his queuelimit");
 715 			}
 716 		} elsif ( ($msg =~ /^\ *\@$server->{nick}-stats.*/i) || ($msg =~ /^\ *\@$server->{nick}-que.*/i) ) {
 717 			debugprint(10,"[ADMIN] $nick checked queuepositions");
 718 			$server->command("/QUOTE PRIVMSG " . $nick . " :Sending you, your queuepositions");
 719 			for ( my $i = 1; $i <= $lastqueuenumber; $i++ ) { # Loop through the queue
 720 				if ( $nickqueue{$i} eq $nick ) {
 721 					my $nicefile = nicefilename($filequeue{$i});
 722 					$server->command("/QUOTE PRIVMSG " . $nick . " :Pos $i, $nicefile");
 723 				}
 724 			}
 725 		} elsif ( $msg =~ /^\ *\@$server->{nick}-remove.*/i ) {
 726 			if ( $msg =~ /\ *\@$server->{nick}-remove\ *([\d]+)/ ) { # We have a number
 727 				my $qitem = $1;
 728 				debugprint(10,"[ADMIN] $nick is trying to remove queueposition $qitem");
 729 				if ( $nickqueue{$qitem} eq $nick ) {	# Check if the item is owned by the user
 730 					remove_queueitem($qitem);	# Remove the requested queueitem
 731 					$server->command("/QUOTE NOTICE " . $nick . " :Item $qitem has");
 732 				} else {	# Unauthorized removal
 733 					debugprint(10,"[ADMIN] $nick tried to remove other peoples files from queue");
 734 					$server->command("/QUOTE NOTICE " . $nick . " :You can't remove other peoples queueitems");
 735 				}
 736 			} else {			# We dont have a number, ie remove the whole user queue
 737 				debugprint(10,"[ADMIN] $nick has removed all own queueitems");
 738 				for ( my $i = 1; $i <= $lastqueuenumber; $i++ ) { # Loop through the queue
 739 					if ( $nickqueue{$i} eq $nick ) {
 740 						remove_queueitem($i);
 741 					}
 742 				}
 743 				$server->command("/QUOTE NOTICE " . $nick . " :Your whole queue have been deleted");
 744 			}
 745 		} elsif ( $msg =~ /^\ *\@$server->{nick}$/i ) {
 746 			if ( -r $mp3list ) {				# Check if the file is still there
 747 				debugprint(10,"[ADMIN] $nick requested my list: $mp3list");
 748 				$server->command("/QUOTE NOTICE " . $nick . " :Sending you my full list...");
 749 				$server->command("/DCC SEND $nick $mp3list" );
 750 			} else {
 751 				debugprint(5,"[WARNING] the $mp3list doesn't exist!");
 752 				$server->command("/QUOTE NOTICE " . $nick . " :Something wicked happened. My list has disappeared and i have notified the bot owner.");
 753 			}
 754 		} elsif ( ($msg =~ /^\ *\@$server->{nick}\ *help\ *$/i) || ($msg =~ /^\ *\@$server->{nick}-help\ *$/i) ) {
 755 			debugprint(10,"[ADMIN] $nick requested HELP");
 756 			$server->command("/QUOTE PRIVMSG " . $nick . " :Public channel commands:");
 757 			$server->command("/QUOTE PRIVMSG " . $nick . " :\@find [searchpattern] : Searches my database for that file");
 758 			$server->command("/QUOTE PRIVMSG " . $nick . " :!$server->{nick} [file] : Queues that file and it will be sent to you when its your turn");
 759 			$server->command("/QUOTE PRIVMSG " . $nick . " :\@$server->{nick}-stats : Shows you your queuepositions");
 760 			$server->command("/QUOTE PRIVMSG " . $nick . " :\@$server->{nick}-que : Shows you your queuepositions");
 761 			$server->command("/QUOTE PRIVMSG " . $nick . " :\@$server->{nick}-remove : Clears all your queued files");
 762 			$server->command("/QUOTE PRIVMSG " . $nick . " :\@$server->{nick}-remove 2 : Clear your queueposition 2");
 763 			$server->command("/QUOTE PRIVMSG " . $nick . " :$IRSSI{name} v$VERSION $IRSSI{url}");
 764 		} else {
 765 			return; # Just ordinary chatter
 766 		}
 767 	}
 768 	return;	# Just in case
 769 }
 770 
 771 sub check_vital_configuration {
 772 	my $configerror = 0;
 773 	if ( Irssi::settings_get_str('findbot_channels') eq "" ) {
 774 		$configerror = 1;
 775 		Irssi::print("The setting findbot_channels is empty.");
 776 	} elsif (  Irssi::settings_get_str('findbot_summaryfile') eq "" ) {
 777 		$configerror = 1;
 778                 Irssi::print("The setting findbot_summaryfile is empty.");
 779 	} elsif (  Irssi::settings_get_str('findbot_sendlist') eq "" ) {
 780 		$configerror = 1;
 781                 Irssi::print("The setting findbot_sendlist is empty.");
 782 	} elsif (  Irssi::settings_get_int('findbot_maxresults') == 0 ) {
 783                 $configerror = 1;         
 784                 Irssi::print("The setting findbot_maxresults is empty.");
 785         } elsif (  Irssi::settings_get_int('findbot_maxqueue') == 0 ) {
 786                 $configerror = 1;         
 787                 Irssi::print("The setting findbot_maxqueue is empty.");
 788         } elsif (  Irssi::settings_get_int('findbot_maxsends') == 0 ) {
 789                 $configerror = 1;         
 790                 Irssi::print("The setting findbot_maxsends is empty.");
 791         } elsif (  Irssi::settings_get_int('findbot_maxuserqueue') == 0 ) {
 792                 $configerror = 1;         
 793                 Irssi::print("The setting findbot_maxuserqueue is empty.");
 794         } elsif (  Irssi::settings_get_int('findbot_maxusersends') == 0 ) {
 795                 $configerror = 1;         
 796                 Irssi::print("The setting findbot_maxusersends is empty.");
 797         } elsif (  Irssi::settings_get_int('findbot_bannertime') == 0 ) {
 798                 $configerror = 1;
 799                 Irssi::print("The setting findbot_bannertime is empty.");
 800         }
 801 	if ($configerror) {
 802 		Irssi::print("Please correct the settings first. The server will be disabled");
 803 		Irssi::print("You have to reload the script when the settings are correct");
 804 		Irssi::timeout_remove($timeout_tag);
 805 		Irssi::timeout_remove($banner_timeout);
 806 	}
 807 }
 808 
 809 ########
 810 # Main #
 811 ########
 812 
 813 Irssi::settings_add_str("misc", "findbot_channels", "");	# Add a variable inside of irssi
 814 Irssi::settings_add_str("misc", "findbot_summaryfile", "");	# Add a variable inside of irssi
 815 Irssi::settings_add_int("misc", "findbot_maxresults", "");	# Add a variable inside of irssi
 816 Irssi::settings_add_str("misc", "findbot_sendlist", "");	# Add a variable inside of irssi
 817 Irssi::settings_add_int("misc", "findbot_maxqueue", "");	# Add a variable inside of irssi
 818 Irssi::settings_add_int("misc", "findbot_maxsends", "");	# Add a variable inside of irssi
 819 Irssi::settings_add_int("misc", "findbot_maxuserqueue", "");	# Add a variable inside of irssi
 820 Irssi::settings_add_int("misc", "findbot_maxusersends", "");	# Add a variable inside of irssi
 821 Irssi::settings_add_bool("misc", "findbot_showbanner", "");	# Add a variable inside of irssi
 822 Irssi::settings_add_int("misc", "findbot_bannertime", "");	# Add a variable inside of irssi
 823 Irssi::settings_add_bool("misc", "findbot_enabled", "");	# Add a variable inside of irssi
 824 Irssi::settings_add_bool("misc", "findbot_voicegetpriority", "");	# Add a variable inside of irssi
 825 Irssi::settings_add_int("misc", "findbot_minspeed", "");	# Add a variable inside of irssi
 826 Irssi::settings_add_int("misc", "findbot_debuglevel", 10);	# Add a variable inside of irssi
 827 Irssi::settings_add_bool("misc", "findbot_mustbeinchannel", "");
 828 Irssi::settings_add_str("misc", "findbot_timeslots", "");	# Add a variable inside of irssi
 829 Irssi::signal_add_last('message public', 'find_public');	# Hook up a function to public chatter
 830 Irssi::signal_add_last('message private', 'private_get');	# Hook up a function to public chatter
 831 Irssi::signal_add_last('dcc created', 'dcc_created');		# Hook when a dcc is created
 832 Irssi::signal_add_last('dcc closed', 'dcc_closed');		# Hook when a dcc is closed
 833 Irssi::signal_add_last('dcc destroyed', 'dcc_destroyed');
 834 Irssi::signal_add('nicklist changed', 'nickname_changed');
 835 Irssi::signal_add('message kick', 'user_got_kicked');
 836 Irssi::command_bind('findbotqueue', 'admin_showqueue');
 837 Irssi::command_bind('findbotremove', 'admin_removequeue');
 838 Irssi::command_bind('findbotreset', 'admin_reset');
 839 Irssi::command_bind('findbotreload', 'admin_reload');
 840 Irssi::command_bind('findbotactivesends', 'admin_activesends');
 841 
 842 check_vital_configuration();	# Run a subroutine to check all variables before starting
 843 if ( -r Irssi::settings_get_str('findbot_summaryfile') ) {
 844 	open (FINDFILE,Irssi::settings_get_str('findbot_summaryfile'));	# Open the file
 845 	@bigarray = <FINDFILE>; 			# Load it whole into memory :)
 846 	close (FINDFILE);
 847 } else {
 848 	debugprint(10,"The Summaryfile cannot be read. Please check if the path is correct and the file is accually there.");
 849 }
 850 # my $slots_timeout = Irssi::timeout_add(600000, "send_ctcp_slots", ""); # Not implemented yet
 851 $timeout_tag = Irssi::timeout_add(5000, "process_queue", "");	# Add a timeout value the process the queue
 852 #my $bannertime = Irssi::settings_get_int('findbot_bannertime');
 853 #$banner_timeout = Irssi::timeout_add($bannertime * 1000, "print_banner", ""); # Set timeout for banner
 854 Irssi::print("Findbot script v$VERSION by $IRSSI{'authors'} loaded!"); # Show version and stuff when it has been loaded
 855 
 856 if ( Irssi::settings_get_bool('findbot_enabled') ) {
 857 	Irssi::print("Findserver is Online");
 858 } else {
 859 	Irssi::print("Findserver is Offline");
 860 }
 861 debugprint (5,"[ADMIN] Findbot fileserver has been loaded!");
 862 
 863 
 864 #############################
 865 # INSTALLATION INSTRUCTIONS
 866 #############################
 867 # - Making of the "findbot_summaryfile" and "findbot_sendlist"
 868 # 	Run the perlscript below to create the summaryfile and sendlist
 869 #
 870 # - Install it in Irssi
 871 # 	Put the script in your Irssi scripts directory (~.irssi/scripts)
 872 # 	Start Irssi and load it. (/run findbot.pl)
 873 # 	Now start setting all vital variables by using the command /set
 874 #	set the "findbot_summaryfile" and "findbot_sendlist" to the files you just have created with
 875 #	the perlscript below.
 876 #	Dont forget to set all the other variables
 877 
 878 
 879 ####### Here is the script #########
 880 
 881 # #!/usr/bin/perl 
 882 
 883 # if not supplied on cmd line this is the values
 884 #$MP3PATH = "/misc/glftpd/site/mp3/";
 885 #$NICK    = "Donken";
 886 #($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
 887 #
 888 #$year    = sprintf("%04d",$year+1900);
 889 #$mon     = sprintf("%02d",$mon + 1);
 890 #$mday    = sprintf("%02d",$mday);
 891 #$DATE    = "$year-$mon-$mday";
 892 #$LIST    = $NICK . "_mp3s_list.txt";
 893 #$CMD     = $NICK . "_mp3s_cmd.txt";
 894 #$padding = 50;	# How many pad-characters should it be
 895 #
 896 #if( "x" ne  "x$ARGV[0]" ){ $NICK    = $ARGV[0]; }
 897 #if( "x" ne  "x$ARGV[1]" ){ $MP3PATH = $ARGV[1]; }
 898 #if( "x" ne  "x$ARGV[2]" ){ $LIST    = $ARGV[2]; }
 899 #if( "x" ne  "x$ARGV[3]" ){ $CMD     = $ARGV[3]; }
 900 #
 901 #print "Using nick: $NICK\n";
 902 #print "Finding under supplied mp3path $MP3PATH\n";
 903 #@INPUT=`find $MP3PATH -follow -type f`;
 904 #print "Find done\n";
 905 #print "Summaryfile: $LIST\n";
 906 #print "Sendlist:    $CMD\n";
 907 #
 908 #print "Generating lists done/total mp3 files\n";
 909 #open(LIST,">$LIST"); 
 910 #open(CMD,">$CMD");
 911 #
 912 #print LIST "### List generated: $DATE I have a total of $#INPUT mp3s ###\n";
 913 #print CMD  "### List generated: $DATE I have a total of $#INPUT mp3s ###\r\n";
 914 #print CMD  "### This list was created by Findbot for Irssi\r\n";
 915 #print CMD  "### http://irssi.org/scripts\r\n";
 916 #
 917 #$CHECKDIR=""; 
 918 #$CNT=0;
 919 #
 920 ## arrays start 0 and If I have 10 mp3 without +1 it would stat you have 9 ...
 921 #$TOTAL = $#INPUT + 1; 
 922 #
 923 #sub padline {
 924 #	$filename = shift;
 925 #	$filelength = length($filename);
 926 #	$paddchar = "=";
 927 #	if ( $filelength <= $padding ) {
 928 #		for ( $counter = $filelength; $counter < $padding; $counter++ ) {
 929 #			$paddchar .= "=";
 930 #		}
 931 #	}
 932 #	return $paddchar;
 933 #}
 934 #
 935 #foreach( @INPUT ){
 936 #        $CNT++; 
 937 #	print "\r$CNT/" . $TOTAL;
 938 #        chomp $_; 
 939 #
 940 #	$FILE=$_; 
 941 #	$DIR=$_; 
 942 #	$FILEwPATH=$_;
 943 #
 944 #        $FILE =~ s/.*\/(.*)/$1/g; # only the file
 945 #        $DIR =~ s/(.*)\/.*/$1/g; # only the dir
 946 #
 947 #        $STAT_OF_FILE = `file -b "$FILEwPATH"`; # the info about the file
 948 #	$STAT_OF_FILE =~ s#/##gio; # remove /
 949 #        chomp $STAT_OF_FILE;
 950 #
 951 #        print LIST "$FILEwPATH : $STAT_OF_FILE\n"; # output to the LIST-file
 952 #	if( "$DIR" ne "$CHECKDIR" ){ 
 953 #	        # output to the CMD-file 
 954 #		print CMD "\r\n=================================================\r\n";
 955 #		$CHECKDIR = $DIR; print CMD "Files in $DIR\r\n"; 
 956 #		print CMD "=================================================\r\n\r\n";
 957 #	}
 958 #        print CMD "!$NICK $FILE " . padline($FILE) . " $STAT_OF_FILE\r\n"; # output to the CMD-file
 959 #}
 960 #print CMD "EOF\r\n";
 961 #print LIST "EOF\r\n";
 962 #close LIST,CMD;
 963 #print "\nList generation done\n";
 964