This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

a help for this part of a tcl

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
flink
Halfop
Posts: 83
Joined: Sun Feb 21, 2021 9:27 am
Location: Canarias

a help for this part of a tcl

Post by flink »

First of all, congratulations all Happy New Year 2023.

When users make a musical request, the bot sends it to the dj room and writes it in a txt.
When I request the order list
It always comes out, whether there are requests or not: No requests at the moment.
Any suggestion to fix it?

Code: Select all

     bind pub -|- !listapedidos requestlist
proc requestlist {nick uhost hand chan arg} {
       global adminchans1
       if {$chan == $adminchans1} {
               set reqnumber 1
               set filename "lista_peticiones.txt"
               set in [open $filename r]
               while {1} {
                       set line [gets $in]
                       if {$line == ""} {
                        
                                        putnow "PRIVMSG $adminchans1 :No hay solicitudes por el momento."                                              
                                        break
                              } else {
                               if {[eof $in]} {
                                       putnow "PRIVMSG $adminchans1 :Fin Listado peticion."
                                       close $in
                                       break
                               }
                               if {$reqnumber == 0} {
                                       putnow "PRIVMSG $adminchans1 :Inicio Listado peticiones"
                                       incr reqnumber
                               } else {
                                       putnow "PRIVMSG $adminchans1 :$reqnumber: $line "
                                       #putnow "PRIVMSG $adminchans1 :Fin Listado peticiones"
                                       incr reqnumber
                                       
                                      
                               }
                       }
               }
       }
}
Mi ingles: no es el mejor, Manda el traductor... :)
User avatar
CrazyCat
Revered One
Posts: 1306
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Change your loop:

Code: Select all

while {[gets $in line] >= 0} {
See example @ https://www.tcl.tk/man/tcl8.4/TclCmd/gets.html

And if your first line is empty (depend on how your file is done), it's normal.

Without the complete code, I can't help you further
User avatar
flink
Halfop
Posts: 83
Joined: Sun Feb 21, 2021 9:27 am
Location: Canarias

Re: a help for this part of a tcl

Post by flink »

hello crazycat
with this code I request the list of requests
flink wrote:First of all, congratulations all Happy New Year 2023.

When users make a musical request, the bot sends it to the dj room and writes it in a txt.
When I request the order list
It always comes out, whether there are requests or not: No requests at the moment.
Any suggestion to fix it?

Code: Select all

     bind pub -|- !listapedidos requestlist
proc requestlist {nick uhost hand chan arg} {
       global adminchans1
       if {$chan == $adminchans1} {
               set reqnumber 1
               set filename "lista_peticiones.txt"
               set in [open $filename r]
               while {1} {
                       set line [gets $in]
                       if {$line == ""} {

                               putnow "PRIVMSG $adminchans1 :No hay solicitudes por el momento."
                               break

                       } else {
                               if {[eof $in]} {
                                       putnow "PRIVMSG $adminchans1 :Fin Listado peticion."
                                       close $in
                                       break
                               }
                               if {$reqnumber == 0} {
                                       putnow "PRIVMSG $adminchans1 :Inicio Listado peticiones"
                                       incr reqnumber
                               } else {
                                       putnow "PRIVMSG $adminchans1 :$reqnumber: $line "
                                       #putnow "PRIVMSG $adminchans1 :Fin Listado peticiones"
                                       incr reqnumber
                                       
                                      
                               }
                       }
               }
       }
}
this is how you write lista_peticiones.txt

Code: Select all

       set tempeti [open "lista_peticiones.txt" a]      
       puts $tempeti "$nick A Solicitado $arg En El Canal $chan"      
       close $tempeti

what it does when there are requests:
  • @dj : !listapedidos
    @radio : pepe A Solicitado cuatro pizzas para llevar En El Canal #pruebas
    @radio : pepe A Solicitado unas hamburguesas con todo En El Canal #pruebas
    @radio : pepe A Solicitado una lechuga verde En El Canal #pruebas
    @radio : pepe A Solicitado uno de lomo con todo En El Canal #pruebas
    @radio : pepe A Solicitado una lechuga amarilla En El Canal #pruebas
    @radio : pepe A Solicitado una cocacola sin gas En El Canal #pruebas
    @radio : No hay solicitudes por el momento.
when should it be:
  • @dj : !listapedidos
    @radio : pepe A Solicitado cuatro pizzas para llevar En El Canal #pruebas
    @radio : pepe A Solicitado unas hamburguesas con todo En El Canal #pruebas
    @radio : pepe A Solicitado una lechuga verde En El Canal #pruebas
    @radio : pepe A Solicitado uno de lomo con todo En El Canal #pruebas
    @radio : pepe A Solicitado una lechuga amarilla En El Canal #pruebas
    @radio : pepe A Solicitado una cocacola sin gas En El Canal #pruebas
    @radio : Fin Listado petición.
when there is no request list it should be like this:
  • @dj : !listapedidos
    @radio : No hay solicitudes por el momento.
That's what I need the code to do if you can contribute, thank you.
Mi ingles: no es el mejor, Manda el traductor... :)
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

