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.

remote join and part

Help for those learning Tcl or writing their own scripts.
Post Reply
D
Dark_Aaron
Voice
Posts: 10
Joined: Mon Mar 16, 2009 4:55 pm

remote join and part

Post by Dark_Aaron »

here is my first script

Code: Select all

bind pub - "!join" join:proc
bind pub - "!part" part:proc

proc join:proc { chan text nick } {
  global join part
  if {[$nick == Dark_Aaron]} {
   putserv "JOIN :$text"
  }
}

proc part:proc { chan text nick } {
  global part join
  if {[$nick == Dark_Aaron]]} {
   putserv "PART $chan :$text"
  }
}
i am getting

Code: Select all

[19:39] Tcl error [join:proc]: wrong # args: should be "join:proc chan text nick"
when i try to use it
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

You are using "pub" bindings, hence your procs ("functions") need to accept 5 arguments, corresponding to nickname, host, handle, channel, and text of the message that triggered the binding.

Next, this will fail utterly:

Code: Select all

if {[$nick == Dark_aaron]} {
In fact, this will result in remote code exploits. [] are used for command substitutions. That is, take whatever is between the [], execute it as a separate command, and substitute the text (including the []) with whatever was returned by that command execution.
What you should do is this:

Code: Select all

if {[string equal -nocase $nick "Dark_aaron"]} {
Here we execute the command "string" with the parameters "equal", "-nocase", the value of $nick, and "Dark_aaron". Checking the manpage for the string command, this tells us string will compare the two strings (equal) in a case-insensitive (-nocase) manner, and return true if they're the same, false otherwize.

Further,
You have this command-line:

Code: Select all

global part join
The purpose of the global command, is to link local variables to their counterpart in the global namespace. Yet you do not make use either of those variables in either function. This will not cause an error, but it is bad practise, and may cause confusion as to which variables are actually in use. Also be aware of variable name collisions (such as two scripts using the same variable for different purposes).
NML_375
D
Dark_Aaron
Voice
Posts: 10
Joined: Mon Mar 16, 2009 4:55 pm

Post by Dark_Aaron »

so it should look like

Code: Select all

bind pub - "!join" join:proc
bind pub - "!part" part:proc

proc join:proc { nick host hand chan text } {
  if {[string equal -nocase $nick "Dark_aaron"]} {
   putserv "JOIN :$text"
  }
}

proc part:proc { nick host hand chan text } {
  if {[string equal -nocase $nick "Dark_aaron"]} {
   putserv "PART $chan :$text"
  }
}
???
D
Dark_Aaron
Voice
Posts: 10
Joined: Mon Mar 16, 2009 4:55 pm

Post by Dark_Aaron »

Dark_Aaron wrote:so it should look like

Code: Select all

bind pub - "!join" join:proc
bind pub - "!part" part:proc

proc join:proc { nick host hand chan text } {
  if {[string equal -nocase $nick "Dark_aaron"]} {
   putserv "JOIN :$text"
  }
}

proc part:proc { nick host hand chan text } {
  if {[string equal -nocase $nick "Dark_aaron"]} {
   putserv "PART $chan :$text"
  }
}
???
this works but...

here is logs from client and partyline

client:
[8:30:pm] <~Dark_Aaron> !join #q
[8:30:pm] * Eggy (Eggy@ServicesAdmin.TheBeagleClub.net) has joined #q
[8:30:pm] * Eggy (Eggy@ServicesAdmin.TheBeagleClub.net) has left #q

partyline:
[20:24] joined #q but didn't want to!
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

You have to use the commands

channel add $text

and

channel remove $text

to create/delete a dynamic channel record

Code: Select all

bind pub - "!join" join:proc
bind pub - "!part" part:proc

proc join:proc { nick host hand chan text } {
  if {[string equal -nocase $nick "Dark_aaron"]} {
   channel add $text
  }
}

proc part:proc { nick host hand chan text } {
  if {[string equal -nocase $nick "Dark_aaron"]} {
   channel remove $text
  }
}
I would probably add some code to the join proc to check that the bot didn't already have a channel record for $text before adding it. Likewise I would test if the channel record existed and if it was dynamic before attempting to part it.
I must have had nothing to do
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

Here's one I prepared earlier.

Responds to pub or msg commands.

Note that the binds are 'global owner' only. Always a good idea if you are doing stuff like this.

Code: Select all

bind MSG n join prcJoinMsgJoin
bind PUB n !join prcJoinPubJoin
bind MSG n part prcPartMsgPart
bind PUB n !part prcPartPubPart

proc prcJoinMsgJoin {nick uhost hand txt} {
  global botnick
  set tchan [string trim $txt]
  if {[llength [split $tchan]] == 1} {
    if {[regexp {^#} $tchan]} {
      if {![validchan $tchan]} {
        channel add $tchan
        savechannels
        putserv "NOTICE $nick :created dynamic channel record $tchan"
      } else {putserv "NOTICE $nick :error - a channel record for $tchan already exists"}
    } else {putserv "NOTICE $nick :error - $tchan is not in the format of a valid channel name"}
  } else {putserv "NOTICE $nick :error - correct syntax is /msg $botnick join <#channel>"}
  return 0
}

proc prcJoinPubJoin {nick uhost hand channel txt} {
  set tchan [string trim $txt]
  if {[llength [split $tchan]] == 1} {
    if {[regexp {^#} $tchan]} {
      if {![validchan $tchan]} {
        channel add $tchan
        savechannels
        putserv "PRIVMSG $channel :created dynamic channel record $tchan"
      } else {putserv "PRIVMSG $channel :-error- ($nick) - a channel record for $tchan already exists"}
    } else {putserv "PRIVMSG $channel :-error- ($nick) - $tchan is not in the format of a valid channel name"}
  } else {putserv "PRIVMSG $channel :-error- ($nick) - correct syntax is !join <#channel>"}
  return 0
}

proc prcPartMsgPart {nick uhost hand txt} {
  global botnick
  set tchan [string trim $txt]
  if {[llength [split $tchan]] == 1} {
    if {[regexp {^#} $tchan]} {
      if {[validchan $tchan]} {
        if {[isdynamic $tchan]} {
          channel remove $tchan
          savechannels
          putserv "NOTICE $nick :deleted dynamic channel record $tchan"
        } else {putserv "NOTICE $nick :error - only dynamic channels can be parted"}
      } else {putserv "NOTICE $nick :error - a channel record for $tchan does not exist"}
    } else {putserv "NOTICE $nick :error - $tchan is not in the format of a valid channel name"}
  } else {putserv "NOTICE $nick :error - correct syntax is /msg $botnick part <#channel>"}
  return 0
}

proc prcPartPubPart {nick uhost hand channel txt} {
  set tchan [string trim $txt]
  if {[llength [split $tchan]] == 1} {
    if {[regexp {^#} $tchan]} {
      if {[validchan $tchan]} {
        if {[isdynamic $tchan]} {
          channel remove $tchan
          savechannels
          if {![string equal -nocase $tchan $channel]} {
            putserv "PRIVMSG $channel :deleted dynamic channel record $tchan"
          }
        } else {putserv "PRIVMSG $channel :-error- ($nick) - only dynamic channels can be parted"}
      } else {putserv "PRIVMSG $channel :-error- ($nick) - a channel record for $tchan does not exist"}
    } else {putserv "PRIVMSG $channel :-error- ($nick) - $tchan is not in the format of a valid channel name"}
  } else {putserv "PRIVMSG $channel :-error- ($nick) - correct syntax is !part <#channel>"}
  return 0
}
I must have had nothing to do
D
Dark_Aaron
Voice
Posts: 10
Joined: Mon Mar 16, 2009 4:55 pm

Post by Dark_Aaron »

arfer wrote:Here's one I prepared earlier.

Responds to pub or msg commands.

Note that the binds are 'global owner' only. Always a good idea if you are doing stuff like this.

Code: Select all

bind MSG n join prcJoinMsgJoin
bind PUB n !join prcJoinPubJoin
bind MSG n part prcPartMsgPart
bind PUB n !part prcPartPubPart

proc prcJoinMsgJoin {nick uhost hand txt} {
  global botnick
  set tchan [string trim $txt]
  if {[llength [split $tchan]] == 1} {
    if {[regexp {^#} $tchan]} {
      if {![validchan $tchan]} {
        channel add $tchan
        savechannels
        putserv "NOTICE $nick :created dynamic channel record $tchan"
      } else {putserv "NOTICE $nick :error - a channel record for $tchan already exists"}
    } else {putserv "NOTICE $nick :error - $tchan is not in the format of a valid channel name"}
  } else {putserv "NOTICE $nick :error - correct syntax is /msg $botnick join <#channel>"}
  return 0
}

proc prcJoinPubJoin {nick uhost hand channel txt} {
  set tchan [string trim $txt]
  if {[llength [split $tchan]] == 1} {
    if {[regexp {^#} $tchan]} {
      if {![validchan $tchan]} {
        channel add $tchan
        savechannels
        putserv "PRIVMSG $channel :created dynamic channel record $tchan"
      } else {putserv "PRIVMSG $channel :-error- ($nick) - a channel record for $tchan already exists"}
    } else {putserv "PRIVMSG $channel :-error- ($nick) - $tchan is not in the format of a valid channel name"}
  } else {putserv "PRIVMSG $channel :-error- ($nick) - correct syntax is !join <#channel>"}
  return 0
}

proc prcPartMsgPart {nick uhost hand txt} {
  global botnick
  set tchan [string trim $txt]
  if {[llength [split $tchan]] == 1} {
    if {[regexp {^#} $tchan]} {
      if {[validchan $tchan]} {
        if {[isdynamic $tchan]} {
          channel remove $tchan
          savechannels
          putserv "NOTICE $nick :deleted dynamic channel record $tchan"
        } else {putserv "NOTICE $nick :error - only dynamic channels can be parted"}
      } else {putserv "NOTICE $nick :error - a channel record for $tchan does not exist"}
    } else {putserv "NOTICE $nick :error - $tchan is not in the format of a valid channel name"}
  } else {putserv "NOTICE $nick :error - correct syntax is /msg $botnick part <#channel>"}
  return 0
}

proc prcPartPubPart {nick uhost hand channel txt} {
  set tchan [string trim $txt]
  if {[llength [split $tchan]] == 1} {
    if {[regexp {^#} $tchan]} {
      if {[validchan $tchan]} {
        if {[isdynamic $tchan]} {
          channel remove $tchan
          savechannels
          if {![string equal -nocase $tchan $channel]} {
            putserv "PRIVMSG $channel :deleted dynamic channel record $tchan"
          }
        } else {putserv "PRIVMSG $channel :-error- ($nick) - only dynamic channels can be parted"}
      } else {putserv "PRIVMSG $channel :-error- ($nick) - a channel record for $tchan does not exist"}
    } else {putserv "PRIVMSG $channel :-error- ($nick) - $tchan is not in the format of a valid channel name"}
  } else {putserv "PRIVMSG $channel :-error- ($nick) - correct syntax is !part <#channel>"}
  return 0
}
how do i add some1 to global owner list
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

You read the docs that those kind folk at Eggheads sent with the bot.
I must have had nothing to do
Post Reply