Communauté Eggdrop
TCL Liste - Version imprimable

+- Communauté Eggdrop (https://forum.eggdrop.fr)
+-- Forum : Eggdrop et TCL (https://forum.eggdrop.fr/forumdisplay.php?fid=8)
+--- Forum : Scripts TCL (https://forum.eggdrop.fr/forumdisplay.php?fid=4)
+--- Sujet : TCL Liste (/showthread.php?tid=1023)



TCL Liste - Aristide - 02/09/2011

Bonjour,
Je vous explose mon soucis, en faite j'aimerais ajouter une nouvelle fonctionnalité sur mon Bot de gestion Radio, et donc j'ai pris un code TCL qui a été codé pour la gestion des demandes musicales. Je l'ai modifié pour l'utiliser selon mon besoin, mais le soucis que je rencontre, c'est que quand j'essaie de faire retourner la liste des anims en utilisation la commande !listanim, voilà ce que j'ai en retour:

Code :
[-02:13:30-] «Ryan» !listanim
[-02:13:30-] [Notice] Mixer: 2 Testeur - (03:12 02.09.2011)

Alors que çà devait m'affichait comme ceci:

Code :
[-02:13:30-] «Ryan» !listanim
[-02:13:30-] [Notice] Mixer: Liste des animateurs Radio:
[-02:13:30-] [Notice] Mixer: 1- Testeur  a été ajouté par Ryan le: (03:12 02.09.2011)

Voici le code TCL que j'utilise dans ce sens:
Code :
bind pub *|* !listanim show_anims
bind pub *|* !delanim del_anim
bind pub *|* !addanim add_anim


proc del_anim { nick uhost hand chan text } {
global vhostniv2
set chan [string tolower $chan]
  if {[string equal -nocase "#radio+" $chan]} {
    foreach vhost $vhostniv2 {
        if {[string match -nocase $vhost $uhost]}  {
if {$text == ""} {
    putserv "NOTICE $nick :\00312- Syntax !delanim pseudo -"
    return 0
}
  putserv "NOTICE $nick :\0034L'AnimLive \00312$text \0034  a été bien retiré du staff."
  set thereis [file exists [file join ./Anims/ temp_$chan.txt]]
  if {$thereis != 0} {
    eval "exec rm -f ./Anims/temp_$chan.txt"
  }
  set tempfile [open [file join ./Anims/ temp_$chan.txt] "w+"]
  set newsfile [open [file join ./Anims/ Anims_$chan.txt] "r+"]
  if {[eof $newsfile]} {
    putserv "NOTICE $nick :Aucun AnimLive n'a été enregistré dans la base."
    close $newsfile
    close $tempfile
  } else {
    set ln 1
    while {[eof $newsfile] == 0} {
      set line [gets $newsfile]
      set msg $line
      set dele 0
      foreach prm $text {
       if {$ln == $prm} {
        set dele 1
       }
      }
      if {$dele == 0} {
        if {$msg != ""} {
          puts $tempfile "$msg"
        }
      }
      set dele 0
      set ln [expr {$ln} +1]
    }
    close $tempfile
    close $newsfile
    eval "exec mv -f ./Anims/temp_$chan.txt ./Anims/Anims_$chan.txt"
  }
  return 1
}
}
}
}

proc add_anim { nick uhost hand chan text } {
  global vhostniv2
  set chan [string tolower $chan]
  if {[string equal -nocase "#radio+" $chan]} {
    foreach vhost $vhostniv2 {
        if {[string match -nocase $vhost $uhost]}  {
if {$text == ""} {
    putserv "NOTICE $nick :\00312- Syntax !addanim pseudo -"
    return 0
}
  set chkuser [join [list $nick]]
  set msg $text
  set thereis [file exists [file join ./Anims/ Anims_$chan.txt]]
  set cmp [expr {$thereis} == 1]
  if {$cmp} {
    set newsfile [open [file join ./Anims/ Anims_$chan.txt] "a+"]
  } else {
    set newsfile [open [file join ./Anims/ Anims_$chan.txt] "w+"]
  }
  puts $newsfile "+ $msg (+++$chkuser) (+-+[strftime "%H:%M %d.%m.%Y"])"
  putserv "NOTICE $nick :\0034L'AnimLive \00312$text \0034a été bien ajouté dans le staff -"
  close $newsfile
  return 1
}
}
}
}


proc show_anims { nick uhost hand chan text } {
  set chan [string tolower $chan]
  if {[string equal -nocase "#radio+" $chan]} {
    set chkuser [join [list $nick]]
    set npct [lindex $text 0]
    if {[llength $text] > 1 } {
        putserv "NOTICE $nick :Whuz up?"
        return 1
    }
    set thereis [file exists [file join ./Anims/ Anims_$chan.txt]]
    if {$thereis == 0} {
        putserv "NOTICE $nick :Aucun AnimLive n'a été enregistré dans la base."
        return 1
    }
    set nbAnims [lindex [exec wc -l ./Anims/Anims_$chan.txt] 0]
    if {[llength $text] == 0 || $npct > $nbAnims || $npct <= 0} {
        set npct "$nbAnims"
    }
    set newsfile [open "| tail -n $npct [file join ./Anims/ Anims_$chan.txt]" "r+"]
    if {[eof $newsfile]} {
        putserv "NOTICE $nick :Aucun AnimLive n'a été enregistré dans la base."
        close $newsfile
    } else {
        set yes 0
    set nbAnims [lindex [exec wc -l ./Anims/Anims_$chan.txt] 0]
    if {[llength $text] == 0 } {
        set numnews 0
    } else {
        set numnews [expr {$nbAnims - $npct}]
    }
        while {[eof $newsfile] == 0} {
            set line [gets $newsfile]
        incr numnews
            set delimn [string last "(+++" $line]
            set delimt [string last "(+-+" $line]
            set msg [string range $line 2 [expr {$delimn} - 2]]
            set stlen [string length $line]
            set adder [string range $line [expr {$delimn} + 4] [expr {$delimt} - 3]]
            set adtim [string range $line [expr {$delimt} + 4] [expr {$stlen} - 2]]
            if { $msg != "" } {
                putquick "NOTICE $nick :\00304‹\00302$numnews\00304› \00312$msg  - \00301(\00306$adtim\00301)"
            }
            set yes 1
        }
        if { $yes==0 } {
            putserv "NOTICE $nick :Aucun AnimLive n'a été enregistré dans la base."
        }
        close $newsfile
        unset numnews
    }
  return 1
}
}

Merci de votre aide d'avance :).
Cordialement
Aristide


RE: TCL Liste - CrazyCat - 02/09/2011

Pour moi, le script fait ce qu'il doit faire.
Dans la procédure addanim, tu as:
TCL
puts $newsfile "+ $msg (+++$chkuser) (+-+[strftime "%H:%M %d.%m.%Y"])"


(avec $msg qui contient le nick du nouvel animateur)
Et dans listanim, tu as:
TCL
incr numnews
            set delimn [string last "(+++" $line]
            set delimt [string last "(+-+" $line]
            set msg [string range $line 2 [expr {$delimn} - 2]]
            set stlen [string length $line]
            set adder [string range $line [expr {$delimn} + 4] [expr {$delimt} - 3]]
            set adtim [string range $line [expr {$delimt} + 4] [expr {$stlen} - 2]]
            if { $msg != "" } {
                putquick "NOTICE $nick :\00304‹\00302$numnews\00304› \00312$msg  - \00301(\00306$adtim\00301)"


Donc, le retour est correct, il te manque peut-être de la mise en forme, du genre "a été ajouté par $adder"