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.

Solved

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
H
Hero
Halfop
Posts: 49
Joined: Tue Jun 26, 2012 6:27 pm
Location: root@localhost
Contact:

Solved

Post by Hero »

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?
Last edited by Hero on Thu Mar 14, 2019 1:22 am, edited 1 time in total.
The Road To Hell Is Full Of Good Intentions
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Re: Request: Every Day New Text

Post by willyw »

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

Code: Select all

# 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 !
H
Hero
Halfop
Posts: 49
Joined: Tue Jun 26, 2012 6:27 pm
Location: root@localhost
Contact:

Post by Hero »

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
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

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.
:)



Code: Select all

# 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 !
Post Reply