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.

need some help with keyword.tcl need some operator function

Support & discussion of released scripts, and announcements of new releases.
Post Reply
w
wiiguy
Voice
Posts: 9
Joined: Fri Nov 30, 2007 3:30 pm

need some help with keyword.tcl need some operator function

Post by wiiguy »

hello its like the topic said i need some help with this script

this script is so amde everybody can add triggers but i only want operatort can add triggers and delete them those command are !add and !remove i want with operator funtions\

i tried to contact the person who amde this script trough irc and emil but he never answers so i came here for help

pls help me

ty for reading this

Code: Select all

    #                       
    #       +------------------------------------------------------+
    #       | © Christian 'chris' Hopf <mail@dev.christianhopf.de> |
    #       +------------------------------------------------------+
    #                                                                     
    #          
    #           developer:  Christian 'chris' Hopf
    #           system:     eggdrop v1.6.18 - tcl/tk v.8.5a2
    #           product:    user defined triggers
    #           version:    1.4
    #                         
    #           contact:    mail@dev.christianhopf.de
    #           irc:        #chris at QuakeNet
    #           web:        www.christianhopf.de
    #


    # user defined triggers v1.4
    # copyright (c) 2006 Christian 'chris' Hopf

    # This program is free software; you can redistribute it and/or modify
    # it under the terms of the GNU General Public License as published by
    # the Free Software Foundation; either version 2 of the License, or
    # (at your option) any later version.

    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    # GNU General Public License for more details.

    # You should have received a copy of the GNU General Public License
    # along with this program; if not, write to the Free Software
    # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    #
    #
    # changelog
    #
    #   18.12.2005 - v1.0 - release
    #   19.12.2005 - v1.1/v1.2 - fix:
    #                 - Bug by using existing proc names as keyword
    #                       
    #               add:
    #                 - clear function added
    #                 - flood timer for each trigger activated to stop spamming
    #   02.01.2006 - v1.3 - fix:
    #                 - unmatched open quote in list
    #   11.04.2006 - v1.4 - fix:
    #                 - fixed bug with teh "0"
    #                 
    #                add:
    #                 - added new triggers like NULL (only command needed, no trigger)
    #
    # short readme
    #   after setting up your eggdrop, you can get a list of all commands with 
    #   <botnick> help 
    #   or
    #   !help (only if u havn't change anything)
    #
    #   short help:
    #       you can add a keywords trigger with the command "add".
    #       if you want to use a newline, use \n in the message you added.
    #       e.g. /msg <channel> <botnick> add TEST TextOnLine1\nTextOnLine2 etc ...    
    
    # --- namespace ::keyword
    namespace eval ::keyword {
           
  
      # --- namespace variable   
      namespace eval variable {
        
        # string variable trigger
        variable trigger "!"
        
        # string variable keyword [ only need for /msg <botnick> ]
        variable keyword "trigger"        
                
        # string variable flag
        variable flag "n|n"
        
        # string variable database
        variable database ".keyword.db"       
        
        # {{{ NOW don't change anything, if you aren't 100% sure what you are doing }}}
        # {{{ NOW don't change anything, if you aren't 100% sure what you are doing }}}
        # {{{ NOW don't change anything, if you aren't 100% sure what you are doing }}}
        # {{{ NOW don't change anything, if you aren't 100% sure what you are doing }}} 
        
        # string variable author
        variable author "2006 Christian 'chris' Hopf \002(\002#chris - www.christianhopf.de\002)\002"
        
        # string variable version
        variable version "v1.4"
      
      }      
    
      if {![file exists $::keyword::variable::database]} {
        if { [catch { set database [open $::keyword::variable::database "w"] } error] } {
          die "can't create file <:( \[$::keyword::variable::database\]"
        }
        
        puts -nonewline $database ""
        close $database
      }
      
      # binds
      bind PUBM -|- {*} ::keyword::pubm
      bind MSGM -|- {*} ::keyword::msgm
      
      # - void proc pubm {bind PUBM}
      proc pubm { nickname hostname handle channel arguments } {
          ::keyword::irc::parse $nickname $hostname $handle $arguments $channel "pubm"
      }
      
      # - void proc msgm {bind MSGM}
      proc msgm { nickname hostname handle arguments } {
          ::keyword::irc::parse $nickname $hostname $handle $arguments [lindex [split $arguments] 2] "msgm"
      }      
      
      
      # namespace eval irc
      namespace eval irc {
        # - void proc parse
        proc parse { nickname hostname handle arguments channel mode} {
            global botnick lastcommand channelcommand lastnickname lasthandle lastchannel lasttrigger lastucommand
            
            if { [::keyword::utilities::exists [encrypt split $channel] [lindex [split $arguments] 0] "-global"] } {
              set message [join [::keyword::utilities::get:command [lindex [split $arguments] 0]]]
     
              if {[info exists ::keyword(last,used,$channel,[lindex [split $arguments] 0])] && [expr [unixtime] - $::keyword(last,used,$channel,[lindex [split $arguments] 0])] < 30} { 
                return
              }
                
              set ::keyword(last,used,$channel,[lindex [split $arguments] 0]) [unixtime]
                  
              foreach output [split $message "\n"] {
                putquick "NOTICE $nickname :$output"
              }
              
              if { [info proc ::keyword::irc::commands:[string tolower [lindex [split $arguments] 1]]] == "" && [info proc ::keyword::irc::commands:[string tolower [lindex [split $arguments] 0]]] == "" } {
                return
              }
            }
            
            set utrigger [getuser $handle XTRA keyword-trigger]
            set temp $channel
            set save $arguments;
    
            if { $mode == "pubm" } {
              if {[llength $utrigger] < 1} {
                set utrigger [join [string trim $::keyword::variable::trigger]]
              }
    
              if { [string equal -nocase $botnick [lindex [split $arguments] 0]]} {
                set command [string tolower [lindex [split $arguments] 1]]
                set arguments [join [lrange [split $arguments] 2 end]]
                set trigger "$botnick $command"
  
              } elseif { $utrigger == "NULL" }  {
                set command [string tolower [lindex [split $arguments] 0]]
                set arguments [join [lrange [split $arguments] 1 end]]
                
                set trigger "$command"
              
              } elseif { [string equal -nocase [string index [lindex [split $arguments] 0] 0] $utrigger] } {
                set command [string range [string tolower [lindex [split $arguments] 0]] 1 end]
                set arguments [join [lrange [split $arguments] 1 end]]
  
                set trigger "${utrigger}$command"
              } else {
                return
              }
              
              if {[string index [lindex [split $arguments] 0] 0] == "#" && [validchan [lindex [split $arguments] 0]]} {
                set channel [lindex [split $arguments] 0]
                set arguments [join [lrange [split $arguments] 1 end]]
              }
            
            } elseif { $mode == "msgm" } {
              if { [string equal -nocase [lindex [split $arguments] 0] ${::keyword::variable::keyword}] } {
                set command [lindex [split $arguments] 1]
                set channel [lindex [split $arguments] 2]              
                set arguments [join [lrange [split $arguments] 3 end]]
                set trigger "$::keyword::variable::keyword $command"          
              } else {
                return
              }
              
            } else {
              return
            }
            
            if { [string index [lindex [split $arguments] 0] 0] == "#" || [string equal -nocase [lindex [split $arguments] 0] "-global"] } {
              set channel [lindex [split $arguments] 0]
              set arguments [join [lrange [split $arguments] 1 end]]
            }
            
            if { ![matchattr $handle $::keyword::variable::flag $temp] } {
              return
            } elseif {![info exists trigger] || [llength $trigger] < 1} {
              return
            } elseif {(![info exists command] || [llength $command] < 1)} {
              return
            } elseif { [info proc ::keyword::irc::command:$command] == ""  } {
              return
            } elseif { (![regexp -- {^#(.+)$} $channel] || ![validchan $channel]) && ![string equal -nocase $channel "-global"] } {
              putquick "PRIVMSG $nickname :\002(\002keyword\002)\002 you forgot the channel parameter"
              
              return
            }
            
            set channelcommand "$temp"
            set lastcommand  "$trigger"
            set lastucommand "$command"
            set lastnickname "$nickname"
            set lasthandle "$handle"
            set lastchannel "$channel"
            set lasttrigger [join [lrange $trigger 0 end-1]]
            
            ::keyword::irc::command:$command $nickname $hostname $handle $channel $arguments
        }
        
        # - void proc add
        proc command:add { nickname hostname handle channel arguments } {
          global lastcommand
          
          set trigger [::keyword::utilities::trigger $handle]; set keyword [lindex [split $arguments] 0]; set message [join [lrange $arguments 1 end]]
          if { $keyword == "" || $message == "" } { putquick "NOTICE $nickname :\002(\002keyword\002)\002 synta\037x\037\002:\002 $lastcommand \037?#channel?\037 <keyword> <message>"; return;}

          if {[info proc ::keyword::irc::commands:$keyword] != "" || [info proc ::keyword::irc::commands:[string range [join $keyword] 1 end]] != "" } { putquick "NOTICE $nickname :\002(\002keyword\002)\002 \0034error\003\002:\002 sorry but you cant use that keyword, please choose an another one"; return; }
          if {[::keyword::utilities::exists [encrypt split $channel] [join $keyword] "-global"]} {
            putquick "NOTICE $nickname :\002(\002keyword\002)\002 your keyword {$keyword} does already appear in the database."
            putquick "NOTICE $nickname :\002(\002keyword\002)\002 to overwrite use\002:\002 ${trigger}overwrite \037?#channel?\037|\037?-global?\037 <keyword> <message>"
          } elseif {[::keyword::utilities::add [encrypt split $channel] [encrypt split [join $keyword]] [encrypt split $message]]} {
            putquick "NOTICE $nickname :\002(\002keyword\002)\002 {[join $keyword]} was successfully added to the database."           
          } else {
            putquick "NOTICE $nickname :\002(\002keyword\002)\002 \0034error\003\002:\002 while adding channel message to the database."
          }    
        }
        
        # - void proc remove
        proc command:remove { nickname hostname handle channel arguments } {
          global lastcommand
          set trigger [::keyword::utilities::trigger $handle]; set keyword [lindex [split $arguments] 0];
          if { $keyword == "" } { putquick "NOTICE $nickname :\002(\002keyword\002)\002 synta\037x\037\002:\002 $lastcommand \037?#channel?\037 <keyword>"; return; }
                       
          if {![::keyword::utilities::exists [encrypt split $channel] [join $keyword]]} {
            putquick "NOTICE $nickname :\002(\002keyword\002)\002 your keyword {[join $keyword]} doesn't appear in the database."
          } elseif {[::keyword::utilities::remove [encrypt split $channel] [join $keyword]]} {
            putquick "NOTICE $nickname :\002(\002keyword\002)\002 {[join $keyword]} successfully removed from the database."             
          } else {
            putquick "NOTICE $nickname :\002(\002keyword\002)\002 \0034error\003\002:\002 while removing channel message from the database."
          }    
        }
        
        # - void proc clear
        proc command:clear { nickname hostname handle channel arguments } {        
          global lastcommand

          if { $arguments == "*" } { ::keyword::utilities::clear; putquick "NOTICE $nickname :\002(\002keyword\002)\002 database was successfully cleared."
          } elseif {[::keyword::utilities::clear [encrypt split $channel]]} { putquick "NOTICE $nickname :\002(\002keyword\002)\002 {$channel} was successfully cleared." 
          } else { putquick "NOTICE $nickname :\002(\002keyword\002)\002 \0034error\003\002:\002 while removing channel from the database."; }
        }
        
        # - void proc overwrite
        proc command:overwrite { command nickname hostname handle channel arguments } {
          global lastcommand

          set trigger [::keyword::utilities::trigger $handle]; set keyword [lindex [split $arguments] 0]; set message [join [lrange $arguments 1 end]]
          if { $keyword == "" || $message == "" } { putquick "NOTICE $nickname :\002(\002keyword\002)\002 synta\037x\037\002:\002 $lastcommand \037?#channel?\037|\037?-global?\037 <keyword> <message>"; return;}

          if {[info proc ::keyword::irc::commands:$keyword] != ""} { putquick "NOTICE $nickname :\002(\002keyword\002)\002 \0034error\003\002:\002 sorry but you cant use that keyword, please choose an another one"; return; }
          if {![::keyword::utilities::exists [encrypt split $channel] [join $keyword] "-global"]} {
            putquick "NOTICE $nickname :\002(\002keyword\002)\002 your keyword {$keyword} doesn't appear in the database."
          } elseif {[::keyword::utilities::rewrite [encrypt split $channel] [join $keyword] [encrypt split $message]]} {
            putquick "NOTICE $nickname :\002(\002keyword\002)\002 $keyword was successfully re-added to the database."           
          } else {
            putquick "NOTICE $nickname :\002(\002keyword\002)\002 \0034error\003\002:\002 while adding channel message to the database."
          }           
        }
            
        
        # - void procs help|showcommands {required string command} {required string nickname} {required string hostname} {required string handle} {required string channel} {required string arguments}    
        proc commands:help { nickname hostname handle channel arguments } { ::keyword::irc::commands:userhelp $command $nickname $hostname $handle $channel $arguments; }
        proc commands:showcommands { nickname hostname handle channel arguments } { ::keyword::irc::commands:userhelp $command $nickname $hostname $handle $channel $arguments; }
        
        
        # - void proc userhelp
        proc command:userhelp { nickname hostname handle channel arguments } {            
          if { ![matchattr $handle $::keyword::variable::flag $channel] } { return; }
          set trigger [::keyword::utilities::trigger $handle]
          putquick "NOTICE $nickname :\002(\002keyword\002)\002 \037$command overview\002\037:\002"               
          putquick "NOTICE $nickname :\002(\002keyword\002)\002 ${trigger}add \037?channel?\037 \037-global\037 <keyword> <message>"
          putquick "NOTICE $nickname :\002(\002keyword\002)\002 ${trigger}remove \037?channel?\037 \037-global\037 <#id/keyword>"
          putquick "NOTICE $nickname :\002(\002keyword\002)\002 ${trigger}overwrite \037?channel?\037 \037-global\037 <keyword> <message>"
          putquick "NOTICE $nickname :\002(\002keyword\002)\002 ${trigger}list \037?channel?\037|\037-global\037"
          putquick "NOTICE $nickname :\002(\002keyword\002)\002 ${trigger}clear \037?channel?\037|\037-global\037|\037*\037"
          putquick "NOTICE $nickname :\002(\002keyword\002)\002 ${trigger}trigger \037?#id?\037 \002(\002personal trigger, not global trigger\002)\002"
          putquick "NOTICE $nickname :\002(\002keyword\002)\002 ${trigger}version"           
        }
        
        # - void proc trigger
        proc command:trigger { nickname hostname handle channel arguments } { 
            global botnick botname lastcommand
            set trigger [::keyword::utilities::trigger $handle]
  
            array set triggers {
              "1" {$} "2" {!} "3" {?} "4" {.} "5" {-}
              "6" {²} "7" {%} "8" {&} "9" {*} "10" {:}
              "11" {§} "12" {°} "13" {^} "14" {NULL}
            }
                 
            if { [llength $arguments] < 1 } {
              putquick "NOTICE $nickname :\002(\002keyword\002)\002 synta\037x\037\002:\002 $lastcommand \037?#id?\037" 
              putquick "NOTICE $nickname :\002(\002keyword\002)\002 curren\037t\037\002:\002 $trigger"
              set list ""
              set id   0
              
              while {$id < 10} {
                incr id 1
                lappend list "#$id ($triggers($id))"
              }
              
              putquick "NOTICE $nickname :\002(\002keyword\002)\002 available triggers are:"
              putquick "NOTICE $nickname :[join $list ", "]"
              
              return
            }               
            
          if { [string range $arguments 1 2] < 15 && [string range $arguments 1 2] > 0 } {
            setuser $handle XTRA keyword-trigger $triggers([string range $arguments 1 2])
            putquick "NOTICE $nickname :\002(\002keyword\002)\002 your personal trigger is now: [getuser $handle XTRA keyword-trigger]"
          } else {
            putquick "NOTICE $nickname :\002(\002keyword\002)\002 synta\037x\037\002:\002 $lastcommand \037?\002#\002id?\037"
          }
        }              
        
        # - void proc list
        proc command:list { nickname hostname handle channel arguments } {
          set list ""
          set count [llength [::keyword::utilities::create:list $channel]]
          
          if { $count == "1" } {
            putquick "NOTICE $nickname :\002(\002keyword\002)\002 $count message is added on my database\002:\002"
          } else {
            putquick "NOTICE $nickname :\002(\002keyword\002)\002 $count messages are added on my database\002:\002"
          }
          set data ""
          
          foreach messages [::keyword::utilities::create:list $channel] {                
            if { [llength $data] == 5 } {
              putquick "NOTICE $nickname :\002(\002keyword\002)\002 [join $data ", "]"
              set data ""
            }
            lappend data $messages
          }
          
          if { [llength $data] > 1 } {
            putquick "NOTICE $nickname :\002(\002keyword\002)\002 [join $data ", "]"
          } elseif { [llength $data] == 1 } {
            putquick "NOTICE $nickname :\002(\002keyword\002)\002 [join $data]"
          }
        }          
        
        # - void proc version
        proc command:version { nickname hostname handle channel arguments } {            
          if {[info exists ::keyword(protection_v,$channel)] && [expr [unixtime] - $::keyword(protection_v,$channel)] < 30} { return;}
          putquick "NOTICE $nickname :\001ACTION is running the keyword script $::keyword::variable::version \002(\002c\002)\002 $::keyword::variable::author\001"
          set ::keyword(protection_v,$channel) [unixtime]        
        }
        
      }            
      
      # namespace eval utilities
      namespace eval utilities {
        
        # - void proc exists {required string channel} {required string keyword}
        proc exists { channel keyword {global "8427zthgf7tzht"} } {
          if { $keyword == "" || ![info exists keyword] || [string match *\"* $keyword] } { return 0; }
          if {[catch { set database [open $::keyword::variable::database "r"] } error]} { return 0; }
          set number 1
          while {![eof $database]} {
            if {[set line [gets $database]] != ""} {
              if { [lindex [split $line] 0] != $channel && [lindex [split $line] 0] != [encrypt split "$global"]  } { continue; }
              if {![isnumber [string range [join $keyword] 1 end]]} {
                if {([lindex [split $line] 0] == "$channel" || [lindex [split $line] 0] == [encrypt split "$global"]) && [lindex [split $line] 1] == "[encrypt split $keyword]"} {
                  close $database
                  return 1
                }
              } else {
                if {[lindex [split $line] 0] == "$channel" && $number == [string range [join $keyword] 1 end]} {
                  close $database
                  return 1
                }
              }
            }
            incr number
          }          
          close $database
          return 0
        }          
        
        # - void proc add {required string channel} {required string keyword} {required string message}
        proc add { channel keyword message } {
          if {[catch { set database [open $::keyword::variable::database "a"] } error]} { return 0; }
          puts $database "$channel $keyword $message"
          close $database
          return 1
        }          
        
        # - void proc remove {required string channel} {required string keyword}
        proc remove { channel keyword } {
          if {[catch { set database [open $::keyword::variable::database "r"] } error]} { return 0; }
          set refill ""
          set number 1
          while {![eof $database]} {
            if {[set line [gets $database]] != ""} {
              if {[lindex [split $line] 0] == "$channel"} {
                if {[lindex [split $line] 1] == "[encrypt split $keyword]"} { incr number; continue; }
                if {[isnumber [string range [join $keyword] 1 end]] && $number == [string range [join $keyword] 1 end]} { incr number; continue; }       
                incr number;
              }
              lappend refill $line
            }
          }
          close $database
          set database [open $::keyword::variable::database "w"]
          foreach data_refill $refill {
            puts $database $data_refill
          }
          close $database
          return 1
        }       
        
        # - void proc clear {optional string channel}
        proc clear { {channel ""} } {
          if { $channel == "*" || $channel == "" } {
            if {[file exists $::keyword::variable::database]} { file delete $::keyword::variable::database } 
            set database [open $::keyword::variable::database "w"]
            puts -nonewline $database ""
            close $database
            return; 
          }
          
          if {[catch { set database [open $::keyword::variable::database "r"] } error]} { return 0; }
          set refill ""
          set number 1
          while {![eof $database]} {
            if {[set line [gets $database]] != ""} {
              if {[lindex [split $line] 0] == "$channel"} { continue; }
              lappend refill $line
            }
          }
          close $database
          set database [open $::keyword::variable::database "w"]
          foreach data_refill $refill {
            puts $database $data_refill
          }
          close $database
          return 1
        }         
        
        # - void proc rewrite {required string channel} {required string keyword} {required string message}
        proc rewrite { channel keyword message } {
          if {[catch { set database [open $::keyword::variable::database "r"] } error]} { return 0; }
          set refill ""
          set number 1
          while {![eof $database]} {
            if {[set line [gets $database]] != ""} {
              if {[lindex [split $line] 0] == "$channel"} {
                if {[lindex [split $line] 1] == "[encrypt split $keyword]"} { continue; }
              }
              lappend refill $line
            }
          }
          close $database
          set database [open $::keyword::variable::database "w"]
          foreach data_refill $refill {
            puts $database $data_refill
          }
          puts $database "$channel [encrypt split $keyword] $message"
          close $database
          return 1
        }          
        
        # - void proc create:list {required string channel}
        proc create:list { channel } {
          set data ""
          set database [open $::keyword::variable::database "r"]
          while {![eof $database]} {
            if {[set line [gets $database]] != ""} {
              if { [lindex [split $line] 0] == "[encrypt split $channel]" } {
                lappend data "[decrypt split [lindex [split $line] 1]]"
              }
            }
          }
          close $database
          return $data
        }
        
        # - void proc get:command {required string command}
        proc get:command { command } {
          set data ""
          set database [open $::keyword::variable::database "r"]
          while {![eof $database]} {
            if {[set line [gets $database]] != ""} {
              if { [lindex [split $line] 1] == "[encrypt split $command]" } {
                close $database; return [decrypt split [lindex [split $line] 2]];
              }
            }
          }
          close $database
        }          
               
        # - void proc trigger {required string handle}
        proc trigger { handle } {
          set utrigger [getuser $handle XTRA keyword-trigger]
          if {[llength $utrigger] < 1 || ![validuser $handle]} {
            set utrigger [join [string trim $::keyword::variable::trigger]]
          }            
          return $utrigger        
        }
                   
      }  
      
      # log
      putlog "user defined keywords version <${::keyword::variable::version}> (c) $::keyword::variable::author successfully loaded"                   
      
    }
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

It already does check the permissions flags for "n|n" but you can also add that into the binds:

# binds
bind PUBM -|- {*} ::keyword::pubm
bind MSGM -|- {*} ::keyword::msgm


Change those -|- flags to whatever you want.
s
spijon
Voice
Posts: 33
Joined: Sun Aug 27, 2006 9:55 pm

Is there a update?

Post by spijon »

Any fix for this so i works on different channels?

If you make the same cmd for 2channels like :
on #chan1
"eggbot add TEST1 TextOnLine1\nTextOnLine2"

on #chan2
"eggbot add TEST1 TextOnLine3\nTextOnLine4"

And i use the !TEST1 on #chan2 i use the line from #chan1 :/
s
spijon
Voice
Posts: 33
Joined: Sun Aug 27, 2006 9:55 pm

If anyone that can help it will appreciated!!

Post by spijon »

The reason the script is interesting that you can use it as an "custom" chan-info script.

On #MyChan
@user: Eggy add Hp www.mychanpage.com
@user: !Hp
@user: www.mychanpage.com

So you don't need to add chan or the menu in the script but the bot only need to be on a chan.. This would be a really cool script if it worked 100% :)

The original tcl file can be find here:
http://www.egghelp.org/cgi-bin/tcl_arch ... ad&id=1309

Best regards
Post Reply