Quote system + quote searcher

Contenu du snippet

Encore un système de quote... je sais "ENCORE"... Mais celui la a un "quote searcher" comme je l'ai appellé, qui permet de retrouver une quote contenant tel ou tel mot. Assez utile lors ce qu'on a une grande liste de quotes ^^

Pour être honnête je me suis insipré (seulement pour le dialog et en minorité !) du dialog : Quote Express. de BaKa

Source / Exemple :


alias quotes { if (!$dialog(quote)) { dialog -m quote quote } }
dialog quote {
  title "Quoteur"
  size -1 -1 588 378
  list 1, 10 10 450 280, size vsbar
  button "&Ajouter", 2, 475 308 100 25, disable flat
  button "&Supprimer", 3, 475 10 100 25, disable flat
  button "&Editer", 4, 475 50 100 25, disable flat
  text "!addquote <quote>", 5, 460 141 125 16, center
  text "!delquote <num>", 6, 475 170 100 16, center
  text "!quote <num>", 7, 475 200 100 16, center
  button "&Fermer", 8, 475 230 100 54, ok
  edit "", 9, 10 310 451 21, autohs
  button "&Dire Quote", 10, 475 90 100 25, disable flat
  radio "Sur la fenêtre Active", 11, 10 345 205 20, push
  radio "Sur tous les Canaux", 12, 257 345 205 20, push
  text "- Quotes", 13, 487 348 78 16, center
}
on *:dialog:quote:*:*: {
  if $devent == close { hsave quote quote.htable }
  if $devent == dclick { if ($did == 1) { did -ra $dname 9 $gettok($did(1).seltext,2-,32) } }
  if $devent == init {
    if (!$hget(quote)) { hmake quote | hload quote quote.htable }
    did -c $dname $iif($hget(quote,dire) == active,11,12)
    if (!$exists(quotes.txt)) { write quotes.txt }
    if ($hget(quote,modif)) {
      did -a $dname 9 $read(quotes.txt,$hget(quote,modif))
      did -f $dname 9
      did -e $dname 2
      hdel quote modif
    }
    refresh_quote
  }
  if $devent == edit { if ($did == 9) { did [ $+(-,$iif($did(9),e,b)) ] $dname 2 } }
  if $devent == sclick {
    if ($did == 1) && ($did(1).sel) { did -e $dname 3,10,4 }
    if ($did == 11) { hadd quote dire active }
    if ($did == 12) { hadd quote dire all }
    if ($did == 2) { addquote $did(9) | did -r $dname 9 }
    if ($did == 3) {  did -b $dname 3,4,10 | delquote $did(1).sel }
    if ($did == 10) { $iif($hget(quote,dire) == all,amsg,msg $active) Quote N° $+ $did(1).sel » $read(quotes.txt,$did(1).sel) }
    if ($did == 4) { did -ra $dname 9 $read(quotes.txt,$did(1).sel) }
  }
}
alias -l addquote {
  if (!$1) { halt }
  write quotes.txt $1-
  if ($dialog(quote)) { refresh_quote }
  if (!$dialog(quote)) { echo 4 -a Quote ajoutée }
}
alias -l delquote {
  if (!$1) { halt }
  if ($1 !isnum) { echo 4 -a Ce n'est pas un numéro | halt }
  if (!$read(quotes.txt,$1)) { echo 4 -a Ce numéro de quote n'existe pas | halt }
  write $+(-dl,$1) quotes.txt
  if ($dialog(quote)) { refresh_quote }
  if (!$dialog(quote)) { echo 4 -a Quote suprimée }
}
alias -l refresh_quote {
  did -e quote 1
  did -r quote 1
  if (!$read(quotes.txt,1)) { did -b quote 1 | did -a quote 1 Pas de quotes... | did -ra quote 13 0 Quotes | halt }
  window -h @buf
  .fopen quote quotes.txt
  var %a 1, %max $lines(quotes.txt)
  while (%a <= %max) {
    aline @buf %a $+ . $strip($fread(quote))
    inc %a
  }
  .fclose quote
  savebuf @buf tempo.qu
  window -c @buf
  loadbuf -o quote 1 tempo.qu
  .remove tempo.qu
  did -ra quote 13 $lines(quotes.txt) Quote $+ $iif($lines(quotes.txt) > 1,s)
}
on *:input:*: {
  if ($exists(quotes.txt)) {
    if ($1 == !addquote) { if (!$2) { echo 4 -a Synthaxe : !addquote <quote> | halt } | addquote $2- }
    if ($1 == !delquote) { if (!$2) { echo 4 -a Synthaxe : !delquote <n°quote> | halt } | delquote $2 }
    if ($1 == !quote) { 
      if ($read(quotes.txt,1)) {
        if ($2 isnum) { 
          if (!$read(quotes.txt,$2)) { msg $active Ce numéro de quote n'existe pas }
          if ($read(quotes.txt,$2)) { msg $active Quote n° $+ $2 » $read(quotes.txt,$2) }
        }
        if (!$2) { msg $active Quote Aléatoire. $read(quotes.txt) }
      }
      if (!$read(quotes.txt,1)) { msg $active Pas de quotes dans la liste }
    }
    if ($1 == !nbrquote) { msg $active $iif($lines(quotes.txt) > 0,Nombre de quotes dans la liste : $v1 ,Pas de quotes dans la liste) }
  }
}

alias qsearch { if (!$dialog(qsearch)) { dialog -m qsearch qsearch } }
dialog qsearch {
  title "Quote Searcher"
  size -1 -1 463 300
  list 1, 191 27 257 252, size vsbar
  box "Résultats", 2, 180 7 278 285
  combo 3, 13 33 150 103, size edit drop vsbar
  text "Rechercher le(s) mot(s)", 4, 13 10 146 16, center
  button "Effacer l'historique", 5, 13 69 150 25
  button "Démarrer Scan", 6, 13 94 150 25
  box Infos, 7, 13 144 150 92, hide
  text "Quote N° -", 8, 25 164 125 16, hide
  button "Editer la Quote", 9, 25 191 125 25, hide
  button "&Fermer", 10, 25 246 125 41, ok
}
on *:dialog:qsearch:*:*: {
  if $devent == close { hsave quote quote.htable }
  if $devent == init {
    if (!$hget(quote)) { hmake quote | hload quote quote.htable }
    if (!$exists(quotes.txt)) { echo 4 -a Il n'y a pas de quotes enregistrées... | dialog -x $dname | halt }
    if (!$read(quotes.txt,1)) { echo 4 -a Il n'y a pas de quotes enregistrées... | dialog -x $dname | halt }
    if (!$exists(qsearch.data)) { write qsearch.data }
    if ($read(qsearch.data,1)) { refresh_qsearch }
    if ($hget(quote,histo)) { 
      var %a 1
      while ($gettok($hget(quote,histo),%a,230)) {
        did -i $dname 3 %a $ifmatch
        if ($ifmatch == $hget(quote,lastsearch)) { var %b %a }
        inc %a
      }
      did -c $dname 3 %b
      did -f $dname 3
    }
  }
  if $devent == dclick {
    if ($did == 1) {
      if ($did(1).sel) {
        hadd quote modif $gettok($did(1).seltext,1,46)
        dialog -x $dname
        quotes

      }
    }
  }
  if $devent == sclick {
    if ($did == 5) {
      if (!$hget(quote,histo)) { halt }
      var %a $input(Etes vous sûr d'éffacer l'historique ?,w,Historique)
      if (!%a) { halt }
      hdel quote histo
      write -c qsearch.data
      dialog -x $dname
      qsearch
    }
    if ($did == 1) {
      if ($did(1).sel) {
        did -v $dname 8,9,7
        did -ra $dname 8 Quote N° $+ $gettok($did(1).seltext,1,46)
      }
    }
    if ($did == 9) {
      hadd quote modif $gettok($did(1).seltext,1,46)
      dialog -x $dname
      quotes
    }
    if ($did == 6) {
      if ($did(3).text) {
        did -e $dname 1
        did -h $dname 8,9,7
        var %a $did(3).text, $numtok($hget(quote,histo),230)
        inc %z
        if (!$istok($hget(quote,histo),%a,230)) { did -i $dname 3 %z %a }
        hadd quote histo $addtok($hget(quote,histo),$did(3).text,230))
        hadd quote lastsearch %a
        did -r $dname 1
        write -c qsearch.data
        if (!$read(quotes.txt,w,[ [ $+(*,%a,*) ] ])) { did -a $dname 1 Pas de quotes contenant ce mot... | did -b $dname 1 | halt }
        var %b 1, %c $lines(quotes.txt)
        while (%b <= %c) {
          if (%a isin $read(quotes.txt,%b)) { write qsearch.data %b $+ . $v2 }
          inc %b
        }
        refresh_qsearch
      }
    }
  }
}
alias -l refresh_qsearch { loadbuf -o qsearch 1 qsearch.data }
Menu channel,query {
  .-
  .Quote System:/quotes
  .Quote Searcher:/qsearch
  .-
}

Conclusion :


J'attend vos commentaires / réflections sur tout bug qu'il y aurait.

Cordialement

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.

Du même auteur (CestFortEnChocolat)