summaryrefslogtreecommitdiffstats
path: root/scripts/quizgr.pl
blob: a2d36df83fd34d1044d1a13a9124db747dbf3240 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
#!/usr/bin/perl -T
# Quizgr script for irssi with "KAOS" questions enabled, modified for greek too
# copyright Athanasius Emilius Arvanitis
# arvan@kronos.eng.auth.gr
# based on quiz.pl version 0.7
# Quiz script for irssi
# (C) Simon Huggins 2001
# huggie@earth.li

# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place, Suite 330, Boston, MA 02111-1307  USA
#
# DONE:
#       - support for many answers (not alternate though) per question
#       - support for hellenic (aka greek)
#       - remembers the questions that were answered (stores them in
#       ./wr/used_questions)
#       - if nobody says anything for a period of time, game ends
#       - added !repeat to repeat the question
#       - it wont crash if you smile!
# TODO:
#       - known bug: sometimes it ignores some people (they cant join etc).
#	if you join #CHANNEL and the bot is on #channel forget it...
#       - fix kaos hints
#       - if we have kaos, there should be more time to answer
#       - CLEAN up the code
# 	- Do something when people quit (remove from team, readd when rejoin?)

use strict;
use vars qw($VERSION %IRSSI);
    
use Irssi 20020217.1542 (); # Version 0.8.1 or perhaps get the most up to date irssi version
$VERSION = "0.7GR03";
%IRSSI = (
authors     => "Athanasius Emilius Arvanitis based on Simon Huggins quiz 0.7",
contact     => "arvan",
name        => "Quizgr",
description => "Turns irssi into a quiz bot. Has greek language and many answers support",
license     => "GPLv2",
url         => "http://kronos.eng.auth.gr/~arvan/irssi/",
changed     => "Tue Nov 26 13:37:59 EET 2002",
);

use Irssi::Irc;
use Data::Dumper;

Irssi::settings_add_str("misc","quiz_admin","jbg");
Irssi::settings_add_str("misc","quiz_passwd","stuff");
Irssi::settings_add_str("misc","quiz_file","$ENV{HOME}/.irssi/scripts/autorun/gr_quiz_questions");
Irssi::settings_add_str("misc","used_file","$ENV{HOME}/.irssi/scripts/autorun/wr/used_questions");

Irssi::settings_add_int("misc","quiz_qlength",70);
Irssi::settings_add_int("misc","quiz_hints",7);
Irssi::settings_add_int("misc","quiz_target_score",50);
Irssi::settings_add_int("misc","quiz_leave_concealed_chars",1);

Irssi::command("set cmd_queue_speed 2010");