try this.

Post by SpiKe^^ »

Try this

Code: Select all

proc requestlist {nick uhost hand chan arg} {
       global adminchans1
       if {$chan == $adminchans1} {
               set filename "lista_peticiones.txt"
               set in [open $filename r]


               set reqnumber 0

               set data [split [read -nonewline $in] "\n"]
               close $in

               if {![llength $data]} {
                 putnow "PRIVMSG $adminchans1 :No hay solicitudes por el momento."
                 return 0
               }

               foreach line $data {   incr reqnumber
                 putnow "PRIVMSG $adminchans1 :$reqnumber: $line "
               }

               putnow "PRIVMSG $adminchans1 :Fin Listado peticion."
       }
       return 0
}
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
User avatar
flink
Halfop
Posts: 83
Joined: Sun Feb 21, 2021 9:27 am
Location: Canarias

Post by flink »

Hi Spike^^
Thank you for collaborating. What you have posted works, it seems that I forgot to put in the previous examples when the list begins with: Start List of requests. One last bit of help could be that when I send the list it goes like this:
  • @dj : !listapedidos
    @radio : Inicio Listado peticiones.
    @radio : pepe A Solicitado una lechuga amarilla En El Canal #pruebas
    @radio : pepe A Solicitado una cocacola sin gas En El Canal #pruebas
    @radio : Fin Listado petición.
In this part how can I put timestamps on it so that it would look like this in the listings:
@radio : pepe A Requested four takeaway pizzas on 07/01/23 at 12:15 In The Channel #tests

Code: Select all

 set tempeti [open "lista_peticiones.txt" a]     
       put $tempeti "$nick A Solicitado $arg En El Canal $chan"     
       close $tempeti
Mi ingles: no es el mejor, Manda el traductor... :)
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

This should add the new "Start List of requests" line...

Code: Select all

proc requestlist {nick uhost hand chan arg} {
       global adminchans1
       if {$chan == $adminchans1} {
               set filename "lista_peticiones.txt"
               set in [open $filename r]


               set reqnumber 0

               set data [split [read -nonewline $in] "\n"]
               close $in

               if {![llength $data]} {
                 putnow "PRIVMSG $adminchans1 :No hay solicitudes por el momento."
                 return 0
               }

               putnow "PRIVMSG $adminchans1 :Inicio Listado peticiones."

               foreach line $data {   incr reqnumber
                 putnow "PRIVMSG $adminchans1 :$reqnumber: $line "
               }

               putnow "PRIVMSG $adminchans1 :Fin Listado peticion."
       }
       return 0
}
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
User avatar
flink
Halfop
Posts: 83
Joined: Sun Feb 21, 2021 9:27 am
Location: Canarias

Post by flink »

thanks SpiKe^^
the list solution works for me.
for the date and time to be written in each request to be written in list_requests.txt can you help me thank you
Mi ingles: no es el mejor, Manda el traductor... :)
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

strftime

Post by SpiKe^^ »

Try put this, or something like this, in the text you want dated...

Code: Select all

[strftime "on %x at %X"]
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
User avatar
flink
Halfop
Posts: 83
Joined: Sun Feb 21, 2021 9:27 am
Location: Canarias

Post by flink »

Thanks SpiKe^^
you have solved the whole code for me all working
Mi ingles: no es el mejor, Manda el traductor... :)
Post Reply