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 help small script[solved]

Help for those learning Tcl or writing their own scripts.
Post Reply
L
LB_1981
Voice
Posts: 15
Joined: Mon Jun 08, 2009 5:53 am

Need help small script[solved]

Post by LB_1981 »

Any help please I cant get it to work so if any one can help id appreciate it

basicaly is what i need it to do is
/msg botnick kill $nick reason
/msg botnick act $chan text to act
/msg botnick tempshun $nick reason for shun
/msg botnick sajoin $nick $chan
/msg botnick gline $nick 4h reason

I think i got the basics but im stuck going any further with it

Code: Select all

bind msg o kill msg:kill
bind msg o act msg:act
bind msg o tempshun msg:tempshun
bind msg o sajoin msg:sajoin
bind msg o GLINE msg:GLINE
 

proc msg:kill {nick uhost hand arg} { 
 set target [lindex [split $arg] 0] 
 putserv "kill $target" 
}

proc msg:act {nick uhost hand arg} { 
 set target [lindex [split $arg] 0] 
 putserv "act $target" 
}

proc msg:tempshun {nick uhost hand arg} { 
 set target [lindex [split $arg] 0] 
 putserv "tempshun $target" 
}

proc msg:sajoin {nick uhost hand arg} { 
 set target [lindex [split $arg] 0] 
 putserv "sajoin $target" 
}

proc msg:Gline {nick uhost hand arg} { 
 set target [lindex [split $arg] 0] 
 putserv "GLINE $target" 
}
Last edited by LB_1981 on Thu Jun 18, 2009 8:38 pm, edited 1 time in total.
LB_1981
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

I don't have oper privileges on any irc network so I can't be certain of my response.

Your commands seem in some cases incomplete :-
eg. putserv "sajoin $target" should probably be putserv "sajoin $target #channelname"

In other cases in error :-
eg. you declare a bind proc as msg:GLINE then go on to define a proc named msg:Gline

I have tried to code two of the commands (sajoin and kill). Documentation suggests that the bot would need Csop privileges for sajoin command and IRCop privileges for kill command.

I have also included a catch for raw 481, which is what the bot would receive from the ircd if it tried to use either command but did not have the appropriate privileges.

I have also commented the code so that you can follow the logic and code the other commands in a similar manner. Note that, for completeness, other ircd error responses (besides RAW 481) may occur. What happens if you try to kill a nick that is frozen or not online. These are issues that would have to be addressed and accounted for if you want a 'complete' and competent script.

Code: Select all

# syntax /msg botnick sajoin ?nick? <channel>
# forces ?nick? to join <channel>
# acts on the script user in the absence of the optional argument ?nick?
# requires script user to have global owner bot flag
# requires bot to have Csop priviledges
bind MSG n sajoin msg:sajoin

