IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage Perl Discussion :

Aide pour Bot IRC Perl


Sujet :

Langage Perl

  1. #1
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Octobre 2007
    Messages
    1
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2007
    Messages : 1
    Points : 1
    Points
    1
    Par défaut Aide pour Bot IRC Perl
    Bonjour
    Je suis debutant , je viens de créer un BOT Irc en perl,
    Jusqu'ici tout va bien il se connecte .....

    Maintenant je voudrais le faire parler

    voila mon bout de code

    sub on_public
    {
    my ($conn, $event) = @_;
    my $text = $event->{'args'}[0];
    my $range = 2;
    my $random_number = int(rand($range));
    $conn->privmsg($channel, $non-definie');
    }

    Donc en gros en fonction des mots sur le chan, je voudrais que le bot réponde ...

    ex:
    <moi> : Salut
    <réponse du bot> : Salut toi

    En gros je souhaite récupérer des mots tel que Salut qui se trouve dans la variable $text(salut) ensuite je voudrais lister tout les documents texte qui auront comme nom la variable $text (salut) si celui-ci existe alors je compte le nombre de ligne dans le fichier $text(Salut.txt) [sinon le bot reste inactif ] je definie la variable $range en fonction du resultat puis je fais un $random_number (my $random_number = int(rand($range)); )
    et j'affiche le resultat ( $conn->privmsg($channel, $non-definie'); )

    J'espere que vous allez pouvoir me donner un coup de pouce .....

    Merci d'avance

  2. #2
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    161
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 161
    Points : 89
    Points
    89
    Par défaut
    plop,

    Voici un bot que j'avais fais avec un pote y a pas mal de temps.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
     
    #!/usr/local/bin/perl -w           
    #By le_rasta && Nickname               
    #Thx chan #perl                             
    ###########################
     
    use IO::Socket;                             
    use strict;                                       
     
    ########VARIABLES############
     
    my $server = "irc.geekirc.org";
    my $nick = "bot_nick";
    my $login = "bot";
    my $channel = "#SoH";
    my $mess = "Tu me veux plus hein saligo";
    my @link=qw (<a href="http://www.bribes.org" target="_blank">www.bribes.org</a> <a href="http://www.cpan.org" target="_blank">www.cpan.org</a> perl.active-venture.com <a href="http://www.addict3d.org" target="_blank">www.addict3d.org</a> <a href="http://www.developpez.com" target="_blank">www.developpez.com</a> <a href="http://www.spiritofhack.net" target="_blank">www.spiritofhack.net</a>) ;
    my $choix=$link[rand(scalar(@link))];
    my $time= scalar(localtime);
     
    #############################################
    ##########PENDU#############
    my @mots = ("arbalette", "geek", "weed", "unmotquetutrouverapas", "anticonstitutionnellement", "elite", "apache", "oracle", "mongueurs");
    my $mot;
    my @lettres;
    my @pendus;
    my $faux;
    my $good;
    my $session = 0;
    my $narvalo;
    my @narvaloo;
    my $verif;
    my $poubelle;
     
    ##############################################
    #########SOCKET#############
    my $socket = new IO::Socket::INET(PeerAddr => $server,
                                    PeerPort => 6667,
                                    Proto => 'tcp') or die "tu pux du boule\n";
     
    print $socket "NICK $nick\r\n";
    print $socket "USER $login 8 * :$login\r\n";
    print $socket "JOIN $channel\r\n";
     
    #############################################
    #########PROG###############
     
    print $socket "PRIVMSG $channel :yeap all\n";
    #print $socket "PRIVMSG $channel :!start pour lancer le pendu, have fun! :\n";
    #print $socket "PRIVMSG $channel :donner une lettre ou dites 'stop' pour areter le jeu :\n";
    while (my $input = <$socket>) {
    chomp($input);
    chop ($input);   
        if ($input =~ /^PING(.*)$/i) {
            print $socket "PONG $1\r\n";
        }
       else {
            print "$input\n";
        }
        if($input =~ /^:(\S+)!(\S+)\@(\S+) PRIVMSG $channel :touff/gi){
    print $socket "PRIVMSG $channel :Vive rasta\n";
    }
        if($input =~ /^:(\S+)!(\S+)\@(\S+) PRIVMSG $channel :!away/gi){
    print $socket "AWAY :Pu la\n";
    }
        if($input =~ /^:(\S+)!(\S+)\@(\S+) PRIVMSG $channel :!retour/gi){
    print $socket "AWAY \n";
    }
     
        if($input =~ /^:(\S+)!(\S+)\@(\S+) PRIVMSG $channel :!leave/gi){
    print $socket "PRIVMSG $channel :$mess\n";
    exit(0);
    }
        if($input =~ /^:(\S+)!(\S+)\@(\S+) PRIVMSG $channel :!lien/gi){
    print $socket "PRIVMSG $channel :$link[rand(scalar(@link))]\n";
     
    }
        if($input =~ /^:(\S+)!(\S+)\@(\S+) PRIVMSG $channel :!time/gi){
    print $socket "PRIVMSG $channel :$time\n";
    }
     
    ##############################################
    ########PENDU###############
        if($input =~ /^:(\S+)!(\S+)\@(\S+) PRIVMSG $channel :\!stop/i)
          {
              if($session == 0)
              {
              print $socket "PRIVMSG $channel : le jeu est deja terminer bouffon ! :p \n";
              }
              else
              {
              $session = 0;
              print $socket "PRIVMSG $channel :le jeu est terminer !\n";
              }
          }
          elsif($input =~ /^:(\S+)!(\S+)\@(\S+) PRIVMSG $channel :\!start/i) {
          if($session == 1)
          {   
          print $socket "PRIVMSG $channel :le jeu est deja commencer bouffon ! :p \n";
          }
          else
          {   
          $session = 1;
          $mot = $mots[rand(scalar(@mots))];
          @lettres = split(//, $mot);
          print $socket "PRIVMSG $channel :le jeu du pendu a commencer !, donner une vos reponses sous la forme -> lettre: <lettre> ou mot: <mot>\n";
          my $cache = "-" x length($mot);
          print $socket "PRIVMSG $channel :voila le mot caché: $cache \n";
          @pendus = split(//, $cache);
          $faux = 0;
          $good = 0;
          $narvalo = "0-|--<";
          @narvaloo = split(//, $narvalo);
          $poubelle = undef;
          $verif = undef;
          }
          }
     
          elsif($input =~ /^:(\S+)!(\S+)\@(\S+) PRIVMSG $channel :(lettre: |mot: )(.+)/i)
          {
          my $type = $4;
          my $text = $5;
          my $auteur = $1;
          print "$type $text\n";
     
              if($session == 1)
              {
     
             if($type eq "lettre: " && $text =~ /^[a-zA-Z]{2,}$/) { print $socket "PRIVMSG $channel :il faut qu'une lettre! pas 2 ni 3 tricheur ! :p \n"; }
     
             elsif($type eq "lettre: " && $text =~ /^[a-zA-Z]{1}$/)
             {
             my $correct = 0;
             if($poubelle =~ /$text/i) { print $socket "PRIVMSG $channel : bien essayer ! mais marche pas lettre deja dite !\n"; }
             else
             {
                 for(my $i = 0; $i<@lettres; $i++)
                 {
                 my $total;
     
                if($text eq $lettres[$i])
                {
     
                $poubelle .= $text;
                $pendus[$i] = $text;
                print $socket "PRIVMSG $channel :yeah $auteur tu a trouver la lettre $text !\n";
     
                    foreach (@pendus) { $total .= $_; }
     
                print $socket "PRIVMSG $channel :mot cache : $total\n";
                $good++;
                $correct = 1;
                    if($good == length($mot)) { print $socket "PRIVMSG $channel :Chapeau bas a l'artiste ... le mot etait bien $mot =]\n"; $session = 0; }
                }
                 }
                if($correct == 0)
                {
                $verif .= $narvaloo[$faux];
                print $socket "PRIVMSG $channel :pendu: $verif \n";
                $faux++;
                    if($faux == 6) { print $socket "PRIVMSG $channel :Gardes !! kon pende $auteur sur le champ !!! =P [ le mot etait $mot ] \n"; $session = 0; }
                }
     
             }
              }
             elsif($type eq "mot: " && $text =~ /\w+/)
             {
                 if($text eq $mot) { print $socket "PRIVMSG $channel :bien jouer tu a trouver le mot : c bien $mot \n"; $session = 0;}
                 else
                 {
                 $verif .= $narvaloo[$faux];
                 print $socket "PRIVMSG $channel :pendu: $verif \n";
                 $faux++;
                 if($faux == 6) { print $socket "PRIVMSG $channel :Gardes !! kon pende $auteur sur le champ !!! =P \n"; }
                 }
             }
     
              }
          }
    ##############################################
    }                    
    #####################FIN#######################
    ################LE PERL EST MERVEILLEUX#############
    ###################BY NICKNAME##################
    En espérant que ca réponde à ta question

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
      if($input =~ /^:(\S+)!(\S+)\@(\S+) PRIVMSG $channel :salut/gi){
    print $socket "PRIVMSG $channel :salut toi\n";
    }

  3. #3
    Nouveau Candidat au Club
    Inscrit en
    Septembre 2010
    Messages
    1
    Détails du profil
    Informations forums :
    Inscription : Septembre 2010
    Messages : 1
    Points : 1
    Points
    1
    Par défaut
    Citation Envoyé par Nickname Voir le message

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
      if($input =~ /^:(\S+)!(\S+)\@(\S+) PRIVMSG $channel :salut/gi){
    print $socket "PRIVMSG $channel :salut toi\n";
    }
    plop, je suis parti de ton bot aussi pour créer un bot IRC
    cependant j'aurai besoins de quelques explications pour implémenter une fonctionnalités:
    si j'envoi le message privé au bot suivant:
    !msgs ce que j'ai a dire
    qu'il écrit ce qui suit après "!msgs "

    par rapport au code ci dessous:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    if($input =~ /^:(\S+)!(\S+)\@(\S+) PRIVMSG $nick :msgs/gi){
    my ..... = $monmessage
    print $socket "PRIVMSG $channel :$monmessage\n";
    }
    je dois mettre quoi?

    car si je mets directe
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    print $socket "PRIVMSG $channel :$input
    ça donne ce retour:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    :nomdelauteur!~clientIRC@gateway/monnomPC/nomdupc/x-iovpvzmxapygkqpj PRIVMSG nomdubot :msgs tout ce qui suit apres msgs

  4. #4
    Membre confirmé
    Avatar de Schmorgluck
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    371
    Détails du profil
    Informations personnelles :
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations forums :
    Inscription : Mai 2006
    Messages : 371
    Points : 558
    Points
    558
    Par défaut
    Vous avez envisagé d'utiliser le module Bot::BasicBot ?
    There's nothing like $HOME!

Discussions similaires

  1. Besoin aide pour bot en python.
    Par -Xoom- dans le forum Programmation multimédia/Jeux
    Réponses: 0
    Dernier message: 04/04/2010, 16h04
  2. bot irc perl
    Par Mirelagord dans le forum Langage
    Réponses: 2
    Dernier message: 09/02/2009, 22h13
  3. aide pour explication synthaxe perl
    Par donny dans le forum Langage
    Réponses: 5
    Dernier message: 29/10/2008, 12h57
  4. Besoin d'aide pour traduire du perl
    Par king_neo2001 dans le forum Langage
    Réponses: 5
    Dernier message: 22/05/2007, 15h10
  5. aide pour debutant en perl
    Par donny dans le forum Langage
    Réponses: 3
    Dernier message: 30/08/2006, 18h13

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo