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.

add text timer + remove

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
s
spijon
Voice
Posts: 33
Joined: Sun Aug 27, 2006 9:55 pm

add text timer + remove

Post by spijon »

Hey and happy new-year :)

I'm looking for a script that user can add a text and + timer and remove when timer ends.

@user :!addtext tralalala 1h
@user2 :!addtext tralalala2 1h
@user3 :!text
@bot :tralala addet by user (59min ago)
@bot :tralala2 addet by user2 (59min ago)

and an admin cmd

@admin :!deltext tralala

Been looking around in the forum but couldn't find anything.

Best regards
User avatar
TCL_no_TK
Owner
Posts: 509
Joined: Fri Aug 25, 2006 7:05 pm
Location: England, Yorkshire

Post by TCL_no_TK »

I'm still working on this, but as it dose what its ment to. I felt like posting it, see if anyone else gives any input on it or not maybe :idea:

The commands are as above, just type them in the channel once the script is loaded for the full syntax.

Code: Select all

#
# upload the 'pda.tcl' to your shell in the 'scripts/' directory of your eggdrop
# load the script by adding 'source scripts/pda.tcl' to eggdrop's config file
# .rehash the eggdrop
# and type '!addtext' in the (public) channel where the eggdrop is
#
##

proc pda {what} {
 global pda pdacount
 switch -- [string tolower [lindex [split $what] 0]] {
  "get_id" {
            set string [join [lrange [split $what] 1 end]]
            foreach ids [array names pda] {
             set tt [join [lrange [split $pda($ids) ","] 3 end]]
             if {[string match -nocase "$tt" "$string"]} {
              return $ids
             }
            }
           }
  "valid_id" {return [info exists pda([lindex [split $what] 1])]}
  "kill_id" {
             set pid [lindex [split $what] 1]
             if {[info exists pda($pid)]} {
              unset pda($pid)
              pda_killtimers -matching "*$pid*"
              return 1
             } else {
              return 0
             }
            }
  "display_id" {
                set did [lindex [split $what] 1]
                if {[info exists pda($did)]} {
                 set chan [join [lrange [split $pda($did) ","] 1 1]]
                 set rest [join [lrange [split $pda($did) ","] 3 end]]
                 puthelp "PRIVMSG $chan :$rest"
                 unset pda($did)
                 return
                } else {
                 error "PDA: \"$did\" is not a valid ID"
                }
               }
  "current_id" {
                if {![info exists pdacount(current)]} {
                 set pdacount(current) 1
                 return $pdacount(current)
                } else {
                 set pdacount(current) [expr {$pdacount(current)+1}]
                 return $pdacount(current)
                }
               }
  default {error "should be: pda \[what\]"}
 }
}

proc pda_killtimers {type {args ""}} {
 global pda
 switch -- [string tolower $type] {
  "-matching" {
               if {$args != ""} {
                foreach t [timers] {
                 set sc [lindex $t 1]
                 if {[string match -nocase "*$sc*" "$args"]} {
                  killtimer [lindex $t 2]
                 }
                }; return 1
               } else {
                return 0
               }
              }
  "-all" {
          foreach t [timers] {
           set ss [lindex $t 1]
           if {[string match -nocase "*pda*" "$ss"]} {
            killtimer [lindex $t 2]
           }
          }
         }
  default {
           error "invalid type: should be: pda_killters ?-all? ?-matching? ?string?"
          }
 }
}

proc addtext:pub {nick uhost hand chan text} {
 global pda
  if {[isop $nick $chan]} {
   if {[llength [lindex [split $text] 0]] == 0} {
    puthelp "NOTICE $nick :\002Usage\002: !addtext \[Text\] \[Time\]"
    return 0
   }
   if {![regexp -- {^([0-9]*[dhm])([0-9]*[dhm])?([0-9]*[dhm])?$} "[join [lrange [split $text] end end]]"]} {
    puthelp "NOTICE $nick :\002Error\002: No Time Given/Invaild Time"
    return 0
   }
   set t_note [join [lrange [split $text] 0 end-1]]
   set t_time [join [lrange [split $text] end end]]
   set e $t_time
   if {($e == "") || ($e == 0)} {
    puthelp "NOTICE $nick :\002Error\002: Time to low or invalid."
    return 0
   }
   if {![regexp -- {([0-9]*)m} "$e" -> min]  || ($min == "")}  {set min  0}
   if {![regexp -- {([0-9]*)h} "$e" -> hour] || ($hour == "")} {set hour 0}
   if {![regexp -- {([0-9]*)d} "$e" -> day]  || ($day == "")}  {set day  0}
    set t_hours [expr ($min*60)+($hour*3600)+($day*86400)]
    set t_mins [expr {$t_hours/60}]
   if {$t_mins>0} {
    set t_ts [clock scan "$t_mins min"]
    set id [pda current_id]
    set pda($id) "$nick,$chan,$t_ts,$t_note"
    timer $t_mins [list pda "display_id $id"]
    puthelp "NOTICE $nick :Thank You, '$t_note' has been added."
    return 1
   } else {
    puthelp "NOTICE $nick :\002Error\002: Time to lower"
    return 0
   }
  }
}

proc text:pub {nick uhost hand chan text} {
 global pda
  if {[llength [array names pda]] == 0} {
   puthelp "PRIVMSG $chan :\002No Text's\002"
   puthelp "PRIVMSG $chan :Please add one by typing \002!addtext <text> <time>\002  (Ops Only!)"
   return 1
  } else {
   set m [llength [array names pda]]
   set c 0
   while {$c != $m} {
    set id [lindex [array names pda] $c]
    set t_by [lindex [split $pda($id) ","] 0]
    set t_ch [lindex [split $pda($id) ","] 1]
    set t_ts [lindex [split $pda($id) ","] 2]
    set t_note [join [lrange [split $pda($id) ","] 3 end]]
    puthelp "PRIVMSG $chan :\002$t_note\002 Added By $t_by@$t_ch [duration [expr { $t_ts - [clock seconds]}]] ago. (#ID:$id)"
    set c [expr {$c+1}]
   }
   return 1
  }
}

proc deltext:pub {nick uhost hand chan text} {
 global pda
  set string [lindex [split $text] 0]
  if {$string == ""} {
   puthelp "NOTICE $nick :USage: !deltext <id | *string*>"
   return 0
  }
  if {[regexp {^[0-9]} "$string"]} {
   set gid $string
   if {[pda "valid_id $gid"]} {
    if {[pda "kill_id $gid"]} {
     puthelp "NOTICE $nick :Removed '$gid'"
     return 1
    } else {
     puthelp "NOTICE $nick :Failed (unable to remove '$gid')"
     return 0
    }
   } else {
    puthelp "NOTICE $nick :unable to find '$gid' --it may be invalid"
    return 0
   }
  } else {
   set gid [pda "get_id $string"]
   if {[pda "valid_id $gid"]} {
    if {[pda "kill_id $gid"]} {
     puthelp "NOTICE $nick :Removed '$string' ($gid)"
     return 1
    } else {
     puthelp "NOTICE $nick :Failed (unable to remove '$string')"
     return 0
    }
   } else {
    puthelp "NOTICE $nick :unable to find '$string' --it may be invalid"
    return 0
   }
  }
}

bind pub o !addtext addtext:pub
bind pub n !deltext deltext:pub
bind pub - !text text:pub

putlog "loaded pda.tcl version 2.6(alpha) by TCL_no_TK"
return
I've got it working without any errors that would cause problems for the bot, or prevent the scrip from working. If you get an error thats not in the script, let me know and i'll try and fix it. :)

:arrow: Thanks to MC_8 for the "time" code.
Post Reply