Ia bot

Description

C'est un bot qui sera rien dire et vous devez lui aprendre à parler. Le bot aprend relativement rapidement (disons qu'en 10minutes de conversation il connait pas mal de mot). L'interrêt de la chose est ... euh ... bah j'avais scripté ça par défi, on peut critiquer mon système mais il a l'avantage d'être simple, ludique et rapide.
Si vous arrivez à faire un bot qui s'exprime assez bien vous pouvez m'envoyer la bd à tiot@redpowa.com je la posterai sur mon site (http://moipetit.free.fr/ia/) essayez de ne pas écrire comme un porc.

Normalement cette add-on ne marche que sur mIRC 6.03 et 6.1x

Source / Exemple :


;*******************************************
;***                                     ***
;**                                       **
;*       IA BOT VERSION 1.5b BY TIOT        *
;*                                         *
;**                                       **
;***                                     ***
;*******************************************

;La super moderne menubar 
menu menubar {
  ia 
  .config:dialog -m ia ia
  .connection:if ((%ia.ip) && (%ia.port)) if (%ia.nick) ia.co
  .déconnection:{ .timeria off | if ($hget(ia)) hsave -o ia ia/ia.hash | hfree -w ia* | ia.s QUIT :ia bot by tiot }
}

;-----------------------------
;
;         LES REMOTES
;
;-----------------------------

;un tit dialog
dialog ia {
  title "ia config"
  size -1 -1 197 172
  option dbu

  button "Annuler",77, 73 132 37 12, cancel
  button "OK", 5, 16 131 37 12, ok
  edit %ia.ip,1,60 19 75 10 
  edit %ia.port,2, 60 34 75 10  
  edit %ia.nick,3, 60 49 75 10
  edit %ia.Md,4, 60 64 75 10
  edit %ia.JOIN, 7, 60 79 75 10
  edit %ia.call, 8, 60 94 75 10
  text "Serveur",10,7 20 50 8, center
  text "Port",11,7 35 50 8, center
  text "Nickname",12, 7 50 50 8, center
  text "Mode par défault",13,7 65 50 8, center
  text "chans join",14,7 80 50 8, center
  text cmde d'apelle,15,7 95 50 8, center
  check "log pv",61,140 19 50 10
  check "fenetre debug",62,140 29 50 10
}

on 1:dialog:ia:init:0:{
  if (%ia.log) did -c ia 61
  if (%ia.debug) did -c ia 62
}

;Quand on appuie sur "ok" çà sauve tout
on 1:dialog:ia:sclick:5:{
  set %ia.ip $did(1).text
  set %ia.port $did(2).text
  set %ia.nick $did(3).text
  set %ia.Md $did(4).text
  set %ia.join $did(7).text
  set %ia.call $iif($left($did(8).text,1) != :,:) $+ $did(8).text
  set %ia.log $did(61).state
  set %ia.debug $did(62).state
}

on 1:load:{
  if ($version < 6.00) { echo -a 12Votre version de mIRC est trop vielle pour suporter cette add-on | return }
  if ($version < 6.03) echo -a 12Version mIRC <6.03 des commandes ne marcheront plus : /ia.saveBD !eff !wm et surment d'autre commandes
  mkdir ia
  mkdir ia\log
  if (!%ia.port) {
    set %ia.port 6667
    set %ia.nick ia
    set %ia.Md n
    set %ia.call ia
  }
  echo -a 12Ia bot chargé dans votre mIRC
}

on 1:exit:if ($hget(ia)) hsave -o ia ia\ia.hash

;***************************
;****                   ****
;***                     ***
;**      LES SOCKETS      **
;***                     ***
;****                   ****
;***************************

;Sert à faire envoyer des cmdes aux serveur à la main
alias ia.s sockwrite -n ia $1-

;Sert à se connecter au serveur
alias ia.co sockopen ia %ia.ip %ia.port

on 1:sockopen:ia:{
  sockwrite -n ia NICK %ia.nick
  sockwrite -n ia USER ia "" "" :ia by tiot
  echo -a 2Connection ouverte
}

on 1:sockread:ia:{
  if ($sockerr > 0) return 
  var %temp
  sockread %temp 
  tokenize 32 %temp  
  if ($1 == PING) sockwrite -n $sockname PONG $2

  ;On fait un montage, si c sur un salon à fait : 
  ;ia.traite $chan $nick phrase
  ;si c'est dans un pv
  ;ia.traite $nick $nick phrase

  elseif ($2 == PRIVMSG) {
    ;%temp contiendra l'host du gars, cela m'évite de le passer en paramètre.
    set %ia.temp $gettok($1,2,64)
    if ($asc($3) == 35) { if ($strip($4) == %ia.call) ia.traite $3 $right($gettok($1,1,33),-1) $strip($5-) }
    else ia.traite $right($gettok($1,1,33),-1) $right($gettok($1,1,33),-1) $strip($right($4-,-1))
  }
  ;Si le nick est déjà prit on rajoute un `
  elseif ($2 == 433) sockwrite -n ia NICK %ia.nick $+ ` 
  elseif ($2 == 001) { if (%ia.join) sockwrite -n ia JOIN %ia.join | echo -a 2Bot connecté }

}

;***************************
;****                   ****
;***                     ***
;**       LES ALIAS       **
;***                     ***
;****                   ****
;***************************

;-----------------------
;
;LES ALIAS INDIPENSABLE
;
;-----------------------

;Vas traiter l'entrée.
;$1 = Où il doit dire la phrase.
;$2 = Nick du gars
;$3- = phrase dite par le gars
;%ia.temp = qqch qui identifie la personne. Par default (avec les socket) c l'host de la personne

alias ia.traite {
  ;%c = Phrase dite par la personne
  ;%ia.axx = access de la personne (l n c o a) 

  var %c,%ia.axx
  %ia.axx = $ia.axx(%ia.temp)

  ;On inianalise
  if (!$hget(ia)) ia.init

  if ($left($3,1) == !) {
    if ($3 == !help) ia.out $1 Toutes l'aide sur ce bot se trouve sur: 2http://moipetit.free.fr/ia/readme.htm 
    elseif ($3 == !syn) { 
      if ($ia.axx2(%ia.axx,c)) ia.out $1 $gettok($ia.syn($4-),2-,32) 
      else ia.out $1 Access insufisant     
    }
    elseif ($3 == !eff) {
      if ($ia.axx2(%ia.axx,c)) ia.out $1 $gettok($ia.eff($4-),2-,32)
      else ia.out $1 Access insufisant 
    }
    elseif ($3 == !non) {
      if (!$ia.axx2(%ia.axx,l)) { ia.out $1 Access insufisant | return }
      if ($hget(ia,t2. $+ %ia.temp) != $null ) {
        hadd ia t1. $+ %ia.temp $hget(ia,t2. $+ %ia.temp)
        ia.CmotP $4-
      }
      hadd ia t3. $+ %ia.temp $hget(ia,t2. $+ %ia.temp)    
      hadd ia t2. $+ %ia.temp $hget(ia,t1. $+ %ia.temp)
      hadd ia t1. $+ %ia.temp $4-
      ia.out $1 $iif($asc($1) == 35,$2 $+ :) $4-
    }
    elseif ($3 == !reco) {
      hdel -w ia t?. $+ %ia.temp
      hadd ia idk. $+ %ia.temp 1    
      ia.out $1 La conversation recommence depuis le début
    }
    elseif ($3 == !stats ) ia.out $1 Je connais $hget(ia,Nbr) phrases, $hfind(ia,^m([^?])+$,0,r) mots et ma bd pèse $bytes($file(ia\ia.txt).size).suf    
    elseif ($3 == !version) ia.out $1 Ia bot version 1.5b by tiot (2http://moipetit.free.fr/ia/)     
    elseif ($istok(!addm !delm !addp !Wm !Wp !Remplace,$3,32)) {
      if ($ia.axx2(%ia.axx,c)) {
        var %c
        if ($3 == !addm) %c = $ia.addm($4-)
        elseif ($3 == !delm) %c = $ia.delm($4-)
        elseif ($3 == !addp) %c = $ia.addp($4-)
        elseif ($3 == !wp) %c = $ia.wp($4-) 
        elseif ($3 == !wm) %c = $ia.wm($4-)
        elseif ($3 == !remplace) %c = $ia.Remplace($4-)
      }
      ia.out $1 $gettok(%c,2-,32)
      else ia.out $1 Access insufisant     
    } 
    elseif ($istok(!auth !addh !delh !listh !addaxx !delaxx !listaxx,$3,32)) return $ia.BotAxx($1,$3-)    
    return
  }

  ;bordel
  %c = $ia.cher($3-,$hget(ia,t1. $+ %ia.temp))
  if ($ia.axx2(%ia.axx,l)) ia.CmotP $3-

  if ($asc($1) == 35) ia.out $1 $2 $+ : %c
  else {
    if (%ia.log) {
      write ia\log\ $+ %ia.temp $+ $date(dd.mm.yy) $+ .log $timestamp $+(<,$1,>) $3- 
      write ia\log\ $+ %ia.temp $+ $date(dd.mm.yy) $+ .log $timestamp $+(<,%ia.nick,>) %c
    }
    if (%ia.debug) {
      if (!$window(@Ia)) window -en @ia
      aline @ia $2 -> $3-
      aline @ia %ia.nick -> %c
    }
    ia.out $1 %c
  }
  ;ia,idk = 1 si il a trouver une réponse, sinon il est égal à 0
  if (!$hget(ia,idk. $+ %ia.temp)) { 
    hadd ia t3. $+ %ia.temp $hget(ia,t2. $+ %ia.temp)    
    hadd ia t2. $+ %ia.temp $hget(ia,t1. $+ %ia.temp)
    hadd ia t1. $+ %ia.temp $3-
    hadd ia idk. $+ %ia.temp 1
  }
  else {
    hadd ia t3. $+ %ia.temp $hget(ia,t2. $+ %ia.temp)    
    hadd ia t2. $+ %ia.temp $3-
    hadd ia t1. $+ %ia.temp %c
  }
}

;$1 = #canaux/nick vers lequelle vas le msg
;$2- = phrase que le bot dit
;C'est l'alias qui indique la sortit, dans ce le cas par default c un socket. 
alias ia.out {
  sockwrite -n ia PRIVMSG $1 : $+ $2- 
}

;Vas lié chaque mot de $hget(ia,t1. $+ %ia.temp) avec la phrase $1-
alias ia.CmotP { 
  var %P = $hget(ia,t1. $+ %ia.temp),%ia.Np,%b,%a,%c
  if ($read(ia\ia.txt,w,$1-)) %ia.Np = $readn
  else {
    write ia\ia.txt $1- 
    hinc ia Nbr 
    %ia.Np = $hget(ia,Nbr) 
  }
  %P = $replace(%P,$chr(44),$chr(32),',$chr(32),?,$chr(32) $+ ?)
  %P = $remove(%P,?)
  %b = $numtok(%P,32)
  while (%b) {
    %c = %a
    %a = $gettok(%P,%b,32)
    dec %b
    if ($hgeti(ia,eff,%a)) continue
    if ($hgetg(ia,s. $+ %a,1) == 0) %a = $hgetg(ia,s. $+ %a,2)
    %c = %a $+ ? $+ %c
    ia.LPM %a %ia.Np
    ia.LPM %c %ia.Np
  }
  hdel -w ia m.*?
  hdel -w ia m.?*  
  return 1 Les phrase sont bien lié
}

;C'est l'alias qui vas chercher la bonne phrase celon $1 et $2
;$1 est la phrase primordial et $2 au cas où 
alias ia.cher {
  hdel -w ia2 *
  if (($numtok($1,32) < 4) && ($2 != $null)) tokenize 32 $1 $1 $2
  else tokenize 32 $1
  var %list,%phrase,%a1,%c1,%c2,%a2,%b,%a,%b2,%b1 = $0,%Max = 0

  ;%Phrase = c la phrase qu'il va sortir
  ;%List = liste des n° de phrases possible 
  ;%a1 = c un MOT de la phrase
  ;%c1 = c un groupe de mot de la phrase
  ;%a2 = c une des phrases liées a %a1
  ;%b,%b1,%b2 = compteurs de boucle
  ;%Max = max de fois qu'une phrase est cité

  while (%b1) {
    %c1 = %a1     
    %a1 = $gettok($1-,%b1,32)
    if ($hgetg(ia,s. $+ %a1,1) == 0) %a1 = $hgetg(ia,s. $+ %a1,2) 
    %c1 = %a1 $+ ? $+ %c1  
    %b2 = $numtok($ia.m(%a1),32)
    while (%b2) {
      %a2 = $gettok($ia.m(%a1),%b2,32)    
      hinc ia2 %a2   
      if ($hget(ia2,%a2) > %Max) %Max = $ifmatch
      dec %b2    
    }

    %b2 = $numtok($ia.m(%c1),32)
    while (%b2) {
      %a2 = $gettok($ia.m(%c1),%b2,32)     
      hinc ia2 %a2 2
      if ($hget(ia2,%a2) > %Max) %Max = $ifmatch
      dec %b2    
    }
    dec %b1
  }
  ;On recherche les phrases les plus cités.
  %b = $hfind(ia2,%max,0,n).data
  while (%b) {
    if ($len(%list) > 900) break
    %list = %list $hfind(ia2,%max,%b,n).data  
    dec %b  
  }

  ;%phrase contient maintenant la phrase final, il faut maintenant chercher les synonymes. 
  %phrase = $read(ia\ia.txt,$gettok(%list,$rand(1,$numtok(%list,32)),32)) 
  %b = $numtok(%phrase,32)
  while (%b) {
    %a = $gettok(%phrase,%b,32)
    if ($hget(ia,s. $+ %a) != $null) {
      if ($hgetg(ia,s. $+ %a,1) == 0) %a = $hgetg(ia,s. $+ %a,2) 
      %a = $hget(ia,s. $+ %a)      
      %a = $gettok(%a,$rand(2,$numtok(%a,32)),32))
      %Phrase = $puttok(%Phrase,%a,%b,32)
    }
    dec %b
  }
  if (%Phrase == $null) { hadd ia idk. $+ %ia.temp 0 | return j'aurais du dire ... ? }
  else return %Phrase
}

;Lié Le mot $1 avec la phrase n° $2
;-Si $2 est déjà dans $1 on le met en pôle position
;-Si l'item est remplit on vire le dernièrs token et on place notre $2 en -20 position
:-tout ce passe bien on le met normal (en dernièrs position comme même)
alias ia.LPM {
  if ($hgeti(ia,m. $+ $1,$2)) {
    hdelt ia m. $+ $1 $2
    hadd ia m. $+ $1 $2 $ia.m($1)
    return 1
  }
  if ($len($ia.m($1)) > 900) {
    hadd ia m. $+ $1 $instok($deltok($ia.m($1),-1,32),$2,-20,32)
    return 1
  }
  haddt ia m. $+ $1 $2
  return 1
}

;$1 = access de la personne
;$2 = commande qu'il veut éxercé (c l a o)
;return 1 si il peut éxercer la commande, sinon 0.
;Cette alias sert uniquement si vous voulez intégré l'ia à votre bot.  
alias ia.axx2 {
  if ($2 isin $1) return 1
  else return 0
}

;Cette alias retourne l'access de la personne par raport à %ia.temp (par défault contient l'host). 
;Vous pouvez ici personalisez vos access pour intégrer l'ia à votre bot. 
alias ia.axx {
  if ($hget(ia,a. $+ $1) != $null) return $ifmatch
  else return %ia.Md
}

;retourne les lien du mot $1 (c un alias de fainiantise)
alias ia.m return $hget(ia,m. $+ $1)

;Cette alias sert à inialiser le bot. 
alias ia.init {
  .hmake -s ia 100
  if (!$hget(ia2)) .hmake -s ia2 100
  if ($exists(ia\ia.hash)) hload ia ia\ia.hash
  else {
    hadd ia eff la le un une l' des les d'
    hadd ia a. $+ %ia.temp olac 
  }
  hadd ia Nbr $lines(ia\ia.txt)
  .timeria 0 300 hsave -o ia ia\ia.hash 
  if ($hget(ia,NL) != $null) ia.ConBD
}
;-------------------------------------------------------------------
;
;Les alias indispensables et qui peuvent servir dans d'autre script
;
;-------------------------------------------------------------------

;Rajoute $3 à la listes de token de l'item $2 de la hash $1
alias haddt hadd $1 $2 $addtok($hget($1,$2),$3,32)

;Enlève $3 à la listes de token de l'item $2 de la hash $1
alias hdelt hadd $1 $2 $remtok($hget($1,$2),$3,1,32)

;Retourne $true si $3 est dans la liste de token de l'item $2 de la hash $1
alias hgeti return $istok($hget($1,$2),$3,32)

;Return le $3 de la listes des token de l'item $2 de la hash $1
alias hgetg return $gettok($hget($1,$2),$3,32)

;---------------------
;
;Les alias optionnels
;
;---------------------

;-0 para : liste des synonymes
;-1 para : liste des synonymes de 1
;-2 para : mettre $1 synonyme à $2
alias ia.syn {
  tokenize 32 $1-
  if (!$1) {
    var %list,%b = $hfind(ia,s.*,0,w) 
    while (%b) {
      %list = $addtok(%list,$right($hfind(ia,s.*,%b,w),-2),32)
      dec %b
    }     
    return 1 %list
  }
  if (!$2) {
    ;La on recherche tous les synonyme du mot et les balance. Si le mot n'existe pas on fait un return
    ;Si par contre le première lettre est "0" (cad ce n'est pas un syn de référence, on balance le syn de ref)
    if (!$hget(ia,s. $+ $1)) return 0 $1 n'a aucun synonyme 
    if (!$hgetg(ia,s. $+ $1,1)) tokenize 32 $hgetg(ia,s. $+ $1,2)
    return 1 $hgetg(ia,s. $+ $1,2-)
  }
  ;Il y a un synonyme de référence, c lui qui à tout les liens.
  ;Chaque synonyme on pour nom "s.Nom" leur item contient "N syn", N est de 0 si le synonyme n'est pas de référence.
  ;Si n = 1 alors le synonyme est dé référence, et tout ce qui est après le N se sont les synonyme qui se réfère à lui
  ;Donc une prise de tête en perspective pour gérer tout çà 
  :syn    
  var %a1 = $hget(ia,s. $+ $1),%a2 = $hget(ia,s. $+ $2),%c1 = $gettok(%a1,2-,32),%c2 = $gettok(%a2,2-,32),%r1 = $gettok(%a1,1,32),%r2 = $gettok(%a2,1,32)
  ;A chaque fois le 1 c pour $1 et le 2 pour $2 (dans les var)
  :%a = N syn (est nul si $1 n'a aucun synonyme)
  ;%c = liste des syonyme 
  ;%r = 1 si synonyme est de référence sinon 0

  ;si $1 n'existe pas
  if (!%a1) {
    ;si $1 et $2 n'ont aucun synonyme 
    if (!%a2) {
      hadd ia s. $+ $1 1 $2
      hadd ia s. $+ $2 0 $1
      ia.ccl $2 $1
      ia.RP $2 $1
    }
    ;si $1 n'existe pas et $2 lui éxiste. 
    else {
      ;si $2 est une référence
      if (%r2) {
        haddt ia s. $+ $2 $1
        hadd ia s. $+ $1 0 $2
        ia.ccl $1 $2     
        ia.RP $1 $2    
      }
      ;si $2 n'est pas une référence (mais $1 n'éxiste pas) on dit $1 synonyme de la référence de $2
      else {
        haddt ia s. $+ %c2 $1
        hadd ia s. $+ $1 0 %c2
        ia.ccl $1 %c2 
        ia.RP $1 %c2
      }
    }
  }
  ;Par contre si $1 n'est pas null 
  else {
    ;Si $1 est une référence 
    if (%r1) {
      ;Si $2 n'éxiste pas
      if (!%a2) {
        haddt ia s. $+ $1 $2
        hadd ia s. $+ $2 0 $1
        ia.ccl $2 $1
        ia.RP $2 $1
      }
      ;Si $2 éxite 
      else {
        ;Si $2 et $1 sont des référence alors $1 devient la référence de $2 est donc des référencés de $2
        if (%r2) {
          var %a,%b = $numtok(%a2,32)
          while (%b) {
            %a = $gettok(%a2,%b,32)
            haddt ia s. $+ $1 %a 
            hadd ia s. $+ %a 0 $1           
            dec %b
          }
          haddt ia s. $+ $1 $2
          hadd ia s. $+ $2 0 $1
          ia.ccl $2 $1
          ia.RP $2 $1
        }
        ;$1 est une référence et $2 a pour référence %a2. Donc $1 synonyme de %c2
        else {
          if ($1 == %c2) return 0 $1 déjà synonyme avec $2
          tokenize 32 $1 %c2
          goto syn 
        }
      }
    }
    ;Si $1 éxiste mais n'est pas une référence, donc il est référencé à %c1
    else {
      ;Cela revient à $2 synonyme de %c1
      if ($2 == %c1) return 0 $1 déjà synonyme avec $2 
      tokenize 32 %c1 $2
      goto syn  
    }      
  }
  return 1 $1 Synonyme bien enregistré   
}

;Copie les liens de $1 dans $2 puis efface $1
alias ia.ccl {
  var %a = $ia.m($1),%b = $numtok(%a,32)
  while (%b) {
    ia.LPM $2 $gettok(%a,%b,32)
    dec %b
  }
  hdel ia m. $+ $1
}

;Remplace dans toutes les phrase $1 par $2 et dans tous les groupes de mots.
alias ia.RP {
  var %b = 1,%c,%d,%b2
  while ($read(ia\ia.txt,w,* $+ $1 $+ *,%b)) {
    %d = $ifmatch    
    %c = $readn
    %b = %c
    %b2 = $findtok(%d,$1,0,32)
    while (%b2) {
      write -l $+ %c ia\ia.txt $reptok(%d,$1,$2,%b2,32)
      dec %b2
    }
    inc %b
  }
  %b = $hfind(ia,m. $+ $1 $+ ?*,0,w)
  while (%b) {
    %c = $hfind(ia,m. $+ $1 $+ ?*,%b,w)
    dec %b
    if ($hget(ia,m. $+ $2 $+ ? $+ $gettok(%c,2,164)) != $null) { ia.ccl %c $2 $+ ? $+ $gettok(%c,2,164) | continue }
    hadd ia m. $+ $2 $+ ? $+ $gettok(%c,2,164) $hget(ia,%c)
    hdel ia %c
  }
  %b = $hfind(ia,m.*? $+ $1,0,w)
  while (%b) {
    %c = $hfind(ia,m.*? $+ $1,%b,w)
    dec %b
    if ($hget(ia,m. $+ $gettok(%c,1,164) $+ ? $+ $1) != $null) { ia.ccl %c $gettok(%c,1,164) $+ ? $+ $1 | continue }
    hadd ia m. $+ $gettok(%c,1,164) $+ ? $+ $1 $hget(ia,%c)
    hdel ia %c
  }
}

;Efface la phrase $1- ou le n° de phrase $1
alias ia.eff {
  tokenize 32 $1-
  if ($1 == null) return 0 Pas assez de paramètre
  if ($1- !isnum) {
    if ($read(ia\ia.txt,w,$1-) == $null) return 0 La phrase n'existe pas
    tokenize 32 $readn
  }
  write -l $+ $1 ia\ia.txt --- ligne éffacé --- $ticks
  ;Le (^|\s) $+ $1 $+ (\s|$) et pour "$1 mot de l'item"
  %b = $hfind(ia,(^|\s) $+ $1 $+ (\s|$),0,r).data
  while (%b) {
    %c = $hfind(ia,(^|\s) $+ $1 $+ (\s|$),%b,r).data
    ;Le if sert à savoir si on loock bien un mot
    if ($left(%c,2) == m.) hdelt ia %c $1 
    dec %b
  }
  return 1 Phrase corectement éffacé. 
}

;---------------------------------------------
;
; ALIAS DE MODIFICATION DE LA BD AVANCÉE 
;
;----------------------------------------------

;Lie les mots $2- à la phrase n° $1 
;$1 = n° de phrase valide
;$2- = mot 
alias ia.addm {
  tokenize 32 $1-  
  if ($2 == $null) return 0 Pas assez de paramètre 
  if ($1 !isnum) return 0 $1 n'est pas un n° 
  if ($1 > $hget(ia,Nbr)) return 0 $1 ne corespond à aucune phrase 
  var %a,%b = $numtok($2-,32)
  while (%b) {
    %a =  $gettok($2-,%b,32)
    if (? isin %a) {
      if ($hgetg(ia,s. $+ $gettok(%a,1,164),1) == 0) %a = $hgetg(ia,s. $+ $gettok(%a,1,164),2) $+ ? $+ $gettok(%a,2,164) 
      if ($hgetg(ia,s. $+ $gettok(%a,2,164),1) == 0) %a = $gettok(%a,1,164) $+ ? $+ $hgetg(ia,s. $+ $gettok(%a,2,164),2)  
    }
    if ($hgetg(ia,s. $+ %a,1) == 0) %a = $hgetg(ia,s. $+ %a,2)   
    ia.LPM %a $1
    dec %b
  }
  return 1 Les mots $2- on été lié à la phrase n° $1 
}

alias ia.delm {
  tokenize 32 $1-
  if ($2 == $null) return 0 Pas assez de paramètre 
  if ($1 !isnum) return 0 $1 n'est pas un n° 
  if ($1 > $read(ia\ia.txt,0)) return 0 $1 ne corespond à aucune phrase 
  var %b = $numtok($2-,32)
  while (%b) {
    hdelt ia m. $+ $gettok($2-,%b,32) $1
    dec %b
  }
  return 1 Les mots $2- ne sont plus liés avec la phrase n° $1 
}

alias ia.addp {
  tokenize 32 $1-
  if ($1 isnum) {
    if ($2 == $null) return 0 Pas assez de paramètre
    if ($1 > $hget(ia,Nbr)) return 0 Erreur, la phrase n° $+ $1 n'éxiste pas
    write -l $+ $1 ia\ia.txt $2-
  }
  else {
    if ($read(ia\ia.txt,w,$1-)) return 0 La phrase est déjà enregistré n° $readn
    write ia\ia.txt $1-
    hinc ia Nbr
  } 
  return 1 Phrase bien ajouté et à pour n° $hget(ia,Nbr) 
}
alias ia.Wp {
  tokenize 32 $1-
  if (($1 isnum) && ($2 == $null)) return 1 La phrase n° $1 Correspond à $read(ia\ia.txt,$1) 
  if ($read(ia\ia.txt,w,$1-)) return 1 La phrase a pour numero: $readn
  else return 0 La phrase n'est pas dans la BD
}

alias ia.Wm {
  tokenize 32 $1-
  if ((!$1) || ($1 !isnum)) return 0 $1 n'éxiste pas ou n'est pas un nombre
  var %b1,%list,%c
  %b1 = $hfind(ia,(^|\s) $+ $1 $+ (\s|$),0,r).data  
  %list = $null    
  while (%b1) {
    %c = $hfind(ia,(^|\s) $+ $1 $+ (\s|$),%b1,r).data
    ;Le if sert à savoir si on loock bien un mot      
    if ($left(%c,2) == m.)  %list = %list $right(%c,-2)
    dec %b1
  }
  return 1  2 $+ %list lié à4 $1 
}

alias ia.remplace {
  tokenize 32 $1-
  if ($2 == $null) return 0 Pas assez de paramètre
  if ($1 === $2) return 0  $1 et $2 c la même chose chez moi 
  ia.ccl $1 $2
  ia.RP $1 $2
  return 1 Opération réussi: $1 a été remplacé par $2 
}
;-------------------------------------------------------
;
;Alias s'occupant de SAUV - LOAD - CONVERTIR la BD
;
;-------------------------------------------------------

alias ia.saveBD {
  if (!$1) { echo -a precisez le nom de votre sauvgarde: /ia.saveBD pokemon.txt | return }
  if (!$exist(ia\save\)) mkdir ia\save  
  var %a,%b,%b1,%i,%c,%c1
  %i = $ticks
  %c = $gettok($ia.syn,2-,32)
  %b = $numtok(%c,32)
  while (%b) {
    %a = $gettok(%c,%b,32)
    write ia\save\ $+ $1 s: %a $hgetg(ia,s. $+ %a,2-)
    dec %b
  }
  %b = 1
  var %list
  while ($read(ia\ia.txt,%b)) {
    write ia\save\ $+ $1 m %b $ifmatch
    %b1 = $hfind(ia,(^|\s) $+ %b $+ (\s|$),0,r).data  
    %list = $null    
    while (%b1) {
      %c = $hfind(ia,(^|\s) $+ %b $+ (\s|$),%b1,r).data
      ;Le if sert à savoir si on loock bien un mot
      if ($len(%list) > 900) {
        write ia\save\ $+ $1 mm %b %list
        %list = $null
      }      
      if ($left(%c,2) == m.)  %list = %list $right(%c,-2)
      dec %b1
    }
    write ia\save\ $+ $1 mm %b %list
    inc %b
  }
  if ($isid) return 1 La BD a bien été sauvé en $calc($ticks - %i) ms
  else echo 2 -a La BD a bien été sauvé en $calc($ticks - %i) ms
}

alias ia.LoadBD {
  var %b,%b1,%c,%N,%der,%ou = $shortfn($sfile($mircdir,Choisit la BD à loader,LOAD))
  %b = 1
  if (!$hget(ia)) ia.init
  if ($1 == -r) {
    hdel -w ia m.*
    hdel -w ia s.*
    remove ia\ia.txt
  }  
  while ($read(%ou,%b)) { 
    tokenize 32 $ifmatch    
    if ($1 == s:) ia.syn $2 $3
    elseif ($1 == m) {
      if ($read(ia\ia.txt,w,$3-)) %N = $readn
      else {
        write ia\ia.txt $3- 
        hinc ia Nbr 
        %N = $hget(ia,Nbr) 
      }
      %der = $2
    }
    elseif ($1 == mm) {
      if (%der != $2) return 0 problème lors du chargement de la BD 
      ia.addm %N $3-
    }
    else return 0 Ce fichier n'est pas un BD d'une ia 
    inc %b
  }
  if ($isid) return 1 chargement réussi
  else echo 2 -a Chargement réussi
}
alias ia.ConBD {
  hadd ia Nbr $hget(ia,Nl)
  hdel ia Nl
  var %b,%c
  %b = $hfind(ia,1.*,0,w)
  while (%b) {
    %c = $hfind(ia,1.*,%b,w)
    hadd ia m. $+ $right(%c,-2) $hget(ia,%c)
    hdel ia %c
    dec %b
  }
  hdel -w ia 0.*
  hdel -w ia 1.*
  hdel -w ia 2.*
  hdel -w ia 3.*
  hdel -w ia t.*
  %b = $hfind(ia,syn.*,0,w) 
  while (%b) {
    %c = $hfind(ia,syn.*,%b,w)
    hadd ia s. $+ $right(%c,-4) $hget(ia,%c)
    hdel ia %c
    dec %b
  }
  hdel -w ia syn.*
  hadd ia eff la le un une l' des les d'
  return 1 Convertion de la base réussi
}

;--------------------------------------------------------
;
;L'alias s'occupant de la gestion des access
;
;--------------------------------------------------------

alias ia.BotAxx {
  var %axx = $ia.axx(%ia.temp)
  var %nick = $1
  tokenize 32 $2 
  if ($1 == !addh) { 
    if ((a !isin %axx) || (!$3)) return 
    if ((o isin $hget(ia,a. $+ $2)) && (o !isin %axx)) return
    hadd ia a. $+ $2 $3
    ia.out %nick $2 avec les modes $3 a bien été rajouté (ou modifié)
  }
  elseif ($1 == !delh) {
    if ((a !isin %axx) || (!$2)) return
    if (!$hget(ia,a. $+ $2)) { ia.out %nick $2 n'existe pas | return }
    if ((o isin $hget(ia,a. $+ $2)) && (o !isin %axx)) return
    hdel ia a. $+ $2 
    ia.out %nick l'host de $2 a été bien éffacé
  }
  elseif ($1 == !listh) {
    var %list,%c,%b = $hfind(ia,a.*,0,w)   
    while (%b) {
      %c = $hfind(ia,a.*,%b,w)
      if ($len(%list) > 400) { ia.out %nick Liste des axxh: %list | %list = $null }         
      %list = %list ( $+ $right(%c,-2) $+ : $+ $hget(ia,%c) $+ )  
      dec %b
    }
    ia.out %nick Liste des axxh: %list
  }
  elseif ($1 == !addaxx) {
    if ((a !isin %axx) || (!$4)) return 
    if ((o isin $gettok($hget(ia,axx. $+ $2),2,32)) && (o !isin %axx)) return
    hadd ia axx. $+ $2 $3 $4
    ia.out %nick Un axx à été rajouté (username $2 et mode $4 $+ )
  }
  elseif ($1 == !delaxx) {
    if ((a !isin %axx) && (!$2)) return 
    if (o isin $gettok($hget(ia,axx. $+ $2),2,32) && (o !isin %axx)) return 
    hdel ia axx. $+ $2      
  }
  elseif ($1 == !listaxx) {
    var %list,%c,%b = $hfind(ia,axx.*,0,w)
    while (%b) {
      %c = $hfind(ia,axx.*,%b,w)
      if ($len(%list) > 400) { ia.out %nick Liste des axx: %list | %list = $null }         
      %list = %list ( $+ $right(%c,-4) $+ : $+ $gettok($hget(ia,%c),2,32) $+ )
      dec %b
    }
    ia.out %nick Liste des axx: %list
  }
  elseif ($1 == !auth) {
    var %c = $hget(ia,axx. $+ $2)
    if ((!$3) || (!%c)) return
    if ($3 != $gettok(%c,1,32)) return
    hadd ia a. $+ %ia.temp $gettok(%c,2,32)
  }
  return
}

Conclusion :


Je pense que c'est la dernière version de mon bot ...

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.