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.

Holiday / event topic changer

Support & discussion of released scripts, and announcements of new releases.
Post Reply
C
CP1832
Halfop
Posts: 68
Joined: Thu Oct 09, 2014 4:03 pm

Holiday / event topic changer

Post by CP1832 »

I created a script so as to be able to change the channel's topic for a given date.

Code: Select all

foreach bind [binds topic_holiday] {lassign $bind type flags mask num proc; unbind $type $flags $mask $proc}
foreach bind [binds pubholiday] {lassign $bind type flags mask num proc; unbind $type $flags $mask $proc}

bind time - "00 00 * * *" topic_holiday
bind pub - .date pubholiday

set date_file "date.txt"

if {![file exists $date_file]} {
    fconfigure [set datefile [open $date_file w]] -encoding binary
    close $datefile
}

proc topic_holiday {min hour day month year} {
   global date_file
   fconfigure [set datefile [open $date_file r]] -encoding binary
   set today [clock format [clock seconds] -format "%d %m"]
   set holidays [list] 
   while {![eof $datefile]} {
	set CurEntry "[gets $datefile]"
        set date [lrange $CurEntry 0 1]
        if {[string match -nocase $today $date]} {
	lappend holidays "[lrange $CurEntry 2 end]"
   	}
   }
   close $datefile
   if {[string length $holidays] > 0} {
   	foreach channel [channels] {
		if {[validchan $channel] && [botonchan $channel] && [botisop $channel]} {
   			putserv "TOPIC $channel :[join $holidays]"
   		}
	}
   }
putlog "Changing topic to [join $holidays]"
}

proc pubholiday {nick uhost hand chan text} { 
        set choice [lindex $text 0]
	set dd [lindex $text 1]
	set mm [lindex $text 2]
	set desc [lrange $text 3 end]

	if {[string equal -nocase "delete" $choice]} {
	
        if {[GetDate $dd $mm] == "There are no events loaded for that date" || [GetDate $dd $mm] == "That date / month combination doesn't exist"} {
        	puthelp "PRIVMSG $chan :ERROR: [GetDate $dd $mm]"
		return 1
	}
	DeleteDate $dd $mm
    	puthelp "PRIVMSG $chan :$nick deleted $dd $mm"

	} elseif {[string equal -nocase "get" $choice]} {

	puthelp "PRIVMSG $chan :[GetDate $dd $mm]"
	return 1

	} elseif {[string equal -nocase "set" $choice]} {

        if {$desc==""} {
		puthelp "PRIVMSG $chan :ERROR: Add a description for the event"
		return 1 
		}
        if {[GetDate $dd $mm] == "That date / month combination doesn't exist"} {
        	puthelp "PRIVMSG $chan :ERROR: [GetDate $dd $mm]"
		return 1
	} elseif {[GetDate $dd $mm] != "There are no events loaded for that date"} {
	        puthelp "PRIVMSG $chan :ERROR: An event already exists for that date"
		return 1
	}
	SetDate $dd $mm "$desc"
    	puthelp "PRIVMSG $chan :Ahora: $dd $mm == [GetDate $dd $mm]"
    	return 1

	} else {
		puthelp "PRIVMSG $chan :\[DATE sintaxis\]"
		puthelp "PRIVMSG $chan :Use: .date get <DD> <MM> - Shows the event on the calendar for the specified date"
		puthelp "PRIVMSG $chan :Use: .date set <DD> <MM> <Description> - Changes the channel topic to <Description> on the specified date"
		puthelp "PRIVMSG $chan :Use: .date delete <DD> <MM> - Deletes the event on the calendar for the specified date"
  	        puthelp "PRIVMSG $chan :\[DATE sintaxis\]"
		return 1
	}
return 1
}

proc GetDate {dd mm} {

	regsub -all {[0-9]} $mm {1} myresult
	if {$myresult != 11 && $myresult != 1 } {
		return "That date / month combination doesn't exist"
	}
	if {$myresult == 1 } {
		set mm 0$mm
	}
	if {$mm > 12 || $mm == 0} {
		return "That date / month combination doesn't exist"
	}
	
	regsub -all {[0-9]} $dd {1} myresult
	if {$myresult != 11 && $myresult != 1 } {
		return "That date / month combination doesn't exist"
	}
	if {$myresult == 1 } {
		set dd 0$dd
	}

	if {[string index $mm 0] eq 0} { 
		set month [string index $mm 1] 
		} else {
			set month $mm 
		}

        set days "31 29 31 30 31 30 31 31 30 31 30 31"
        if {[lindex $days ${month}-1] < $dd || $dd == 0} {
        	return "That date / month combination doesn't exist"
        }


    global date_file
    fconfigure [set datefile [open $date_file r]] -encoding binary
    set retval "There are no events loaded for that date"
    set entry "$dd $mm"
    while {![eof $datefile]} {
	set CurEntry "[gets $datefile]"
	set EntryName [string tolower [lrange $CurEntry 0 1]]
	if {$EntryName==$entry} {
	    set retval "[lrange $CurEntry 2 end]"
	}
    }
    close $datefile

    return $retval
}

proc DeleteDate {dd mm} {
    global date_file

    regsub -all {[0-9]} $mm {1} myresult
    if {$myresult == 1 } { set mm 0$mm }

    regsub -all {[0-9]} $dd {1} myresult
    if {$myresult == 1 } { set dd 0$dd }

    fconfigure [set datefile [open $date_file r]] -encoding binary
    set entry "$dd $mm"
    while {![eof $datefile]} {
	set CurLine "[gets $datefile]"
	if {[lrange $CurLine 0 1]!=$entry} {lappend dateList $CurLine}
    }
    close $datefile
    fconfigure [set datefile [open $date_file w]] -encoding binary
    foreach CurLine $dateList {
	if {$CurLine!=""} {puts $datefile $CurLine}
    }
    close $datefile
    SortDate 1
}

proc SetDate {dd mm definition} {
    global date_file

    regsub -all {[0-9]} $mm {1} myresult
    if {$myresult == 1 } { set mm 0$mm }

    regsub -all {[0-9]} $dd {1} myresult
    if {$myresult == 1 } { set dd 0$dd }

    set entry "$dd $mm"
    set entry [string trim [string tolower $entry] \=]
    fconfigure [set datefile [open $date_file r]] -encoding binary
    while {![eof $datefile]} {
	set CurLine "[gets $datefile]"
	if {[lrange $CurLine 0 1]!=$entry} {
	    lappend dateList $CurLine
	}
    }
    close $datefile
    fconfigure [set datefile [open $date_file w]] -encoding binary
    foreach CurLine $dateList {
	if {$CurLine!=""} {puts $datefile $CurLine}
    }
    puts $datefile "$dd $mm $definition"
    close $datefile
    SortDate 1
}

proc SortDate {type} {
	global date_file
	set t [clock clicks -milliseconds]
	fconfigure [set datefile [open $date_file r]] -encoding binary
	set txt ""
	while {![eof $datefile]} {
		set tmp "[gets $datefile]"
		if {[info exists tmp]&&$tmp!=""} {
		set a [lindex $tmp 1][lindex $tmp 0]
		lappend txt [list $a $tmp]
		}
	}
	close $datefile
	set txt [lsort -index 0 $txt]
	fconfigure [set datefile [open $date_file w]] -encoding binary
	foreach tmp $txt {
		puts $datefile [lindex $tmp 1]
	}
	close $datefile
	putlog "Sorting done of data on the database ($date_file)->[expr double([clock clicks -milliseconds]-$t)/1000]s"
}

putlog "Holiday topic changer... Loaded"
Last edited by CP1832 on Wed Jun 08, 2016 12:46 am, edited 1 time in total.
g
gembels
Voice
Posts: 26
Joined: Sat Jul 07, 2012 9:31 pm

for

Post by gembels »

can you show us format for date.txt ? or sample data maybe ? or full version of your date.txt please
C
CP1832
Halfop
Posts: 68
Joined: Thu Oct 09, 2014 4:03 pm

Re: for

Post by CP1832 »

gembels wrote:can you show us format for date.txt ? or sample data maybe ? or full version of your date.txt please
Hi gembels. Here's a sample of my date.txt

Code: Select all

25 12 Merry Christmas!
31 12 Happy new year!
By the way, you can a couple of dates via command and see the format, then add yours manually.
g
gamefan098
Voice
Posts: 8
Joined: Thu May 19, 2016 8:56 am

Post by gamefan098 »

[18:19] <o_o> [18:19:38] can't read "cmdchar": no such variable
[18:19] <o_o> while executing
[18:19] <o_o> "bind pub - ${cmdchar}date pubholiday"
[18:19] <o_o> (file "scripts/HolidayTopick.tcl" line 5)
[18:19] <o_o> invoked from within
[18:19] <o_o> "source scripts/HolidayTopick.tcl"
[18:19] <o_o> (file "eggdrop.conf" line 1431)
[18:19] <o_o> [18:19:38] * CONFIG FILE NOT LOADED (NOT FOUND, OR ERROR)
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Replace the:

Code: Select all

bind pub - ${cmdchar}date pubholiday 
line with:

Code: Select all

bind pub - !date pubholiday 
for instance if want to call the script like !date, or replace that ! with a . (dot) or whatever you want.
Once the game is over, the king and the pawn go back in the same box.
g
gamefan098
Voice
Posts: 8
Joined: Thu May 19, 2016 8:56 am

Post by gamefan098 »

[21:00] <o_o> [21:00:27] Tcl error [pubholiday]: invalid command name "checkUser"
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

You get this error cos the function is missing from the original post. Can't help you with something i don't know. Sorry buddy.
Once the game is over, the king and the pawn go back in the same box.
g
gamefan098
Voice
Posts: 8
Joined: Thu May 19, 2016 8:56 am

Post by gamefan098 »

Np. I thanx for all the help that you give :)
C
CP1832
Halfop
Posts: 68
Joined: Thu Oct 09, 2014 4:03 pm

Post by CP1832 »

gamefan098 wrote:[21:00] <o_o> [21:00:27] Tcl error [pubholiday]: invalid command name "checkUser"
Sorry about that, I added that función to every públic command to avoid throttling from the users and forgot to delete that líne when I posted the code. I also replaced ${cmdchar} with dot as I have set cmdchar elsewhere.
g
gembels
Voice
Posts: 26
Joined: Sat Jul 07, 2012 9:31 pm

Re: for

Post by gembels »

CP1832 wrote:
gembels wrote:can you show us format for date.txt ? or sample data maybe ? or full version of your date.txt please
Hi gembels. Here's a sample of my date.txt

Code: Select all

25 12 Merry Christmas!
31 12 Happy new year!
By the way, you can a couple of dates via command and see the format, then add yours manually.
Image

Image

why is not working with that format ?
C
CP1832
Halfop
Posts: 68
Joined: Thu Oct 09, 2014 4:03 pm

Re: for

Post by CP1832 »

Hi gembels. Can you add a leading zero for one digit numbers to the text file and try again, i. e. 06 04 Hari Nelayan Nasional?
g
gembels
Voice
Posts: 26
Joined: Sat Jul 07, 2012 9:31 pm

Re: for

Post by gembels »

CP1832 wrote:Hi gembels. Can you add a leading zero for one digit numbers to the text file and try again, i. e. 06 04 Hari Nelayan Nasional?
aha.. got it... must be 2 digit... tha
Post Reply