| View previous topic :: View next topic |
| Author |
Message |
LB_1981 Voice
Joined: 08 Jun 2009 Posts: 15
|
Posted: Wed Jun 10, 2009 7:49 am Post subject: Need help small script[solved] |
|
|
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: | 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"
}
|
_________________ LB_1981
Last edited by LB_1981 on Thu Jun 18, 2009 8:38 pm; edited 1 time in total |
|
| Back to top |
|
 |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Tue Jun 16, 2009 10:12 am Post subject: |
|
|
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: |
# 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 |
|
| Back to top |
|
 |
LB_1981 Voice
Joined: 08 Jun 2009 Posts: 15
|
Posted: Wed Jun 17, 2009 8:23 am Post subject: |
|
|
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: | 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 |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Wed Jun 17, 2009 8:52 am Post subject: |
|
|
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: | 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"
} |
_________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
LB_1981 Voice
Joined: 08 Jun 2009 Posts: 15
|
Posted: Thu Jun 18, 2009 8:36 pm Post subject: |
|
|
changed that over this is what i have now
| Code: | 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 |
|
| Back to top |
|
 |
|