proc msg:sajoin {nick uhost hand text} {

    # declare as global and set command user for use in further error messages
    global cmduser
    set cmduser $nick

    # unset the global variable cmduser in case of ircd response not occuring within a reasonable timescale
    utimer 10 [list unset cmduser]

    # remove any spurious leading/trailing space characters from the text arguments
    set arguments [string trim $text]

    # check the number of text arguments provided and assign variables accordingly
    # notice the script user with error message if an incorrect number of arguments is provided
    switch -- [llength [split $arguments]] {
        1 {
            set username $nick
            set channel $arguments
        }
        2 {
            set username [lindex [split $arguments] 0]
            set channel [lindex [split $arguments] 1]
        }
        default {
            putserv "NOTICE $nick :-error- correct syntax is /msg botnick sajoin ?nick? <channel>"
            return 0
        }
    }

    # check that the username argument provided is in the format of a valid irc nick
    # otherwise notice the script user with error message
    if {[regexp -- {^[\x41-\x7D][-\d\x41-\x7D]*$} $username]} {
          
        # check that the channel argument proovided is in the format of a valid irc channel
        # otherwise notice the script user with error message
        if {[regexp -- {^#} $channel]} {

            # send the sajoin command to the ircd
            putserv "sajoin $username $channel"

        } else {putserv "NOTICE $nick :-error- $channel is not in the format of a valid irc channel"}
    } else {putserv "NOTICE $nick :-error- $username is not in the format of a valid irc nick"}
    return 0
}

# syntax /msg botnick kill <nick> ?reason?
# forcibly disconnects <nick> from all linked servers for ?reason? if specified
# provides default reason text if optional ?reason? argument is not specified
# requires script user to have global owner bot flag
# requires bot to have IRCop priviledges
bind MSG n kill msg:kill

proc msg:kill {nick uhost hand text} {

    # declare as global and set command user for use in further error messages
    global cmduser
    set cmduser $nick

    # unset the global variable cmduser in case of ircd response not occuring within a reasonable timescale
    utimer 10 [list unset cmduser]

    # remove any spurious leading/trailing space characters from the text arguments
    set arguments [string trim $text]

    # check the number of text arguments provided and assign variables accordingly
    # notice the script user with error message if an incorrect number of arguments is provided
    switch -- [llength [split $arguments]] {
        0 {
            putserv "NOTICE $nick :-error- correct syntax is /msg botnick kill <nick> ?reason?"
            return 0
        }
        1 {
            set username $arguments
            set reason "no reason specified"
        }
        default {
            set username [lindex [split $arguments] 0]
            set reason [join [lrange [split $arguments] 1 end]]
        }
    }

    # check that the username argument provided is in the format of a valid irc nick
    # otherwise notice the script user with error message
    if {[regexp -- {^[\x41-\x7D][-\d\x41-\x7D]*$} $username]} {
          
        # send the kill command to the ircd
        putserv "kill $username $reason"

    } else {putserv "NOTICE $nick :-error- $username is not in the format of a valid irc nick"}
    return 0
}

# a raw 481 is received by the bot from the ircd server if it tries to use oper commands but does not have oper privileges
bind RAW - 481 msg:raw481

proc msg:raw481 {from keyword text} {

    # allow use of global variable cmduser within this proc
    global cmduser
    
    # if the global variable cmduser exists, notice the command user and unset cmduser
    if {[info exists cmduser]} {
        putserv "NOTICE $cmduser :Permission denied, I do not have the correct irc operator privileges"
        unset cmduser
    }
    return 0
}
I must have had nothing to do
L
LB_1981
Voice
Posts: 15
Joined: Mon Jun 08, 2009 5:53 am

Post by LB_1981 »

Many thanks for your reply i have however managed to sort some of this script myself after a few days of rapping my brains and going through some of the old forums ive come up with this and it all seems to work ok

Code: Select all

bind msg o|o act cmd:act
bind msg o|o notice cmd:notice
bind msg o|o forcejoin cmd:forcejoin
bind msg o|o tempshun cmd:tempshun
bind msg o|o kill cmd:kill


proc cmd:act {nick uhost hand args} {
  set args [join $args]
  set chan [lindex $args 0]
  set text [lrange $args 1 end]

   putserv "PRIVMSG $chan :\001ACTION $text\001"
}

proc cmd:notice {nick uhost hand args} {
  set args [join $args]
  set chan [lindex $args 0]
  set text [lrange $args 1 end]

   putserv "NOTICE $chan :$text"
}

proc cmd:forcejoin {nick uhost hand args} {
  set args [join $args]
  set nick [lindex $args 0]
  set chan [lrange $args 1 end]

   putserv "SAJOIN $nick :$chan"
}

proc cmd:tempshun {nick uhost hand args} {
  set args [join $args]
  set nick [lindex $args 0]
  set reason [lrange $args 1 end]

   putserv "TEMPSHUN $nick :$reason"
}

proc cmd:kill {nick uhost hand args} {
  set args [join $args]
  set username [lindex $args 0]
  set reason [lrange $args 1 end]

   putserv "KILL $username :$reason"
}






LB_1981
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

The variable "args" has a special meaning in Tcl and shouldn't be used as an argument for "text" in your procedures. Instead, do it like this:

Code: Select all

proc cmd:act {nick uhost hand arg} {
  set chan [lindex [split $arg] 0]
  set text [lrange [split $arg] 1 end]
  putserv "PRIVMSG $chan :\001ACTION $text\001"
}
L
LB_1981
Voice
Posts: 15
Joined: Mon Jun 08, 2009 5:53 am

Post by LB_1981 »

changed that over this is what i have now

Code: Select all

bind msg o|o act cmd:act
bind msg o|o notice cmd:notice
bind msg o|o forcejoin cmd:forcejoin
bind msg o|o sapart cmd:sapart
bind msg o|o tempshun cmd:tempshun
bind msg o|o kill cmd:kill
bind msg o|o tempgline cmd:tempgline


proc cmd:act {nick uhost hand arg} { 
  set chan [lindex [split $arg] 0] 
  set text [lrange [split $arg] 1 end] 
  putserv "PRIVMSG $chan :\001ACTION $text\001" 
}

proc cmd:notice {nick uhost hand arg} {
  set chan [lindex [split $arg] 0] 
  set text [lrange [split $arg] 1 end] 
  putserv "NOTICE $chan :$text"
}

proc cmd:forcejoin {nick uhost hand args} {
  set args [join $args]
  set nick [lindex $args 0]
  set chan [lrange $args 1 end]
  putserv "SAJOIN $nick :$chan"
}

proc cmd:sapart {nick uhost hand args} {
  set args [join $args]
  set nick [lindex $args 0]
  set chan [lrange $args 1 end]
  putserv "SAPART $nick :$chan"
}

proc cmd:tempshun {nick uhost hand arg} {
  set nick [lindex [split $arg] 0] 
  set reason [lrange [split $arg] 1 end] 
  putserv "TEMPSHUN $nick :$reason"
  
} 

proc cmd:kill {nick uhost hand arg} {
   set username [lindex [split $arg] 0] 
   set reason [lrange [split $arg] 1 end] 
   putserv "KILL $username :$reason"
  
} 

proc cmd:tempgline {nick uhost hand args} {
  set args [join $args]
  set username [lindex $args 0]
  set reason [lrange $args 1 end]
  putserv "GLINE $username 4H :$reason"
  
} 



all seems to work ok many thanks for your help
LB_1981
Post Reply