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 

add text timer + remove

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


Joined: 27 Aug 2006
Posts: 33

PostPosted: Thu Jan 01, 2009 4:16 pm    Post subject: add text timer + remove Reply with quote

Hey and happy new-year Smile

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
Back to top
View user's profile Send private message
TCL_no_TK
Owner


Joined: 25 Aug 2006
Posts: 509
Location: England, Yorkshire

PostPosted: Tue Feb 24, 2009 1:37 pm    Post subject: Reply with quote

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

Arrow Thanks to MC_8 for the "time" code.
_________________
TCL the misunderstood
Back to top
View user's profile Send private message Send e-mail
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