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 

global announcement with pub command

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


Joined: 22 Mar 2015
Posts: 941

PostPosted: Thu Apr 16, 2015 10:07 am    Post subject: global announcement with pub command Reply with quote

i was looking to make this code to be used with pub command
like: !global cron message
!globstop

to set cron and message and to stop


Code:
    #################################################################################
    #Begin Setup
     
    #Set global message the bot will post once every hour:
    set globalmsg "Welcome on irc.server.net to play quiz join #quiz #kwis #espana"
     
    #End Setup
    #########################################################
    #DO NOT EDIT BELOW HERE UNLESS YOU KNOW HOW TO WRITE .tcl
    #########################################################
    bind cron - {* */1 * * *} radioglobal_proc
    proc radioglobal_proc {minute hour day month year} {
      global botnick globalmsg
      putserv "NOTICE $*.*   \002\GLOBAL:\002 $globalmsg "
      return 0
    }
    putlog "Auto Global Message v0.01 by: play4free2 irc.420-hightimes.com #snoopdogg loaded!"

Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Thu Apr 16, 2015 11:38 am    Post subject: Reply with quote

Code:

#################################################################################
#Begin Setup
       
#Set global message the bot will post once every hour:
set globalmsg "Welcome on irc.server.net to play quiz join #quiz #kwis #espana"

### <add some settings to control the new PUB Bind> ###
# Set public trigger
set globaltrigger "!postmessage"

#Set flags required to use the public trigger
set globalflag "o|o"
       
#End Setup
#########################################################
#DO NOT EDIT BELOW HERE UNLESS YOU KNOW HOW TO WRITE .tcl
#########################################################

### <change the bind to a PUB Bind> ###
bind pub $globalflag $globaltrigger radioglobal_proc

### <change the process to accept the args from the PUB Bind> ###
proc radioglobal_proc {nick uhost hand chan text} {

  global botnick globalmsg
  putserv "NOTICE $*.*   \002\GLOBAL:\002 $globalmsg "
  return 0
}
putlog "PUBLIC Global Message v0.01 by: play4free2 irc.420-hightimes.com #snoopdogg loaded!"


_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Back to top
View user's profile Send private message Visit poster's website
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Thu Apr 16, 2015 11:42 am    Post subject: Reply with quote

but that doesnt set time to keep sending ?

i want to have the option to halt it and to set it with a set time
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Thu Apr 16, 2015 11:56 am    Post subject: Reply with quote

Oh, you changed your request between the time I First read it and when I posted that reply:)
Your initial request just read...
Quote:
i was looking to make this code to be used with pub command


No, that reply no longer answers your request as it is now.
_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Back to top
View user's profile Send private message Visit poster's website
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Fri Apr 17, 2015 1:17 am    Post subject: Reply with quote

Let me know if this runs and what it's missing.
Code:

AutoGlobalMessage v0.1 by SpiKe^^

#########################################################
#### Begin Settings ####

# Set the file to store the dynamic 'Auto Global Message' settings in.
set autoGlobal(file) "autoGlobal.conf"

# Set default 'Auto Global Message' text. (this can be changed by /msg command)
set autoGlobal(def_text) "Welcome on irc.server.net to play quiz join #quiz #kwis #espana"

# Set default 'Auto Global Message' time. (this can be changed by /msg command)
set autoGlobal(def_time) "60"    ;# number of minutes between global messages #

# Set the 'Auto Global Message' Command to add/change dynamic settings.
set autoGlobal(cmd) "!global"

# Set the flags required to use the 'Auto Global Message' Command.
set autoGlobal(flag) "o|o"

# Set the 'Auto Global Message' Command option to turn off the messages.
#  examples:  !global -off  :OR:  !global -stop
set autoGlobal(off) "-off"

# Set the 'Auto Global Message' Command option to turn on the messages.
#  examples:  !global -on  :OR:  !global -start
set autoGlobal(on) "-on"

# Set the 'Auto Global Message' Command option to change the message timing.
#  examples:  !global -time 30  :OR:  !global -minutes 45
set autoGlobal(time) "-time"

# Set the 'Auto Global Message' Command option to change the message text.
#  example:  !global -text Some new message to change to.
set autoGlobal(text) "-text"

##### End Settings #####
#########################################################

proc aGlobal:chkFile {} {
  global autoGlobal

  if {![file exists $autoGlobal(file)]} {
    if {![info exists autoGlobal(-on)]} {
      set autoGlobal(-on) 1
    }
    if {![info exists autoGlobal(-text)]} {
      set autoGlobal(-text) $autoGlobal(def_text)
    }
    if {![info exists autoGlobal(-time)]} {
      set autoGlobal(-time) $autoGlobal(def_time)
    }
    set openFile [open $autoGlobal(file) w]
    puts $openFile $autoGlobal(-on)
    puts $openFile $autoGlobal(-text)
    puts $openFile $autoGlobal(-time)
    close $openFile
  } else {
    set openFile [open $autoGlobal(file)]
    set autoGlobal(-on) [gets $openFile]
    set autoGlobal(-text) [gets $openFile]
    set autoGlobal(-time) [gets $openFile]
    close $openFile
  }
}
aGlobal:chkFile

proc aGlobal:chkTimer {} {
  global autoGlobal

  if {[info exists autoGlobal(timer)]} {
    if {$autoGlobal(-on) == "0"} {
      catch {killtimer $autoGlobal(timer)}
      unset autoGlobal(timer)
    }
  } elseif {$autoGlobal(-on) == "1"} {
    if {$autoGlobal(-time) > "5"} {  set x 5
    } else {  set x $autoGlobal(-time)  }
    set autoGlobal(timer) [timer $x [list aGlobal:doMessage]]
  }
}
aGlobal:chkTimer

proc aGlobal:doMessage {} {
  global autoGlobal

  putserv "NOTICE $*.*   \002\GLOBAL:\002 $autoGlobal(-text) "

  set autoGlobal(timer) [timer $autoGlobal(-time) [list aGlobal:doMessage]]
}

bind pub $autoGlobal(flag) $autoGlobal(cmd) aGlobal:pubCommand


proc aGlobal:pubCommand {nk uh hn ch tx} {
  global autoGlobal

  set tx [split $tx]

  while {[llength $tx] > "0"} {
    set opt [lindex $tx 0]
    set tx [lrange $tx 1 end]

    if {$opt eq $autoGlobal(off)} {
      set on 0
      continue
    }
    if {$opt eq $autoGlobal(on)} {
      set on 1
      continue
    }
    if {$opt eq $autoGlobal(time)} {
      set x [lindex $tx 0]
      if {[string is digit -strict $x] && $x > "0"} {
        set time $x
        set tx [lrange $tx 1 end]
        continue
      }
      set err 1
      break
    }
    if {$opt eq $autoGlobal(text)} {
      set x [string trim [join $tx]]
      if {$x ne ""} {
        set text $x
        break
      }
      set err 2
      break
    }
    set err 3
    break
  }

  set update 0

  if {[info exists on]} {
    if {$on == "0"} {
      if {$autoGlobal(-on) == "1"} {
        set autoGlobal(-on) 0
        aGlobal:chkTimer
        incr update
        putserv "PRIVMSG $ch :AutoGlobalMessage is now turned off."
      } else {
        putserv "PRIVMSG $ch :AutoGlobalMessage is already stopped."
      }
    } else {
      if {$autoGlobal(-on) == "0"} {
        set autoGlobal(-on) 1
        set doTimer 1
        incr update
        putserv "PRIVMSG $ch :AutoGlobalMessage is now turned on."
      } else {
        putserv "PRIVMSG $ch :AutoGlobalMessage is already running."
      }
    }
  }

  if {[info exists time]} {
    if {$time != $autoGlobal(-time)} {
      set autoGlobal(-time) $time
      incr update
      putserv "PRIVMSG $ch :AutoGlobalMessage time is now $time minutes."
    } else {
      putserv "PRIVMSG $ch :AutoGlobalMessage time is already $time minutes."
    }
  }

  if {[info exists doTimer]} {  aGlobal:chkTimer  }

  if {[info exists text]} {
    if {$text ne $autoGlobal(-text)} {
      set autoGlobal(-text) $text
      incr update
      putserv "PRIVMSG $ch :AutoGlobalMessage text is now: $text"
    } else {
      putserv "PRIVMSG $ch :AutoGlobalMessage text is already: $text"
    }
  }

  if {$update > "0"} {
    file delete $autoGlobal(file)
    aGlobal:chkFile
  }

  if {[info exists err]} {
    if {$err == "1"} {
      putserv "PRIVMSG $ch :Error: $autoGlobal(time) must be followed by a number greater than 0"
    } elseif {$err == "2"} {
      putserv "PRIVMSG $ch :Error: $autoGlobal(text) must be followed by the new text to show"
    } else {
      set x "$autoGlobal(on) $autoGlobal(off) $autoGlobal(time) $autoGlobal(text)"
      putserv "PRIVMSG $ch :Error: Unknown command option, $opt. Valid options: $x"
    }
  }

  return 0
}

putlog "AutoGlobalMessage v0.1 by SpiKe^^ loaded."


_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.


Last edited by SpiKe^^ on Sat Apr 18, 2015 10:34 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
simo
Owner


Joined: 22 Mar 2015
Posts: 941

PostPosted: Sat Apr 18, 2015 7:48 am    Post subject: Reply with quote

it works nice tnx spike^^
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Fri Apr 24, 2015 10:48 pm    Post subject: Reply with quote

This is the more complete script, please give it a try...
Code:

# AutoGlobalMessage v1.1 (24Apr2015) by SpiKe^^

# Important Note: The bot Must be opered for this script to work!

#########################################################
#### Begin Settings ####

# Set the default AutoGlobalMessage time between global messages.
# Note: This can be changed by public command:  !global -time <minutes>
#       You can always go back to this setting with:  !global -time def
set aGlobal(def_time) "60"    ;## Number of minutes between global messages ##

# Set the default AutoGlobalMessage text.
# Note: This can be changed by public command:  !global -text <new message>
#       You can always go back to this setting with:  !global -text def
set aGlobal(def_text) "Welcome on irc.server.net to play quiz join #quiz #kwis #espana"

# Set the public AutoGlobalMessage Command to add/change dynamic settings.
set aGlobal(cmd) "!global"

# Set the AutoGlobalMessage Command option to turn on the messages.
#  examples:  !global -on  :OR:  !global -start
set aGlobal(on) "-on"

# Set the AutoGlobalMessage Command option to turn off the messages.
#  examples:  !global -off  :OR:  !global -stop
set aGlobal(off) "-off"

# Set the AutoGlobalMessage Command option to change the message timing.
#  examples:  !global -time 30  :OR:  !global -minutes 45
# Note: You can go back to the default setting with:  !global -time def
set aGlobal(time) "-time"

# Set the AutoGlobalMessage Command option to change the message text.
#  example:  !global -text Some new message to change to.
# Note: You can go back to the default setting with:  !global -text def
set aGlobal(text) "-text"

# Set the AutoGlobalMessage Command option to check the script status.
#  examples:  !global -info  :OR:  !global -status
set aGlobal(info) "-info"

# Set the AutoGlobalMessage Command option to get help for this script.
#  example:  !global -help
set aGlobal(help) "-help"

#############################################################
## -= Advanced Public AutoGlobalMessage Command Options =- ##
# You can also set multiple script options in one command.  #
# Examples:                                                 #
#  !global -on -time 60                                     #
#  !global -text def -time def -off                         #
#  !global -time 30 -on -text some new global message text. #
#                                                           #
# Important Note: If setting New message text, -text Must   #
#   be the last command option in the list of options!      #
#############################################################

# Set the flags required to use the public AutoGlobalMessage Commands.
set aGlobal(flag) "o|o"

# Set the file to store the dynamic AutoGlobalMessage settings in.
set aGlobal(file) "autoGlobal.conf"

##### End Settings #####
#########################################################

if {![string is digit -strict $aGlobal(def_time)] || $aGlobal(def_time)<"1"} {
  set aGlobal(def_time) 60
}

proc aGlobal:chkFile {} {
  global aGlobal

  if {![file exists $aGlobal(file)]} {
    if {![info exists aGlobal(-on)]} {
      set aGlobal(-on) 1
    }
    if {![info exists aGlobal(-text)]} {
      set aGlobal(-text) $aGlobal(def_text)
    }
    if {![info exists aGlobal(-time)]} {
      set aGlobal(-time) $aGlobal(def_time)
    }
    set openFile [open $aGlobal(file) w]
    puts $openFile $aGlobal(-on)
    puts $openFile $aGlobal(-text)
    puts $openFile $aGlobal(-time)
    close $openFile
  } else {
    set openFile [open $aGlobal(file)]
    set aGlobal(-on) [gets $openFile]
    set aGlobal(-text) [gets $openFile]
    set aGlobal(-time) [gets $openFile]
    close $openFile
  }

}
aGlobal:chkFile

set aGlobal(-sec) [expr {$aGlobal(-time)*60}]

proc aGlobal:chkTimer {} {
  global aGlobal

  if {$aGlobal(-on) == "0"} {
    if {[info exists aGlobal(timer)]} {
      catch {  killutimer $aGlobal(timer)  }
      unset aGlobal(timer)
    }
    foreach tmr [utimers] {
      if {[lindex $tmr 1] eq "aGlobal:doMessage"} {
        catch {  killutimer [lindex $tmr 2]  }
      }
    }
  } elseif {![info exists aGlobal(timer)]} {
    if {$aGlobal(-time) > "5"} {  set x 300
    } else {  set x $aGlobal(-sec)  }
    set aGlobal(timer) [utimer $x [list aGlobal:doMessage]]
    return $x
  }
}
aGlobal:chkTimer

proc aGlobal:doMessage {} {
  global aGlobal

  putserv "NOTICE $*.*   \002\GLOBAL:\002 $aGlobal(-text) "

  set aGlobal(timer) [utimer $aGlobal(-sec) [list aGlobal:doMessage]]
}

bind pub $aGlobal(flag) $aGlobal(cmd) aGlobal:pubCommand


proc aGlobal:pubCommand {nk uh hn ch tx} {
  global aGlobal

  set tx [string trim $tx]
  if {$tx eq ""} {  set help 1
  } else {  set tx [split $tx]  }

  while {[llength $tx] > "0"} {
    set opt [lindex $tx 0]  ;  set tx [lrange $tx 1 end]

    switch -- $opt $aGlobal(off) {  set on 0
    } $aGlobal(on) {  set on 1
    } $aGlobal(help) {  set help 1
    } $aGlobal(info) {  set info 1
    } $aGlobal(time) {  set x [lindex $tx 0]
      if {[string is digit -strict $x] && $x > "0"} {
        set time $x  ;  set tx [lrange $tx 1 end]
      } elseif {$x eq "def"} {
        set time $aGlobal(def_time)
        set tx [lrange $tx 1 end]
      } else {  set err 1  ;  break  }
    } $aGlobal(text) {  set x [lindex $tx 0]
      if {$x eq "def"} {
        set text $aGlobal(def_text)
        set tx [lrange $tx 1 end]
      } else {  set x [string trim [join $tx]]
        if {$x ne ""} {  set text $x
        } else {  set err 2  }
        break
      }
    } default {  set err 3  ;  break  }
  }

  set update 0  ;  set did 0
  set cmd $aGlobal(cmd)
  set logo "AutoGlobalMessage"

  if {[info exists on]} {  incr did
    if {$on == "0"} {
      if {$aGlobal(-on) == "1"} {  incr update
        set aGlobal(-on) 0  ;  aGlobal:chkTimer
        putserv "PRIVMSG $ch :$logo is now turned off."
      } else {  putserv "PRIVMSG $ch :$logo is already stopped."
        putserv "PRIVMSG $ch : To start this script, use: $cmd $aGlobal(on)"
      }
    } else {
      if {$aGlobal(-on) == "0"} {  incr update
        set doTimer "First"
        putserv "PRIVMSG $ch :$logo is now turned on."
      } else {  putserv "PRIVMSG $ch :$logo is already running."
        putserv "PRIVMSG $ch : To stop this script, use: $cmd $aGlobal(off)"
      }
    }
  }

  if {[info exists time]} {  incr did
    if {$time != $aGlobal(-time)} {  incr update
      set aGlobal(-time) $time
      set aGlobal(-sec) [expr {$time*60}]
      if {$aGlobal(-on) == "1"} {  set doTimer "Next"  }
      putserv "PRIVMSG $ch :$logo time is now set to $time minutes."
    } else {
      putserv "PRIVMSG $ch :$logo time is already set to $time minutes."
    }
  }

  if {[info exists text]} {  incr did
    if {$text ne $aGlobal(-text)} {  incr update
      set aGlobal(-text) $text
      putserv "PRIVMSG $ch :$logo text is now: $text"
    } else {
      putserv "PRIVMSG $ch :$logo text is already: $text"
    }
  }

  if {[info exists doTimer]} {
    if {$doTimer eq "Next"} {
      set aGlobal(-on) 0
      aGlobal:chkTimer
    }
    set aGlobal(-on) 1
    set sec [aGlobal:chkTimer]
  } elseif {$aGlobal(-on) == "1"} {  set doTimer "Next"
    foreach tmr [utimers] {
      if {[lindex $tmr 2] eq $aGlobal(timer)} {
        set sec [lindex $tmr 0]  ;  break
      }
    }
  }

  if {[info exists sec]} {
    set x [expr {$sec/60}]  ;  set y [expr {$sec%60}]
    if {$x>30} {  set sec [expr {$x*60}]
      if {$y>30} {  incr sec 60  }
    } elseif {$y<5 && $x>0} {  set sec [expr {$x*60}]
    } elseif {$y>55} {  set sec [expr {($x+1)*60}]  }
    set sec [duration $sec]
  }

  if {$update > 0} {
    file delete $aGlobal(file)
    aGlobal:chkFile
  }

  if {$did > 0 && [info exists sec] && ![info exists info]} {
    putserv "PRIVMSG $ch : $doTimer global message in $sec."
    unset sec
  }

  if {[info exists err]} {
    if {$did > 0} {  putserv "PRIVMSG $ch : "  }
    incr did

    if {$err == "1"} {
      putserv "PRIVMSG $ch :$logo $aGlobal(time) syntax: $cmd\
               $aGlobal(time) <minutes between global messages>"
      putserv "PRIVMSG $ch : Examples:  $cmd $aGlobal(time) 30 \
               :OR:  $cmd $aGlobal(time) 120"
      putserv "PRIVMSG $ch : Use: $cmd $aGlobal(time) def :to go\
               back to the default time setting ($aGlobal(def_time))."
      putserv "PRIVMSG $ch : Current $logo time is set to\
               $aGlobal(-time) minutes."
    } elseif {$err == "2"} {
      putserv "PRIVMSG $ch :$logo $aGlobal(text) syntax: $cmd\
               $aGlobal(text) <new text for the global message>"
      putserv "PRIVMSG $ch : Example:  $cmd $aGlobal(text) Welcome\
               to irc.server.net! For help or questions join #admin"
      putserv "PRIVMSG $ch : Use: $cmd $aGlobal(text) def :to go\
               back to the default text string ($aGlobal(def_text))."
      putserv "PRIVMSG $ch : Current $logo text is: $aGlobal(-text)"
    } else {  set help 1
      putserv "PRIVMSG $ch :$logo Error: Unknown command option, $opt."
    }

    if {[info exists sec] && ![info exists info]} {
      putserv "PRIVMSG $ch : $doTimer global message in $sec."
      unset sec
    }
  }

  if {[info exists help]} {
    if {$did > 0} {  putserv "PRIVMSG $ch :  "  }
    incr did

    putserv "PRIVMSG $ch :-= $logo Public Commands Help =-"
    putserv "PRIVMSG $ch :$cmd $aGlobal(on)  :Turn on the global messages."
    putserv "PRIVMSG $ch :$cmd $aGlobal(off)  :Turn off the global messages."
    putserv "PRIVMSG $ch :$cmd $aGlobal(time) <minutes> \
             :change the global message timing."
    putserv "PRIVMSG $ch :  Use: $cmd $aGlobal(time)\
             :for more help with this command."
    putserv "PRIVMSG $ch :$cmd $aGlobal(text) <new message> \
             :change the global message text."
    putserv "PRIVMSG $ch :  Use: $cmd $aGlobal(text)\
             :for more help with this command."
    putserv "PRIVMSG $ch :$cmd $aGlobal(info) \
             :See the current status of this script."
    putserv "PRIVMSG $ch :$cmd $aGlobal(help) \
             :See this $logo public commands help."

    if {[info exists sec] && ![info exists info]} {
      putserv "PRIVMSG $ch :   "
      putserv "PRIVMSG $ch :$doTimer global message in $sec."
    }
  }


  if {[info exists info]} {
    if {$did > 0} {  putserv "PRIVMSG $ch :   "  }

    putserv "PRIVMSG $ch :-= Current $logo Status =-"
    if {$aGlobal(-on) == "1"} {
      putserv "PRIVMSG $ch :$logo is running./
               $doTimer global message in $sec."
    } else {  putserv "PRIVMSG $ch :$logo is stopped."  }
    putserv "PRIVMSG $ch :$logo time is set to $aGlobal(-time) minutes."
    putserv "PRIVMSG $ch :$logo text is: $aGlobal(-text)"
    putserv "PRIVMSG $ch :Use: $cmd $aGlobal(help)\
             :for help with this script."
  }

  return 0
}

putlog "AutoGlobalMessage v1.1 by SpiKe^^ loaded."


_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Back to top
View user's profile Send private message Visit poster's website
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