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 

Solved

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
Hero
Halfop


Joined: 26 Jun 2012
Posts: 49
Location: root@localhost

PostPosted: Wed Mar 13, 2019 8:53 am    Post subject: Solved Reply with quote

Hello I wanna request tcl, function is on everyday bot advertise new texts, for example it should read from file like:
monday.txt
tuesday.txt
wednesday.txt
.....

on monday it repeats text from monday.txt and same goes on.. Anyone can give a try if possible?
_________________
The Road To Hell Is Full Of Good Intentions


Last edited by Hero on Thu Mar 14, 2019 1:22 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1017

PostPosted: Wed Mar 13, 2019 10:37 am    Post subject: Re: Request: Every Day New Text Reply with quote

Give this a try. It has been tested only briefly - obviously to actually test it in use would take a week.

Code:

# March 13, 2019

# http://forum.egghelp.org/viewtopic.php?t=20606

# Hello I wanna request tcl, function is on everyday bot advertise new texts, for example it should read from file like:
# monday.txt
# tuesday.txt
# wednesday.txt
# .....
#
# on monday it repeats text from monday.txt and same goes on.. Anyone can give a try if possible?



### Configuration ###

# Set the path to the directory where files to read are saved (must end with a / )
set where_files_are "scripts/added/experimenting_for_somebody/"

# Set the channel in which to announce
set ad_chan "#your_chan_here"

### End configuration ###



###
bind cron - "0 12 * * 0" say_sunday
bind cron - "0 12 * * 1" say_monday
bind cron - "0 12 * * 2" say_tuesday
bind cron - "0 12 * * 3" say_wednesday
bind cron - "0 12 * * 4" say_thursday
bind cron - "0 12 * * 5" say_friday
bind cron - "0 12 * * 6" say_saturday

# The above binds will trigger at 12 noon daily.
# For refence on how to adjust the time that a bind cron triggers, see:
# https://crontab.guru/

###
proc say_sunday {min hour day month weekday} {
global where_files_are ad_chan


        if {$weekday == 0} {
                set fname [join "$where_files_are sunday.txt" ""]
        }

         if {$weekday == 1} {
                set fname [join "$where_files_are monday.txt" ""]
        }

         if {$weekday == 2} {
                set fname [join "$where_files_are tuesday.txt" ""]
        }

         if {$weekday == 3} {
                set fname [join "$where_files_are wednesday.txt" ""]
        }

         if {$weekday == 4} {
                set fname [join "$where_files_are thursday.txt" ""]
        }

         if {$weekday == 5} {
                set fname [join "$where_files_are friday.txt" ""]
        }

         if {$weekday == 6} {
                set fname [join "$where_files_are saturday.txt" ""]
        }


        if {![file exists $fname]} {
                ##putserv "privmsg $ad_chan :Sorry, $fname not found"
                return 0
        }


        set fp [open $fname "r"]
        set data [read -nonewline $fp]
        close $fp
        set lines [split $data "\n"]

        foreach l $lines {
                putserv "privmsg $ad_chan :$l"
        }
}

# reference  :http://forum.egghelp.org/viewtopic.php?t=6885


###

_________________
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
Back to top
View user's profile Send private message
Hero
Halfop


Joined: 26 Jun 2012
Posts: 49
Location: root@localhost

PostPosted: Wed Mar 13, 2019 12:52 pm    Post subject: Reply with quote

willy, Thanks for quick reply, Can you make little bit change, e.g on respective day, it Should Repeat Lines from .txt file every 60 min like this?

because I am to put many lines in each day file, so It should post line after every 60 min or 120 min from same day file.
_________________
The Road To Hell Is Full Of Good Intentions
Back to top
View user's profile Send private message Visit poster's website
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1017

PostPosted: Wed Mar 13, 2019 4:33 pm    Post subject: Reply with quote

1.) Cleaned up some... got rid of all the if lines... using strftime to determine day of week now.

2.) See comments in script below, on how to go about making such changes as you requested.

3.) Be sure to completely remove the previous script from bot. To do that, do not simply .rehash. Do .restart , after removing source line that loads previous script.

I hope this helps.
Smile




Code:

# March 13, 2019

# http://forum.egghelp.org/viewtopic.php?t=20606

# Hello I wanna request tcl, function is on everyday bot advertise new texts, for example it should read from file like:
# monday.txt
# tuesday.txt
# wednesday.txt
# .....
#
# on monday it repeats text from monday.txt and same goes on.. Anyone can give a try if possible?

#

# March 13, 2019
# Can you make little bit change, e.g on respective day, it Should Repeat Lines from .txt file every 60 min like this?
# because I am to put many lines in each day file, so It should post line after every 60 min or 120 min from same day file.




### Configuration ###

# Set the path to the directory where files to read are saved (must end with a / )
set where_files_are "scripts/added/experimenting_for_somebody/daily_advertiser/"

# Set the channel in which to announce
set ad_chan "#your_chan_here"

### End configuration ###



###
bind cron - "0 * * * *" do_announce

# Put this in Google: crontab "how to repeat every 60 minutes"
# and it finds several things to read.
# The first, and very simple one is :
# https://crontab.guru/
# and it says to use   "0 * * * *"  for every 60 minutes.
# So, see above bind command line.  It is now that.  Need to let it run, to test it.
#
# If you want to change it, feel free.  Just look it up with  https://crontab.guru/, edit the bind line while being sure to not change the format of
# the line

###


###
proc do_announce {min hour day month weekday} {
global where_files_are ad_chan

        set fname [join "$where_files_are [string tolower [strftime %A]] .txt" ""]

        if {![file exists $fname]} {
                #putserv "privmsg $ad_chan :Sorry, $fname not found"
                return 0
        }

        set fp [open $fname "r"]
        set data [read -nonewline $fp]
        close $fp
        set lines [split $data "\n"]

        foreach l $lines {
                putserv "privmsg $ad_chan :$l"
        }
}

# reference  :http://forum.egghelp.org/viewtopic.php?t=6885


###

_________________
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
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 -> Script Requests 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