egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

a help for this part of a tcl

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
flink
Halfop


Joined: 21 Feb 2021
Posts: 70
Location: Canarias

PostPosted: Fri Jan 06, 2023 9:53 am    Post subject: a help for this part of a tcl Reply with quote

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:
     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... Smile
Back to top
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1108
Location: France

PostPosted: Fri Jan 06, 2023 11:10 am    Post subject: Reply with quote

Change your loop:
Code:
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
_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
flink
Halfop


Joined: 21 Feb 2021
Posts: 70
Location: Canarias

PostPosted: Fri Jan 06, 2023 2:15 pm    Post subject: Re: a help for this part of a tcl Reply with quote

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:
     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:
       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... Smile
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 826
Location: Tennessee, USA

PostPosted: Fri Jan 06, 2023 5:37 pm    Post subject: try this. Reply with quote

Try this
Code:
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
.
Back to top
View user's profile Send private message Visit poster's website
flink
Halfop


Joined: 21 Feb 2021
Posts: 70
Location: Canarias

PostPosted: Sat Jan 07, 2023 7:14 am    Post subject: Reply with quote

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:
 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... Smile
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 826
Location: Tennessee, USA

PostPosted: Sat Jan 07, 2023 10:29 am    Post subject: Reply with quote

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

Code:
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
.
Back to top
View user's profile Send private message Visit poster's website
flink
Halfop


Joined: 21 Feb 2021
Posts: 70
Location: Canarias

PostPosted: Sat Jan 07, 2023 12:02 pm    Post subject: Reply with quote

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... Smile
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 826
Location: Tennessee, USA

PostPosted: Sat Jan 07, 2023 7:46 pm    Post subject: strftime Reply with quote

Try put this, or something like this, in the text you want dated...
Code:
[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
.
Back to top
View user's profile Send private message Visit poster's website
flink
Halfop


Joined: 21 Feb 2021
Posts: 70
Location: Canarias

PostPosted: Sun Jan 08, 2023 6:39 am    Post subject: Reply with quote

Thanks SpiKe^^
you have solved the whole code for me all working
_________________
Mi ingles: no es el mejor, Manda el traductor... Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber