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 

Holiday / event topic changer

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
CP1832
Halfop


Joined: 09 Oct 2014
Posts: 45

PostPosted: Wed Jun 24, 2015 11:19 am    Post subject: Holiday / event topic changer Reply with quote

I created a script so as to be able to change the channel's topic for a given date.
Code:
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
Back to top
View user's profile Send private message
gembels
Voice


Joined: 07 Jul 2012
Posts: 26

PostPosted: Sun Mar 27, 2016 8:16 am    Post subject: for Reply with quote

can you show us format for date.txt ? or sample data maybe ? or full version of your date.txt please
Back to top
View user's profile Send private message
CP1832
Halfop


Joined: 09 Oct 2014
Posts: 45

PostPosted: Fri May 27, 2016 2:12 pm    Post subject: Re: for Reply with quote

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:
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.
Back to top
View user's profile Send private message
gamefan098
Voice


Joined: 19 May 2016
Posts: 8

PostPosted: Tue Jun 07, 2016 11:21 am    Post subject: Reply with quote

Quote:

[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)
Back to top
View user's profile Send private message
caesar
Ass Kicker


Joined: 14 Oct 2001
Posts: 3401
Location: Area 51

PostPosted: Tue Jun 07, 2016 12:50 pm    Post subject: Reply with quote

Replace the:
Code:

bind pub - ${cmdchar}date pubholiday

line with:
Code:

bind pub - !date pubholiday

for instance if want to call the script like !date, or replace that ! with a . (dot) or whatever you want.
_________________
You may say anything about me, but don't misspell my name.
Back to top
View user's profile Send private message
gamefan098
Voice


Joined: 19 May 2016
Posts: 8

PostPosted: Tue Jun 07, 2016 2:01 pm    Post subject: Reply with quote

[21:00] <o_o> [21:00:27] Tcl error [pubholiday]: invalid command name "checkUser"
Back to top
View user's profile Send private message
caesar
Ass Kicker


Joined: 14 Oct 2001
Posts: 3401
Location: Area 51

PostPosted: Tue Jun 07, 2016 3:06 pm    Post subject: Reply with quote

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.
_________________
You may say anything about me, but don't misspell my name.
Back to top
View user's profile Send private message
gamefan098
Voice


Joined: 19 May 2016
Posts: 8

PostPosted: Tue Jun 07, 2016 4:42 pm    Post subject: Reply with quote

Np. I thanx for all the help that you give :)
Back to top
View user's profile Send private message
CP1832
Halfop


Joined: 09 Oct 2014
Posts: 45

PostPosted: Wed Jun 08, 2016 12:52 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
gembels
Voice


Joined: 07 Jul 2012
Posts: 26

PostPosted: Thu Apr 06, 2017 9:39 am    Post subject: Re: for Reply with quote

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






why is not working with that format ?
Back to top
View user's profile Send private message
CP1832
Halfop


Joined: 09 Oct 2014
Posts: 45

PostPosted: Thu Apr 06, 2017 12:17 pm    Post subject: Re: for Reply with quote

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?
Back to top
View user's profile Send private message
gembels
Voice


Joined: 07 Jul 2012
Posts: 26

PostPosted: Fri Apr 07, 2017 7:26 am    Post subject: Re: for Reply with quote

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
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 Support & Releases 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