{
# when warnings used $s complains
my $s;
my $answerBAKforCHAOS;

sub load_questions($$) {
	my ($game,$force) = @_;
	my $tag = $game->{'tag'};
	my $channel = $game->{'channel'};

	$game->{'used_questions'}=[];

	my $server = Irssi::server_find_tag($tag);

	if (!defined $server) {
		Irssi::print("Hrm, couldn't find server for tag ($tag) in load_questions");
		return;
	}

	return if $game->{'questions'} and not $force;

	#the next must be checked

	my $file = Irssi::settings_get_str("quiz_file");
	if (open(QS, "<", $file)) { #open for QS
		@{$game->{'questions'}}=sort <QS>;
		close(QS);
		Irssi::print("Loaded questions");

		my $file2 = Irssi::settings_get_str("used_file");
		if (open(QS2, "<", $file2)) { #open for QS2
			@{$game->{'used_questions'}}=sort <QS2>;
			close(QS2);

			#from perlfaq copy paste 
			@{$game->{'intersection'}} = @{$game->{'difference'}} = ();
			%{$game->{'count'}} = ();

			my $element;
			foreach $element (@{$game->{'questions'}}, @{$game->{'used_questions'}}) { ${$game->{'count'}}{$element}++ };

			foreach $element (keys %{$game->{'count'}}) { #open foreach
				push @{ ${$game->{'count'}}{$element} > 1 ? \@{$game->{'intersection'}} : \@{$game->{'difference'}} }, $element;
				} #close foreach

			my $ts = Irssi::settings_get_int("quiz_target_score");
			my $qCounter=@{$game->{'questions'}};
			${$game->{'usedCounter'}}=@{$game->{'used_questions'}};

			my $qGOT=($qCounter - ${$game->{'usedCounter'}}); 
			my $qNEEDED=(2*($ts)+12);
			Irssi::print("${$game->{'usedCounter'}} used out of $qCounter total questions");

			if ( $qGOT >= $qNEEDED ) { 
				@{$game->{'questions'}}=@{$game->{'difference'}};
				Irssi::print("Loaded not used questions");
				return 1;#used
				}

			if ( $qGOT < $qNEEDED ) { 
				@{$game->{'used_questions'}}=();
				Irssi::print("Clearing used questions");
				return 1;#used
				}
		} #close QS2

		return 1;#questions
		} #close QS

	  else {
		$server->command("msg $channel Can't find quiz questions, sorry.");
		return;
		}



}

sub start_game($) {
	my $game = shift;
	my $tag = $game->{'tag'};
	my $channel = $game->{'channel'};
	my $server = Irssi::server_find_tag($tag);

	if (!defined $server) {
		Irssi::print("Hrm, couldn't find server for tag ($tag) in start_game");
		return;
		}

	Irssi::timeout_remove($game->{'timeouttag'});
	undef $game->{'timeouttag'};

	if (!keys %{$game->{'teams'}}) {
		$server->command("msg $channel Sorry no one joined!");
		$game->{'state'} = "over";
		game_over($game);
		return;
		}

	$game->{'state'} = "game";

	$server->command("msg $channel Game starts now. Questions last ".
		Irssi::settings_get_int("quiz_qlength").
		" seconds and there are ".
		(Irssi::settings_get_int("quiz_hints")-1).
		" hints.  First to reach ".
		Irssi::settings_get_int("quiz_target_score")." wins.");
	next_question($game);
}

sub show_scores($) {
	my $game = shift;
	my $tag = $game->{'tag'};
	my $channel = $game->{'channel'};
	my $server = Irssi::server_find_tag($tag);

	if (!defined $server) {
		Irssi::print("Hrm, couldn't find server for tag ($tag) in show_scores");
		return;
		}

	my (@redscorers,@bluescorers);

	foreach my $score (sort keys %{$game->{'scores'}}) {
		if ($score =~ /^blue/) {
			$score =~ s/^blue//;
			push @bluescorers, "$score(".
				$game->{'scores'}->{"blue".$score}.")";
		} else {
			$score =~ s/^red//;
			push @redscorers, "$score(".
				$game->{'scores'}->{"red".$score}.")";
		}
	}

	$server->command("msg $channel 12Blue: ".$game->{'bluescore'}
		."  ".join(",",@bluescorers));
	$server->command("msg $channel 4Red: ".$game->{'redscore'}
		."  ".join(",",@redscorers));
	
	my $ts = Irssi::settings_get_int("quiz_target_score");

	if ($game->{'bluescore'} >= $ts or $game->{'redscore'} >= $ts) {
		if ($game->{'bluescore'} > $game->{'redscore'}) {
			$server->command("msg $channel 12Blue team wins ".
				$game->{'bluescore'}." to ".
				$game->{'redscore'});
		} else {
			$server->command("msg $channel 4Red team wins ".
				$game->{'redscore'}." to ".
				$game->{'bluescore'});
		}
		$game->{'state'}="over";
	} elsif ($game->{'state'} ne "over") {
		$game->{'state'}="pause";
		$server->command("msg $channel Next question in 6 20 seconds.");
		if ($game->{'timeouttag'}) {
			Irssi::timeout_remove($game->{'timeouttag'});
		}
		$game->{'timeouttag'} = Irssi::timeout_add(20000,
			"next_question",$game);
		$game->{'timeout'} = time() + 20;
	}
	game_over($game);
}

sub hint($) {
	my $game = shift;
	my $tag = $game->{'tag'};
	my $channel = $game->{'channel'};
	my $server = Irssi::server_find_tag($tag);

	if (!defined $server) {
		Irssi::print("Hrm, couldn't find server for tag ($tag) in hint");
		return;
		}

	return if game_over($game);
	if ($game->{'end'} <= time()) {
		$server->command("msg $channel Time's up.  The answer is: 2  ".$game->{'answer'});
		show_scores($game);
	} else {
		$game->{'hint'}++;
		my $num = $game->{'current_answer'} =~ s/\*/*/g;
		if ($num <= Irssi::settings_get_int("quiz_leave_concealed_chars")) {
			return;
			}

		my $pos = index($game->{'current_answer'},"*");
		if ($pos >= 0) {
			#$game->{'current_answer'} =~ s/\*/substr($game->{'answer'},$pos,1)/e;
			$game->{'current_answer'} =~ s/\*/substr($answerBAKforCHAOS,$pos,1)/e;
			}

		my $hinttime = $game->{'hint'}*$game->{'hintlen'};
		if ($hinttime != int($hinttime)) {
			$hinttime = sprintf("%.2f", $hinttime);
			}
		$server->command("msg $channel 2  $hinttime second hint: 6  ".
			$game->{'current_answer'});
	} #else end
}

