Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/perl -w
- use strict;
- use IO::Socket;
- ### INSERIMENTO DATI NELLE VARIABILI ###
- my $server = "irc.unitx.net";
- my $nick = "BotSenzascopo";
- my $user = "BotSenzascopo";
- my $pass = "tuamamma";
- my $login = "BotSenzascopo";
- my $channel = "#unit-x";
- ### CONNESSIONE AL SERVER ###
- my $sock = new IO::Socket::INET(PeerAddr => $server,
- PeerPort => 6667,
- Proto => 'tcp') or
- die "Non posso connettermi a $server\n";
- ### LOGIN ###
- print $sock "PASS $pass\r\n";
- print $sock "NICK $nick\r\n";
- print $sock "USER $login 8 * :$nick\r\n";
- print $sock "MODE $channel +m $nick\n";
- print $sock "JOIN $channel\r\n";
- print $sock "PRIVMSG $channel :Ciao a tutti! ;)\r\n";
- &azioni;
- sub azioni {
- ### AZIONI DEL BOT ###
- while (my $input = <$sock>) {
- chomp $input;
- if ($input =~ /^PING(.*)$/i) {
- print $sock "PONG $1\r\n";
- }
- else {
- print "$input\n";
- }
- if ($input =~ /^:?.+?!~?.+?@[^ ]+ PRIVMSG $channel :!start$/) {
- open FILE, "<", "domande.txt" or die "Errore: $!\n";
- my $content;
- while (<FILE>) {
- $content .= $_;
- }
- my $domande = {};
- my @lines = split /\n/, $content;
- for (my $i = 0; $i < scalar (@lines); $i += 2) {
- my $domris = $lines[$i] . "\n" . $lines[$i + 1];
- if ($domris =~ /d(\d+) ([^\n]+).+?r\d+ ([^\n]+)$/ims) {
- $domande->{$1} = {"domanda" => $2, "risposta" => $3};
- }
- }
- my @ordinato = sort {$a <=> $b} keys %{$domande};
- foreach my $info (@ordinato) {
- print $sock "PRIVMSG $channel :Domanda numero ${info}: $domande->{$info}->{'domanda'} \r\n";
- my $risposta= $domande->{$info}->{"risposta"};
- if ($input =~ /^$risposta$/) {
- print "Complimenti! Hai indovinato!\n"
- }
- }
- } ### Fine Play ###
- }
- } ### Fine sub Azioni ###
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement