SHARE
TWEET

Untitled

a guest Jun 5th, 2017 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/local/bin/perl -w
  2.  
  3. use strict;
  4.  
  5.  
  6. use IO::Socket;
  7. ### INSERIMENTO DATI NELLE VARIABILI ###
  8. my $server = "irc.unitx.net";
  9. my $nick = "BotSenzascopo";
  10. my $user = "BotSenzascopo";
  11. my $pass = "tuamamma";
  12. my $login = "BotSenzascopo";
  13. my $channel = "#unit-x";
  14.  
  15. ### CONNESSIONE AL SERVER ###
  16.  
  17.  
  18. my $sock = new IO::Socket::INET(PeerAddr => $server,
  19.                                 PeerPort => 6667,
  20.                                 Proto => 'tcp') or
  21.                                     die "Non posso connettermi a $server\n";
  22.  
  23.  
  24. ### LOGIN ###
  25. print $sock "PASS $pass\r\n";
  26. print $sock "NICK $nick\r\n";
  27. print $sock "USER $login 8 * :$nick\r\n";
  28.  
  29.  
  30.  
  31. print $sock "MODE $channel +m $nick\n";
  32.  
  33. print $sock "JOIN $channel\r\n";
  34.  
  35. print $sock "PRIVMSG $channel :Ciao a tutti! ;)\r\n";
  36.  
  37.  
  38.  
  39. &azioni;
  40. sub azioni {
  41.  
  42.  
  43. ### AZIONI DEL BOT ###
  44. while (my $input = <$sock>) {
  45.     chomp $input;
  46.     if ($input =~ /^PING(.*)$/i) {
  47.  
  48.         print $sock "PONG $1\r\n";
  49.     }
  50.     else {
  51.  
  52.         print "$input\n";
  53.         }
  54.        
  55.        
  56.         if ($input =~ /^:?.+?!~?.+?@[^ ]+ PRIVMSG $channel :!start$/)  {
  57.            
  58.            
  59. open FILE, "<", "domande.txt" or die "Errore: $!\n";
  60.  
  61. my $content;
  62. while (<FILE>) {
  63.     $content .= $_;
  64. }
  65.  
  66. my $domande = {};
  67. my @lines = split /\n/, $content;
  68. for (my $i = 0; $i < scalar (@lines); $i += 2) {
  69.     my $domris = $lines[$i] . "\n" . $lines[$i + 1];
  70.     if ($domris =~ /d(\d+) ([^\n]+).+?r\d+ ([^\n]+)$/ims) {
  71.         $domande->{$1} = {"domanda" => $2, "risposta" => $3};
  72.     }
  73. }
  74.  
  75. my @ordinato = sort {$a <=> $b} keys %{$domande};
  76. foreach my $info (@ordinato) {
  77.     print $sock "PRIVMSG $channel :Domanda numero ${info}: $domande->{$info}->{'domanda'} \r\n";
  78.    
  79.     my $risposta= $domande->{$info}->{"risposta"};
  80.    
  81.         if ($input =~ /^$risposta$/) {
  82.            
  83.  
  84.     print "Complimenti! Hai indovinato!\n"
  85.    
  86.     }
  87. }
  88.  
  89.  
  90.            
  91.            
  92.            
  93.            
  94.            
  95.         } ### Fine Play ###
  96.    
  97.    
  98.  
  99.    
  100.    
  101.  
  102. }
  103. } ### Fine sub Azioni ###
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top