sub game_over($) {
	my $game = shift;
	my $tag = $game->{'tag'};
	my $channel = $game->{'channel'};
	my $server = Irssi::server_find_tag($tag);

	if (!defined $server) {
		Irssi::print("Hrm, couldn't find server for tag ($tag) in game_over");
		return;
	}

	if ($game->{'state'} eq "over") {
		Irssi::timeout_remove($game->{'timeouttag'});
		undef $game->{'timeouttag'};
		undef $game->{'state'};
		undef $game->{'teams'};
		undef $game->{'scores'};

                #save used questions
                my $file2 = Irssi::settings_get_str("used_file");
                if (open(QS2, ">", $file2)) {
                        my $line;
			@{$game->{'used_questions'}}=sort @{$game->{'used_questions'}};
                        foreach $line (@{$game->{'used_questions'}}){
                                print QS2 $line ;
                                }
                        close(QS2);
                        Irssi::print("Saved used questions");
                        }


		$server->command("msg $channel Trivia is disabled.  Use !start or !trivon to restart.");
		return 1;
	}
	return;
}

sub next_question($) {
	my $game = shift;
	my $tag = $game->{'tag'};
	my $channel = $game->{'channel'};
	my $server = Irssi::server_find_tag($tag);

	if (!defined $server) {
		Irssi::print("Hrm, couldn't find server for tag ($tag) in next_question");
		return;
	}

	#check previous text time and
	#if noone says anything for 180 seconds end game
	if (defined $game->{'time_last_text'}) {
		my $diff2=time() - $game->{'time_last_text'};
		if ( $diff2 > 180) {
			$game->{'state'}="over";
		}
	}


	my $len = Irssi::settings_get_int("quiz_qlength")/
		Irssi::settings_get_int("quiz_hints");
	if ($game->{'timeouttag'}) {
		Irssi::timeout_remove($game->{'timeouttag'});
	}
	$game->{'timeouttag'} = Irssi::timeout_add($len*1000, "hint",$game);
	my $t = time();
	$game->{'timeout'} = $t + $len;
	$game->{'end'} = Irssi::settings_get_int("quiz_qlength")+$t;
	$game->{'hint'}=0;
	$game->{'hintlen'} = $len;
	if (!@{$game->{'questions'}}) {
		load_questions($game,1);
		if (!$game->{'questions'}) {
			$server->command("msg $channel Hmmm, no questions found sorry");
			$game->{'state'}="over";
		}
		Irssi::print("Questions looped");
	}
	return if game_over($game);

	#random question
	${$game->{'randIDX'}}= @{$game->{'questions'}};
	${$game->{'randIDX'}}=rand(${$game->{'randIDX'}});
	my $q = ${$game->{'questions'}}[${$game->{'randIDX'}}];
	${$game->{'the_question'}} = $q;

	#removing it from the questions
	splice (@{$game->{'questions'}}, ${$game->{'randIDX'}}, 1);

	#see faq for splice/random may be bad
	#my $q = splice(@{$game->{'questions'}},rand(@{$game->{'questions'}}),1);
	chomp $q;
	$q =~ s///;
	#($game->{'answer'} = $q) =~ s/^(.*)\|//;

	($game->{'question'}, $game->{'answer'}) = split(/\|/, $q,2);
	$answerBAKforCHAOS = $game->{'answer'};
	if ( $game->{'answer'} =~ /\|/ ) 
		{ $server->command("msg $channel KAOS CHAOS ����!!!"); 
			$game->{'answer'} = $game->{'answer'}."|";

		}
	$server->command("msg $channel 13Question: 10 $game->{'question'} ");
	#added �-��-� so it can hide greek too
	($game->{'current_answer'} = $game->{'answer'}) =~ s/[a-zA-Z0-9�-��-�]/*/g;
	#$q = s/^(.*)\|.*?$/$1/;
	$server->command("msg $channel Answer:  ".$game->{'current_answer'});
	$game->{'state'}="question";
}

sub invite_join($$) {
	my ($server,$channel) = @_;
	my $game = $s->{$server->{'tag'}}->{$channel};

	$server->command("msg $channel Team Trivia thingummie v($VERSION) starts in 1 minute.  Type 4!join red or 12!join blue");
	$game->{'timeouttag'} = Irssi::timeout_add(60000,"start_game",$game);
	$game->{'timeout'} = time()+60;
}

sub secstonormal($) {
	my $seconds = shift;
	my ($m,$s);

	$s = $seconds % 60;
	$m = ($seconds - $s)/60;
	return sprintf("%02d:%02d",$m,$s);
}

sub do_pubcommand($$$$) {
	my ($command,$channel,$server,$nick) = @_;
	my $game = $s->{$server->{'tag'}}->{$channel};

	$command = lc $command;
	$command =~ s/\s*$//;

	if ($command =~ /^!bang$/) {
		$server->command("msg $channel Dumping...");
		foreach (split /\n/,Dumper($s)) {
			Irssi::print("$_");
		}
	} elsif ($command =~ /^!trivon$|^!start$|!����$/) {
		if ($s->{$server->{'tag'}}->{$channel}) {
			if ($s->{$server->{'tag'}}->{$channel}->{'state'}) {
				$server->command("msg $nick Trivia is already on.  Use !trivoff or !stop to remove it.");
				return;
			}
			#undef $s->{$server->{'tag'}}->{$channel};
		} else {
			# create structure magically
			$game = $s->{$server->{'tag'}}->{$channel} = {};
			$game->{'tag'} = $server->{'tag'};
			$game->{'channel'} = $channel;
		}
		$game->{'teams'}={};
		$game->{'redscore'} = 0;
		$game->{'bluescore'} = 0;
		load_questions($game,0);
		$game->{'state'} = "join";
		invite_join($server,$channel);
	} elsif ($command =~ /^!trivoff$|^!stop$|!������$/) {
		return if !$game->{'state'};
		$game->{'state'}="over";
		game_over($game);
	} elsif ($command =~ /^!join/) {
		if ($command =~ /^!join (red|blue)$/) {
			return if !$game->{'state'};
			$game->{'teams'}->{$nick}=$1;
			if ($1 eq "blue") {
				$server->command("notice $nick You have joined the 12Blue team");
			} else {
				$server->command("notice $nick You have joined the 4Red team");
			}
		}
	} elsif ($command =~ /^!teams/) {
		return if !$game->{'state'};
		my @blue=();
		my @red=();
		foreach (sort keys %{$game->{'teams'}}) {
			push @blue, $_ if $game->{'teams'}->{$_} eq "blue";
			push @red,  $_ if $game->{'teams'}->{$_} eq "red";
		}
		$server->command("msg $channel 12Blue: ".join(",",@blue));
		$server->command("msg $channel 4Red : ".join(",",@red));
	} elsif ($command =~ /^!repeat$/) {
		return if !$game->{'state'};
		$server->command("msg $channel Question is $game->{'question'}");
	} elsif ($command =~ /^!timeleft$/) {
		if ($game->{'state'} eq "join" and $game->{'timeout'}) {
			my $diff = $game->{'timeout'} - time();
			if ($diff > 0) {
				$server->command("msg $channel Time left: ".secstonormal($diff));
			} else {
				Irssi::print("Timeleft: $diff ??");
			}
		}
	}
}

sub do_command($$$) {
	my ($command,$nick,$server) = @_;

	$command = lc $command;
	$command =~ s/\s*$//;

	if ($command =~ /^!bang$/) {
		$server->command("msg $nick BOOM!");
	} elsif ($command =~ /^admin/) {
		if ($command !~ /^admin (.*)$/) {
			$server->command("msg $nick admin needs a nick to change the admin user to!");
		} else {
			Irssi::settings_remove("quiz_admin");
			Irssi::settings_add_str("misc","quiz_admin",$1);
			$server->command("msg $nick admin user is now $1");
		}
	} else {
		#$server->command("msg $nick Unknown command '$command'");
	}
}

#check check_answer for bad { }

sub check_answer($$$$) {
	my ($server,$channel,$nick,$text) = @_;
	my $game = $s->{$server->{'tag'}}->{$channel};

	return if not exists $game->{'teams'}->{$nick};

	#if $text exist check time and remembers it for end-game
	if (defined $text) {
		$game->{'time_last_text'} = time();
		}


	$text =~ s/\s*$//;
	$text =~ s/^ //;
	$text =~ s/ $//;
	
	#from cgi input-purify / try without it and it will crash with :( 
	#dont know if it needs em all, may check it in future
	
	if ($text =~ s/([\&;\`'\\\|"*?~<>^\(\)\[\]\{\}\$\n\r])/\\$1/g)
		{ $text="abcdef";
		}
	# is the above the reason it didnt join?

	#if greek supports troubles you comment the next
	$text =~ y/����������������ڼ�ۿ������������������������/���������������������������������������������/;

	my $answerNOtonos = lc $game->{'answer'};
	#if greek supports troubles you comment the next
	$answerNOtonos =~ y/����������������ڼ�ۿ������������������������/���������������������������������������������/;

	if ( $answerNOtonos =~ /\|/) { 

			if ( ($answerNOtonos =~ /\|$text\|/)||($answerNOtonos =~ /^$text\|/) ) 
			{
			$answerNOtonos =~ s/$text\|//;

	 		$game->{'answer'}=$answerNOtonos; 


			$server->command("msg $channel  2Correct answer by ".
			($game->{'teams'}->{$nick} eq "blue"?"12":"4").
			 $nick.": ".$text);

			$game->{$game->{'teams'}->{$nick}."score"}++;
			$game->{'scores'}->{$game->{'teams'}->{$nick}.$nick}++;

			if ($answerNOtonos eq "") { 

        			#putting it in used
				if (@{$game->{'used_questions'}}){
        			${$game->{'usedCounter'}} = @{$game->{'used_questions'}};
				} else {${$game->{'usedCounter'}}=0;}

        			${$game->{'used_questions'}}[${$game->{'usedCounter'}}]=${$game->{'the_question'}};

				$game->{'state'}="won";

				$server->command("msg $channel 2  $answerBAKforCHAOS") ;
				show_scores($game);
				return;
				}

			#show_scores($game);
			}
	}


                elsif (( $answerNOtonos !~ /\|/) && (lc $text eq $answerNOtonos))  {

			$server->command("msg $channel 2Correct answer by ".
			($game->{'teams'}->{$nick} eq "blue"?"12":"4").
			$nick.": ".$game->{'answer'});
			$game->{'state'}="won";

        			#putting it in used
				if (@{$game->{'used_questions'}}){
        			${$game->{'usedCounter'}} = @{$game->{'used_questions'}};
				} else {${$game->{'usedCounter'}} =0;}

        			${$game->{'used_questions'}}[${$game->{'usedCounter'}}]=${$game->{'the_question'}};

			$game->{$game->{'teams'}->{$nick}."score"}++;
			$game->{'scores'}->{$game->{'teams'}->{$nick}.$nick}++;
			show_scores($game);
			return;
		}



	my $show=0;
	my @chars = split //,$text;

	for (my $i=0; $i<length($game->{'answer'}); $i++) {
		if (lc $chars[$i] eq lc substr($game->{'answer'},$i,1)) {
			$show = 1 if substr($game->{'current_answer'},$i,1)
				eq "*";
			substr($game->{'current_answer'},$i,1) =
				substr($game->{'answer'},$i,1);
		}
	}

	$server->command("msg $channel Answer: ".$game->{'current_answer'})
		if $show;
}



sub event_privmsg {
	my ($server,$data,$nick,$address) = @_;
	my ($target, $text) = split / :/,$data,2;
	my ($command);

	if ($target =~ /^#/) {
		my $game = $s->{$server->{'tag'}}->{$target};
		if ($text =~ /^!/) {
			do_pubcommand($text,$target,$server,$nick);
		} elsif ($game->{'state'} eq "question") {
			check_answer($server,$target,$nick,$text);
		}
	} else {
		if ($nick ne Irssi::settings_get_str("quiz_admin")) {
			my ($passwd);
			($passwd, $command) = split /\s/,$text,2;
			if ($passwd ne Irssi::settings_get_str("quiz_passwd")) {
				#Irssi::print("$nick tried to do $command but got the password wrong.");
				Irssi::print("$nick got the password wrong.");
			}
		} else {
			$command = $text;
		}
		do_command($command,$nick,$server);
	}
}

sub event_changed_nick {
	my ($channel,$nick,$oldnick) = @_;
	my $server = $channel->{'server'};
	my $game = $s->{$server->{'tag'}}->{$channel->{'name'}};

	return if !$game->{'state'};
	
	my $nicktxt = $nick->{'nick'};
	if ($game->{'teams'}->{$oldnick}) {
		$game->{'teams'}->{$nicktxt} = $game->{'teams'}->{$oldnick};
		delete $game->{'teams'}->{$oldnick};
		}

}


}

Irssi::signal_add_last("event privmsg", "event_privmsg");
# Irssi::signal_add_last("massjoin", "sig_massjoin");
#Irssi::signal_add_last("message nick", "on_nick"); #when /nick
#Irssi::signal_add_last("message part", "on_part");
#Irssi::signal_add_last("message join", "on_join");
#Irssi::signal_add_last("message quit", "on_quit");

# Channel::nicks(channel) Return a list of all nicks in channel.

Irssi::signal_add("nicklist changed", "event_changed_nick");